feat: channels autocomplete
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
6ac347ef07
commit
ee692a5a60
|
|
@ -98,7 +98,7 @@ fun String.applyAutocompleteSuggestion(
|
||||||
}
|
}
|
||||||
|
|
||||||
is AutocompleteSuggestion.Channel -> {
|
is AutocompleteSuggestion.Channel -> {
|
||||||
if (suggestion.channel.name?.contains(" ") == true) {
|
if (suggestion.channel.name?.contains(" ", ignoreCase = true) == true) {
|
||||||
this.replaceRange(
|
this.replaceRange(
|
||||||
cursorPosition - suggestion.query.length - 1,
|
cursorPosition - suggestion.query.length - 1,
|
||||||
cursorPosition,
|
cursorPosition,
|
||||||
|
|
@ -277,7 +277,12 @@ fun NativeMessageField(
|
||||||
},
|
},
|
||||||
label = { Text("#${item.channel.name}") },
|
label = { Text("#${item.channel.name}") },
|
||||||
icon = {
|
icon = {
|
||||||
item.channel.channelType?.let { type -> ChannelIcon(channelType = type) }
|
item.channel.channelType?.let { type ->
|
||||||
|
ChannelIcon(
|
||||||
|
channelType = type,
|
||||||
|
modifier = Modifier.size(SuggestionChipDefaults.IconSize)
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.animateItemPlacement()
|
.animateItemPlacement()
|
||||||
|
|
@ -418,6 +423,16 @@ fun NativeMessageField(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastWord.startsWith('#') -> {
|
||||||
|
if (this.serverId == null) return
|
||||||
|
autocompleteSuggestions.addAll(
|
||||||
|
Autocomplete.channel(
|
||||||
|
this.serverId!!,
|
||||||
|
lastWord.substring(1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ object Autocomplete {
|
||||||
fun emoji(query: String): List<AutocompleteSuggestion.Emoji> {
|
fun emoji(query: String): List<AutocompleteSuggestion.Emoji> {
|
||||||
val unicodeResults = emojiImpl.shortcodeContains(query).map {
|
val unicodeResults = emojiImpl.shortcodeContains(query).map {
|
||||||
AutocompleteSuggestion.Emoji(
|
AutocompleteSuggestion.Emoji(
|
||||||
it.shortcodes.find { shortcode -> shortcode.contains(query) }
|
it.shortcodes.find { shortcode -> shortcode.contains(query, ignoreCase = true) }
|
||||||
?: it.shortcodes.first(),
|
?: it.shortcodes.first(),
|
||||||
it.base.joinToString("") { s -> String(Character.toChars(s.toInt())) },
|
it.base.joinToString("") { s -> String(Character.toChars(s.toInt())) },
|
||||||
null,
|
null,
|
||||||
|
|
@ -19,7 +19,9 @@ object Autocomplete {
|
||||||
}.distinctBy { it.shortcode }
|
}.distinctBy { it.shortcode }
|
||||||
|
|
||||||
val customResults =
|
val customResults =
|
||||||
RevoltAPI.emojiCache.values.filter { it.name?.contains(query) ?: false }.map {
|
RevoltAPI.emojiCache.values.filter {
|
||||||
|
it.name?.contains(query, ignoreCase = true) ?: false
|
||||||
|
}.map {
|
||||||
if (it.name != null) {
|
if (it.name != null) {
|
||||||
AutocompleteSuggestion.Emoji(
|
AutocompleteSuggestion.Emoji(
|
||||||
":${it.id}:",
|
":${it.id}:",
|
||||||
|
|
@ -47,7 +49,7 @@ object Autocomplete {
|
||||||
val otherUser = channel.recipients?.find { it != RevoltAPI.selfId }
|
val otherUser = channel.recipients?.find { it != RevoltAPI.selfId }
|
||||||
if (otherUser != null) {
|
if (otherUser != null) {
|
||||||
val user = RevoltAPI.userCache[otherUser]
|
val user = RevoltAPI.userCache[otherUser]
|
||||||
if (user != null && user.username?.contains(query) == true) {
|
if (user != null && user.username?.contains(query, ignoreCase = true) == true) {
|
||||||
listOf(
|
listOf(
|
||||||
AutocompleteSuggestion.User(
|
AutocompleteSuggestion.User(
|
||||||
user,
|
user,
|
||||||
|
|
@ -67,7 +69,7 @@ object Autocomplete {
|
||||||
val users =
|
val users =
|
||||||
channel.recipients?.mapNotNull { RevoltAPI.userCache[it] } ?: emptyList()
|
channel.recipients?.mapNotNull { RevoltAPI.userCache[it] } ?: emptyList()
|
||||||
users
|
users
|
||||||
.filter { it.username?.contains(query) ?: false }
|
.filter { it.username?.contains(query, ignoreCase = true) ?: false }
|
||||||
.map {
|
.map {
|
||||||
AutocompleteSuggestion.User(
|
AutocompleteSuggestion.User(
|
||||||
it,
|
it,
|
||||||
|
|
@ -79,7 +81,11 @@ object Autocomplete {
|
||||||
|
|
||||||
ChannelType.SavedMessages -> {
|
ChannelType.SavedMessages -> {
|
||||||
val user = RevoltAPI.userCache[RevoltAPI.selfId]
|
val user = RevoltAPI.userCache[RevoltAPI.selfId]
|
||||||
return if (user != null && user.username?.contains(query) == true) {
|
return if (user != null && user.username?.contains(
|
||||||
|
query,
|
||||||
|
ignoreCase = true
|
||||||
|
) == true
|
||||||
|
) {
|
||||||
listOf(
|
listOf(
|
||||||
AutocompleteSuggestion.User(
|
AutocompleteSuggestion.User(
|
||||||
user,
|
user,
|
||||||
|
|
@ -134,4 +140,19 @@ object Autocomplete {
|
||||||
null -> emptyList()
|
null -> emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun channel(
|
||||||
|
serverId: String,
|
||||||
|
query: String
|
||||||
|
): List<AutocompleteSuggestion.Channel> {
|
||||||
|
val server = RevoltAPI.serverCache[serverId] ?: return emptyList()
|
||||||
|
val channels = server.channels?.mapNotNull { RevoltAPI.channelCache[it] } ?: emptyList()
|
||||||
|
|
||||||
|
return channels.filter { it.name?.contains(query, ignoreCase = true) ?: false }.map {
|
||||||
|
AutocompleteSuggestion.Channel(
|
||||||
|
it,
|
||||||
|
query
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue