Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/feat-stable-recent-emoji.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Swap to using the stable identifier `m.recent_emoji` for recent emojis and add migration logic.
7 changes: 6 additions & 1 deletion src/app/hooks/useRecentEmoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const useRecentEmoji = (mx: MatrixClient, limit?: number): IEmoji[] => {

useEffect(() => {
const handleAccountData = (event: MatrixEvent) => {
if (event.getType() !== (CustomAccountDataEvent.ElementRecentEmoji as string)) return;
if (
event.getType() !== (CustomAccountDataEvent.RecentEmoji as string) &&
event.getType() !== (CustomAccountDataEvent.LegacyElementRecentEmoji as string)
) {
return;
}
setRecentEmoji(getRecentEmojis(mx, limit));
};

Expand Down
21 changes: 18 additions & 3 deletions src/app/plugins/recent-emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ export type IRecentEmojiContent = {
};

export const getRecentEmojis = (mx: MatrixClient, limit?: number): IEmoji[] => {
const recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.ElementRecentEmoji);
let recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.RecentEmoji);
let isLegacy = false;
if (!recentEmojiEvent) {
recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.LegacyElementRecentEmoji);
isLegacy = true;
}
const recentEmoji = recentEmojiEvent?.getContent<IRecentEmojiContent>().recent_emoji;

if (isLegacy && Array.isArray(recentEmoji)) {
mx.setAccountData(CustomAccountDataEvent.RecentEmoji, {
recent_emoji: recentEmoji,
}).catch(() => {});
}

if (!Array.isArray(recentEmoji)) return [];

return recentEmoji
Expand All @@ -28,7 +40,10 @@ export const getRecentEmojis = (mx: MatrixClient, limit?: number): IEmoji[] => {
};

export function addRecentEmoji(mx: MatrixClient, unicode: string) {
const recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.ElementRecentEmoji);
let recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.RecentEmoji);
if (!recentEmojiEvent) {
recentEmojiEvent = getAccountData(mx, CustomAccountDataEvent.LegacyElementRecentEmoji);
}
const recentEmojiContent = recentEmojiEvent?.getContent<IRecentEmojiContent>();
const recentEmoji =
recentEmojiContent && Array.isArray(recentEmojiContent.recent_emoji)
Expand All @@ -45,7 +60,7 @@ export function addRecentEmoji(mx: MatrixClient, unicode: string) {
entry[1] += 1;
}
recentEmoji.unshift(entry);
mx.setAccountData(CustomAccountDataEvent.ElementRecentEmoji, {
mx.setAccountData(CustomAccountDataEvent.RecentEmoji, {
recent_emoji: recentEmoji.slice(0, 100),
});
}
3 changes: 2 additions & 1 deletion src/types/matrix-sdk-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ declare module 'matrix-js-sdk/lib/@types/event' {

interface AccountDataEvents {
[prefix.MATRIX_CINNY_UNSTABLE_ACCOUNT_SPACES_PROPERTY_NAME]: InCinnySpacesContent;
[prefix.MATRIX_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME]: IRecentEmojiContent;
[prefix.MATRIX_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME]: IRecentEmojiContent;
[prefix.MATRIX_LEGACY_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME]: IRecentEmojiContent;
[prefix.MATRIX_UNSTABLE_ACCOUNT_USER_EMOTES_PROPERTY_NAME]: PackContent;
[prefix.MATRIX_UNSTABLE_ACCOUNT_EMOTE_ROOMS_PROPERTY_NAME]: EmoteRoomsContent;
[prefix.MATRIX_SABLE_UNSTABLE_ACCOUNT_NICKNAMES_PROPERTY_NAME]: Record<string, string>;
Expand Down
4 changes: 3 additions & 1 deletion src/types/matrix/accountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as prefix from '$unstable/prefixes';

export const CustomAccountDataEvent = {
CinnySpaces: prefix.MATRIX_CINNY_UNSTABLE_ACCOUNT_SPACES_PROPERTY_NAME,
ElementRecentEmoji: prefix.MATRIX_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME,
LegacyElementRecentEmoji:
prefix.MATRIX_LEGACY_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME,
RecentEmoji: prefix.MATRIX_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME,
PoniesUserEmotes: prefix.MATRIX_UNSTABLE_ACCOUNT_USER_EMOTES_PROPERTY_NAME,
PoniesEmoteRooms: prefix.MATRIX_UNSTABLE_ACCOUNT_EMOTE_ROOMS_PROPERTY_NAME,
SableNicknames: prefix.MATRIX_SABLE_UNSTABLE_ACCOUNT_NICKNAMES_PROPERTY_NAME,
Expand Down
3 changes: 2 additions & 1 deletion src/unstable/prefixes/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const MATRIX_COMMET_UNSTABLE_PROFILE_STATUS_PROPERTY_NAME = 'chat.commet.
export const MATRIX_CINNY_UNSTABLE_ACCOUNT_SPACES_PROPERTY_NAME = 'in.cinny.spaces';
export const MATRIX_CINNY_UNSTABLE_STATE_ROOM_POWER_LEVELS_LABEL_PROPERTY_NAME =
'in.cinny.room.power_level_tags';
export const MATRIX_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME =
export const MATRIX_LEGACY_ELEMENT_UNSTABLE_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME =
'io.element.recent_emoji';
export const MATRIX_ACCOUNT_RECENT_EMOJIS_PROPERTY_NAME = 'm.recent_emoji';
export const MATRIX_ELEMENT_UNSTABLE_STATE_ROOM_WIDGET_PROPERTY_NAME = 'im.vector.modular.widgets';

export const MATRIX_UNSTABLE_STATE_ROOM_BANNER_PROPERTY_NAME =
Expand Down
Loading