You've already forked matrix-js-sdk
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:
@@ -168,6 +168,11 @@ export const UNSTABLE_ELEMENT_FUNCTIONAL_USERS = new UnstableValue(
|
||||
"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 {
|
||||
url: string;
|
||||
mimetype?: string;
|
||||
|
||||
@@ -24,7 +24,12 @@ import { EventEmitter } from 'events';
|
||||
|
||||
import { logger } from '../logger';
|
||||
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 { deepSortedObjectEntries } from "../utils";
|
||||
import { RoomMember } from "./room-member";
|
||||
@@ -401,6 +406,17 @@ export class MatrixEvent extends EventEmitter {
|
||||
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
|
||||
* state events which exist in the timeline.
|
||||
|
||||
@@ -315,7 +315,7 @@ export class SyncApi {
|
||||
public partitionThreadedEvents(events: MatrixEvent[]): [MatrixEvent[], MatrixEvent[]] {
|
||||
if (this.opts.experimentalThreadSupport) {
|
||||
return events.reduce((memo, event: MatrixEvent) => {
|
||||
memo[event.replyEventId ? 1 : 0].push(event);
|
||||
memo[event.replyInThread ? 1 : 0].push(event);
|
||||
return memo;
|
||||
}, [[], []]);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user