forked from Mirrors/gomuks
web/client: preserve other fields when updating recent emoji
This commit is contained in:
parent
21e2dcbc43
commit
52fc7e5cdf
1 changed files with 22 additions and 14 deletions
|
@ -16,7 +16,17 @@
|
||||||
import { CachedEventDispatcher } from "../util/eventdispatcher.ts"
|
import { CachedEventDispatcher } from "../util/eventdispatcher.ts"
|
||||||
import RPCClient, { SendMessageParams } from "./rpc.ts"
|
import RPCClient, { SendMessageParams } from "./rpc.ts"
|
||||||
import { RoomStateStore, StateStore } from "./statestore"
|
import { RoomStateStore, StateStore } from "./statestore"
|
||||||
import type { ClientState, EventID, EventType, ImagePackRooms, RPCEvent, RoomID, RoomStateGUID, UserID } from "./types"
|
import type {
|
||||||
|
ClientState,
|
||||||
|
ElementRecentEmoji,
|
||||||
|
EventID,
|
||||||
|
EventType,
|
||||||
|
ImagePackRooms,
|
||||||
|
RPCEvent,
|
||||||
|
RoomID,
|
||||||
|
RoomStateGUID,
|
||||||
|
UserID,
|
||||||
|
} from "./types"
|
||||||
|
|
||||||
export default class Client {
|
export default class Client {
|
||||||
readonly state = new CachedEventDispatcher<ClientState>()
|
readonly state = new CachedEventDispatcher<ClientState>()
|
||||||
|
@ -127,29 +137,27 @@ export default class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
async incrementFrequentlyUsedEmoji(targetEmoji: string) {
|
async incrementFrequentlyUsedEmoji(targetEmoji: string) {
|
||||||
let recentEmoji = this.store.accountData.get("io.element.recent_emoji")?.recent_emoji as
|
const content = Object.assign({}, this.store.accountData.get("io.element.recent_emoji")) as ElementRecentEmoji
|
||||||
[string, number][] | undefined
|
if (!Array.isArray(content.recent_emoji)) {
|
||||||
if (!Array.isArray(recentEmoji)) {
|
content.recent_emoji = []
|
||||||
recentEmoji = []
|
|
||||||
}
|
}
|
||||||
let found = false
|
let found = false
|
||||||
for (const [idx, [emoji, count]] of recentEmoji.entries()) {
|
for (const [idx, [emoji, count]] of content.recent_emoji.entries()) {
|
||||||
if (emoji === targetEmoji) {
|
if (emoji === targetEmoji) {
|
||||||
recentEmoji.splice(idx, 1)
|
content.recent_emoji.splice(idx, 1)
|
||||||
recentEmoji.unshift([emoji, count + 1])
|
content.recent_emoji.unshift([emoji, count + 1])
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
recentEmoji.unshift([targetEmoji, 1])
|
content.recent_emoji.unshift([targetEmoji, 1])
|
||||||
}
|
}
|
||||||
if (recentEmoji.length > 100) {
|
if (content.recent_emoji.length > 100) {
|
||||||
recentEmoji.pop()
|
content.recent_emoji.pop()
|
||||||
}
|
}
|
||||||
const newContent = { recent_emoji: recentEmoji }
|
this.store.accountData.set("io.element.recent_emoji", content)
|
||||||
this.store.accountData.set("io.element.recent_emoji", newContent)
|
await this.rpc.setAccountData("io.element.recent_emoji", content)
|
||||||
await this.rpc.setAccountData("io.element.recent_emoji", newContent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#handleEmoteRoomsChange() {
|
#handleEmoteRoomsChange() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue