From ea2375d6322e3594f274e684f1763b835082c8d1 Mon Sep 17 00:00:00 2001 From: nipun-mallipeddi <105442557+nmscode@users.noreply.github.com> Date: Sat, 13 Aug 2022 12:50:37 -0400 Subject: [PATCH] added autocomplete custom emote functionality --- src/autocomplete/Components.tsx | 4 ++-- src/autocomplete/EmojiProvider.tsx | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/autocomplete/Components.tsx b/src/autocomplete/Components.tsx index 079e407c5e2..db217cac1b7 100644 --- a/src/autocomplete/Components.tsx +++ b/src/autocomplete/Components.tsx @@ -46,7 +46,7 @@ export const TextualCompletion = forwardRef((props aria-selected={ariaSelectedAttribute} ref={ref} > - { title } + {title} { subtitle } { description } @@ -75,7 +75,7 @@ export const PillCompletion = forwardRef((props, ref) ref={ref} > { children } - { title } + {} { subtitle } { description } diff --git a/src/autocomplete/EmojiProvider.tsx b/src/autocomplete/EmojiProvider.tsx index 4a2c37988ae..eba94a6a047 100644 --- a/src/autocomplete/EmojiProvider.tsx +++ b/src/autocomplete/EmojiProvider.tsx @@ -32,6 +32,7 @@ import SettingsStore from "../settings/SettingsStore"; import { EMOJI, IEmoji, getEmojiFromUnicode } from '../emoji'; import { TimelineRenderingType } from '../contexts/RoomContext'; import * as recent from '../emojipicker/recent'; +import { mediaFromMxc } from "../customisations/Media"; const LIMIT = 20; @@ -75,9 +76,15 @@ export default class EmojiProvider extends AutocompleteProvider { matcher: QueryMatcher; nameMatcher: QueryMatcher; private readonly recentlyUsed: IEmoji[]; - + emotes:Dictionary; constructor(room: Room, renderingType?: TimelineRenderingType) { super({ commandRegex: EMOJI_REGEX, renderingType }); + let emotesEvent = room?.currentState.getStateEvents("m.room.emotes", ""); + let rawEmotes = emotesEvent ? (emotesEvent.getContent() || {}) : {}; + this.emotes = {}; + for (let key in rawEmotes) { + this.emotes[key] = ""; + } this.matcher = new QueryMatcher(SORTED_EMOJI, { keys: [], funcs: [o => o.emoji.shortcodes.map(s => `:${s}:`)], @@ -102,7 +109,20 @@ export default class EmojiProvider extends AutocompleteProvider { if (!SettingsStore.getValue("MessageComposerInput.suggestEmoji")) { return []; // don't give any suggestions if the user doesn't want them } - + let emojisAndEmotes=[...SORTED_EMOJI]; + for(let key in this.emotes){ + emojisAndEmotes.push({ + emoji:{label:key, + shortcodes:[this.emotes[key]], + hexcode:"", + unicode:":"+key+":", + + }, + _orderBy:0 + }) + } + this.matcher.setObjects(emojisAndEmotes); + this.nameMatcher.setObjects(emojisAndEmotes); let completions = []; const { command, range } = this.getCurrentCommand(query, selection); @@ -146,8 +166,8 @@ export default class EmojiProvider extends AutocompleteProvider { completions = completions.map(c => ({ completion: c.emoji.unicode, component: ( - - { c.emoji.unicode } + + { this.emotes[c.emoji.shortcodes[0]]? this.emotes[c.emoji.shortcodes[0]]:c.emoji.unicode } ), range,