Skip to content

Commit c687f32

Browse files
committed
Port over custom vector roomlist controller with mini callview
1 parent 3845a98 commit c687f32

2 files changed

Lines changed: 170 additions & 1 deletion

File tree

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
'use strict';
18+
19+
var React = require("react");
20+
var MatrixClientPeg = require("matrix-react-sdk/lib/MatrixClientPeg");
21+
var RoomListSorter = require("matrix-react-sdk/lib/RoomListSorter");
22+
var dis = require("matrix-react-sdk/lib/dispatcher");
23+
24+
var sdk = require('matrix-react-sdk');
25+
var VectorConferenceHandler = require("../../modules/VectorConferenceHandler");
26+
var CallHandler = require("matrix-react-sdk/lib/CallHandler");
27+
28+
var HIDE_CONFERENCE_CHANS = true;
29+
30+
module.exports = {
31+
componentWillMount: function() {
32+
var cli = MatrixClientPeg.get();
33+
cli.on("Room", this.onRoom);
34+
cli.on("Room.timeline", this.onRoomTimeline);
35+
cli.on("Room.name", this.onRoomName);
36+
37+
var rooms = this.getRoomList();
38+
this.setState({
39+
roomList: rooms,
40+
activityMap: {}
41+
});
42+
},
43+
44+
componentDidMount: function() {
45+
this.dispatcherRef = dis.register(this.onAction);
46+
},
47+
48+
onAction: function(payload) {
49+
switch (payload.action) {
50+
// listen for call state changes to prod the render method, which
51+
// may hide the global CallView if the call it is tracking is dead
52+
case 'call_state':
53+
this._recheckCallElement(this.props.selectedRoom);
54+
break;
55+
}
56+
},
57+
58+
componentWillUnmount: function() {
59+
dis.unregister(this.dispatcherRef);
60+
if (MatrixClientPeg.get()) {
61+
MatrixClientPeg.get().removeListener("Room", this.onRoom);
62+
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
63+
MatrixClientPeg.get().removeListener("Room.name", this.onRoomName);
64+
}
65+
},
66+
67+
componentWillReceiveProps: function(newProps) {
68+
this.state.activityMap[newProps.selectedRoom] = undefined;
69+
this._recheckCallElement(newProps.selectedRoom);
70+
this.setState({
71+
activityMap: this.state.activityMap
72+
});
73+
},
74+
75+
onRoom: function(room) {
76+
this.refreshRoomList();
77+
},
78+
79+
onRoomTimeline: function(ev, room, toStartOfTimeline) {
80+
if (toStartOfTimeline) return;
81+
82+
var newState = {
83+
roomList: this.getRoomList()
84+
};
85+
if (
86+
room.roomId != this.props.selectedRoom &&
87+
ev.getSender() != MatrixClientPeg.get().credentials.userId)
88+
{
89+
var hl = 1;
90+
91+
var actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
92+
if (actions && actions.tweaks && actions.tweaks.highlight) {
93+
hl = 2;
94+
}
95+
// obviously this won't deep copy but this shouldn't be necessary
96+
var amap = this.state.activityMap;
97+
amap[room.roomId] = Math.max(amap[room.roomId] || 0, hl);
98+
99+
newState.activityMap = amap;
100+
}
101+
this.setState(newState);
102+
},
103+
104+
onRoomName: function(room) {
105+
this.refreshRoomList();
106+
},
107+
108+
refreshRoomList: function() {
109+
var rooms = this.getRoomList();
110+
this.setState({
111+
roomList: rooms
112+
});
113+
},
114+
115+
getRoomList: function() {
116+
return RoomListSorter.mostRecentActivityFirst(
117+
MatrixClientPeg.get().getRooms().filter(function(room) {
118+
var me = room.getMember(MatrixClientPeg.get().credentials.userId);
119+
var shouldShowRoom = (
120+
me && (me.membership == "join" || me.membership == "invite")
121+
);
122+
// hiding conf rooms only ever toggles shouldShowRoom to false
123+
if (shouldShowRoom && HIDE_CONFERENCE_CHANS) {
124+
// we want to hide the 1:1 conf<->user room and not the group chat
125+
var joinedMembers = room.getJoinedMembers();
126+
if (joinedMembers.length === 2) {
127+
var otherMember = joinedMembers.filter(function(m) {
128+
return m.userId !== me.userId
129+
})[0];
130+
if (VectorConferenceHandler.isConferenceUser(otherMember)) {
131+
// console.log("Hiding conference 1:1 room %s", room.roomId);
132+
shouldShowRoom = false;
133+
}
134+
}
135+
}
136+
return shouldShowRoom;
137+
})
138+
);
139+
},
140+
141+
_recheckCallElement: function(selectedRoomId) {
142+
// if we aren't viewing a room with an ongoing call, but there is an
143+
// active call, show the call element - we need to do this to make
144+
// audio/video not crap out
145+
var activeCall = CallHandler.getAnyActiveCall();
146+
var callForRoom = CallHandler.getCallForRoom(selectedRoomId);
147+
var showCall = (activeCall && !callForRoom);
148+
this.setState({
149+
show_call_element: showCall
150+
});
151+
},
152+
153+
makeRoomTiles: function() {
154+
var self = this;
155+
var RoomTile = sdk.getComponent("molecules.RoomTile");
156+
return this.state.roomList.map(function(room) {
157+
var selected = room.roomId == self.props.selectedRoom;
158+
return (
159+
<RoomTile
160+
room={room}
161+
key={room.roomId}
162+
selected={selected}
163+
unread={self.state.activityMap[room.roomId] === 1}
164+
highlight={self.state.activityMap[room.roomId] === 2}
165+
/>
166+
);
167+
});
168+
}
169+
};

src/skins/vector/views/organisms/RoomList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
var React = require('react');
2020
var sdk = require('matrix-react-sdk')
2121

22-
var RoomListController = require('matrix-react-sdk/lib/controllers/organisms/RoomList')
22+
var RoomListController = require('../../../../controllers/organisms/RoomList')
2323

2424
module.exports = React.createClass({
2525
displayName: 'RoomList',

0 commit comments

Comments
 (0)