From 511c1c8da8cac03682574f850c535c30962c9dd6 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 9 May 2024 09:33:20 +0200 Subject: [PATCH] Render captions --- generate_patches.sh | 1 + merge_upstream.sh | 1 + ...hildi-fetch-package.ts-modifications.patch | 2 +- ...Add-fields-for-media-caption-support.patch | 56 +++++++++ .../0001-Disable-sticky-rooms.patch | 2 +- .../0002-Bring-back-unified-room-list.patch | 8 +- ...-rooms-to-bottom-I-still-want-to-see.patch | 2 +- ...rendering-captions-in-media-messages.patch | 109 ++++++++++++++++++ 8 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 patches/matrix-js-sdk/0001-Add-fields-for-media-caption-support.patch create mode 100644 patches/matrix-react-sdk/0004-Add-support-for-rendering-captions-in-media-messages.patch diff --git a/generate_patches.sh b/generate_patches.sh index c7bdcef..b456c34 100755 --- a/generate_patches.sh +++ b/generate_patches.sh @@ -35,5 +35,6 @@ persist_patches() { persist_patches element-desktop #persist_patches element-web persist_patches matrix-react-sdk +persist_patches matrix-js-sdk popd > /dev/null diff --git a/merge_upstream.sh b/merge_upstream.sh index d293e31..805fe8c 100755 --- a/merge_upstream.sh +++ b/merge_upstream.sh @@ -51,6 +51,7 @@ make clean make setup # Apply our patches +apply_patches matrix-js-sdk apply_patches matrix-react-sdk #apply_patches element-web apply_patches element-desktop diff --git a/patches/element-desktop/0001-Add-back-schildi-fetch-package.ts-modifications.patch b/patches/element-desktop/0001-Add-back-schildi-fetch-package.ts-modifications.patch index 0eb8055..879fc73 100644 --- a/patches/element-desktop/0001-Add-back-schildi-fetch-package.ts-modifications.patch +++ b/patches/element-desktop/0001-Add-back-schildi-fetch-package.ts-modifications.patch @@ -1,4 +1,4 @@ -From 7f932f56b483fa784260a9581e1a410fccd9a1ef Mon Sep 17 00:00:00 2001 +From bf8d7700c8680a0324ddf3b0d32c8a16af2176ae Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sat, 2 Dec 2023 12:57:26 +0100 Subject: Add back schildi fetch-package.ts modifications diff --git a/patches/matrix-js-sdk/0001-Add-fields-for-media-caption-support.patch b/patches/matrix-js-sdk/0001-Add-fields-for-media-caption-support.patch new file mode 100644 index 0000000..a94bfa1 --- /dev/null +++ b/patches/matrix-js-sdk/0001-Add-fields-for-media-caption-support.patch @@ -0,0 +1,56 @@ +From b3e2e01c33bacd014287ab5dc7477fc70d91f9ab Mon Sep 17 00:00:00 2001 +From: SpiritCroc +Date: Thu, 9 May 2024 09:21:21 +0200 +Subject: Add fields for media caption support + +--- + src/@types/media.ts | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/src/@types/media.ts b/src/@types/media.ts +index 20e5ca6c6..920d77667 100644 +--- a/src/@types/media.ts ++++ b/src/@types/media.ts +@@ -180,6 +180,9 @@ export interface FileContent extends BaseContent { + * One of: [m.file]. + */ + msgtype: MsgType.File; ++ ++ format?: string; ++ formatted_body?: string; + } + + /** +@@ -202,6 +205,9 @@ export interface ImageContent extends BaseContent { + * One of: [m.image]. + */ + msgtype: MsgType.Image; ++ ++ format?: string; ++ formatted_body?: string; + } + + /** +@@ -223,6 +229,9 @@ export interface AudioContent extends BaseContent { + * One of: [m.audio]. + */ + msgtype: MsgType.Audio; ++ ++ format?: string; ++ formatted_body?: string; + } + + /** +@@ -244,6 +253,9 @@ export interface VideoContent extends BaseContent { + * One of: [m.video]. + */ + msgtype: MsgType.Video; ++ ++ format?: string; ++ formatted_body?: string; + } + + /** +-- +2.45.0 + diff --git a/patches/matrix-react-sdk/0001-Disable-sticky-rooms.patch b/patches/matrix-react-sdk/0001-Disable-sticky-rooms.patch index c9c4e68..3036c1f 100644 --- a/patches/matrix-react-sdk/0001-Disable-sticky-rooms.patch +++ b/patches/matrix-react-sdk/0001-Disable-sticky-rooms.patch @@ -1,4 +1,4 @@ -From 26074d71cfc060952e9a63efd462b8450eb4d445 Mon Sep 17 00:00:00 2001 +From 88515b6ab68264a4773dd07efbf0a9e01ab05d8b Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 18 Jan 2022 13:28:22 +0100 Subject: Disable sticky rooms diff --git a/patches/matrix-react-sdk/0002-Bring-back-unified-room-list.patch b/patches/matrix-react-sdk/0002-Bring-back-unified-room-list.patch index 1627722..b717146 100644 --- a/patches/matrix-react-sdk/0002-Bring-back-unified-room-list.patch +++ b/patches/matrix-react-sdk/0002-Bring-back-unified-room-list.patch @@ -1,4 +1,4 @@ -From 4447153bc30c98caed3b6896e1814daadd5fc101 Mon Sep 17 00:00:00 2001 +From 4acd52e0e85d0217b7203fa81bfa709ccaf6d2aa Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 5 May 2024 10:12:17 +0200 Subject: Bring back unified room list @@ -16,7 +16,7 @@ Co-authored-by: su-ex 5 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx -index 073950e30f..7488ffd2c6 100644 +index d573f3bbf0..ced4e7bb47 100644 --- a/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx @@ -77,11 +77,13 @@ interface IState { @@ -124,10 +124,10 @@ index 073950e30f..7488ffd2c6 100644 (this.props.activeSpace === MetaSpace.Favourites && orderedTagId !== DefaultTagID.Favourite) || (this.props.activeSpace === MetaSpace.People && orderedTagId !== DefaultTagID.DM) || diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx -index 6be0a6b46f..e96e29944a 100644 +index 2137837500..49d96c7840 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx -@@ -206,6 +206,14 @@ export interface IFeature extends Omit, "isFeature"> { +@@ -207,6 +207,14 @@ export interface IFeature extends Omit, "isFeature"> { export type ISetting = IBaseSetting | IFeature; export const SETTINGS: { [setting: string]: ISetting } = { diff --git a/patches/matrix-react-sdk/0003-Don-t-sort-muted-rooms-to-bottom-I-still-want-to-see.patch b/patches/matrix-react-sdk/0003-Don-t-sort-muted-rooms-to-bottom-I-still-want-to-see.patch index f264bcf..f3db324 100644 --- a/patches/matrix-react-sdk/0003-Don-t-sort-muted-rooms-to-bottom-I-still-want-to-see.patch +++ b/patches/matrix-react-sdk/0003-Don-t-sort-muted-rooms-to-bottom-I-still-want-to-see.patch @@ -1,4 +1,4 @@ -From 6e32e2d55772a95bc660b27605981e46b805f821 Mon Sep 17 00:00:00 2001 +From 5c361faad5325629b5db9bdd6c0e69218bc53132 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 17 Dec 2023 11:11:58 +0100 Subject: Don't sort muted rooms to bottom, I still want to see them. diff --git a/patches/matrix-react-sdk/0004-Add-support-for-rendering-captions-in-media-messages.patch b/patches/matrix-react-sdk/0004-Add-support-for-rendering-captions-in-media-messages.patch new file mode 100644 index 0000000..745fb5f --- /dev/null +++ b/patches/matrix-react-sdk/0004-Add-support-for-rendering-captions-in-media-messages.patch @@ -0,0 +1,109 @@ +From f9fdcd1fa38c883a07ef1b519217a1927f40547d Mon Sep 17 00:00:00 2001 +From: Tulir Asokan +Date: Tue, 12 Jul 2022 15:34:57 +0300 +Subject: Add support for rendering captions in media messages + +--- + src/components/views/messages/IBodyProps.ts | 2 ++ + src/components/views/messages/MessageEvent.tsx | 15 +++++++++++++++ + src/components/views/messages/TextualBody.tsx | 11 +++++++++++ + src/utils/FileUtils.ts | 4 +++- + 4 files changed, 31 insertions(+), 1 deletion(-) + +diff --git a/src/components/views/messages/IBodyProps.ts b/src/components/views/messages/IBodyProps.ts +index fcc204dae3..95cb2eb37d 100644 +--- a/src/components/views/messages/IBodyProps.ts ++++ b/src/components/views/messages/IBodyProps.ts +@@ -59,4 +59,6 @@ export interface IBodyProps { + // Set to `true` to disable interactions (e.g. video controls) and to remove controls from the tab order. + // This may be useful when displaying a preview of the event. + inhibitInteraction?: boolean; ++ ++ OrigBodyType?: React.ComponentType>; + } +diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx +index db0016de7b..dd7a864300 100644 +--- a/src/components/views/messages/MessageEvent.tsx ++++ b/src/components/views/messages/MessageEvent.tsx +@@ -183,6 +183,15 @@ export default class MessageEvent extends React.Component implements IMe + } + } + ++ // @ts-ignore ++ const hasCaption = [MsgType.Image, MsgType.File, MsgType.Audio, MsgType.Video].includes(msgtype) ++ && content.filename && content.filename !== content.body; ++ let OrigBodyType; ++ if (hasCaption) { ++ OrigBodyType = BodyType ++ BodyType = CaptionBody ++ } ++ + if (SettingsStore.getValue("feature_mjolnir")) { + const key = `mx_mjolnir_render_${this.props.mxEvent.getRoomId()}__${this.props.mxEvent.getId()}`; + const allowRender = localStorage.getItem(key) === "true"; +@@ -216,7 +225,13 @@ export default class MessageEvent extends React.Component implements IMe + getRelationsForEvent={this.props.getRelationsForEvent} + isSeeingThroughMessageHiddenForModeration={this.props.isSeeingThroughMessageHiddenForModeration} + inhibitInteraction={this.props.inhibitInteraction} ++ OrigBodyType={OrigBodyType} + /> + ) : null; + } + } ++ ++const CaptionBody: React.FunctionComponent>}> = ({OrigBodyType, ...props}) => (
++ ++ ++
) +diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx +index f0b5c70f17..e28ed3fad7 100644 +--- a/src/components/views/messages/TextualBody.tsx ++++ b/src/components/views/messages/TextualBody.tsx +@@ -575,11 +575,14 @@ export default class TextualBody extends React.Component { + const content = mxEvent.getContent(); + let isNotice = false; + let isEmote = false; ++ let isCaption = false; + + // only strip reply if this is the original replying event, edits thereafter do not have the fallback + const stripReply = !mxEvent.replacingEvent() && !!getParentEventId(mxEvent); + isEmote = content.msgtype === MsgType.Emote; + isNotice = content.msgtype === MsgType.Notice; ++ // @ts-ignore ++ isCaption = [MsgType.Image, MsgType.File, MsgType.Audio, MsgType.Video].includes(content.msgtype); + let body = HtmlUtils.bodyToHtml(content, this.props.highlights, { + disableBigEmoji: isEmote || !SettingsStore.getValue("TextualBody.enableBigEmoji"), + // Part of Replies fallback support +@@ -651,6 +654,14 @@ export default class TextualBody extends React.Component { + + ); + } ++ if (isCaption) { ++ return ( ++
++ { body } ++ { widgets } ++
++ ); ++ } + return ( +
+ {body} +diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts +index 75511756f5..a8e3b9cceb 100644 +--- a/src/utils/FileUtils.ts ++++ b/src/utils/FileUtils.ts +@@ -46,7 +46,9 @@ export function presentableTextForFile( + shortened = false, + ): string { + let text = fallbackText; +- if (content.body?.length) { ++ if (content.filename?.length) { ++ text = content.filename ++ } else if (content.body?.length) { + // The content body should be the name of the file including a + // file extension. + text = content.body; +-- +2.45.0 +