From f2fee53a0efb2dff9d192a7bd661fb775d8ee6fd Mon Sep 17 00:00:00 2001 From: Germain Date: Fri, 3 Dec 2021 08:22:13 +0000 Subject: [PATCH] Allow stickers to be sent in a Thread (#7267) --- src/ContentMessages.tsx | 11 +++++++++-- src/components/structures/RoomView.tsx | 8 +++++--- src/components/views/elements/AppTile.tsx | 10 +++++++++- src/components/views/rooms/MessageComposer.tsx | 6 ++++++ src/components/views/rooms/Stickerpicker.tsx | 6 ++++++ 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 16804ae82d..a5a34c0099 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -419,9 +419,16 @@ export default class ContentMessages { private inprogress: IUpload[] = []; private mediaConfig: IMediaConfig = null; - sendStickerContentToRoom(url: string, roomId: string, info: IImageInfo, text: string, matrixClient: MatrixClient) { + sendStickerContentToRoom( + url: string, + roomId: string, + threadId: string | null, + info: IImageInfo, + text: string, + matrixClient: MatrixClient, + ) { const startTime = CountlyAnalytics.getTimestamp(); - const prom = matrixClient.sendStickerMessage(roomId, url, info, text).catch((e) => { + const prom = matrixClient.sendStickerMessage(roomId, threadId, url, info, text).catch((e) => { logger.warn(`Failed to send content with URL ${url} to room ${roomId}`, e); throw e; }); diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 9f4c291adf..6b50ce5370 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -843,7 +843,8 @@ export class RoomView extends React.Component { this.injectSticker( payload.data.content.url, payload.data.content.info, - payload.data.description || payload.data.name); + payload.data.description || payload.data.name, + payload.data.threadId); break; case 'picture_snapshot': ContentMessages.sharedInstance().sendContentListToRoom( @@ -1352,13 +1353,14 @@ export class RoomView extends React.Component { }); }; - private injectSticker(url: string, info: object, text: string) { + private injectSticker(url: string, info: object, text: string, threadId: string | null) { if (this.context.isGuest()) { dis.dispatch({ action: 'require_registration' }); return; } - ContentMessages.sharedInstance().sendStickerContentToRoom(url, this.state.room.roomId, info, text, this.context) + ContentMessages.sharedInstance() + .sendStickerContentToRoom(url, this.state.room.roomId, threadId, info, text, this.context) .then(undefined, (error) => { if (error.name === "UnknownDeviceError") { // Let the staus bar handle this diff --git a/src/components/views/elements/AppTile.tsx b/src/components/views/elements/AppTile.tsx index 3eaf0daf34..af8aeee30c 100644 --- a/src/components/views/elements/AppTile.tsx +++ b/src/components/views/elements/AppTile.tsx @@ -47,6 +47,7 @@ interface IProps { // If room is not specified then it is an account level widget // which bypasses permission prompts as it was added explicitly by that user room: Room; + threadId?: string | null; // Specifying 'fullWidth' as true will render the app tile to fill the width of the app drawer continer. // This should be set to true when there is only one widget in the app drawer, otherwise it should be false. fullWidth?: boolean; @@ -100,6 +101,7 @@ export default class AppTile extends React.Component { handleMinimisePointerEvents: false, userWidget: false, miniMode: false, + threadId: null, }; private contextMenuButton = createRef(); @@ -322,7 +324,13 @@ export default class AppTile extends React.Component { switch (payload.action) { case 'm.sticker': if (this.sgWidget.widgetApi.hasCapability(MatrixCapabilities.StickerSending)) { - dis.dispatch({ action: 'post_sticker_message', data: payload.data }); + dis.dispatch({ + action: 'post_sticker_message', + data: { + ...payload.data, + threadId: this.props.threadId, + }, + }); dis.dispatch({ action: 'stickerpicker_close' }); } else { logger.warn('Ignoring sticker message. Invalid capability'); diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 4d2e66724e..aedad1848c 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -656,9 +656,15 @@ export default class MessageComposer extends React.Component { yOffset={-50} />; } + + const threadId = this.props.relation?.rel_type === RelationType.Thread + ? this.props.relation.event_id + : null; + controls.push( void; @@ -62,6 +63,10 @@ interface IState { @replaceableComponent("views.rooms.Stickerpicker") export default class Stickerpicker extends React.PureComponent { + static defaultProps = { + threadId: null, + }; + static currentWidget; private dispatcherRef: string; @@ -287,6 +292,7 @@ export default class Stickerpicker extends React.PureComponent {