Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Rewrite the room list store #4253

Merged
merged 36 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
82b55ff
Add temporary timing functions to old RoomListStore
turt2live Mar 12, 2020
08419d1
Initial breakout for room list rewrite
turt2live Mar 20, 2020
861268d
Invent an AsyncStore and use it for room lists
turt2live Apr 27, 2020
becadde
Categorize rooms by effective membership
turt2live Apr 28, 2020
00d400b
Possible framework for a proof of concept
turt2live Apr 29, 2020
9c04226
Add another thought
turt2live Apr 29, 2020
e7fffee
Remove the need for a tag manager
turt2live Apr 29, 2020
d244eeb
Break up algorithms and use the new layering
turt2live Apr 29, 2020
ecf8090
Handle DMs
turt2live Apr 30, 2020
09b7f39
Simple rendering of the room list for visual aid
turt2live Apr 30, 2020
5dda7f0
Early handling of dispatched events
turt2live May 4, 2020
ea34bb3
Make component index happy
turt2live May 4, 2020
e1fab9a
Work out the new category index for each room update
turt2live May 7, 2020
4a0d14e
Make missing rooms throw instead
turt2live May 7, 2020
e88788f
Handle event decryption too
turt2live May 8, 2020
cb3d17e
Bare minimum for rendering a room list
turt2live May 8, 2020
df3d5c4
Update i18n for room list
turt2live May 11, 2020
9f08102
Clean up imports and other minor lints
turt2live May 11, 2020
715dd7e
Prepare tooltip for collapsed support
turt2live May 11, 2020
6bdcbd0
Support switching rooms
turt2live May 11, 2020
e8c3316
Initial work on badges
turt2live May 12, 2020
c373526
Fix bold rooms not bolding
turt2live May 14, 2020
f8cbada
Clean up comments in skeleton components
turt2live May 14, 2020
aafbd7f
Update misc documentation and spell indices correctly
turt2live May 14, 2020
9fbd489
Update i18n
turt2live May 14, 2020
8e047c3
Update README for room list store
turt2live May 14, 2020
2b4c19e
Merge branch 'travis/dispatcher-types' into travis/room-list-2
turt2live May 14, 2020
6cb1efc
Use the new TS dispatcher
turt2live May 14, 2020
91a997d
Replace ChaoticAlgorithm for tag sorting with deterministic behaviour
turt2live May 14, 2020
b7ba9b3
Replace ChaoticAlgorithm with NaturalAlgorithm for list behaviour
turt2live May 14, 2020
5cfe29d
Update AsyncStore's docs to be slightly more clear
turt2live May 14, 2020
21e4713
Revert "Add temporary timing functions to old RoomListStore"
turt2live Mar 12, 2020
38920e7
Merge branch 'develop' into travis/room-list-2
turt2live May 19, 2020
559dd98
Fix comment style to be less bothersome
turt2live May 21, 2020
a11985f
Which component? The room list!
turt2live May 21, 2020
e3c0b47
Hyphenize algorithm directories
turt2live May 21, 2020
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"dependencies": {
"@babel/runtime": "^7.8.3",
"await-lock": "^2.0.1",
"blueimp-canvas-to-blob": "^3.5.0",
"browser-encrypt-attachment": "^0.3.0",
"browser-request": "^0.3.3",
Expand Down
5 changes: 3 additions & 2 deletions src/actions/RoomListActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ limitations under the License.
*/

import { asyncAction } from './actionCreators';
import RoomListStore, { TAG_DM } from '../stores/RoomListStore';
import { TAG_DM } from '../stores/RoomListStore';
import Modal from '../Modal';
import * as Rooms from '../Rooms';
import { _t } from '../languageHandler';
import * as sdk from '../index';
import { MatrixClient } from "matrix-js-sdk/src/client";
import { Room } from "matrix-js-sdk/src/models/room";
import { AsyncActionPayload } from "../dispatcher/payloads";
import { RoomListStoreTempProxy } from "../stores/room-list/RoomListStoreTempProxy";

export default class RoomListActions {
/**
Expand Down Expand Up @@ -51,7 +52,7 @@ export default class RoomListActions {

// Is the tag ordered manually?
if (newTag && !newTag.match(/^(m\.lowpriority|im\.vector\.fake\.(invite|recent|direct|archived))$/)) {
Copy link
Member

Choose a reason for hiding this comment

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

not sure that JS will cache the regexp properly - i'd play it safe and precompile it.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the same as what was there before, and for the old room list store - I suspect the whole file will need replacing eventually with the new room list work.

const lists = RoomListStore.getRoomLists();
const lists = RoomListStoreTempProxy.getRoomLists();
const newList = [...lists[newTag]];

newList.sort((a, b) => a.tags[newTag].order - b.tags[newTag].order);
Expand Down
34 changes: 25 additions & 9 deletions src/components/structures/LeftPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as VectorConferenceHandler from '../../VectorConferenceHandler';
import SettingsStore from '../../settings/SettingsStore';
import {_t} from "../../languageHandler";
import Analytics from "../../Analytics";
import RoomList2 from "../views/rooms/RoomList2";


const LeftPanel = createReactClass({
Expand Down Expand Up @@ -273,6 +274,29 @@ const LeftPanel = createReactClass({
breadcrumbs = (<RoomBreadcrumbs collapsed={this.props.collapsed} />);
}

let roomList = null;
if (SettingsStore.isFeatureEnabled("feature_new_room_list")) {
roomList = <RoomList2
onKeyDown={this._onKeyDown}
resizeNotifier={this.props.resizeNotifier}
collapsed={this.props.collapsed}
searchFilter={this.state.searchFilter}
ref={this.collectRoomList}
onFocus={this._onFocus}
onBlur={this._onBlur}
/>;
} else {
roomList = <RoomList
onKeyDown={this._onKeyDown}
onFocus={this._onFocus}
onBlur={this._onBlur}
ref={this.collectRoomList}
resizeNotifier={this.props.resizeNotifier}
collapsed={this.props.collapsed}
searchFilter={this.state.searchFilter}
ConferenceHandler={VectorConferenceHandler} />;
}

return (
<div className={containerClasses}>
{ tagPanelContainer }
Expand All @@ -284,15 +308,7 @@ const LeftPanel = createReactClass({
{ exploreButton }
{ searchBox }
</div>
<RoomList
onKeyDown={this._onKeyDown}
onFocus={this._onFocus}
onBlur={this._onBlur}
ref={this.collectRoomList}
resizeNotifier={this.props.resizeNotifier}
collapsed={this.props.collapsed}
searchFilter={this.state.searchFilter}
ConferenceHandler={VectorConferenceHandler} />
{roomList}
</aside>
</div>
);
Expand Down
13 changes: 7 additions & 6 deletions src/components/structures/LoggedInView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import dis from '../../dispatcher/dispatcher';
import sessionStore from '../../stores/SessionStore';
import {MatrixClientPeg, MatrixClientCreds} from '../../MatrixClientPeg';
import SettingsStore from "../../settings/SettingsStore";
import RoomListStore from "../../stores/RoomListStore";

import TagOrderActions from '../../actions/TagOrderActions';
import RoomListActions from '../../actions/RoomListActions';
Expand All @@ -42,6 +41,8 @@ import * as KeyboardShortcuts from "../../accessibility/KeyboardShortcuts";
import HomePage from "./HomePage";
import ResizeNotifier from "../../utils/ResizeNotifier";
import PlatformPeg from "../../PlatformPeg";
import { RoomListStoreTempProxy } from "../../stores/room-list/RoomListStoreTempProxy";
import { DefaultTagID } from "../../stores/room-list/models";
// We need to fetch each pinned message individually (if we don't already have it)
// so each pinned message may trigger a request. Limit the number per room for sanity.
// NB. this is just for server notices rather than pinned messages in general.
Expand Down Expand Up @@ -297,18 +298,18 @@ class LoggedInView extends React.PureComponent<IProps, IState> {
};

onRoomStateEvents = (ev, state) => {
const roomLists = RoomListStore.getRoomLists();
if (roomLists['m.server_notice'] && roomLists['m.server_notice'].some(r => r.roomId === ev.getRoomId())) {
const roomLists = RoomListStoreTempProxy.getRoomLists();
if (roomLists[DefaultTagID.ServerNotice] && roomLists[DefaultTagID.ServerNotice].some(r => r.roomId === ev.getRoomId())) {
this._updateServerNoticeEvents();
}
};

_updateServerNoticeEvents = async () => {
const roomLists = RoomListStore.getRoomLists();
if (!roomLists['m.server_notice']) return [];
const roomLists = RoomListStoreTempProxy.getRoomLists();
if (!roomLists[DefaultTagID.ServerNotice]) return [];

const pinnedEvents = [];
for (const room of roomLists['m.server_notice']) {
for (const room of roomLists[DefaultTagID.ServerNotice]) {
const pinStateEvent = room.currentState.getStateEvents("m.room.pinned_events", "");

if (!pinStateEvent || !pinStateEvent.getContent().pinned) continue;
Expand Down
9 changes: 5 additions & 4 deletions src/components/views/dialogs/InviteDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import {humanizeTime} from "../../../utils/humanize";
import createRoom, {canEncryptToAllUsers} from "../../../createRoom";
import {inviteMultipleToRoom} from "../../../RoomInvite";
import SettingsStore from '../../../settings/SettingsStore';
import RoomListStore, {TAG_DM} from "../../../stores/RoomListStore";
import {Key} from "../../../Keyboard";
import {Action} from "../../../dispatcher/actions";
import {RoomListStoreTempProxy} from "../../../stores/room-list/RoomListStoreTempProxy";
import {DefaultTagID} from "../../../stores/room-list/models";

export const KIND_DM = "dm";
export const KIND_INVITE = "invite";
Expand Down Expand Up @@ -344,10 +345,10 @@ export default class InviteDialog extends React.PureComponent {
_buildRecents(excludedTargetIds: Set<string>): {userId: string, user: RoomMember, lastActive: number} {
const rooms = DMRoomMap.shared().getUniqueRoomsWithIndividuals(); // map of userId => js-sdk Room

// Also pull in all the rooms tagged as TAG_DM so we don't miss anything. Sometimes the
// Also pull in all the rooms tagged as DefaultTagID.DM so we don't miss anything. Sometimes the
// room list doesn't tag the room for the DMRoomMap, but does for the room list.
const taggedRooms = RoomListStore.getRoomLists();
const dmTaggedRooms = taggedRooms[TAG_DM];
const taggedRooms = RoomListStoreTempProxy.getRoomLists();
const dmTaggedRooms = taggedRooms[DefaultTagID.DM];
const myUserId = MatrixClientPeg.get().getUserId();
for (const dmRoom of dmTaggedRooms) {
const otherMembers = dmRoom.getJoinedMembers().filter(u => u.userId !== myUserId);
Expand Down
15 changes: 8 additions & 7 deletions src/components/views/rooms/RoomList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import rate_limited_func from "../../../ratelimitedfunc";
import * as Rooms from '../../../Rooms';
import DMRoomMap from '../../../utils/DMRoomMap';
import TagOrderStore from '../../../stores/TagOrderStore';
import RoomListStore, {TAG_DM} from '../../../stores/RoomListStore';
import CustomRoomTagStore from '../../../stores/CustomRoomTagStore';
import GroupStore from '../../../stores/GroupStore';
import RoomSubList from '../../structures/RoomSubList';
Expand All @@ -41,6 +40,8 @@ import * as Receipt from "../../../utils/Receipt";
import {Resizer} from '../../../resizer';
import {Layout, Distributor} from '../../../resizer/distributors/roomsublist2';
import {RovingTabIndexProvider} from "../../../accessibility/RovingTabIndex";
import {RoomListStoreTempProxy} from "../../../stores/room-list/RoomListStoreTempProxy";
import {DefaultTagID} from "../../../stores/room-list/models";
import * as Unread from "../../../Unread";
import RoomViewStore from "../../../stores/RoomViewStore";

Expand Down Expand Up @@ -161,7 +162,7 @@ export default createReactClass({
this.updateVisibleRooms();
});

this._roomListStoreToken = RoomListStore.addListener(() => {
this._roomListStoreToken = RoomListStoreTempProxy.addListener(() => {
this._delayedRefreshRoomList();
});

Expand Down Expand Up @@ -521,7 +522,7 @@ export default createReactClass({
},

getTagNameForRoomId: function(roomId) {
const lists = RoomListStore.getRoomLists();
const lists = RoomListStoreTempProxy.getRoomLists();
for (const tagName of Object.keys(lists)) {
for (const room of lists[tagName]) {
// Should be impossible, but guard anyways.
Expand All @@ -541,7 +542,7 @@ export default createReactClass({
},

getRoomLists: function() {
const lists = RoomListStore.getRoomLists();
const lists = RoomListStoreTempProxy.getRoomLists();

const filteredLists = {};

Expand Down Expand Up @@ -773,10 +774,10 @@ export default createReactClass({
incomingCall: incomingCallIfTaggedAs('m.favourite'),
},
{
list: this.state.lists[TAG_DM],
list: this.state.lists[DefaultTagID.DM],
label: _t('Direct Messages'),
tagName: TAG_DM,
incomingCall: incomingCallIfTaggedAs(TAG_DM),
tagName: DefaultTagID.DM,
incomingCall: incomingCallIfTaggedAs(DefaultTagID.DM),
onAddRoom: () => {dis.dispatch({action: 'view_create_chat'});},
addRoomLabel: _t("Start chat"),
},
Expand Down
Loading