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

Commit 7f3b593

Browse files
authored
Merge pull request #2044 from matrix-org/t3chguy/optional_new_behaviour_roomsublist
make new hiding of roomsublist behaviour opt-in
2 parents 6e92cc3 + 168edbc commit 7f3b593

File tree

5 files changed

+69
-56
lines changed

5 files changed

+69
-56
lines changed

src/components/structures/RoomSubList.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import * as RoomNotifs from '../../RoomNotifs';
2727
import * as FormattingUtils from '../../utils/FormattingUtils';
2828
import { KeyCode } from '../../Keyboard';
2929
import { Group } from 'matrix-js-sdk';
30+
import PropTypes from 'prop-types';
3031

3132

3233
// turn this on for drop & drag console debugging galore
@@ -40,27 +41,28 @@ const RoomSubList = React.createClass({
4041
debug: debug,
4142

4243
propTypes: {
43-
list: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
44-
label: React.PropTypes.string.isRequired,
45-
tagName: React.PropTypes.string,
46-
editable: React.PropTypes.bool,
44+
list: PropTypes.arrayOf(PropTypes.object).isRequired,
45+
label: PropTypes.string.isRequired,
46+
tagName: PropTypes.string,
47+
editable: PropTypes.bool,
4748

48-
order: React.PropTypes.string.isRequired,
49+
order: PropTypes.string.isRequired,
4950

5051
// passed through to RoomTile and used to highlight room with `!` regardless of notifications count
51-
isInvite: React.PropTypes.bool,
52-
53-
startAsHidden: React.PropTypes.bool,
54-
showSpinner: React.PropTypes.bool, // true to show a spinner if 0 elements when expanded
55-
collapsed: React.PropTypes.bool.isRequired, // is LeftPanel collapsed?
56-
onHeaderClick: React.PropTypes.func,
57-
alwaysShowHeader: React.PropTypes.bool,
58-
incomingCall: React.PropTypes.object,
59-
onShowMoreRooms: React.PropTypes.func,
60-
searchFilter: React.PropTypes.string,
61-
emptyContent: React.PropTypes.node, // content shown if the list is empty
62-
headerItems: React.PropTypes.node, // content shown in the sublist header
63-
extraTiles: React.PropTypes.arrayOf(React.PropTypes.node), // extra elements added beneath tiles
52+
isInvite: PropTypes.bool,
53+
54+
startAsHidden: PropTypes.bool,
55+
showSpinner: PropTypes.bool, // true to show a spinner if 0 elements when expanded
56+
collapsed: PropTypes.bool.isRequired, // is LeftPanel collapsed?
57+
onHeaderClick: PropTypes.func,
58+
alwaysShowHeader: PropTypes.bool,
59+
incomingCall: PropTypes.object,
60+
onShowMoreRooms: PropTypes.func,
61+
searchFilter: PropTypes.string,
62+
emptyContent: PropTypes.node, // content shown if the list is empty
63+
headerItems: PropTypes.node, // content shown in the sublist header
64+
extraTiles: PropTypes.arrayOf(PropTypes.node), // extra elements added beneath tiles
65+
showEmpty: PropTypes.bool,
6466
},
6567

6668
getInitialState: function() {
@@ -79,6 +81,7 @@ const RoomSubList = React.createClass({
7981
}, // NOP
8082
extraTiles: [],
8183
isInvite: false,
84+
showEmpty: true,
8285
};
8386
},
8487

@@ -392,17 +395,29 @@ const RoomSubList = React.createClass({
392395
const TruncatedList = sdk.getComponent('elements.TruncatedList');
393396

394397
let content;
395-
if (this.state.sortedList.length === 0 && this.props.extraTiles.length === 0) {
396-
// if no search filter is applied and there is a placeholder defined then show it, otherwise show nothing
397-
if (!this.props.searchFilter && this.props.emptyContent) {
398+
399+
if (this.props.showEmpty) {
400+
// this is new behaviour with still controversial UX in that in hiding RoomSubLists the drop zones for DnD
401+
// are also gone so when filtering users can't DnD rooms to some tags but is a lot cleaner otherwise.
402+
if (this.state.sortedList.length === 0 && !this.props.searchFilter && this.props.extraTiles.length === 0) {
398403
content = this.props.emptyContent;
399404
} else {
400-
// don't show an empty sublist
401-
return null;
405+
content = this.makeRoomTiles();
406+
content.push(...this.props.extraTiles);
402407
}
403408
} else {
404-
content = this.makeRoomTiles();
405-
content.push(...this.props.extraTiles);
409+
if (this.state.sortedList.length === 0 && this.props.extraTiles.length === 0) {
410+
// if no search filter is applied and there is a placeholder defined then show it, otherwise show nothing
411+
if (!this.props.searchFilter && this.props.emptyContent) {
412+
content = this.props.emptyContent;
413+
} else {
414+
// don't show an empty sublist
415+
return null;
416+
}
417+
} else {
418+
content = this.makeRoomTiles();
419+
content.push(...this.props.extraTiles);
420+
}
406421
}
407422

408423
if (this.state.sortedList.length > 0 || this.props.extraTiles.length > 0 || this.props.editable) {

src/components/structures/UserSettings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const SIMPLE_SETTINGS = [
8181
{ id: "VideoView.flipVideoHorizontally" },
8282
{ id: "TagPanel.disableTagPanel" },
8383
{ id: "enableWidgetScreenshots" },
84+
{ id: "RoomSubList.showEmpty" },
8485
];
8586

8687
// These settings must be defined in SettingsStore

src/components/views/rooms/RoomList.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616
*/
1717

1818
'use strict';
19+
import SettingsStore from "../../../settings/SettingsStore";
20+
1921
const React = require("react");
2022
const ReactDOM = require("react-dom");
2123
import PropTypes from 'prop-types';
@@ -608,6 +610,10 @@ module.exports = React.createClass({
608610
const RoomSubList = sdk.getComponent('structures.RoomSubList');
609611
const GeminiScrollbarWrapper = sdk.getComponent("elements.GeminiScrollbarWrapper");
610612

613+
// XXX: we can't detect device-level (localStorage) settings onChange as the SettingsStore does not notify
614+
// so checking on every render is the sanest thing at this time.
615+
const showEmpty = SettingsStore.getValue('RoomSubList.showEmpty');
616+
611617
const self = this;
612618
return (
613619
<GeminiScrollbarWrapper className="mx_RoomList_scrollbar"
@@ -623,6 +629,7 @@ module.exports = React.createClass({
623629
searchFilter={self.props.searchFilter}
624630
onHeaderClick={self.onSubListHeaderClick}
625631
onShowMoreRooms={self.onShowMoreRooms}
632+
showEmpty={showEmpty}
626633
/>
627634

628635
<RoomSubList list={self.state.lists['im.vector.fake.invite']}
@@ -635,6 +642,7 @@ module.exports = React.createClass({
635642
searchFilter={self.props.searchFilter}
636643
onHeaderClick={self.onSubListHeaderClick}
637644
onShowMoreRooms={self.onShowMoreRooms}
645+
showEmpty={showEmpty}
638646
/>
639647

640648
<RoomSubList list={self.state.lists['m.favourite']}
@@ -647,7 +655,8 @@ module.exports = React.createClass({
647655
collapsed={self.props.collapsed}
648656
searchFilter={self.props.searchFilter}
649657
onHeaderClick={self.onSubListHeaderClick}
650-
onShowMoreRooms={self.onShowMoreRooms} />
658+
onShowMoreRooms={self.onShowMoreRooms}
659+
showEmpty={showEmpty} />
651660

652661
<RoomSubList list={self.state.lists['im.vector.fake.direct']}
653662
label={_t('People')}
@@ -661,7 +670,8 @@ module.exports = React.createClass({
661670
alwaysShowHeader={true}
662671
searchFilter={self.props.searchFilter}
663672
onHeaderClick={self.onSubListHeaderClick}
664-
onShowMoreRooms={self.onShowMoreRooms} />
673+
onShowMoreRooms={self.onShowMoreRooms}
674+
showEmpty={showEmpty} />
665675

666676
<RoomSubList list={self.state.lists['im.vector.fake.recent']}
667677
label={_t('Rooms')}
@@ -673,7 +683,8 @@ module.exports = React.createClass({
673683
collapsed={self.props.collapsed}
674684
searchFilter={self.props.searchFilter}
675685
onHeaderClick={self.onSubListHeaderClick}
676-
onShowMoreRooms={self.onShowMoreRooms} />
686+
onShowMoreRooms={self.onShowMoreRooms}
687+
showEmpty={showEmpty} />
677688

678689
{ Object.keys(self.state.lists).map((tagName) => {
679690
if (!tagName.match(STANDARD_TAGS_REGEX)) {
@@ -688,7 +699,8 @@ module.exports = React.createClass({
688699
collapsed={self.props.collapsed}
689700
searchFilter={self.props.searchFilter}
690701
onHeaderClick={self.onSubListHeaderClick}
691-
onShowMoreRooms={self.onShowMoreRooms} />;
702+
onShowMoreRooms={self.onShowMoreRooms}
703+
showEmpty={showEmpty} />;
692704
}
693705
}) }
694706

@@ -702,7 +714,8 @@ module.exports = React.createClass({
702714
collapsed={self.props.collapsed}
703715
searchFilter={self.props.searchFilter}
704716
onHeaderClick={self.onSubListHeaderClick}
705-
onShowMoreRooms={self.onShowMoreRooms} />
717+
onShowMoreRooms={self.onShowMoreRooms}
718+
showEmpty={showEmpty} />
706719

707720
<RoomSubList list={self.state.lists['im.vector.fake.archived']}
708721
emptyContent={self.props.collapsed ? null :
@@ -722,7 +735,8 @@ module.exports = React.createClass({
722735
onHeaderClick={self.onArchivedHeaderClick}
723736
incomingCall={self.state.incomingCall}
724737
searchFilter={self.props.searchFilter}
725-
onShowMoreRooms={self.onShowMoreRooms} />
738+
onShowMoreRooms={self.onShowMoreRooms}
739+
showEmpty={showEmpty} />
726740
</div>
727741
</GeminiScrollbarWrapper>
728742
);

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
"Enable URL previews by default for participants in this room": "Enable URL previews by default for participants in this room",
235235
"Room Colour": "Room Colour",
236236
"Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets",
237+
"Show empty room list headings": "Show empty room list headings",
237238
"Collecting app version information": "Collecting app version information",
238239
"Collecting logs": "Collecting logs",
239240
"Uploading report": "Uploading report",
@@ -335,7 +336,9 @@
335336
"You have <a>disabled</a> URL previews by default.": "You have <a>disabled</a> URL previews by default.",
336337
"URL previews are enabled by default for participants in this room.": "URL previews are enabled by default for participants in this room.",
337338
"URL previews are disabled by default for participants in this room.": "URL previews are disabled by default for participants in this room.",
339+
"In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.": "In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.",
338340
"URL Previews": "URL Previews",
341+
"When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website.": "When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website.",
339342
"Cannot add any more widgets": "Cannot add any more widgets",
340343
"The maximum permitted number of widgets have already been added to this room.": "The maximum permitted number of widgets have already been added to this room.",
341344
"Add a widget": "Add a widget",
@@ -575,31 +578,6 @@
575578
"Scroll to unread messages": "Scroll to unread messages",
576579
"Jump to first unread message.": "Jump to first unread message.",
577580
"Close": "Close",
578-
"Invalid alias format": "Invalid alias format",
579-
"'%(alias)s' is not a valid format for an alias": "'%(alias)s' is not a valid format for an alias",
580-
"Invalid address format": "Invalid address format",
581-
"'%(alias)s' is not a valid format for an address": "'%(alias)s' is not a valid format for an address",
582-
"not specified": "not specified",
583-
"not set": "not set",
584-
"Remote addresses for this room:": "Remote addresses for this room:",
585-
"Addresses": "Addresses",
586-
"The main address for this room is": "The main address for this room is",
587-
"Local addresses for this room:": "Local addresses for this room:",
588-
"This room has no local addresses": "This room has no local addresses",
589-
"New address (e.g. #foo:%(localDomain)s)": "New address (e.g. #foo:%(localDomain)s)",
590-
"Invalid community ID": "Invalid community ID",
591-
"'%(groupId)s' is not a valid community ID": "'%(groupId)s' is not a valid community ID",
592-
"Flair": "Flair",
593-
"Showing flair for these communities:": "Showing flair for these communities:",
594-
"This room is not showing flair for any communities": "This room is not showing flair for any communities",
595-
"New community ID (e.g. +foo:%(localDomain)s)": "New community ID (e.g. +foo:%(localDomain)s)",
596-
"You have <a>enabled</a> URL previews by default.": "You have <a>enabled</a> URL previews by default.",
597-
"You have <a>disabled</a> URL previews by default.": "You have <a>disabled</a> URL previews by default.",
598-
"URL previews are enabled by default for participants in this room.": "URL previews are enabled by default for participants in this room.",
599-
"URL previews are disabled by default for participants in this room.": "URL previews are disabled by default for participants in this room.",
600-
"In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.": "In encrypted rooms, like this one, URL previews are disabled by default to ensure that your homeserver (where the previews are generated) cannot gather information about links you see in this room.",
601-
"URL Previews": "URL Previews",
602-
"When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website.": "When someone puts a URL in their message, a URL preview can be shown to give more information about that link such as the title, description, and an image from the website.",
603581
"Sunday": "Sunday",
604582
"Monday": "Monday",
605583
"Tuesday": "Tuesday",

src/settings/Settings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,9 @@ export const SETTINGS = {
284284
supportedLevels: ['room-device'],
285285
default: false,
286286
},
287+
"RoomSubList.showEmpty": {
288+
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
289+
displayName: _td('Show empty room list headings'),
290+
default: true,
291+
},
287292
};

0 commit comments

Comments
 (0)