Skip to content

Commit 7fe7af6

Browse files
committed
refactor out the sections of the RoomList into RoomSubLists. Start wiring up tags
1 parent 8b9b268 commit 7fe7af6

9 files changed

Lines changed: 298 additions & 105 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"q": "^1.4.1",
3535
"react": "^0.13.3",
3636
"react-loader": "^1.4.0",
37-
"sanitize-html": "^1.11.1"
37+
"react-dnd": "^1.1.8",
38+
"sanitize-html": "^1.0.0"
3839
},
3940
"devDependencies": {
4041
"babel": "^5.8.23",

‎src/controllers/organisms/RoomList.js‎

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ var dis = require("matrix-react-sdk/lib/dispatcher");
2323

2424
var sdk = require('matrix-react-sdk');
2525
var VectorConferenceHandler = require("../../modules/VectorConferenceHandler");
26-
var CallHandler = require("matrix-react-sdk/lib/CallHandler");
2726

2827
var HIDE_CONFERENCE_CHANS = true;
2928

3029
module.exports = {
3130
getInitialState: function() {
3231
return {
3332
activityMap: null,
34-
inviteList: [],
35-
roomList: [],
33+
lists: {},
3634
}
3735
},
3836

@@ -41,6 +39,7 @@ module.exports = {
4139
cli.on("Room", this.onRoom);
4240
cli.on("Room.timeline", this.onRoomTimeline);
4341
cli.on("Room.name", this.onRoomName);
42+
cli.on("Room.tags", this.onRoomTags);
4443
cli.on("RoomState.events", this.onRoomStateEvents);
4544
cli.on("RoomMember.name", this.onRoomMemberName);
4645

@@ -55,11 +54,6 @@ module.exports = {
5554

5655
onAction: function(payload) {
5756
switch (payload.action) {
58-
// listen for call state changes to prod the render method, which
59-
// may hide the global CallView if the call it is tracking is dead
60-
case 'call_state':
61-
this._recheckCallElement(this.props.selectedRoom);
62-
break;
6357
case 'view_tooltip':
6458
this.tooltip = payload.tooltip;
6559
this._repositionTooltip();
@@ -80,7 +74,6 @@ module.exports = {
8074

8175
componentWillReceiveProps: function(newProps) {
8276
this.state.activityMap[newProps.selectedRoom] = undefined;
83-
this._recheckCallElement(newProps.selectedRoom);
8477
this.setState({
8578
activityMap: this.state.activityMap
8679
});
@@ -117,6 +110,10 @@ module.exports = {
117110
this.refreshRoomList();
118111
},
119112

113+
onRoomTags: function(room) {
114+
this.refreshRoomList();
115+
},
116+
120117
onRoomStateEvents: function(ev, state) {
121118
setTimeout(this.refreshRoomList, 0);
122119
},
@@ -125,26 +122,31 @@ module.exports = {
125122
setTimeout(this.refreshRoomList, 0);
126123
},
127124

128-
129125
refreshRoomList: function() {
126+
// TODO: rather than bluntly regenerating and re-sorting everything
127+
// every time we see any kind of room change from the JS SDK
128+
// we could do incremental updates on our copy of the state
129+
// based on the room which has actually changed. This would stop
130+
// us re-rendering all the sublists every time anything changes anywhere
131+
// in the state of the client.
130132
this.setState(this.getRoomLists());
131133
},
132134

133135
getRoomLists: function() {
134-
var s = {};
135-
var inviteList = [];
136-
s.roomList = RoomListSorter.mostRecentActivityFirst(
137-
MatrixClientPeg.get().getRooms().filter(function(room) {
138-
var me = room.getMember(MatrixClientPeg.get().credentials.userId);
139-
140-
if (me && me.membership == "invite") {
141-
inviteList.push(room);
142-
return false;
143-
}
136+
var s = { lists: {} };
137+
138+
MatrixClientPeg.get().getRooms().forEach(function(room) {
139+
var me = room.getMember(MatrixClientPeg.get().credentials.userId);
144140

141+
if (me && me.membership == "invite") {
142+
s.lists["invites"] = s.lists["invites"] || [];
143+
s.lists["invites"].push(room);
144+
}
145+
else {
145146
var shouldShowRoom = (
146147
me && (me.membership == "join")
147148
);
149+
148150
// hiding conf rooms only ever toggles shouldShowRoom to false
149151
if (shouldShowRoom && HIDE_CONFERENCE_CHANS) {
150152
// we want to hide the 1:1 conf<->user room and not the group chat
@@ -159,23 +161,27 @@ module.exports = {
159161
}
160162
}
161163
}
162-
return shouldShowRoom;
163-
})
164-
);
165-
s.inviteList = RoomListSorter.mostRecentActivityFirst(inviteList);
166-
return s;
167-
},
168164

169-
_recheckCallElement: function(selectedRoomId) {
170-
// if we aren't viewing a room with an ongoing call, but there is an
171-
// active call, show the call element - we need to do this to make
172-
// audio/video not crap out
173-
var activeCall = CallHandler.getAnyActiveCall();
174-
var callForRoom = CallHandler.getCallForRoom(selectedRoomId);
175-
var showCall = (activeCall && !callForRoom);
176-
this.setState({
177-
show_call_element: showCall
165+
if (shouldShowRoom) {
166+
var tagNames = Object.keys(room.tags);
167+
if (tagNames.length) {
168+
for (var i = 0; i < tagNames.length; i++) {
169+
var tagName = tagNames[i];
170+
s.lists[tagName] = s.lists[tagName] || [];
171+
s.lists[tagNames[i]].push(room);
172+
}
173+
}
174+
else {
175+
s.lists["recents"] = s.lists["recents"] || [];
176+
s.lists["recents"].push(room);
177+
}
178+
}
179+
}
178180
});
181+
182+
// we actually apply the sorting to this when receiving the prop in RoomSubLists.
183+
184+
return s;
179185
},
180186

181187
_repositionTooltip: function(e) {
@@ -184,23 +190,4 @@ module.exports = {
184190
this.tooltip.style.top = (scroll.parentElement.offsetTop + this.tooltip.parentElement.offsetTop - scroll.scrollTop) + "px";
185191
}
186192
},
187-
188-
makeRoomTiles: function(list, isInvite) {
189-
var self = this;
190-
var RoomTile = sdk.getComponent("molecules.RoomTile");
191-
return list.map(function(room) {
192-
var selected = room.roomId == self.props.selectedRoom;
193-
return (
194-
<RoomTile
195-
room={room}
196-
key={room.roomId}
197-
collapsed={self.props.collapsed}
198-
selected={selected}
199-
unread={self.state.activityMap[room.roomId] === 1}
200-
highlight={self.state.activityMap[room.roomId] === 2}
201-
isInvite={isInvite}
202-
/>
203-
);
204-
});
205-
}
206193
};

‎src/skins/vector/css/organisms/LeftPanel.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ limitations under the License.
3434
cursor: pointer;
3535
}
3636

37+
.mx_LeftPanel_callView {
38+
39+
}
40+
3741
.mx_LeftPanel .mx_RoomList {
3842
-webkit-box-ordinal-group: 1;
3943
-moz-box-ordinal-group: 1;

‎src/skins/vector/css/organisms/RoomList.css‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,9 @@ limitations under the License.
1818
padding-top: 24px;
1919
}
2020

21-
.mx_RoomList_invites,
22-
.mx_RoomList_recents {
23-
display: table;
24-
table-layout: fixed;
25-
width: 100%;
26-
}
27-
2821
.mx_RoomList_expandButton {
2922
margin-left: 8px;
3023
cursor: pointer;
3124
padding-left: 12px;
3225
padding-right: 12px;
3326
}
34-
35-
.mx_RoomList h2 {
36-
text-transform: uppercase;
37-
color: #3d3b39;
38-
font-weight: 600;
39-
font-size: 14px;
40-
padding-left: 12px;
41-
padding-right: 12px;
42-
margin-top: 8px;
43-
margin-bottom: 4px;
44-
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
.mx_RoomSubList {
18+
display: table;
19+
table-layout: fixed;
20+
width: 100%;
21+
}
22+
23+
.mx_RoomSubList_label {
24+
text-transform: uppercase;
25+
color: #3d3b39;
26+
font-weight: 600;
27+
font-size: 14px;
28+
padding-left: 12px;
29+
padding-right: 12px;
30+
margin-top: 8px;
31+
margin-bottom: 4px;
32+
}

‎src/skins/vector/skindex.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ skin['atoms.LogoutButton'] = require('./views/atoms/LogoutButton');
3030
skin['atoms.MemberAvatar'] = require('./views/atoms/MemberAvatar');
3131
skin['atoms.MessageTimestamp'] = require('./views/atoms/MessageTimestamp');
3232
skin['atoms.RoomAvatar'] = require('./views/atoms/RoomAvatar');
33+
skin['atoms.Spinner'] = require('./views/atoms/Spinner');
3334
skin['atoms.create_room.CreateRoomButton'] = require('./views/atoms/create_room/CreateRoomButton');
3435
skin['atoms.create_room.Presets'] = require('./views/atoms/create_room/Presets');
3536
skin['atoms.create_room.RoomAlias'] = require('./views/atoms/create_room/RoomAlias');
@@ -80,9 +81,11 @@ skin['organisms.QuestionDialog'] = require('./views/organisms/QuestionDialog');
8081
skin['organisms.RightPanel'] = require('./views/organisms/RightPanel');
8182
skin['organisms.RoomDirectory'] = require('./views/organisms/RoomDirectory');
8283
skin['organisms.RoomList'] = require('./views/organisms/RoomList');
84+
skin['organisms.RoomSubList'] = require('./views/organisms/RoomSubList');
8385
skin['organisms.RoomView'] = require('./views/organisms/RoomView');
8486
skin['organisms.UserSettings'] = require('./views/organisms/UserSettings');
8587
skin['organisms.ViewSource'] = require('./views/organisms/ViewSource');
88+
skin['pages.CompatibilityPage'] = require('./views/pages/CompatibilityPage');
8689
skin['pages.MatrixChat'] = require('./views/pages/MatrixChat');
8790
skin['templates.Login'] = require('./views/templates/Login');
8891
skin['templates.Register'] = require('./views/templates/Register');

‎src/skins/vector/views/organisms/LeftPanel.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,51 @@ var React = require('react');
2020
var sdk = require('matrix-react-sdk')
2121
var dis = require('matrix-react-sdk/lib/dispatcher');
2222

23+
var CallHandler = require("matrix-react-sdk/lib/CallHandler");
24+
2325
module.exports = React.createClass({
2426
displayName: 'LeftPanel',
2527

28+
getInitialState: function() {
29+
return {
30+
showCallElement: null,
31+
};
32+
},
33+
34+
componentDidMount: function() {
35+
this.dispatcherRef = dis.register(this.onAction);
36+
},
37+
38+
componentWillReceiveProps: function(newProps) {
39+
this._recheckCallElement(newProps.selectedRoom);
40+
},
41+
42+
componentWillUnmount: function() {
43+
dis.unregister(this.dispatcherRef);
44+
},
45+
46+
onAction: function(payload) {
47+
switch (payload.action) {
48+
// listen for call state changes to prod the render method, which
49+
// may hide the global CallView if the call it is tracking is dead
50+
case 'call_state':
51+
this._recheckCallElement(this.props.selectedRoom);
52+
break;
53+
}
54+
},
55+
56+
_recheckCallElement: function(selectedRoomId) {
57+
// if we aren't viewing a room with an ongoing call, but there is an
58+
// active call, show the call element - we need to do this to make
59+
// audio/video not crap out
60+
var activeCall = CallHandler.getAnyActiveCall();
61+
var callForRoom = CallHandler.getCallForRoom(selectedRoomId);
62+
var showCall = (activeCall && !callForRoom);
63+
this.setState({
64+
showCallElement: showCall
65+
});
66+
},
67+
2668
onHideClick: function() {
2769
dis.dispatch({
2870
action: 'hide_left_panel',
@@ -44,10 +86,17 @@ module.exports = React.createClass({
4486
// collapseButton = <img className="mx_LeftPanel_hideButton" onClick={ this.onHideClick } src="img/hide.png" width="12" height="20" alt="<"/>
4587
}
4688

89+
var callPreview;
90+
if (this.state.showCallElement) {
91+
var CallView = sdk.getComponent('molecules.voip.CallView');
92+
callPreview = <CallView className="mx_LeftPanel_callView"/>
93+
}
94+
4795
return (
4896
<aside className={classes}>
4997
{ collapseButton }
5098
<IncomingCallBox />
99+
{ callPreview }
51100
<RoomList selectedRoom={this.props.selectedRoom} collapsed={this.props.collapsed}/>
52101
<BottomLeftMenu collapsed={this.props.collapsed}/>
53102
</aside>

0 commit comments

Comments
 (0)