Skip to content

Commit 1bc1fc7

Browse files
authored
Merge pull request element-hq#2028 from vector-im/wmwragg/direct-chat-sublist
Wmwragg/direct chat sublist
2 parents 5f233d7 + b91a0dd commit 1bc1fc7

6 files changed

Lines changed: 259 additions & 51 deletions

File tree

‎src/components/structures/RoomSubList.js‎

Lines changed: 132 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ limitations under the License.
1717
'use strict';
1818

1919
var React = require('react');
20+
var ReactDOM = require('react-dom');
21+
var classNames = require('classnames');
2022
var DropTarget = require('react-dnd').DropTarget;
2123
var sdk = require('matrix-react-sdk')
2224
var dis = require('matrix-react-sdk/lib/dispatcher');
2325
var Unread = require('matrix-react-sdk/lib/Unread');
2426
var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg');
27+
var RoomNotifs = require('matrix-react-sdk/lib/RoomNotifs');
2528

2629
// turn this on for drop & drag console debugging galore
2730
var debug = false;
2831

32+
const TRUNCATE_AT = 10;
33+
2934
var roomListTarget = {
3035
canDrop: function() {
3136
return true;
@@ -80,7 +85,8 @@ var RoomSubList = React.createClass({
8085
getInitialState: function() {
8186
return {
8287
hidden: this.props.startAsHidden || false,
83-
truncateAt: 20,
88+
capTruncate: this.props.list.length > TRUNCATE_AT,
89+
truncateAt: this.props.list.length > TRUNCATE_AT ? TRUNCATE_AT : -1,
8490
sortedList: [],
8591
};
8692
},
@@ -109,17 +115,62 @@ var RoomSubList = React.createClass({
109115
});
110116
},
111117

118+
// The header is collapsable if it is hidden or not stuck
119+
// The dataset elements are added in the RoomList _initAndPositionStickyHeaders method
120+
isCollapsableOnClick: function() {
121+
var stuck = this.refs.header.dataset.stuck;
122+
if (this.state.hidden || stuck === undefined || stuck === "none") {
123+
return true;
124+
} else {
125+
return false;
126+
}
127+
},
128+
112129
onClick: function(ev) {
113-
var isHidden = !this.state.hidden;
114-
this.setState({ hidden : isHidden });
130+
if (this.isCollapsableOnClick()) {
131+
// The header iscCollapsable, so the click is to be interpreted as collapse and truncation logic
132+
var isHidden = false;
133+
var isTruncatable = this.props.list.length > TRUNCATE_AT;
134+
135+
if (this.state.hidden && (this.state.capTruncate && isTruncatable)) {
136+
isHidden = false;
137+
this.setState({
138+
hidden : isHidden,
139+
capTruncate : true,
140+
truncateAt : TRUNCATE_AT
141+
});
142+
} else if ((!this.state.hidden && this.state.capTruncate)
143+
|| (this.state.hidden && (this.state.capTruncate && !isTruncatable)))
144+
{
145+
isHidden = false;
146+
this.setState({
147+
hidden : isHidden,
148+
capTruncate : false,
149+
truncateAt : -1
150+
});
151+
} else if (!this.state.hidden && !this.state.capTruncate) {
152+
isHidden = true;
153+
this.setState({
154+
hidden : isHidden,
155+
capTruncate : true,
156+
truncateAt : TRUNCATE_AT
157+
});
158+
} else {
159+
// Catch any weird states the system gets into
160+
isHidden = false;
161+
this.setState({
162+
hidden : isHidden,
163+
capTruncate : true,
164+
truncateAt : TRUNCATE_AT
165+
});
166+
}
115167

116-
if (isHidden) {
117-
// as good a way as any to reset the truncate state
118-
this.setState({ truncateAt : 20 });
119168
this.props.onShowMoreRooms();
169+
this.props.onHeaderClick(isHidden);
170+
} else {
171+
// The header is stuck, so the click is to be interpreted as a scroll to the header
172+
this.props.onHeaderClick(this.state.hidden, this.refs.header.dataset.originalPosition);
120173
}
121-
122-
this.props.onHeaderClick(isHidden);
123174
},
124175

125176
tsOfNewestEvent: function(room) {
@@ -186,6 +237,44 @@ var RoomSubList = React.createClass({
186237
this.setState({ sortedList: list.sort(comparator) });
187238
},
188239

240+
_shouldShowNotifBadge: function(roomNotifState) {
241+
const showBadgeInStates = [RoomNotifs.ALL_MESSAGES, RoomNotifs.ALL_MESSAGES_LOUD];
242+
return showBadgeInStates.indexOf(roomNotifState) > -1;
243+
},
244+
245+
_shouldShowMentionBadge: function(roomNotifState) {
246+
return roomNotifState != RoomNotifs.MUTE;
247+
},
248+
249+
roomNotificationCount: function() {
250+
var self = this;
251+
252+
return this.props.list.reduce(function(result, room) {
253+
var roomNotifState = RoomNotifs.getRoomNotifsState(room.roomId);
254+
var highlight = room.getUnreadNotificationCount('highlight') > 0 || self.props.label === 'Invites';
255+
var notificationCount = room.getUnreadNotificationCount();
256+
257+
const notifBadges = notificationCount > 0 && self._shouldShowNotifBadge(roomNotifState);
258+
const mentionBadges = highlight && self._shouldShowMentionBadge(roomNotifState);
259+
const badges = notifBadges || mentionBadges;
260+
261+
if (badges) {
262+
result[0] += notificationCount;
263+
if (highlight) {
264+
result[1] = true;
265+
}
266+
}
267+
return result;
268+
}, [0, false]);
269+
},
270+
271+
_updateSubListCount: function() {
272+
// Force an update by setting the state to the current state
273+
// Doing it this way rather than using forceUpdate(), so that the shouldComponentUpdate()
274+
// method is honoured
275+
this.setState(this.state);
276+
},
277+
189278
moveRoomTile: function(room, atIndex) {
190279
if (debug) console.log("moveRoomTile: id " + room.roomId + ", atIndex " + atIndex);
191280
//console.log("moveRoomTile before: " + JSON.stringify(this.state.rooms));
@@ -293,42 +382,55 @@ var RoomSubList = React.createClass({
293382
unread={ Unread.doesRoomHaveUnreadMessages(room) }
294383
highlight={ room.getUnreadNotificationCount('highlight') > 0 || self.props.label === 'Invites' }
295384
isInvite={ self.props.label === 'Invites' }
385+
refreshSubList={ self._updateSubListCount }
296386
incomingCall={ self.props.incomingCall && (self.props.incomingCall.roomId === room.roomId) ? self.props.incomingCall : null } />
297387
);
298388
});
299389
},
300390

301391
_getHeaderJsx: function() {
302392
var TintableSvg = sdk.getComponent("elements.TintableSvg");
303-
return (
304-
<h2 onClick={ this.onClick } className="mx_RoomSubList_label">
305-
{ this.props.collapsed ? '' : this.props.label }
306-
<img className="mx_RoomSubList_chevron"
307-
src={ this.state.hidden ? "img/list-close.svg" : "img/list-open.svg" }
308-
width="10" height="10" />
309-
</h2>
310-
);
311-
},
312393

313-
_createOverflowTile: function(overflowCount, totalCount) {
314-
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
315-
// XXX: this is duplicated from RoomTile - factor it out
394+
var subListNotifications = this.roomNotificationCount();
395+
var subListNotifCount = subListNotifications[0];
396+
var subListNotifHighlight = subListNotifications[1];
397+
398+
var roomCount = this.props.list.length > 0 ? this.props.list.length : '';
399+
var isTruncatable = this.props.list.length > TRUNCATE_AT;
400+
if (!this.state.hidden && this.state.capTruncate && isTruncatable) {
401+
roomCount = TRUNCATE_AT + " of " + roomCount;
402+
}
403+
404+
var chevronClasses = classNames({
405+
'mx_RoomSubList_chevron': true,
406+
'mx_RoomSubList_chevronUp': this.state.hidden,
407+
'mx_RoomSubList_chevronRight': !this.state.hidden && this.state.capTruncate,
408+
'mx_RoomSubList_chevronDown': !this.state.hidden && !this.state.capTruncate,
409+
});
410+
411+
var badgeClasses = classNames({
412+
'mx_RoomSubList_badge': true,
413+
'mx_RoomSubList_badgeHighlight': subListNotifHighlight,
414+
});
415+
416+
var badge;
417+
if (subListNotifCount > 0) {
418+
badge = <div className={badgeClasses}>{subListNotifCount > 99 ? "99+" : subListNotifCount}</div>;
419+
}
420+
316421
return (
317-
<div className="mx_RoomTile mx_RoomTile_ellipsis" onClick={this._showFullMemberList}>
318-
<div className="mx_RoomTile_avatar">
319-
<BaseAvatar url="img/ellipsis.svg" name="..." width={24} height={24} />
422+
<div className="mx_RoomSubList_labelContainer" ref="header">
423+
<div onClick={ this.onClick } className="mx_RoomSubList_label">
424+
{ this.props.collapsed ? '' : this.props.label }
425+
<div className="mx_RoomSubList_roomCount">{roomCount}</div>
426+
<div className={chevronClasses}></div>
427+
{badge}
320428
</div>
321-
<div className="mx_RoomTile_name">and { overflowCount } others...</div>
322429
</div>
323430
);
324431
},
325432

326-
_showFullMemberList: function() {
327-
this.setState({
328-
truncateAt: -1
329-
});
330-
this.props.onShowMoreRooms();
331-
},
433+
_createOverflowTile: function() {}, // NOP
332434

333435
// Fix any undefined order elements of a room in a manual ordered list
334436
// room.tag[tagname].order

‎src/skins/vector/css/matrix-react-sdk/structures/SearchBox.css‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ limitations under the License.
2020
margin-right: 16px;
2121
padding-top: 24px;
2222
padding-bottom: 22px;
23-
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
2423

2524
display: flex;
2625
display: -webkit-flex;

‎src/skins/vector/css/matrix-react-sdk/views/rooms/RoomList.css‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
.mx_RoomList {
18-
padding-top: 8px;
1918
padding-bottom: 12px;
2019
min-height: 400px;
2120
}
@@ -33,3 +32,8 @@ limitations under the License.
3332
overflow-x: hidden ! important;
3433
overflow-y: scroll ! important;
3534
}
35+
36+
/* Make sure the scrollbar is above the sticky headers from RoomList */
37+
.mx_RoomList_scrollbar .gm-scrollbar.-vertical {
38+
z-index: 5;
39+
}

‎src/skins/vector/css/matrix-react-sdk/views/rooms/RoomTile.css‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ limitations under the License.
109109
}
110110

111111
.collapsed .mx_RoomTile_badge {
112-
top: -2px;
112+
top: 0px;
113113
min-width: 12px;
114-
height: 16px;
115114
border-radius: 16px;
116115
padding: 0px 4px 0px 4px;
117116
z-index: 200;
@@ -129,22 +128,22 @@ limitations under the License.
129128
display: block;
130129
width: 0;
131130
height: 0;
132-
margin-left: 6px;
133-
border-top: 8px solid #ff0064;
134-
border-right: 10px solid transparent;
131+
margin-left: 5px;
132+
border-top: 5px solid #ff0064;
133+
border-right: 7px solid transparent;
135134
}
136135

137136
.mx_RoomTile_badge {
138137
display: inline-block;
139-
min-width: 19px;
140-
height: 17px;
138+
min-width: 15px;
139+
height: 15px;
141140
position: absolute;
142141
right: 8px; /*gutter */
143142
top: 9px;
144-
border-radius: 14px;
143+
border-radius: 8px;
145144
color: #fff;
146145
font-weight: 600;
147-
font-size: 11px;
146+
font-size: 10px;
148147
text-align: center;
149148
padding-top: 1px;
150149
padding-left: 4px;
@@ -175,7 +174,7 @@ limitations under the License.
175174
}
176175

177176
.mx_RoomTile_selected {
178-
background-color: rgba(118,207,166,0.2);
177+
background-color: rgba(255, 255, 255, 0.8);
179178
}
180179

181180
.mx_RoomTile .mx_RoomTile_name.mx_RoomTile_badgeShown {
@@ -187,5 +186,3 @@ limitations under the License.
187186
right: 0px;
188187
}
189188

190-
.mx_RoomTile:hover {
191-
}

‎src/skins/vector/css/vector-web/structures/LeftPanel.css‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ limitations under the License.
4949
flex: 1 1 0;
5050

5151
overflow-y: auto;
52+
z-index: 5;
5253
}
5354

5455
.mx_LeftPanel.collapsed .mx_BottomLeftMenu {
@@ -62,7 +63,7 @@ limitations under the License.
6263
-webkit-order: 3;
6364
order: 3;
6465

65-
border-top: 1px solid rgba(0, 0, 0, 0.1);
66+
border-top: 1px solid rgba(118, 207, 166, 0.2);
6667
margin-left: 16px; /* gutter */
6768
margin-right: 16px; /* gutter */
6869
-webkit-flex: 0 0 60px;

0 commit comments

Comments
 (0)