This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Make RoomListStore aware of Room.timeline events #1756
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,16 @@ import Unread from '../Unread'; | |
* the RoomList. | ||
*/ | ||
class RoomListStore extends Store { | ||
|
||
static _listOrders = { | ||
"m.favourite": "manual", | ||
"im.vector.fake.invite": "recent", | ||
"im.vector.fake.recent": "recent", | ||
"im.vector.fake.direct": "recent", | ||
"m.lowpriority": "recent", | ||
"im.vector.fake.archived": "recent", | ||
}; | ||
|
||
constructor() { | ||
super(dis); | ||
|
||
|
@@ -68,6 +78,15 @@ class RoomListStore extends Store { | |
this._generateRoomLists(); | ||
} | ||
break; | ||
case 'MatrixActions.Room.timeline': { | ||
if (!this._state.ready || | ||
!payload.isLiveEvent || | ||
!payload.isLiveUnfilteredRoomTimelineEvent || | ||
!this._eventTriggersRecentReorder(payload.event) | ||
) break; | ||
this._generateRoomLists(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't _generateRoomLists have a ratelimiter on it? surely this is quite a heavy operation, and we shouldn't be doing it each and every time a live timeline event happens? |
||
} | ||
break; | ||
case 'MatrixActions.accountData': { | ||
if (payload.event_type !== 'm.direct') break; | ||
this._generateRoomLists(); | ||
|
@@ -159,18 +178,9 @@ class RoomListStore extends Store { | |
} | ||
}); | ||
|
||
const listOrders = { | ||
"m.favourite": "manual", | ||
"im.vector.fake.invite": "recent", | ||
"im.vector.fake.recent": "recent", | ||
"im.vector.fake.direct": "recent", | ||
"m.lowpriority": "recent", | ||
"im.vector.fake.archived": "recent", | ||
}; | ||
|
||
Object.keys(lists).forEach((listKey) => { | ||
let comparator; | ||
switch (listOrders[listKey]) { | ||
switch (RoomListStore._listOrders[listKey]) { | ||
case "recent": | ||
comparator = this._recentsComparator; | ||
break; | ||
|
@@ -188,13 +198,17 @@ class RoomListStore extends Store { | |
}); | ||
} | ||
|
||
_eventTriggersRecentReorder(ev) { | ||
return ev.getTs() && ( | ||
Unread.eventTriggersUnreadCount(ev) || | ||
ev.getSender() === this._matrixClient.credentials.userId | ||
); | ||
} | ||
|
||
_tsOfNewestEvent(room) { | ||
for (let i = room.timeline.length - 1; i >= 0; --i) { | ||
const ev = room.timeline[i]; | ||
if (ev.getTs() && | ||
(Unread.eventTriggersUnreadCount(ev) || | ||
(ev.getSender() === this._matrixClient.credentials.userId)) | ||
) { | ||
if (this._eventTriggersRecentReorder(ev)) { | ||
return ev.getTs(); | ||
} | ||
} | ||
|
@@ -210,6 +224,8 @@ class RoomListStore extends Store { | |
} | ||
|
||
_recentsComparator(roomA, roomB) { | ||
// XXX: We could use a cache here and update it when we see new | ||
// events that trigger a reorder | ||
return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks seem to have disappeared, as well as the _delayedRefreshRoomList?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So:
_delayedRefreshRoomList
is done when we get an update from RoomListStore;isLiveEvent
? Unless I've got that confused?toStartOfTimeline
this is handled byisLiveEvent
, which includes!toStartOfTimeline
.!room
nothing uses theroom
, so I'll remove it from the MatrixAction.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, OK. I think this almost all true apart from the timeline set check, where live timeline !== unfiltered timeline set. There are multiple timeline sets, the first is the unfiltered one (the normal one that isn't a search result). Each timeline set has many timelines, one of which is live.
liveEvent
is telling you if it's to the live timeline in a timeline set, not if it's to the timeline set you're interested in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in theory we shouldn't get live events for search result or any other timeline set apart from the unfiltered one. We're not sure how true this is though. Investigation of exactly when Room.timeline is emitted will have to be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemingly this isn't true, as @dbkr has said, each set (be it a room timeline, notification timeline, rooms timeline) has a live timeline, and the only way of us knowing which is the room's live timeline if by comparing references.