Fix explicit replies in threads (#8210)

This commit is contained in:
Michael Telatynski 2022-03-31 18:40:35 +01:00 committed by GitHub
parent f4c25e06cd
commit 17cfd45eb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 27 deletions

View file

@ -47,6 +47,7 @@ import { decorateStartSendingTime, sendRoundTripMetric } from "./sendTimePerform
import { TimelineRenderingType } from "./contexts/RoomContext"; import { TimelineRenderingType } from "./contexts/RoomContext";
import RoomViewStore from "./stores/RoomViewStore"; import RoomViewStore from "./stores/RoomViewStore";
import { addReplyToMessageContent } from "./utils/Reply"; import { addReplyToMessageContent } from "./utils/Reply";
import { attachRelation } from "./components/views/rooms/SendMessageComposer";
const MAX_WIDTH = 800; const MAX_WIDTH = 800;
const MAX_HEIGHT = 600; const MAX_HEIGHT = 600;
@ -585,10 +586,7 @@ export default class ContentMessages {
msgtype: "", // set later msgtype: "", // set later
}; };
if (relation) { attachRelation(content, relation);
content["m.relates_to"] = relation;
}
if (replyToEvent) { if (replyToEvent) {
addReplyToMessageContent(content, replyToEvent, { addReplyToMessageContent(content, replyToEvent, {
includeLegacyFallback: false, includeLegacyFallback: false,

View file

@ -60,14 +60,12 @@ import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
import { PosthogAnalytics } from "../../../PosthogAnalytics"; import { PosthogAnalytics } from "../../../PosthogAnalytics";
import { addReplyToMessageContent } from '../../../utils/Reply'; import { addReplyToMessageContent } from '../../../utils/Reply';
export function attachRelation( // Merges favouring the given relation
content: IContent, export function attachRelation(content: IContent, relation?: IEventRelation): void {
relation?: IEventRelation,
): void {
if (relation) { if (relation) {
content['m.relates_to'] = { content['m.relates_to'] = {
...relation, // the composer can have a default ...(content['m.relates_to'] || {}),
...content['m.relates_to'], ...relation,
}; };
} }
} }
@ -100,6 +98,7 @@ export function createMessageContent(
content.formatted_body = formattedBody; content.formatted_body = formattedBody;
} }
attachRelation(content, relation);
if (replyToEvent) { if (replyToEvent) {
addReplyToMessageContent(content, replyToEvent, { addReplyToMessageContent(content, replyToEvent, {
permalinkCreator, permalinkCreator,
@ -107,13 +106,6 @@ export function createMessageContent(
}); });
} }
if (relation) {
content['m.relates_to'] = {
...relation,
...content['m.relates_to'],
};
}
return content; return content;
} }

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { IContent, IEventRelation, MatrixEvent } from "matrix-js-sdk/src/models/event";
import sanitizeHtml from "sanitize-html"; import sanitizeHtml from "sanitize-html";
import escapeHtml from "escape-html"; import escapeHtml from "escape-html";
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread"; import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
@ -22,7 +22,6 @@ import { MsgType } from "matrix-js-sdk/src/@types/event";
import { PERMITTED_URL_SCHEMES } from "../HtmlUtils"; import { PERMITTED_URL_SCHEMES } from "../HtmlUtils";
import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks"; import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks";
import { RecursivePartial } from "../@types/common";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
export function getParentEventId(ev?: MatrixEvent): string | undefined { export function getParentEventId(ev?: MatrixEvent): string | undefined {
@ -144,16 +143,20 @@ export function getNestedReplyText(
return { body, html }; return { body, html };
} }
export function makeReplyMixIn(ev?: MatrixEvent): RecursivePartial<IContent> { export function makeReplyMixIn(ev?: MatrixEvent): IEventRelation {
if (!ev) return {}; if (!ev) return {};
return { const mixin: IEventRelation = {
'm.relates_to': { 'm.in_reply_to': {
'm.in_reply_to': { 'event_id': ev.getId(),
'event_id': ev.getId(),
},
}, },
}; };
if (SettingsStore.getValue("feature_thread") && ev.threadRootId) {
mixin.is_falling_back = false;
}
return mixin;
} }
export function shouldDisplayReply(event: MatrixEvent): boolean { export function shouldDisplayReply(event: MatrixEvent): boolean {
@ -189,8 +192,10 @@ export function addReplyToMessageContent(
includeLegacyFallback: true, includeLegacyFallback: true,
}, },
): void { ): void {
const replyContent = makeReplyMixIn(replyToEvent); content["m.relates_to"] = {
Object.assign(content, replyContent); ...(content["m.relates_to"] || {}),
...makeReplyMixIn(replyToEvent),
};
if (opts.includeLegacyFallback) { if (opts.includeLegacyFallback) {
// Part of Replies fallback support - prepend the text we're sending with the text we're replying to // Part of Replies fallback support - prepend the text we're sending with the text we're replying to