Support rendering emote pack display name
Change-Id: I93b422f3931128dd75de8ee570c56976a93702c8
This commit is contained in:
parent
e3a7ef911e
commit
e4e4e0a388
|
@ -188,6 +188,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_named_other_room">\"%1$s\" from %2$s</string>
|
||||
<string name="custom_emotes_account_data">Own emojis</string>
|
||||
<string name="standard_emojis">Standard emojis</string>
|
||||
|
||||
|
|
|
@ -10,10 +10,18 @@ import org.matrix.android.sdk.api.session.room.powerlevels.Role
|
|||
@JsonClass(generateAdapter = true)
|
||||
data class RoomEmoteContent(
|
||||
@Json(name = "images") val images: Map<String, EmoteImage>? = null,
|
||||
// TODO: "pack" support
|
||||
@Json(name = "pack") val pack: RoomEmotePackContent? = null,
|
||||
) {
|
||||
companion object {
|
||||
const val USAGE_EMOTICON = "emoticon"
|
||||
const val USAGE_STICKER = "sticker"
|
||||
}
|
||||
}
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class RoomEmotePackContent(
|
||||
@Json(name = "display_name") val displayName: String? = null,
|
||||
@Json(name = "avatar_url") val avatarUrl: String? = null,
|
||||
@Json(name = "usage") val usage: Array<String>? = null,
|
||||
@Json(name = "attribution") val attribution: String? = null,
|
||||
)
|
||||
|
|
|
@ -135,21 +135,33 @@ class AutocompleteEmojiPresenter @AssistedInject constructor(
|
|||
val packRoom = session.getRoom(packRoomId) ?: return@forEach
|
||||
packsEnabled.forEach roomPack@{ roomPack ->
|
||||
val packId = roomPack.key as? String ?: return@roomPack
|
||||
val emojiItems = packRoom.getEmojiItems(query, QueryStringValue.Equals(packId))
|
||||
val packName = emojiItems.first
|
||||
// Filter out duplicate emotes with the exact same mxc url
|
||||
val packImages = packRoom.getEmojiItems(query, QueryStringValue.Equals(packId)).filter {
|
||||
val packImages = emojiItems.second.filter {
|
||||
it.mxcUrl !in emoteUrls
|
||||
}.limit(AutocompleteEmojiController.CUSTOM_OTHER_ROOM_MAX)
|
||||
// Add header + emotes
|
||||
if (packImages.isNotEmpty()) {
|
||||
packsAdded++
|
||||
emoteUrls.addAll(packImages.map { it.mxcUrl })
|
||||
val packRoomName = packRoom.roomSummary()?.displayName ?: packRoomId
|
||||
roomPack.value
|
||||
emoteData += listOf(
|
||||
AutocompleteEmojiDataItem.Header(
|
||||
packRoomId,
|
||||
if (packName != null) {
|
||||
context.getString(
|
||||
R.string.custom_emotes_named_other_room,
|
||||
packName,
|
||||
packRoomName
|
||||
)
|
||||
} else {
|
||||
context.getString(
|
||||
R.string.custom_emotes_other_room,
|
||||
packRoom.roomSummary()?.displayName ?: packRoomId
|
||||
packRoomName
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
emoteData += packImages.toAutocompleteItems()
|
||||
|
@ -172,8 +184,10 @@ class AutocompleteEmojiPresenter @AssistedInject constructor(
|
|||
return map { AutocompleteEmojiDataItem.Emoji(it) }
|
||||
}
|
||||
|
||||
private fun Room.getEmojiItems(query: CharSequence?, queryStringValue: QueryStateEventValue): List<EmojiItem> {
|
||||
return getStateEvent(EventType.ROOM_EMOTES, queryStringValue)?.content?.toModel<RoomEmoteContent>().getEmojiItems(query)
|
||||
private fun Room.getEmojiItems(query: CharSequence?, queryStringValue: QueryStateEventValue): Pair<String?, List<EmojiItem>> {
|
||||
val content = getStateEvent(EventType.ROOM_EMOTES, queryStringValue)?.content?.toModel<RoomEmoteContent>()
|
||||
val packName = content?.pack?.displayName
|
||||
return Pair(packName, content.getEmojiItems(query))
|
||||
}
|
||||
|
||||
private fun Room.getAllEmojiItems(query: CharSequence?): List<EmojiItem> {
|
||||
|
|
Loading…
Reference in New Issue