Override the room directory with the selected group's rooms
This commit is contained in:
parent
dc95ca6776
commit
1b5abdab23
1 changed files with 88 additions and 29 deletions
|
@ -30,6 +30,10 @@ import { instanceForInstanceId, protocolNameForInstanceId } from '../../utils/Di
|
||||||
import Analytics from '../../Analytics';
|
import Analytics from '../../Analytics';
|
||||||
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
|
||||||
import {ALL_ROOMS} from "../views/directory/NetworkDropdown";
|
import {ALL_ROOMS} from "../views/directory/NetworkDropdown";
|
||||||
|
import SettingsStore from "../../settings/SettingsStore";
|
||||||
|
import TagOrderStore from "../../stores/TagOrderStore";
|
||||||
|
import GroupStore from "../../stores/GroupStore";
|
||||||
|
import FlairStore from "../../stores/FlairStore";
|
||||||
|
|
||||||
const MAX_NAME_LENGTH = 80;
|
const MAX_NAME_LENGTH = 80;
|
||||||
const MAX_TOPIC_LENGTH = 160;
|
const MAX_TOPIC_LENGTH = 160;
|
||||||
|
@ -46,6 +50,7 @@ export default createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
const selectedCommunityId = TagOrderStore.getSelectedTags()[0];
|
||||||
return {
|
return {
|
||||||
publicRooms: [],
|
publicRooms: [],
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -54,6 +59,10 @@ export default createReactClass({
|
||||||
instanceId: undefined,
|
instanceId: undefined,
|
||||||
roomServer: MatrixClientPeg.getHomeserverName(),
|
roomServer: MatrixClientPeg.getHomeserverName(),
|
||||||
filterString: null,
|
filterString: null,
|
||||||
|
selectedCommunityId: SettingsStore.getValue("feature_communities_v2_prototypes")
|
||||||
|
? selectedCommunityId
|
||||||
|
: null,
|
||||||
|
communityName: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -71,28 +80,39 @@ export default createReactClass({
|
||||||
this.setState({protocolsLoading: false});
|
this.setState({protocolsLoading: false});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MatrixClientPeg.get().getThirdpartyProtocols().then((response) => {
|
|
||||||
this.protocols = response;
|
if (!this.state.selectedCommunityId) {
|
||||||
this.setState({protocolsLoading: false});
|
MatrixClientPeg.get().getThirdpartyProtocols().then((response) => {
|
||||||
}, (err) => {
|
this.protocols = response;
|
||||||
console.warn(`error loading third party protocols: ${err}`);
|
this.setState({protocolsLoading: false});
|
||||||
this.setState({protocolsLoading: false});
|
}, (err) => {
|
||||||
if (MatrixClientPeg.get().isGuest()) {
|
console.warn(`error loading third party protocols: ${err}`);
|
||||||
// Guests currently aren't allowed to use this API, so
|
this.setState({protocolsLoading: false});
|
||||||
// ignore this as otherwise this error is literally the
|
if (MatrixClientPeg.get().isGuest()) {
|
||||||
// thing you see when loading the client!
|
// Guests currently aren't allowed to use this API, so
|
||||||
return;
|
// ignore this as otherwise this error is literally the
|
||||||
}
|
// thing you see when loading the client!
|
||||||
track('Failed to get protocol list from homeserver');
|
return;
|
||||||
const brand = SdkConfig.get().brand;
|
}
|
||||||
this.setState({
|
track('Failed to get protocol list from homeserver');
|
||||||
error: _t(
|
const brand = SdkConfig.get().brand;
|
||||||
'%(brand)s failed to get the protocol list from the homeserver. ' +
|
this.setState({
|
||||||
'The homeserver may be too old to support third party networks.',
|
error: _t(
|
||||||
{ brand },
|
'%(brand)s failed to get the protocol list from the homeserver. ' +
|
||||||
),
|
'The homeserver may be too old to support third party networks.',
|
||||||
|
{brand},
|
||||||
|
),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
// We don't use the protocols in the communities v2 prototype experience
|
||||||
|
this.setState({protocolsLoading: false});
|
||||||
|
|
||||||
|
// Grab the profile info async
|
||||||
|
FlairStore.getGroupProfileCached(MatrixClientPeg.get(), this.state.selectedCommunityId).then(profile => {
|
||||||
|
this.setState({communityName: profile.name});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.refreshRoomList();
|
this.refreshRoomList();
|
||||||
},
|
},
|
||||||
|
@ -105,6 +125,33 @@ export default createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshRoomList: function() {
|
refreshRoomList: function() {
|
||||||
|
if (this.state.selectedCommunityId) {
|
||||||
|
this.setState({
|
||||||
|
publicRooms: GroupStore.getGroupRooms(this.state.selectedCommunityId).map(r => {
|
||||||
|
return {
|
||||||
|
// Translate all the group properties to the directory format
|
||||||
|
room_id: r.roomId,
|
||||||
|
name: r.name,
|
||||||
|
topic: r.topic,
|
||||||
|
canonical_alias: r.canonicalAlias,
|
||||||
|
num_joined_members: r.numJoinedMembers,
|
||||||
|
avatarUrl: r.avatarUrl,
|
||||||
|
world_readable: r.worldReadable,
|
||||||
|
guest_can_join: r.guestsCanJoin,
|
||||||
|
};
|
||||||
|
}).filter(r => {
|
||||||
|
const filterString = this.state.filterString;
|
||||||
|
if (filterString) {
|
||||||
|
const containedIn = (s: string) => (s || "").toLowerCase().includes(filterString.toLowerCase());
|
||||||
|
return containedIn(r.name) || containedIn(r.topic) || containedIn(r.canonical_alias);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
loading: false,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.nextBatch = null;
|
this.nextBatch = null;
|
||||||
this.setState({
|
this.setState({
|
||||||
publicRooms: [],
|
publicRooms: [],
|
||||||
|
@ -114,6 +161,7 @@ export default createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
getMoreRooms: function() {
|
getMoreRooms: function() {
|
||||||
|
if (this.state.selectedCommunityId) return Promise.resolve(); // no more rooms
|
||||||
if (!MatrixClientPeg.get()) return Promise.resolve();
|
if (!MatrixClientPeg.get()) return Promise.resolve();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -239,7 +287,7 @@ export default createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoomClicked: function(room, ev) {
|
onRoomClicked: function(room, ev) {
|
||||||
if (ev.shiftKey) {
|
if (ev.shiftKey && !this.state.selectedCommunityId) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.removeFromDirectory(room);
|
this.removeFromDirectory(room);
|
||||||
} else {
|
} else {
|
||||||
|
@ -610,6 +658,18 @@ export default createReactClass({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let dropdown = (
|
||||||
|
<NetworkDropdown
|
||||||
|
protocols={this.protocols}
|
||||||
|
onOptionChange={this.onOptionChange}
|
||||||
|
selectedServerName={this.state.roomServer}
|
||||||
|
selectedInstanceId={this.state.instanceId}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
if (this.state.selectedCommunityId) {
|
||||||
|
dropdown = null;
|
||||||
|
}
|
||||||
|
|
||||||
listHeader = <div className="mx_RoomDirectory_listheader">
|
listHeader = <div className="mx_RoomDirectory_listheader">
|
||||||
<DirectorySearchBox
|
<DirectorySearchBox
|
||||||
className="mx_RoomDirectory_searchbox"
|
className="mx_RoomDirectory_searchbox"
|
||||||
|
@ -619,12 +679,7 @@ export default createReactClass({
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
showJoinButton={showJoinButton}
|
showJoinButton={showJoinButton}
|
||||||
/>
|
/>
|
||||||
<NetworkDropdown
|
{dropdown}
|
||||||
protocols={this.protocols}
|
|
||||||
onOptionChange={this.onOptionChange}
|
|
||||||
selectedServerName={this.state.roomServer}
|
|
||||||
selectedInstanceId={this.state.instanceId}
|
|
||||||
/>
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
const explanation =
|
const explanation =
|
||||||
|
@ -637,12 +692,16 @@ export default createReactClass({
|
||||||
}},
|
}},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const title = this.state.selectedCommunityId
|
||||||
|
? _t("Explore rooms in %(communityName)s", {
|
||||||
|
communityName: this.state.communityName || this.state.selectedCommunityId,
|
||||||
|
}) : _t("Explore rooms");
|
||||||
return (
|
return (
|
||||||
<BaseDialog
|
<BaseDialog
|
||||||
className={'mx_RoomDirectory_dialog'}
|
className={'mx_RoomDirectory_dialog'}
|
||||||
hasCancel={true}
|
hasCancel={true}
|
||||||
onFinished={this.props.onFinished}
|
onFinished={this.props.onFinished}
|
||||||
title={_t("Explore rooms")}
|
title={title}
|
||||||
>
|
>
|
||||||
<div className="mx_RoomDirectory">
|
<div className="mx_RoomDirectory">
|
||||||
{explanation}
|
{explanation}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue