Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track if user has participated in a thread or not #2075

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}