Skip to content

Commit

Permalink
Track if user has participated in a thread or not (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain committed Dec 16, 2021
1 parent 95f718b commit f46968c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/@types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ export enum MsgType {
KeyVerificationRequest = "m.key.verification.request",
}

/* eslint-disable camelcase */
export interface IThreadBundledRelation {
// eslint-disable-next-line camelcase
latest_event: IEvent;
count: number;
current_user_participated?: boolean;
}
/* eslint-enable camelcase */

export const RoomCreateTypeField = "type";

Expand Down
10 changes: 10 additions & 0 deletions src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
private _head: MatrixEvent;
private eventToPreview: MatrixEvent = null;
private replyCount = 0;
private _currentUserParticipated = false;

public _hasServerSideSupport = false;

Expand Down Expand Up @@ -207,6 +208,7 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
});
EventTimeline.setEventMetadata(this.eventToPreview, this.roomState, false);
this.replyCount = threadBundle.count;
this._currentUserParticipated = threadBundle.current_user_participated === true;
} else {
this.addEvent(this._head);
this.replyCount = 0;
Expand Down Expand Up @@ -269,6 +271,10 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
this.emit(ThreadEvent.NewReply, this, event);
}

if (!this._currentUserParticipated) {
this._currentUserParticipated = event.getSender() === this.client.getUserId();
}

this.emit(ThreadEvent.Update, this);
this.emit(ThreadEvent.New, this);
}
Expand Down Expand Up @@ -332,4 +338,8 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
public get ready(): boolean {
return this._ready;
}

public get currentUserParticipated(): boolean {
return this._currentUserParticipated;
}
}

0 comments on commit f46968c

Please sign in to comment.