Use updates stable relations from js-sdk (#8715)

* Use updates stable relations from js-sdk

* Relations is now accessible on the Room instead

* Reuse more existing code and ditch confusing `isThreadRelation`

* Fix last usage of removed `isThreadRelation`

* Update tests to match removal of isThreadRelation

* Tweak method naming to closer match spec

* Fix missing method name change
This commit is contained in:
Michael Telatynski 2022-06-07 11:16:54 +01:00 committed by GitHub
parent 56b0b79fb7
commit 21d0aaf524
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 54 deletions

View file

@ -469,12 +469,9 @@ export default class MessagePanel extends React.Component<IProps, IState> {
// TODO: Implement granular (per-room) hide options
public shouldShowEvent(mxEv: MatrixEvent, forceHideEvents = false): boolean {
if (this.props.hideThreadedMessages && this.threadsEnabled) {
if (mxEv.isThreadRelation) {
return false;
}
if (this.shouldLiveInThreadOnly(mxEv)) {
if (this.props.hideThreadedMessages && this.threadsEnabled && this.props.room) {
const { shouldLiveInRoom } = this.props.room.eventShouldLiveIn(mxEv, this.props.events);
if (!shouldLiveInRoom) {
return false;
}
}
@ -497,24 +494,6 @@ export default class MessagePanel extends React.Component<IProps, IState> {
return !shouldHideEvent(mxEv, this.context);
}
private shouldLiveInThreadOnly(event: MatrixEvent): boolean {
const associatedId = event.getAssociatedId();
const targetsThreadRoot = event.threadRootId === associatedId;
if (event.isThreadRoot || targetsThreadRoot || !event.isThreadRelation) {
return false;
}
// If this is a reply, then we use the associated event to decide whether
// this should be thread only or not
const parentEvent = this.props.room.findEventById(associatedId);
if (parentEvent) {
return this.shouldLiveInThreadOnly(parentEvent);
} else {
return true;
}
}
public readMarkerForEvent(eventId: string, isLastEvent: boolean): ReactNode {
const visible = !isLastEvent && this.props.readMarkerVisible;

View file

@ -974,9 +974,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
CHAT_EFFECTS.forEach(effect => {
if (containsEmoji(ev.getContent(), effect.emojis) || ev.getContent().msgtype === effect.msgType) {
// For initial threads launch, chat effects are disabled
// see #19731
if (!SettingsStore.getValue("feature_thread") || !ev.isThreadRelation) {
// For initial threads launch, chat effects are disabled see #19731
if (!SettingsStore.getValue("feature_thread") || !ev.isRelation(THREAD_RELATION_TYPE.name)) {
dis.dispatch({ action: `effects.${effect.command}` });
}
}

View file

@ -1425,27 +1425,18 @@ class TimelinePanel extends React.Component<IProps, IState> {
// if we're at the end of the live timeline, append the pending events
if (!this.timelineWindow.canPaginate(EventTimeline.FORWARDS)) {
const pendingEvents = this.props.timelineSet.getPendingEvents();
if (this.context.timelineRenderingType === TimelineRenderingType.Thread) {
events.push(...pendingEvents.filter(e => e.threadRootId === this.context.threadId));
} else {
events.push(...pendingEvents.filter(e => {
const hasNoRelation = !e.getRelation();
if (hasNoRelation) {
return true;
}
events.push(...pendingEvents.filter(event => {
const {
shouldLiveInRoom,
threadId,
} = this.props.timelineSet.room.eventShouldLiveIn(event, pendingEvents);
if (e.isThreadRelation) {
return false;
}
const parentEvent = this.props.timelineSet.findEventById(e.getAssociatedId());
if (!parentEvent) {
return false;
} else {
return !parentEvent.isThreadRelation;
}
}));
}
if (this.context.timelineRenderingType === TimelineRenderingType.Thread) {
return threadId === this.context.threadId;
} {
return shouldLiveInRoom;
}
}));
}
return {
@ -1678,7 +1669,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
eventId: string,
relationType: RelationType,
eventType: EventType | string,
) => this.props.timelineSet.getRelationsForEvent(eventId, relationType, eventType);
) => this.props.timelineSet.relations?.getChildEventsForEvent(eventId, relationType, eventType);
private buildCallEventGroupers(events?: MatrixEvent[]): void {
this.callEventGroupers = buildCallEventGroupers(this.callEventGroupers, events);