1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Add reply events rendering hint

Adds an unstable hint for clients to know whether to render an event in the room timeline or in a thread

There are currently no MSC associated with that unstable "io.element.in_thread" property as I am only experimenting before settling on a specific approach
This commit is contained in:
Germain Souquet
2021-09-01 12:12:01 +01:00
parent 2783d162b7
commit fa44300abc
3 changed files with 23 additions and 2 deletions

View File

@@ -168,6 +168,11 @@ export const UNSTABLE_ELEMENT_FUNCTIONAL_USERS = new UnstableValue(
"io.element.functional_members", "io.element.functional_members",
"io.element.functional_members"); "io.element.functional_members");
export const UNSTABLE_ELEMENT_REPLY_IN_THREAD = new UnstableValue(
"m.in_thread",
"io.element.in_thread",
);
export interface IEncryptedFile { export interface IEncryptedFile {
url: string; url: string;
mimetype?: string; mimetype?: string;

View File

@@ -24,7 +24,12 @@ import { EventEmitter } from 'events';
import { logger } from '../logger'; import { logger } from '../logger';
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest"; import { VerificationRequest } from "../crypto/verification/request/VerificationRequest";
import { EventType, MsgType, RelationType } from "../@types/event"; import {
EventType,
MsgType,
RelationType,
UNSTABLE_ELEMENT_REPLY_IN_THREAD,
} from "../@types/event";
import { Crypto } from "../crypto"; import { Crypto } from "../crypto";
import { deepSortedObjectEntries } from "../utils"; import { deepSortedObjectEntries } from "../utils";
import { RoomMember } from "./room-member"; import { RoomMember } from "./room-member";
@@ -401,6 +406,17 @@ export class MatrixEvent extends EventEmitter {
return relations?.["m.in_reply_to"]?.["event_id"]; return relations?.["m.in_reply_to"]?.["event_id"];
} }
/**
* @experimental
* Determines whether a reply should be rendered in a thread
* or in the main room timeline
*/
public get replyInThread(): boolean {
const relations = this.getWireContent()["m.relates_to"];
return this.replyEventId
&& relations[UNSTABLE_ELEMENT_REPLY_IN_THREAD.name];
}
/** /**
* Get the previous event content JSON. This will only return something for * Get the previous event content JSON. This will only return something for
* state events which exist in the timeline. * state events which exist in the timeline.

View File

@@ -315,7 +315,7 @@ export class SyncApi {
public partitionThreadedEvents(events: MatrixEvent[]): [MatrixEvent[], MatrixEvent[]] { public partitionThreadedEvents(events: MatrixEvent[]): [MatrixEvent[], MatrixEvent[]] {
if (this.opts.experimentalThreadSupport) { if (this.opts.experimentalThreadSupport) {
return events.reduce((memo, event: MatrixEvent) => { return events.reduce((memo, event: MatrixEvent) => {
memo[event.replyEventId ? 1 : 0].push(event); memo[event.replyInThread ? 1 : 0].push(event);
return memo; return memo;
}, [[], []]); }, [[], []]);
} else { } else {