Skip to content

Fix mark as unread button #3393

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

Merged
merged 7 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 11 additions & 6 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ describe("Room", function () {
tsThread?: number,
): { mainEvent?: MatrixEvent; threadEvent?: MatrixEvent } => {
const result: { mainEvent?: MatrixEvent; threadEvent?: MatrixEvent } = {};
const { rootEvent, thread } = mkThread({
room,
client: new TestClient().client,
authorId: "@bob:example.org",
participantUserIds: ["@bob:example.org"],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that adding this here means that we are no longer testing the behaviour when there are no thread events? Or is that tested somewhere else?

I'm unclear what exactly addRoomMainAndThreadMessages is supposed to do, and what the semantics of tsMain and tsThread are supposed to do. Given the fact that we need to change this, I'm evidently not alone.

Please could you give the function a proper doc comment describing what it does, and what tsMain and tsThread do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richvdh take a look at the last commit. I threw away the magic setup function. It should (hopefully) be clearer now.


if (tsMain) {
result.mainEvent = mkMessage({ ts: tsMain });
room.addLiveEvents([result.mainEvent]);
}

if (tsThread) {
const { rootEvent, thread } = mkThread({
room,
client: new TestClient().client,
authorId: "@bob:example.org",
participantUserIds: ["@bob:example.org"],
});
result.threadEvent = mkThreadResponse(rootEvent, { ts: tsThread });
thread.liveTimeline.addEvent(result.threadEvent, { toStartOfTimeline: true });
}
Expand Down Expand Up @@ -3562,6 +3562,11 @@ describe("Room", function () {
lastEventInMainTimeline = addRoomMainAndThreadMessages(room, 42, 23).mainEvent!;
expect(room.getLastLiveEvent()).toBe(lastEventInMainTimeline);
});

it("and both events have the same timestamp, it should return the last event from the thread", () => {
lastEventInThread = addRoomMainAndThreadMessages(room, 23, 23).threadEvent!;
expect(room.getLastLiveEvent()).toBe(lastEventInThread);
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {

const lastThreadEvent = lastThread.events[lastThread.events.length - 1];

return (lastRoomEvent?.getTs() ?? 0) > (lastThreadEvent.getTs() ?? 0) ? lastRoomEvent : lastThreadEvent;
return (lastRoomEvent?.getTs() ?? 0) > (lastThreadEvent?.getTs() ?? 0) ? lastRoomEvent : lastThreadEvent;
}

/**
Expand Down