From 0ee6a21f7c39617551a546e95c638bcee623150b Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 4 Jan 2022 16:32:00 -0700 Subject: [PATCH 1/8] Render events as extensible events (behind labs) --- src/TextForEvent.tsx | 20 +++- src/components/views/messages/TextualBody.tsx | 99 ++++++++++++------- src/i18n/strings/en_EN.json | 1 + src/settings/Settings.tsx | 7 ++ 4 files changed, 88 insertions(+), 39 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 639bec8a3d3..f00a7889868 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -1,5 +1,5 @@ /* -Copyright 2015, 2016 OpenMarket Ltd +Copyright 2015 - 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import defaultDispatcher from './dispatcher/dispatcher'; import { SetRightPanelPhasePayload } from './dispatcher/payloads/SetRightPanelPhasePayload'; import { MatrixClientPeg } from "./MatrixClientPeg"; import { ROOM_SECURITY_TAB } from "./components/views/dialogs/RoomSettingsDialog"; +import { EmoteEvent, NoticeEvent, MessageEvent as ExtEvMessageEvent } from "matrix-events-sdk"; // These functions are frequently used just to check whether an event has // any text to display at all. For this reason they return deferred values @@ -333,10 +334,23 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null { if (redactedBecauseUserId && redactedBecauseUserId !== ev.getSender()) { const room = MatrixClientPeg.get().getRoom(ev.getRoomId()); const sender = room?.getMember(redactedBecauseUserId); - message = _t("Message deleted by %(name)s", { name: sender?.name - || redactedBecauseUserId }); + message = _t("Message deleted by %(name)s", { + name: sender?.name || redactedBecauseUserId, + }); } } + + if (SettingsStore.isEnabled("feature_extensible_events")) { + const extev = ev.unstable_extensibleEvent; + if (extev) { + if (extev instanceof EmoteEvent) { + return `* ${senderDisplayName} ${extev.text}`; + } else if (extev instanceof NoticeEvent || extev instanceof ExtEvMessageEvent) { + return `${senderDisplayName}: ${extev.text}`; + } + } + } + if (ev.getContent().msgtype === MsgType.Emote) { message = "* " + senderDisplayName + " " + message; } else if (ev.getContent().msgtype === MsgType.Image) { diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index 66a5cc8b544..ca134cff694 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -45,6 +45,7 @@ import EditMessageComposer from '../rooms/EditMessageComposer'; import LinkPreviewGroup from '../rooms/LinkPreviewGroup'; import { IBodyProps } from "./IBodyProps"; import RoomContext from "../../../contexts/RoomContext"; +import { isEventLike, LegacyMsgType, MessageEvent } from "matrix-events-sdk/lib"; const MAX_HIGHLIGHT_LENGTH = 4096; @@ -508,17 +509,44 @@ export default class TextualBody extends React.Component { } const mxEvent = this.props.mxEvent; const content = mxEvent.getContent(); + let isNotice = false; + let isEmote = false; // only strip reply if this is the original replying event, edits thereafter do not have the fallback const stripReply = !mxEvent.replacingEvent() && !!ReplyChain.getParentEventId(mxEvent); - let body = HtmlUtils.bodyToHtml(content, this.props.highlights, { - disableBigEmoji: content.msgtype === MsgType.Emote - || !SettingsStore.getValue('TextualBody.enableBigEmoji'), - // Part of Replies fallback support - stripReplyFallback: stripReply, - ref: this.contentRef, - returnString: false, - }); + let body; + if (SettingsStore.isEnabled("feature_extensible_events")) { + const extev = this.props.mxEvent.unstable_extensibleEvent; + if (extev && extev instanceof MessageEvent) { + isEmote = isEventLike(extev.wireFormat, LegacyMsgType.Emote); + isNotice = isEventLike(extev.wireFormat, LegacyMsgType.Notice); + body = HtmlUtils.bodyToHtml({ + body: extev.text, + format: extev.html ? "org.matrix.custom.html" : undefined, + formatted_body: extev.html, + msgtype: MsgType.Text, + }, this.props.highlights, { + disableBigEmoji: isEmote + || !SettingsStore.getValue('TextualBody.enableBigEmoji'), + // Part of Replies fallback support + stripReplyFallback: stripReply, + ref: this.contentRef, + returnString: false, + }); + } + } + if (!body) { + isEmote = content.msgtype === MsgType.Emote; + isNotice = content.msgtype === MsgType.Notice; + body = HtmlUtils.bodyToHtml(content, this.props.highlights, { + disableBigEmoji: isEmote + || !SettingsStore.getValue('TextualBody.enableBigEmoji'), + // Part of Replies fallback support + stripReplyFallback: stripReply, + ref: this.contentRef, + returnString: false, + }); + } if (this.props.replacingEventId) { body = <> { body } @@ -544,36 +572,35 @@ export default class TextualBody extends React.Component { />; } - switch (content.msgtype) { - case MsgType.Emote: - return ( -
- *  - + if (isEmote) { + return ( +
+ *  + { mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender() } -   - { body } - { widgets } -
- ); - case MsgType.Notice: - return ( -
- { body } - { widgets } -
- ); - default: // including "m.text" - return ( -
- { body } - { widgets } -
- ); +   + { body } + { widgets } +
+ ); } + if (isNotice) { + return ( +
+ { body } + { widgets } +
+ ); + } + return ( +
+ { body } + { widgets } +
+ ); } } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 93cb7e3a8b3..83c77f99621 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -871,6 +871,7 @@ "Show message previews for reactions in DMs": "Show message previews for reactions in DMs", "Show message previews for reactions in all rooms": "Show message previews for reactions in all rooms", "Offline encrypted messaging using dehydrated devices": "Offline encrypted messaging using dehydrated devices", + "Show extensible event representation of events": "Show extensible event representation of events", "Polls (under active development)": "Polls (under active development)", "Location sharing (under active development)": "Location sharing (under active development)", "Show info about bridges in room settings": "Show info about bridges in room settings", diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index a96ad66e044..c526d009521 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -300,6 +300,13 @@ export const SETTINGS: {[setting: string]: ISetting} = { supportedLevels: LEVELS_FEATURE, default: false, }, + "feature_extensible_events": { + isFeature: true, + labsGroup: LabGroup.Developer, // developer for now, eventually Messaging and default on + supportedLevels: LEVELS_FEATURE, + displayName: _td("Show extensible event representation of events"), + default: false, + }, "feature_polls": { isFeature: true, labsGroup: LabGroup.Messaging, From 7c5a44f6a699d8bcca9fa3b6f59cc1bc3a74a690 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 4 Jan 2022 16:59:05 -0700 Subject: [PATCH 2/8] Include the SDK --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index 8831f25725b..92c257b516c 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "lodash": "^4.17.20", "maplibre-gl": "^1.15.2", "matrix-analytics-events": "https://github.com/matrix-org/matrix-analytics-events.git#1eab4356548c97722a183912fda1ceabbe8cc7c1", + "matrix-events-sdk": "^0.0.1-beta.1", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "matrix-widget-api": "^0.1.0-beta.18", "minimist": "^1.2.5", diff --git a/yarn.lock b/yarn.lock index 00acd506cee..a3f4e19a394 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6145,6 +6145,11 @@ mathml-tag-names@^2.1.3: version "0.0.1" resolved "https://github.com/matrix-org/matrix-analytics-events.git#1eab4356548c97722a183912fda1ceabbe8cc7c1" +matrix-events-sdk@^0.0.1-beta.1: + version "0.0.1-beta.1" + resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.1.tgz#e41e6d6da89f387b0a65ae21b0c102e9a82deb7a" + integrity sha512-rTcAWcrULpk+bpbO5ptbMdmCleqeVtNHPk1ZFwCVXCQib4XaVNqCjdZcirNccu4qgqvUrH7QQVMpulmBC6YN6g== + "matrix-js-sdk@github:matrix-org/matrix-js-sdk#develop": version "15.3.0" resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/f780e1dbc3918d3665f3b7f1214562f598486670" From 886ccea0a6a6bf15c351ec0ad593f773ee31c29e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 6 Jan 2022 11:56:54 -0700 Subject: [PATCH 3/8] Appease linter --- src/TextForEvent.tsx | 4 ++-- src/components/views/messages/TextualBody.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index f00a7889868..26fb819f0cf 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -20,6 +20,7 @@ import { logger } from "matrix-js-sdk/src/logger"; import { removeDirectionOverrideChars } from 'matrix-js-sdk/src/utils'; import { GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/@types/partials"; import { EventType, MsgType } from "matrix-js-sdk/src/@types/event"; +import { EmoteEvent, NoticeEvent, MessageEvent } from "matrix-events-sdk"; import { _t } from './languageHandler'; import * as Roles from './Roles'; @@ -33,7 +34,6 @@ import defaultDispatcher from './dispatcher/dispatcher'; import { SetRightPanelPhasePayload } from './dispatcher/payloads/SetRightPanelPhasePayload'; import { MatrixClientPeg } from "./MatrixClientPeg"; import { ROOM_SECURITY_TAB } from "./components/views/dialogs/RoomSettingsDialog"; -import { EmoteEvent, NoticeEvent, MessageEvent as ExtEvMessageEvent } from "matrix-events-sdk"; // These functions are frequently used just to check whether an event has // any text to display at all. For this reason they return deferred values @@ -345,7 +345,7 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null { if (extev) { if (extev instanceof EmoteEvent) { return `* ${senderDisplayName} ${extev.text}`; - } else if (extev instanceof NoticeEvent || extev instanceof ExtEvMessageEvent) { + } else if (extev instanceof NoticeEvent || extev instanceof MessageEvent) { return `${senderDisplayName}: ${extev.text}`; } } diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index ca134cff694..ec18d35428d 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -18,6 +18,7 @@ import React, { createRef, SyntheticEvent } from 'react'; import ReactDOM from 'react-dom'; import highlight from 'highlight.js'; import { MsgType } from "matrix-js-sdk/src/@types/event"; +import { isEventLike, LegacyMsgType, MessageEvent } from "matrix-events-sdk"; import * as HtmlUtils from '../../../HtmlUtils'; import { formatDate } from '../../../DateUtils'; @@ -45,7 +46,6 @@ import EditMessageComposer from '../rooms/EditMessageComposer'; import LinkPreviewGroup from '../rooms/LinkPreviewGroup'; import { IBodyProps } from "./IBodyProps"; import RoomContext from "../../../contexts/RoomContext"; -import { isEventLike, LegacyMsgType, MessageEvent } from "matrix-events-sdk/lib"; const MAX_HIGHLIGHT_LENGTH = 4096; From c2697da20a836db468a38c7ee4fa01d0652b6c82 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 6 Jan 2022 11:58:07 -0700 Subject: [PATCH 4/8] Update for changed property name --- src/TextForEvent.tsx | 2 +- src/components/views/messages/TextualBody.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index 608a4bffec5..d16dfe42af2 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -341,7 +341,7 @@ function textForMessageEvent(ev: MatrixEvent): () => string | null { } if (SettingsStore.isEnabled("feature_extensible_events")) { - const extev = ev.unstable_extensibleEvent; + const extev = ev.unstableExtensibleEvent; if (extev) { if (extev instanceof EmoteEvent) { return `* ${senderDisplayName} ${extev.text}`; diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index ec18d35428d..4eec66a2733 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -516,7 +516,7 @@ export default class TextualBody extends React.Component { const stripReply = !mxEvent.replacingEvent() && !!ReplyChain.getParentEventId(mxEvent); let body; if (SettingsStore.isEnabled("feature_extensible_events")) { - const extev = this.props.mxEvent.unstable_extensibleEvent; + const extev = this.props.mxEvent.unstableExtensibleEvent; if (extev && extev instanceof MessageEvent) { isEmote = isEventLike(extev.wireFormat, LegacyMsgType.Emote); isNotice = isEventLike(extev.wireFormat, LegacyMsgType.Notice); From 6102a6e10fbee7bb20a021e2efce52531b523735 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 6 Jan 2022 12:02:36 -0700 Subject: [PATCH 5/8] Fix formatting error --- src/components/views/messages/TextualBody.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/messages/TextualBody.tsx b/src/components/views/messages/TextualBody.tsx index 4eec66a2733..a2c6bbb1d48 100644 --- a/src/components/views/messages/TextualBody.tsx +++ b/src/components/views/messages/TextualBody.tsx @@ -580,8 +580,8 @@ export default class TextualBody extends React.Component { className="mx_MEmoteBody_sender" onClick={this.onEmoteSenderClick} > - { mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender() } - + { mxEvent.sender ? mxEvent.sender.name : mxEvent.getSender() } +   { body } { widgets } From f92707c74f3b0db06985ed14741113ecd0dc0535 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 6 Jan 2022 12:10:25 -0700 Subject: [PATCH 6/8] Fix branch matching for build steps --- scripts/fetchdep.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/fetchdep.sh b/scripts/fetchdep.sh index 8c97670339a..f23b510a2e3 100755 --- a/scripts/fetchdep.sh +++ b/scripts/fetchdep.sh @@ -49,11 +49,18 @@ elif [ -n "$REVIEW_ID" ]; then getPRInfo $REVIEW_ID fi -# $head will always be in the format "fork:branch", so we split it by ":" into -# an array. The first element will then be the fork and the second the branch. -# Based on that we clone +# for forks, $head will be in teh format "fork:branch", so we split it by ":" +# into an array. On non-forks, this has the effect of splitting into a single +# element array given ":" shouldn't appear in the head - it'll just be the +# branch name. Based on the results, we clone. BRANCH_ARRAY=(${head//:/ }) -clone ${BRANCH_ARRAY[0]} $defrepo ${BRANCH_ARRAY[1]} +TRY_ORG=$deforg +TRY_BRANCH=${BRANCH_ARRAY[0]} +if [[ "$head" == *":"* ]]; then + TRY_ORG=${BRANCH_ARRAY[0]} + TRY_BRANCH=${BRANCH_ARRAY[1]} +fi +clone ${TRY_ORG} $defrepo ${TRY_BRANCH} # Try the target branch of the push or PR. if [ -n $GITHUB_BASE_REF ]; then From 409d5010d18865089598436d7566f038fbabeef3 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 10 Jan 2022 22:23:32 -0700 Subject: [PATCH 7/8] Update SDK --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 45dbb9bd8c0..7eaa5c6cee4 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "lodash": "^4.17.20", "maplibre-gl": "^1.15.2", "matrix-analytics-events": "https://github.com/matrix-org/matrix-analytics-events.git#1eab4356548c97722a183912fda1ceabbe8cc7c1", - "matrix-events-sdk": "^0.0.1-beta.1", + "matrix-events-sdk": "^0.0.1-beta.2", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "matrix-widget-api": "^0.1.0-beta.18", "minimist": "^1.2.5", diff --git a/yarn.lock b/yarn.lock index ee9a59aef8e..0521a31c862 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6173,10 +6173,10 @@ mathml-tag-names@^2.1.3: version "0.0.1" resolved "https://github.com/matrix-org/matrix-analytics-events.git#1eab4356548c97722a183912fda1ceabbe8cc7c1" -matrix-events-sdk@^0.0.1-beta.1: - version "0.0.1-beta.1" - resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.1.tgz#e41e6d6da89f387b0a65ae21b0c102e9a82deb7a" - integrity sha512-rTcAWcrULpk+bpbO5ptbMdmCleqeVtNHPk1ZFwCVXCQib4XaVNqCjdZcirNccu4qgqvUrH7QQVMpulmBC6YN6g== +matrix-events-sdk@^0.0.1-beta.2: + version "0.0.1-beta.2" + resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.2.tgz#28efdcc3259152c4d53094cedb72b3843e5f772e" + integrity sha512-a3VIZeb9IxxxPrvFnUbt4pjP7A6irv7eWLv1GBoq+80m7v5n3QhzT/mmeUGJx2KNt7jLboFau4g1iIU82H3wEg== "matrix-js-sdk@github:matrix-org/matrix-js-sdk#develop": version "15.3.0" From 01a132029de2bcfb942c367b98e96800b97eb376 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 13 Jan 2022 09:56:24 -0700 Subject: [PATCH 8/8] Update scripts/fetchdep.sh Co-authored-by: Andy Balaam --- scripts/fetchdep.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fetchdep.sh b/scripts/fetchdep.sh index f23b510a2e3..15e998ddbed 100755 --- a/scripts/fetchdep.sh +++ b/scripts/fetchdep.sh @@ -49,7 +49,7 @@ elif [ -n "$REVIEW_ID" ]; then getPRInfo $REVIEW_ID fi -# for forks, $head will be in teh format "fork:branch", so we split it by ":" +# for forks, $head will be in the format "fork:branch", so we split it by ":" # into an array. On non-forks, this has the effect of splitting into a single # element array given ":" shouldn't appear in the head - it'll just be the # branch name. Based on the results, we clone.