Render captions

This commit is contained in:
SpiritCroc 2024-05-09 09:33:20 +02:00
parent 8b9c72584b
commit 511c1c8da8
8 changed files with 174 additions and 7 deletions

View File

@ -35,5 +35,6 @@ persist_patches() {
persist_patches element-desktop persist_patches element-desktop
#persist_patches element-web #persist_patches element-web
persist_patches matrix-react-sdk persist_patches matrix-react-sdk
persist_patches matrix-js-sdk
popd > /dev/null popd > /dev/null

View File

@ -51,6 +51,7 @@ make clean
make setup make setup
# Apply our patches # Apply our patches
apply_patches matrix-js-sdk
apply_patches matrix-react-sdk apply_patches matrix-react-sdk
#apply_patches element-web #apply_patches element-web
apply_patches element-desktop apply_patches element-desktop

View File

@ -1,4 +1,4 @@
From 7f932f56b483fa784260a9581e1a410fccd9a1ef Mon Sep 17 00:00:00 2001 From bf8d7700c8680a0324ddf3b0d32c8a16af2176ae Mon Sep 17 00:00:00 2001
From: SpiritCroc <dev@spiritcroc.de> From: SpiritCroc <dev@spiritcroc.de>
Date: Sat, 2 Dec 2023 12:57:26 +0100 Date: Sat, 2 Dec 2023 12:57:26 +0100
Subject: Add back schildi fetch-package.ts modifications Subject: Add back schildi fetch-package.ts modifications

View File

@ -0,0 +1,56 @@
From b3e2e01c33bacd014287ab5dc7477fc70d91f9ab Mon Sep 17 00:00:00 2001
From: SpiritCroc <dev@spiritcroc.de>
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

View File

@ -1,4 +1,4 @@
From 26074d71cfc060952e9a63efd462b8450eb4d445 Mon Sep 17 00:00:00 2001 From 88515b6ab68264a4773dd07efbf0a9e01ab05d8b Mon Sep 17 00:00:00 2001
From: SpiritCroc <dev@spiritcroc.de> From: SpiritCroc <dev@spiritcroc.de>
Date: Tue, 18 Jan 2022 13:28:22 +0100 Date: Tue, 18 Jan 2022 13:28:22 +0100
Subject: Disable sticky rooms Subject: Disable sticky rooms

View File

@ -1,4 +1,4 @@
From 4447153bc30c98caed3b6896e1814daadd5fc101 Mon Sep 17 00:00:00 2001 From 4acd52e0e85d0217b7203fa81bfa709ccaf6d2aa Mon Sep 17 00:00:00 2001
From: SpiritCroc <dev@spiritcroc.de> From: SpiritCroc <dev@spiritcroc.de>
Date: Sun, 5 May 2024 10:12:17 +0200 Date: Sun, 5 May 2024 10:12:17 +0200
Subject: Bring back unified room list Subject: Bring back unified room list
@ -16,7 +16,7 @@ Co-authored-by: su-ex <codeworks@supercable.onl>
5 files changed, 83 insertions(+), 5 deletions(-) 5 files changed, 83 insertions(+), 5 deletions(-)
diff --git a/src/components/views/rooms/RoomList.tsx b/src/components/views/rooms/RoomList.tsx 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 --- a/src/components/views/rooms/RoomList.tsx
+++ b/src/components/views/rooms/RoomList.tsx +++ b/src/components/views/rooms/RoomList.tsx
@@ -77,11 +77,13 @@ interface IState { @@ -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.Favourites && orderedTagId !== DefaultTagID.Favourite) ||
(this.props.activeSpace === MetaSpace.People && orderedTagId !== DefaultTagID.DM) || (this.props.activeSpace === MetaSpace.People && orderedTagId !== DefaultTagID.DM) ||
diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx 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 --- a/src/settings/Settings.tsx
+++ b/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx
@@ -206,6 +206,14 @@ export interface IFeature extends Omit<IBaseSetting<boolean>, "isFeature"> { @@ -207,6 +207,14 @@ export interface IFeature extends Omit<IBaseSetting<boolean>, "isFeature"> {
export type ISetting = IBaseSetting | IFeature; export type ISetting = IBaseSetting | IFeature;
export const SETTINGS: { [setting: string]: ISetting } = { export const SETTINGS: { [setting: string]: ISetting } = {

View File

@ -1,4 +1,4 @@
From 6e32e2d55772a95bc660b27605981e46b805f821 Mon Sep 17 00:00:00 2001 From 5c361faad5325629b5db9bdd6c0e69218bc53132 Mon Sep 17 00:00:00 2001
From: SpiritCroc <dev@spiritcroc.de> From: SpiritCroc <dev@spiritcroc.de>
Date: Sun, 17 Dec 2023 11:11:58 +0100 Date: Sun, 17 Dec 2023 11:11:58 +0100
Subject: Don't sort muted rooms to bottom, I still want to see them. Subject: Don't sort muted rooms to bottom, I still want to see them.

View File

@ -0,0 +1,109 @@
From f9fdcd1fa38c883a07ef1b519217a1927f40547d Mon Sep 17 00:00:00 2001
From: Tulir Asokan <tulir@maunium.net>
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<Partial<IBodyProps>>;
}
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<IProps> 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<IProps> implements IMe
getRelationsForEvent={this.props.getRelationsForEvent}
isSeeingThroughMessageHiddenForModeration={this.props.isSeeingThroughMessageHiddenForModeration}
inhibitInteraction={this.props.inhibitInteraction}
+ OrigBodyType={OrigBodyType}
/>
) : null;
}
}
+
+const CaptionBody: React.FunctionComponent<IBodyProps & {OrigBodyType: React.ComponentType<Partial<IBodyProps>>}> = ({OrigBodyType, ...props}) => (<div className="mx_EventTile_content">
+ <OrigBodyType {...props}/>
+ <TextualBody {...{...props, ref: undefined}}/>
+</div>)
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<IBodyProps, IState> {
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<boolean>("TextualBody.enableBigEmoji"),
// Part of Replies fallback support
@@ -651,6 +654,14 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
</div>
);
}
+ if (isCaption) {
+ return (
+ <div className="mx_MTextBody mx_EventTile_caption" onClick={this.onBodyLinkClick}>
+ { body }
+ { widgets }
+ </div>
+ );
+ }
return (
<div className="mx_MTextBody mx_EventTile_content" onClick={this.onBodyLinkClick}>
{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