@@ -60,6 +60,7 @@ import {
6060 ANYWHERE_AUTOCOMPLETE_PREFIXES ,
6161 BEGINNING_AUTOCOMPLETE_PREFIXES ,
6262 getLinks ,
63+ replaceWithElement ,
6364} from '$components/editor' ;
6465import { EmojiBoard , EmojiBoardTab } from '$components/emoji-board' ;
6566import { UseStateProvider } from '$components/UseStateProvider' ;
@@ -129,8 +130,11 @@ import { sanitizeText } from '$utils/sanitize';
129130import { PKitCommandMessageHandler } from '$plugins/pluralkit-handler/PKitCommandMessageHandler' ;
130131import { PKitProxyMessageHandler } from '$plugins/pluralkit-handler/PKitProxyMessageHandler' ;
131132import { MATRIX_IMAGE_SOURCE_PACK_PROPERTY_NAME } from '$types/matrix/common' ;
132- import type { IGenericMSC4459 , MSC4459ImagePackReference } from '$types/matrix/common'
133- import { getImagePackReferencesForMxc } from '$utils/msc4459helper' ;
133+ import type { IGenericMSC4459 , MSC4459ImagePackReference } from '$types/matrix/common' ;
134+ import {
135+ getImagePackReferencesForMxc ,
136+ getImagePackReferencesForMxcWrappedInMap ,
137+ } from '$utils/msc4459helper' ;
134138import { ImageUsage } from '$plugins/custom-emoji' ;
135139import { SerializableMap } from '$types/wrapper/SerializableMap' ;
136140import { useSettingsLinkBaseUrl } from '$features/settings/useSettingsLinkBaseUrl' ;
@@ -171,7 +175,7 @@ const getLatestThreadEventId = (room: Room, threadRootId: string): string => {
171175 ev . threadRootId === threadRootId && ev . getId ( ) !== threadRootId && ! reactionOrEditEvent ( ev )
172176 ) ;
173177 if ( liveEvents . length > 0 ) {
174- return liveEvents [ liveEvents . length - 1 ] ! . getId ( ) ?? threadRootId ;
178+ return liveEvents . at ( - 1 ) ! . getId ( ) ?? threadRootId ;
175179 }
176180 return threadRootId ;
177181} ;
@@ -749,6 +753,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
749753 nickNameReplacement : nicknameReplacement ,
750754 } )
751755 ) ;
756+
752757 let msgType = MsgType . Text ;
753758
754759 // quick text react
@@ -809,6 +814,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
809814 }
810815
811816 content [ 'm.mentions' ] = getMentionContent ( Array . from ( mentionData . users ) , mentionData . room ) ;
817+ content [ MATRIX_IMAGE_SOURCE_PACK_PROPERTY_NAME ] = imagePacksUsedRef . current . toJSON ( ) ;
812818
813819 const links = getLinks ( serializedChildren ) ;
814820 content [ 'com.beeper.linkpreviews' ] = [ ] ;
@@ -1122,8 +1128,19 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
11221128 ) ;
11231129
11241130 const handleEmoticonSelect = ( key : string , shortcode : string ) => {
1125- editor . insertNode ( createEmoticonElement ( key , shortcode ) ) ;
1131+ const emoticonEl = createEmoticonElement ( key , shortcode ) ;
1132+ if ( autocompleteQuery ) {
1133+ replaceWithElement ( editor , autocompleteQuery . range , emoticonEl ) ;
1134+ } else {
1135+ editor . insertNode ( emoticonEl ) ;
1136+ }
1137+ if ( ! imagePacksUsedRef . current . has ( key ) )
1138+ imagePacksUsedRef . current . set (
1139+ key ,
1140+ getImagePackReferencesForMxc ( key , mx , ImageUsage . Emoticon )
1141+ ) ;
11261142 moveCursor ( editor ) ;
1143+ handleCloseAutocomplete ( ) ;
11271144 } ;
11281145
11291146 const handleStickerSelect = async ( mxc : string , shortcode : string , label : string ) => {
@@ -1142,7 +1159,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
11421159 } ;
11431160
11441161 // add the image pack reference
1145- content [ MATRIX_IMAGE_SOURCE_PACK_PROPERTY_NAME ] = getImagePackReferencesForMxc (
1162+ content [ MATRIX_IMAGE_SOURCE_PACK_PROPERTY_NAME ] = getImagePackReferencesForMxcWrappedInMap (
11461163 mxc ,
11471164 mx ,
11481165 ImageUsage . Sticker
@@ -1161,6 +1178,11 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
11611178 false
11621179 ) ;
11631180 }
1181+ content [ MATRIX_IMAGE_SOURCE_PACK_PROPERTY_NAME ] = getImagePackReferencesForMxcWrappedInMap (
1182+ mxc ,
1183+ mx ,
1184+ ImageUsage . Sticker
1185+ ) ;
11641186
11651187 if ( replyDraft ) {
11661188 content [ 'm.relates_to' ] = getReplyContent ( replyDraft , room ) ;
@@ -1259,6 +1281,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
12591281 editor = { editor }
12601282 query = { autocompleteQuery }
12611283 requestClose = { handleCloseAutocomplete }
1284+ onEmoticonSelected = { handleEmoticonSelect }
12621285 />
12631286 ) }
12641287 { autocompleteQuery ?. prefix === AutocompletePrefix . Reaction &&
0 commit comments