Add support for sending account custom emotes (MSC-2545)
We had support for room emotes and global room emotes, but this one was missing. Change-Id: Ic21078b6d786b46fbcd5512db03d9fd1483b25b1
This commit is contained in:
parent
a8ac1ebc60
commit
011f9b0853
@ -184,6 +184,7 @@
|
||||
<string name="freeform_reaction_summary">Free-form reaction</string>
|
||||
<string name="custom_emotes_this_room">Room emojis</string>
|
||||
<string name="custom_emotes_other_room">Emojis from %1$s</string>
|
||||
<string name="custom_emotes_account_data">Own emojis</string>
|
||||
<string name="standard_emojis">Standard emojis</string>
|
||||
|
||||
<string name="dev_tools_menu_hidden_events">Hidden events</string>
|
||||
|
@ -29,5 +29,6 @@ object UserAccountDataTypes {
|
||||
const val TYPE_ACCEPTED_TERMS = "m.accepted_terms"
|
||||
const val TYPE_OVERRIDE_COLORS = "im.vector.setting.override_colors"
|
||||
const val TYPE_EMOTE_ROOMS = "im.ponies.emote_rooms"
|
||||
const val TYPE_USER_EMOTES = "im.ponies.user_emotes"
|
||||
const val TYPE_LOCAL_NOTIFICATION_SETTINGS = "org.matrix.msc3890.local_notification_settings."
|
||||
}
|
||||
|
@ -104,6 +104,8 @@ class AutocompleteEmojiController @Inject constructor(
|
||||
const val CUSTOM_THIS_ROOM_MAX = 10
|
||||
// Count of emojis per other image pack
|
||||
const val CUSTOM_OTHER_ROOM_MAX = 3
|
||||
// Count of emojis for global account data
|
||||
const val CUSTOM_ACCOUNT_MAX = 5
|
||||
// Count of other image packs
|
||||
const val MAX_CUSTOM_OTHER_ROOMS = 3
|
||||
// Total max
|
||||
|
@ -103,6 +103,19 @@ class AutocompleteEmojiPresenter @AssistedInject constructor(
|
||||
emoteUrls.addAll(currentRoomEmotes.map { it.mxcUrl })
|
||||
// Global emotes (only while searching)
|
||||
if (!query.isNullOrBlank()) {
|
||||
// Account emotes
|
||||
val userPack = session.accountDataService().getUserAccountDataEvent(UserAccountDataTypes.TYPE_USER_EMOTES)?.content
|
||||
?.toModel<RoomEmoteContent>().getEmojiItems(query)
|
||||
.limit(AutocompleteEmojiController.CUSTOM_ACCOUNT_MAX)
|
||||
if (userPack.isNotEmpty()) {
|
||||
emoteUrls.addAll(userPack.map { it.mxcUrl })
|
||||
emoteData += listOf(AutocompleteEmojiDataItem.Header(
|
||||
"de.spiritcroc.riotx.ACCOUNT_EMOJI_HEADER",
|
||||
context.getString(R.string.custom_emotes_account_data)
|
||||
))
|
||||
emoteData += userPack.toAutocompleteItems()
|
||||
}
|
||||
// Global emotes from rooms
|
||||
val globalPacks = session.accountDataService().getUserAccountDataEvent(UserAccountDataTypes.TYPE_EMOTE_ROOMS)
|
||||
var packsAdded = 0
|
||||
(globalPacks?.content?.get("rooms") as? Map<*, *>)?.forEach { pack ->
|
||||
@ -145,7 +158,11 @@ class AutocompleteEmojiPresenter @AssistedInject constructor(
|
||||
}
|
||||
|
||||
private fun Room.getEmojiItems(query: CharSequence?): List<EmojiItem> {
|
||||
return getStateEvent(EventType.ROOM_EMOTES, QueryStringValue.IsEmpty)?.content?.toModel<RoomEmoteContent>()?.images.orEmpty()
|
||||
return getStateEvent(EventType.ROOM_EMOTES, QueryStringValue.IsEmpty)?.content?.toModel<RoomEmoteContent>().getEmojiItems(query)
|
||||
}
|
||||
|
||||
private fun RoomEmoteContent?.getEmojiItems(query: CharSequence?): List<EmojiItem> {
|
||||
return this?.images.orEmpty()
|
||||
.filter {
|
||||
val usages = it.value.usage
|
||||
usages.isNullOrEmpty() || RoomEmoteContent.USAGE_EMOTICON in usages
|
||||
|
Loading…
x
Reference in New Issue
Block a user