2018-04-12 01:58:04 +03:00
|
|
|
/*
|
2019-07-31 14:19:29 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2021-05-21 15:37:21 +03:00
|
|
|
Copyright 2015, 2016, 2019, 2020, 2021 The Matrix.org Foundation C.I.C.
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2019-12-21 00:41:07 +03:00
|
|
|
import Modal from "../../Modal";
|
2019-02-01 00:35:58 +03:00
|
|
|
import { linkifyAndSanitizeHtml } from '../../HtmlUtils';
|
2018-04-13 02:43:44 +03:00
|
|
|
import { _t } from '../../languageHandler';
|
2020-07-10 21:07:11 +03:00
|
|
|
import SdkConfig from '../../SdkConfig';
|
2019-03-27 17:54:18 +03:00
|
|
|
import { instanceForInstanceId, protocolNameForInstanceId } from '../../utils/DirectoryUtils';
|
|
|
|
import Analytics from '../../Analytics';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { ALL_ROOMS, IFieldType, IInstance, IProtocol, Protocols } from "../views/directory/NetworkDropdown";
|
2020-08-22 00:56:54 +03:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2020-10-10 15:32:58 +03:00
|
|
|
import GroupFilterOrderStore from "../../stores/GroupFilterOrderStore";
|
2020-08-22 00:56:54 +03:00
|
|
|
import GroupStore from "../../stores/GroupStore";
|
|
|
|
import FlairStore from "../../stores/FlairStore";
|
2020-10-29 18:53:14 +03:00
|
|
|
import CountlyAnalytics from "../../CountlyAnalytics";
|
2021-05-19 20:40:03 +03:00
|
|
|
import { replaceableComponent } from "../../utils/replaceableComponent";
|
|
|
|
import { mediaFromMxc } from "../../customisations/Media";
|
|
|
|
import { IDialogProps } from "../views/dialogs/IDialogProps";
|
2021-06-29 15:11:58 +03:00
|
|
|
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
|
2021-05-19 20:40:03 +03:00
|
|
|
import BaseAvatar from "../views/avatars/BaseAvatar";
|
|
|
|
import ErrorDialog from "../views/dialogs/ErrorDialog";
|
|
|
|
import QuestionDialog from "../views/dialogs/QuestionDialog";
|
|
|
|
import BaseDialog from "../views/dialogs/BaseDialog";
|
|
|
|
import DirectorySearchBox from "../views/elements/DirectorySearchBox";
|
|
|
|
import NetworkDropdown from "../views/directory/NetworkDropdown";
|
|
|
|
import ScrollPanel from "./ScrollPanel";
|
|
|
|
import Spinner from "../views/elements/Spinner";
|
|
|
|
import { ActionPayload } from "../../dispatcher/payloads";
|
|
|
|
|
2019-01-13 17:47:08 +03:00
|
|
|
const MAX_NAME_LENGTH = 80;
|
2020-10-02 19:00:58 +03:00
|
|
|
const MAX_TOPIC_LENGTH = 800;
|
2019-01-13 17:47:08 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
function track(action: string) {
|
2019-03-27 17:54:18 +03:00
|
|
|
Analytics.trackEvent('RoomDirectory', action);
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
interface IProps extends IDialogProps {
|
|
|
|
initialText?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
publicRooms: IRoom[];
|
|
|
|
loading: boolean;
|
|
|
|
protocolsLoading: boolean;
|
|
|
|
error?: string;
|
2021-07-07 12:54:53 +03:00
|
|
|
instanceId: string;
|
2021-05-19 20:40:03 +03:00
|
|
|
roomServer: string;
|
|
|
|
filterString: string;
|
|
|
|
selectedCommunityId?: string;
|
|
|
|
communityName?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eslint-disable camelcase */
|
|
|
|
interface IRoom {
|
|
|
|
room_id: string;
|
|
|
|
name?: string;
|
|
|
|
avatar_url?: string;
|
|
|
|
topic?: string;
|
|
|
|
canonical_alias?: string;
|
|
|
|
aliases?: string[];
|
|
|
|
world_readable: boolean;
|
|
|
|
guest_can_join: boolean;
|
|
|
|
num_joined_members: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IPublicRoomsRequest {
|
|
|
|
limit?: number;
|
|
|
|
since?: string;
|
|
|
|
server?: string;
|
|
|
|
filter?: object;
|
|
|
|
include_all_networks?: boolean;
|
|
|
|
third_party_instance_id?: string;
|
|
|
|
}
|
|
|
|
/* eslint-enable camelcase */
|
|
|
|
|
2021-03-09 05:35:10 +03:00
|
|
|
@replaceableComponent("structures.RoomDirectory")
|
2021-05-19 20:40:03 +03:00
|
|
|
export default class RoomDirectory extends React.Component<IProps, IState> {
|
|
|
|
private readonly startTime: number;
|
2021-06-29 15:11:58 +03:00
|
|
|
private unmounted = false;
|
2021-05-19 20:40:03 +03:00
|
|
|
private nextBatch: string = null;
|
|
|
|
private filterTimeout: NodeJS.Timeout;
|
|
|
|
private protocols: Protocols;
|
2020-08-29 14:14:16 +03:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2020-10-30 23:20:58 +03:00
|
|
|
CountlyAnalytics.instance.trackRoomDirectoryBegin();
|
2020-10-29 18:53:14 +03:00
|
|
|
this.startTime = CountlyAnalytics.getTimestamp();
|
|
|
|
|
2021-05-19 21:30:56 +03:00
|
|
|
const selectedCommunityId = SettingsStore.getValue("feature_communities_v2_prototypes")
|
|
|
|
? GroupFilterOrderStore.getSelectedTags()[0]
|
|
|
|
: null;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
let protocolsLoading = true;
|
2019-02-11 15:12:47 +03:00
|
|
|
if (!MatrixClientPeg.get()) {
|
|
|
|
// We may not have a client yet when invoked from welcome page
|
2021-05-19 20:40:03 +03:00
|
|
|
protocolsLoading = false;
|
2021-05-19 21:30:56 +03:00
|
|
|
} else if (!selectedCommunityId) {
|
2020-08-22 00:56:54 +03:00
|
|
|
MatrixClientPeg.get().getThirdpartyProtocols().then((response) => {
|
|
|
|
this.protocols = response;
|
2021-05-19 21:30:56 +03:00
|
|
|
this.setState({ protocolsLoading: false });
|
2020-08-22 00:56:54 +03:00
|
|
|
}, (err) => {
|
|
|
|
console.warn(`error loading third party protocols: ${err}`);
|
2021-05-19 21:30:56 +03:00
|
|
|
this.setState({ protocolsLoading: false });
|
2020-08-22 00:56:54 +03:00
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
// Guests currently aren't allowed to use this API, so
|
|
|
|
// ignore this as otherwise this error is literally the
|
|
|
|
// thing you see when loading the client!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
track('Failed to get protocol list from homeserver');
|
|
|
|
const brand = SdkConfig.get().brand;
|
|
|
|
this.setState({
|
|
|
|
error: _t(
|
|
|
|
'%(brand)s failed to get the protocol list from the homeserver. ' +
|
|
|
|
'The homeserver may be too old to support third party networks.',
|
2021-05-19 21:30:56 +03:00
|
|
|
{ brand },
|
2020-08-22 00:56:54 +03:00
|
|
|
),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// We don't use the protocols in the communities v2 prototype experience
|
2021-05-19 20:40:03 +03:00
|
|
|
protocolsLoading = false;
|
2020-08-22 00:56:54 +03:00
|
|
|
|
|
|
|
// Grab the profile info async
|
|
|
|
FlairStore.getGroupProfileCached(MatrixClientPeg.get(), this.state.selectedCommunityId).then(profile => {
|
2021-05-19 21:30:56 +03:00
|
|
|
this.setState({ communityName: profile.name });
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
2020-08-22 00:56:54 +03:00
|
|
|
}
|
2021-05-19 20:40:03 +03:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
publicRooms: [],
|
|
|
|
loading: true,
|
|
|
|
error: null,
|
|
|
|
instanceId: undefined,
|
|
|
|
roomServer: MatrixClientPeg.getHomeserverName(),
|
|
|
|
filterString: this.props.initialText || "",
|
2021-05-19 21:30:56 +03:00
|
|
|
selectedCommunityId,
|
2021-05-19 20:40:03 +03:00
|
|
|
communityName: null,
|
|
|
|
protocolsLoading,
|
|
|
|
};
|
2020-09-17 00:05:14 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2020-09-17 00:05:14 +03:00
|
|
|
componentDidMount() {
|
2020-03-13 03:02:50 +03:00
|
|
|
this.refreshRoomList();
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2020-03-13 03:02:50 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentWillUnmount() {
|
2018-04-12 01:58:04 +03:00
|
|
|
if (this.filterTimeout) {
|
|
|
|
clearTimeout(this.filterTimeout);
|
|
|
|
}
|
2021-05-19 20:40:03 +03:00
|
|
|
this.unmounted = true;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private refreshRoomList = () => {
|
2020-08-22 00:56:54 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
this.nextBatch = null;
|
|
|
|
this.setState({
|
|
|
|
publicRooms: [],
|
|
|
|
loading: true,
|
|
|
|
});
|
2019-11-18 13:03:05 +03:00
|
|
|
this.getMoreRooms();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-06-22 22:41:26 +03:00
|
|
|
private getMoreRooms(): Promise<boolean> {
|
|
|
|
if (this.state.selectedCommunityId) return Promise.resolve(false); // no more rooms
|
|
|
|
if (!MatrixClientPeg.get()) return Promise.resolve(false);
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2019-09-11 13:52:39 +03:00
|
|
|
this.setState({
|
|
|
|
loading: true,
|
|
|
|
});
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
const filterString = this.state.filterString;
|
|
|
|
const roomServer = this.state.roomServer;
|
2018-04-12 01:58:04 +03:00
|
|
|
// remember the next batch token when we sent the request
|
|
|
|
// too. If it's changed, appending to the list will corrupt it.
|
2021-05-19 20:40:03 +03:00
|
|
|
const nextBatch = this.nextBatch;
|
|
|
|
const opts: IPublicRoomsRequest = { limit: 20 };
|
|
|
|
if (roomServer != MatrixClientPeg.getHomeserverName()) {
|
|
|
|
opts.server = roomServer;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
2020-03-13 03:02:50 +03:00
|
|
|
if (this.state.instanceId === ALL_ROOMS) {
|
2018-04-12 01:58:04 +03:00
|
|
|
opts.include_all_networks = true;
|
2020-03-13 03:02:50 +03:00
|
|
|
} else if (this.state.instanceId) {
|
2021-05-19 20:40:03 +03:00
|
|
|
opts.third_party_instance_id = this.state.instanceId as string;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
if (this.nextBatch) opts.since = this.nextBatch;
|
2021-05-19 20:40:03 +03:00
|
|
|
if (filterString) opts.filter = { generic_search_term: filterString };
|
2018-04-12 01:58:04 +03:00
|
|
|
return MatrixClientPeg.get().publicRooms(opts).then((data) => {
|
|
|
|
if (
|
2021-05-19 20:40:03 +03:00
|
|
|
filterString != this.state.filterString ||
|
|
|
|
roomServer != this.state.roomServer ||
|
|
|
|
nextBatch != this.nextBatch) {
|
2018-04-12 01:58:04 +03:00
|
|
|
// if the filter or server has changed since this request was sent,
|
|
|
|
// throw away the result (don't even clear the busy flag
|
|
|
|
// since we must still have a request in flight)
|
2021-06-22 22:41:26 +03:00
|
|
|
return false;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
if (this.unmounted) {
|
2018-04-12 01:58:04 +03:00
|
|
|
// if we've been unmounted, we don't care either.
|
2021-06-22 22:41:26 +03:00
|
|
|
return false;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
2020-10-29 18:53:14 +03:00
|
|
|
if (this.state.filterString) {
|
|
|
|
const count = data.total_room_count_estimate || data.chunk.length;
|
|
|
|
CountlyAnalytics.instance.trackRoomDirectorySearch(count, this.state.filterString);
|
|
|
|
}
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
this.nextBatch = data.next_batch;
|
2021-05-19 20:40:03 +03:00
|
|
|
this.setState((s) => ({
|
|
|
|
...s,
|
|
|
|
publicRooms: [...s.publicRooms, ...(data.chunk || [])],
|
|
|
|
loading: false,
|
|
|
|
}));
|
2018-04-12 01:58:04 +03:00
|
|
|
return Boolean(data.next_batch);
|
|
|
|
}, (err) => {
|
|
|
|
if (
|
2021-05-19 20:40:03 +03:00
|
|
|
filterString != this.state.filterString ||
|
|
|
|
roomServer != this.state.roomServer ||
|
|
|
|
nextBatch != this.nextBatch) {
|
2021-06-22 22:41:26 +03:00
|
|
|
// as above: we don't care about errors for old requests either
|
|
|
|
return false;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
if (this.unmounted) {
|
2018-04-12 01:58:04 +03:00
|
|
|
// if we've been unmounted, we don't care either.
|
2021-06-22 22:41:26 +03:00
|
|
|
return false;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
console.error("Failed to get publicRooms: %s", JSON.stringify(err));
|
2019-03-27 17:54:18 +03:00
|
|
|
track('Failed to get public room list');
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2019-03-27 17:54:18 +03:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2020-07-10 21:07:11 +03:00
|
|
|
error: (
|
|
|
|
_t('%(brand)s failed to get the public room list.', { brand }) +
|
|
|
|
(err && err.message) ? err.message : _t('The homeserver may be unavailable or overloaded.')
|
|
|
|
),
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A limited interface for removing rooms from the directory.
|
|
|
|
* Will set the room to not be publicly visible and delete the
|
|
|
|
* default alias. In the long term, it would be better to allow
|
|
|
|
* HS admins to do this through the RoomSettings interface, but
|
|
|
|
* this needs SPEC-417.
|
|
|
|
*/
|
2021-05-19 20:40:03 +03:00
|
|
|
private removeFromDirectory(room: IRoom) {
|
|
|
|
const alias = getDisplayAliasForRoom(room);
|
2018-10-27 06:50:35 +03:00
|
|
|
const name = room.name || alias || _t('Unnamed room');
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2018-10-27 06:50:35 +03:00
|
|
|
let desc;
|
2018-04-12 01:58:04 +03:00
|
|
|
if (alias) {
|
2021-06-29 15:11:58 +03:00
|
|
|
desc = _t('Delete the room address %(alias)s and remove %(name)s from the directory?', { alias, name });
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
2021-06-29 15:11:58 +03:00
|
|
|
desc = _t('Remove %(name)s from the directory?', { name: name });
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Modal.createTrackedDialog('Remove from Directory', '', QuestionDialog, {
|
|
|
|
title: _t('Remove from Directory'),
|
|
|
|
description: desc,
|
2021-05-19 20:40:03 +03:00
|
|
|
onFinished: (shouldDelete: boolean) => {
|
|
|
|
if (!shouldDelete) return;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
const modal = Modal.createDialog(Spinner);
|
2021-06-29 15:11:58 +03:00
|
|
|
let step = _t('remove %(name)s from the directory.', { name: name });
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
MatrixClientPeg.get().setRoomDirectoryVisibility(room.room_id, 'private').then(() => {
|
|
|
|
if (!alias) return;
|
2020-04-14 12:06:57 +03:00
|
|
|
step = _t('delete the address.');
|
2018-04-12 01:58:04 +03:00
|
|
|
return MatrixClientPeg.get().deleteAlias(alias);
|
2019-11-18 13:03:05 +03:00
|
|
|
}).then(() => {
|
2018-04-12 01:58:04 +03:00
|
|
|
modal.close();
|
|
|
|
this.refreshRoomList();
|
|
|
|
}, (err) => {
|
|
|
|
modal.close();
|
|
|
|
this.refreshRoomList();
|
|
|
|
console.error("Failed to " + step + ": " + err);
|
|
|
|
Modal.createTrackedDialog('Remove from Directory Error', '', ErrorDialog, {
|
|
|
|
title: _t('Error'),
|
2021-05-19 20:40:03 +03:00
|
|
|
description: (err && err.message)
|
|
|
|
? err.message
|
|
|
|
: _t('The server may be unavailable or overloaded'),
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-27 06:50:35 +03:00
|
|
|
},
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onRoomClicked = (room: IRoom, ev: ButtonEvent) => {
|
2021-06-22 10:12:41 +03:00
|
|
|
// If room was shift-clicked, remove it from the room directory
|
2020-08-22 00:56:54 +03:00
|
|
|
if (ev.shiftKey && !this.state.selectedCommunityId) {
|
2018-04-12 01:58:04 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
this.removeFromDirectory(room);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onOptionChange = (server: string, instanceId?: string | symbol) => {
|
2018-04-12 01:58:04 +03:00
|
|
|
// clear next batch so we don't try to load more rooms
|
|
|
|
this.nextBatch = null;
|
|
|
|
this.setState({
|
|
|
|
// Clear the public rooms out here otherwise we needlessly
|
|
|
|
// spend time filtering lots of rooms when we're about to
|
|
|
|
// to clear the list anyway.
|
|
|
|
publicRooms: [],
|
|
|
|
roomServer: server,
|
|
|
|
instanceId: instanceId,
|
2019-12-17 02:47:33 +03:00
|
|
|
error: null,
|
2018-04-12 01:58:04 +03:00
|
|
|
}, this.refreshRoomList);
|
|
|
|
// We also refresh the room list each time even though this
|
|
|
|
// filtering is client-side. It hopefully won't be client side
|
|
|
|
// for very long, and we may have fetched a thousand rooms to
|
|
|
|
// find the five gitter ones, at which point we do not want
|
|
|
|
// to render all those rooms when switching back to 'all networks'.
|
|
|
|
// Easiest to just blow away the state & re-fetch.
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onFillRequest = (backwards: boolean) => {
|
2018-04-12 01:58:04 +03:00
|
|
|
if (backwards || !this.nextBatch) return Promise.resolve(false);
|
|
|
|
|
|
|
|
return this.getMoreRooms();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onFilterChange = (alias: string) => {
|
2018-04-12 01:58:04 +03:00
|
|
|
this.setState({
|
2021-07-01 11:57:33 +03:00
|
|
|
filterString: alias || "",
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// don't send the request for a little bit,
|
|
|
|
// no point hammering the server with a
|
|
|
|
// request for every keystroke, let the
|
|
|
|
// user finish typing.
|
|
|
|
if (this.filterTimeout) {
|
|
|
|
clearTimeout(this.filterTimeout);
|
|
|
|
}
|
|
|
|
this.filterTimeout = setTimeout(() => {
|
|
|
|
this.filterTimeout = null;
|
|
|
|
this.refreshRoomList();
|
|
|
|
}, 700);
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onFilterClear = () => {
|
2018-04-12 01:58:04 +03:00
|
|
|
// update immediately
|
|
|
|
this.setState({
|
2021-07-01 11:57:33 +03:00
|
|
|
filterString: "",
|
2018-04-12 01:58:04 +03:00
|
|
|
}, this.refreshRoomList);
|
|
|
|
|
|
|
|
if (this.filterTimeout) {
|
|
|
|
clearTimeout(this.filterTimeout);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onJoinFromSearchClick = (alias: string) => {
|
2018-04-12 01:58:04 +03:00
|
|
|
// If we don't have a particular instance id selected, just show that rooms alias
|
2020-03-13 03:02:50 +03:00
|
|
|
if (!this.state.instanceId || this.state.instanceId === ALL_ROOMS) {
|
2018-04-12 01:58:04 +03:00
|
|
|
// If the user specified an alias without a domain, add on whichever server is selected
|
|
|
|
// in the dropdown
|
|
|
|
if (alias.indexOf(':') == -1) {
|
|
|
|
alias = alias + ':' + this.state.roomServer;
|
|
|
|
}
|
2019-06-25 12:18:47 +03:00
|
|
|
this.showRoomAlias(alias, true);
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
|
|
|
// This is a 3rd party protocol. Let's see if we can join it
|
|
|
|
const protocolName = protocolNameForInstanceId(this.protocols, this.state.instanceId);
|
|
|
|
const instance = instanceForInstanceId(this.protocols, this.state.instanceId);
|
2021-05-19 20:40:03 +03:00
|
|
|
const fields = protocolName
|
|
|
|
? this.getFieldsForThirdPartyLocation(alias, this.protocols[protocolName], instance)
|
|
|
|
: null;
|
2018-04-12 01:58:04 +03:00
|
|
|
if (!fields) {
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2018-04-12 01:58:04 +03:00
|
|
|
Modal.createTrackedDialog('Unable to join network', '', ErrorDialog, {
|
|
|
|
title: _t('Unable to join network'),
|
2020-07-10 21:07:11 +03:00
|
|
|
description: _t('%(brand)s does not know how to join a room on this network', { brand }),
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2019-11-18 13:03:05 +03:00
|
|
|
MatrixClientPeg.get().getThirdpartyLocation(protocolName, fields).then((resp) => {
|
2018-04-12 01:58:04 +03:00
|
|
|
if (resp.length > 0 && resp[0].alias) {
|
2019-06-25 12:18:47 +03:00
|
|
|
this.showRoomAlias(resp[0].alias, true);
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialog('Room not found', '', ErrorDialog, {
|
|
|
|
title: _t('Room not found'),
|
|
|
|
description: _t('Couldn\'t find a matching Matrix room'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, (e) => {
|
|
|
|
Modal.createTrackedDialog('Fetching third party location failed', '', ErrorDialog, {
|
|
|
|
title: _t('Fetching third party location failed'),
|
|
|
|
description: _t('Unable to look up room ID from server'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onPreviewClick = (ev: ButtonEvent, room: IRoom) => {
|
2020-09-18 17:43:08 +03:00
|
|
|
this.showRoom(room, null, false, true);
|
2019-09-13 15:33:09 +03:00
|
|
|
ev.stopPropagation();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-09-10 17:07:01 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onViewClick = (ev: ButtonEvent, room: IRoom) => {
|
2020-09-18 17:43:08 +03:00
|
|
|
this.showRoom(room);
|
2019-09-13 15:33:09 +03:00
|
|
|
ev.stopPropagation();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-09-10 17:07:01 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onJoinClick = (ev: ButtonEvent, room: IRoom) => {
|
2019-09-15 23:25:36 +03:00
|
|
|
this.showRoom(room, null, true);
|
2019-09-13 15:33:09 +03:00
|
|
|
ev.stopPropagation();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-09-10 17:07:01 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onCreateRoomClick = () => {
|
2020-10-29 18:53:14 +03:00
|
|
|
this.onFinished();
|
2020-05-12 12:55:46 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_create_room',
|
|
|
|
public: true,
|
2021-05-19 21:20:58 +03:00
|
|
|
defaultName: this.state.filterString.trim(),
|
2020-05-12 12:55:46 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2019-09-11 16:36:29 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private showRoomAlias(alias: string, autoJoin = false) {
|
2019-06-25 12:18:47 +03:00
|
|
|
this.showRoom(null, alias, autoJoin);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private showRoom(room: IRoom, roomAlias?: string, autoJoin = false, shouldPeek = false) {
|
2020-10-29 18:53:14 +03:00
|
|
|
this.onFinished();
|
2021-05-19 20:40:03 +03:00
|
|
|
const payload: ActionPayload = {
|
2019-06-24 00:39:04 +03:00
|
|
|
action: 'view_room',
|
2019-06-25 12:18:47 +03:00
|
|
|
auto_join: autoJoin,
|
2020-09-18 17:43:08 +03:00
|
|
|
should_peek: shouldPeek,
|
2020-10-29 18:53:14 +03:00
|
|
|
_type: "room_directory", // instrumentation
|
2019-06-24 00:39:04 +03:00
|
|
|
};
|
2018-04-12 01:58:04 +03:00
|
|
|
if (room) {
|
|
|
|
// Don't let the user view a room they won't be able to either
|
|
|
|
// peek or join: fail earlier so they don't have to click back
|
|
|
|
// to the directory.
|
|
|
|
if (MatrixClientPeg.get().isGuest()) {
|
|
|
|
if (!room.world_readable && !room.guest_can_join) {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: 'require_registration' });
|
2018-04-12 01:58:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
if (!roomAlias) {
|
|
|
|
roomAlias = getDisplayAliasForRoom(room);
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
payload.oob_data = {
|
|
|
|
avatarUrl: room.avatar_url,
|
|
|
|
// XXX: This logic is duplicated from the JS SDK which
|
|
|
|
// would normally decide what the name is.
|
2021-05-19 20:40:03 +03:00
|
|
|
name: room.name || roomAlias || _t('Unnamed room'),
|
2018-04-12 01:58:04 +03:00
|
|
|
};
|
2020-03-13 12:21:37 +03:00
|
|
|
|
|
|
|
if (this.state.roomServer) {
|
2020-09-18 17:43:08 +03:00
|
|
|
payload.via_servers = [this.state.roomServer];
|
2020-03-13 12:21:37 +03:00
|
|
|
payload.opts = {
|
|
|
|
viaServers: [this.state.roomServer],
|
|
|
|
};
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
// It's not really possible to join Matrix rooms by ID because the HS has no way to know
|
|
|
|
// which servers to start querying. However, there's no other way to join rooms in
|
|
|
|
// this list without aliases at present, so if roomAlias isn't set here we have no
|
|
|
|
// choice but to supply the ID.
|
2021-05-19 20:40:03 +03:00
|
|
|
if (roomAlias) {
|
|
|
|
payload.room_alias = roomAlias;
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
|
|
|
payload.room_id = room.room_id;
|
|
|
|
}
|
|
|
|
dis.dispatch(payload);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private createRoomCells(room: IRoom) {
|
2019-09-10 17:07:01 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const clientRoom = client.getRoom(room.room_id);
|
|
|
|
const hasJoinedRoom = clientRoom && clientRoom.getMyMembership() === "join";
|
|
|
|
const isGuest = client.isGuest();
|
|
|
|
let previewButton;
|
|
|
|
let joinOrViewButton;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-01-19 20:59:30 +03:00
|
|
|
// Element Web currently does not allow guests to join rooms, so we
|
|
|
|
// instead show them preview buttons for all rooms. If the room is not
|
|
|
|
// world readable, a modal will appear asking you to register first. If
|
|
|
|
// it is readable, the preview appears as normal.
|
|
|
|
if (!hasJoinedRoom && (room.world_readable || isGuest)) {
|
2019-09-10 17:07:01 +03:00
|
|
|
previewButton = (
|
2021-05-19 20:40:03 +03:00
|
|
|
<AccessibleButton kind="secondary" onClick={(ev) => this.onPreviewClick(ev, room)}>
|
|
|
|
{ _t("Preview") }
|
|
|
|
</AccessibleButton>
|
2019-09-10 17:07:01 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (hasJoinedRoom) {
|
|
|
|
joinOrViewButton = (
|
2021-05-19 20:40:03 +03:00
|
|
|
<AccessibleButton kind="secondary" onClick={(ev) => this.onViewClick(ev, room)}>
|
|
|
|
{ _t("View") }
|
|
|
|
</AccessibleButton>
|
2019-09-10 17:07:01 +03:00
|
|
|
);
|
2021-01-19 20:59:30 +03:00
|
|
|
} else if (!isGuest) {
|
2019-09-10 17:07:01 +03:00
|
|
|
joinOrViewButton = (
|
2021-05-19 20:40:03 +03:00
|
|
|
<AccessibleButton kind="primary" onClick={(ev) => this.onJoinClick(ev, room)}>
|
|
|
|
{ _t("Join") }
|
|
|
|
</AccessibleButton>
|
2019-09-10 17:07:01 +03:00
|
|
|
);
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
let name = room.name || getDisplayAliasForRoom(room) || _t('Unnamed room');
|
2019-09-10 17:07:01 +03:00
|
|
|
if (name.length > MAX_NAME_LENGTH) {
|
|
|
|
name = `${name.substring(0, MAX_NAME_LENGTH)}...`;
|
|
|
|
}
|
2019-01-13 17:47:08 +03:00
|
|
|
|
2019-09-10 17:07:01 +03:00
|
|
|
let topic = room.topic || '';
|
2020-10-02 19:00:58 +03:00
|
|
|
// Additional truncation based on line numbers is done via CSS,
|
|
|
|
// but to ensure that the DOM is not polluted with a huge string
|
|
|
|
// we give it a hard limit before rendering.
|
2019-09-10 17:07:01 +03:00
|
|
|
if (topic.length > MAX_TOPIC_LENGTH) {
|
|
|
|
topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
2019-09-10 17:07:01 +03:00
|
|
|
topic = linkifyAndSanitizeHtml(topic);
|
2021-03-06 04:45:09 +03:00
|
|
|
let avatarUrl = null;
|
|
|
|
if (room.avatar_url) avatarUrl = mediaFromMxc(room.avatar_url).getSquareThumbnailHttp(32);
|
|
|
|
|
2021-06-22 10:24:42 +03:00
|
|
|
// We use onMouseDown instead of onClick, so that we can avoid text getting selected
|
2021-01-17 19:49:00 +03:00
|
|
|
return [
|
2021-06-22 10:24:42 +03:00
|
|
|
<div
|
|
|
|
key={ `${room.room_id}_avatar` }
|
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
className="mx_RoomDirectory_roomAvatar"
|
2019-09-10 17:07:01 +03:00
|
|
|
>
|
2021-05-19 20:40:03 +03:00
|
|
|
<BaseAvatar
|
|
|
|
width={32}
|
|
|
|
height={32}
|
|
|
|
resizeMethod='crop'
|
|
|
|
name={name}
|
|
|
|
idName={name}
|
|
|
|
url={avatarUrl}
|
2021-01-17 19:49:00 +03:00
|
|
|
/>
|
|
|
|
</div>,
|
2021-06-22 10:24:42 +03:00
|
|
|
<div
|
|
|
|
key={ `${room.room_id}_description` }
|
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
className="mx_RoomDirectory_roomDescription"
|
|
|
|
>
|
2021-06-22 10:16:45 +03:00
|
|
|
<div
|
|
|
|
className="mx_RoomDirectory_name"
|
2021-06-22 10:24:42 +03:00
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-06-22 10:16:45 +03:00
|
|
|
>
|
|
|
|
{ name }
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className="mx_RoomDirectory_topic"
|
2021-06-22 10:24:42 +03:00
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
dangerouslySetInnerHTML={{ __html: topic }}
|
|
|
|
/>
|
2021-06-22 10:16:45 +03:00
|
|
|
<div
|
|
|
|
className="mx_RoomDirectory_alias"
|
2021-06-22 10:24:42 +03:00
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-06-22 10:16:45 +03:00
|
|
|
>
|
|
|
|
{ getDisplayAliasForRoom(room) }
|
|
|
|
</div>
|
2021-01-17 19:49:00 +03:00
|
|
|
</div>,
|
2021-06-22 10:24:42 +03:00
|
|
|
<div
|
|
|
|
key={ `${room.room_id}_memberCount` }
|
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
className="mx_RoomDirectory_roomMemberCount"
|
|
|
|
>
|
|
|
|
{ room.num_joined_members }
|
|
|
|
</div>,
|
2021-06-22 10:24:42 +03:00
|
|
|
<div
|
|
|
|
key={ `${room.room_id}_preview` }
|
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
// cancel onMouseDown otherwise shift-clicking highlights text
|
|
|
|
className="mx_RoomDirectory_preview"
|
|
|
|
>
|
2021-06-22 10:24:42 +03:00
|
|
|
{ previewButton }
|
2021-01-17 19:49:00 +03:00
|
|
|
</div>,
|
2021-06-22 10:24:42 +03:00
|
|
|
<div
|
|
|
|
key={ `${room.room_id}_join` }
|
|
|
|
onMouseDown={(ev) => this.onRoomClicked(room, ev)}
|
2021-01-17 19:49:00 +03:00
|
|
|
className="mx_RoomDirectory_join"
|
|
|
|
>
|
2021-06-22 10:24:42 +03:00
|
|
|
{ joinOrViewButton }
|
2021-01-17 19:49:00 +03:00
|
|
|
</div>,
|
|
|
|
];
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private stringLooksLikeId(s: string, fieldType: IFieldType) {
|
2018-04-12 01:58:04 +03:00
|
|
|
let pat = /^#[^\s]+:[^\s]/;
|
2021-05-19 20:40:03 +03:00
|
|
|
if (fieldType && fieldType.regexp) {
|
|
|
|
pat = new RegExp(fieldType.regexp);
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return pat.test(s);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private getFieldsForThirdPartyLocation(userInput: string, protocol: IProtocol, instance: IInstance) {
|
2018-04-12 01:58:04 +03:00
|
|
|
// make an object with the fields specified by that protocol. We
|
|
|
|
// require that the values of all but the last field come from the
|
|
|
|
// instance. The last is the user input.
|
|
|
|
const requiredFields = protocol.location_fields;
|
|
|
|
if (!requiredFields) return null;
|
|
|
|
const fields = {};
|
|
|
|
for (let i = 0; i < requiredFields.length - 1; ++i) {
|
|
|
|
const thisField = requiredFields[i];
|
|
|
|
if (instance.fields[thisField] === undefined) return null;
|
|
|
|
fields[thisField] = instance.fields[thisField];
|
|
|
|
}
|
|
|
|
fields[requiredFields[requiredFields.length - 1]] = userInput;
|
|
|
|
return fields;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
private onFinished = () => {
|
2020-10-29 18:53:14 +03:00
|
|
|
CountlyAnalytics.instance.trackRoomDirectory(this.startTime);
|
2021-05-19 20:40:03 +03:00
|
|
|
this.props.onFinished(false);
|
2020-10-29 18:53:14 +03:00
|
|
|
};
|
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2018-04-12 01:58:04 +03:00
|
|
|
let content;
|
2019-03-27 17:54:18 +03:00
|
|
|
if (this.state.error) {
|
|
|
|
content = this.state.error;
|
2019-09-11 13:52:39 +03:00
|
|
|
} else if (this.state.protocolsLoading) {
|
2021-05-19 20:40:03 +03:00
|
|
|
content = <Spinner />;
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
2021-01-17 19:49:00 +03:00
|
|
|
const cells = (this.state.publicRooms || [])
|
2021-05-19 20:40:03 +03:00
|
|
|
.reduce((cells, room) => cells.concat(this.createRoomCells(room)), []);
|
2018-04-12 01:58:04 +03:00
|
|
|
// we still show the scrollpanel, at least for now, because
|
|
|
|
// otherwise we don't fetch more because we don't get a fill
|
|
|
|
// request from the scrollpanel because there isn't one
|
2019-09-11 13:52:39 +03:00
|
|
|
|
|
|
|
let spinner;
|
|
|
|
if (this.state.loading) {
|
2021-05-19 20:40:03 +03:00
|
|
|
spinner = <Spinner />;
|
2019-09-11 13:52:39 +03:00
|
|
|
}
|
|
|
|
|
2021-05-19 22:07:54 +03:00
|
|
|
const createNewButton = <>
|
|
|
|
<hr />
|
|
|
|
<AccessibleButton kind="primary" onClick={this.onCreateRoomClick} className="mx_RoomDirectory_newRoom">
|
|
|
|
{ _t("Create new room") }
|
|
|
|
</AccessibleButton>
|
|
|
|
</>;
|
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
let scrollPanelContent;
|
2021-05-19 22:07:54 +03:00
|
|
|
let footer;
|
2021-01-17 19:49:00 +03:00
|
|
|
if (cells.length === 0 && !this.state.loading) {
|
2021-05-19 22:07:54 +03:00
|
|
|
footer = <>
|
|
|
|
<h5>{ _t('No results for "%(query)s"', { query: this.state.filterString.trim() }) }</h5>
|
|
|
|
<p>
|
|
|
|
{ _t("Try different words or check for typos. " +
|
2021-05-21 15:37:21 +03:00
|
|
|
"Some results may not be visible as they're private and you need an invite to join them.") }
|
2021-05-19 22:07:54 +03:00
|
|
|
</p>
|
|
|
|
{ createNewButton }
|
|
|
|
</>;
|
2018-04-12 01:58:04 +03:00
|
|
|
} else {
|
2021-05-19 20:40:03 +03:00
|
|
|
scrollPanelContent = <div className="mx_RoomDirectory_table">
|
2021-01-17 19:49:00 +03:00
|
|
|
{ cells }
|
|
|
|
</div>;
|
2021-05-19 22:07:54 +03:00
|
|
|
if (!this.state.loading && !this.nextBatch) {
|
|
|
|
footer = createNewButton;
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
2021-05-19 20:40:03 +03:00
|
|
|
content = <ScrollPanel
|
2018-04-12 01:58:04 +03:00
|
|
|
className="mx_RoomDirectory_tableWrapper"
|
2021-05-19 22:07:54 +03:00
|
|
|
onFillRequest={this.onFillRequest}
|
2018-04-12 01:58:04 +03:00
|
|
|
stickyBottom={false}
|
|
|
|
startAtBottom={false}
|
|
|
|
>
|
2021-05-19 20:40:03 +03:00
|
|
|
{ scrollPanelContent }
|
2019-09-11 13:52:39 +03:00
|
|
|
{ spinner }
|
2021-05-19 22:07:54 +03:00
|
|
|
{ footer && <div className="mx_RoomDirectory_footer">
|
|
|
|
{ footer }
|
|
|
|
</div> }
|
2018-04-12 01:58:04 +03:00
|
|
|
</ScrollPanel>;
|
|
|
|
}
|
|
|
|
|
2019-03-27 17:17:24 +03:00
|
|
|
let listHeader;
|
|
|
|
if (!this.state.protocolsLoading) {
|
|
|
|
const protocolName = protocolNameForInstanceId(this.protocols, this.state.instanceId);
|
2021-05-19 20:40:03 +03:00
|
|
|
let instanceExpectedFieldType;
|
2019-03-27 17:17:24 +03:00
|
|
|
if (
|
|
|
|
protocolName &&
|
|
|
|
this.protocols &&
|
|
|
|
this.protocols[protocolName] &&
|
|
|
|
this.protocols[protocolName].location_fields.length > 0 &&
|
|
|
|
this.protocols[protocolName].field_types
|
|
|
|
) {
|
2021-05-19 20:40:03 +03:00
|
|
|
const lastField = this.protocols[protocolName].location_fields.slice(-1)[0];
|
|
|
|
instanceExpectedFieldType = this.protocols[protocolName].field_types[lastField];
|
2019-03-27 17:17:24 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2019-09-11 16:36:29 +03:00
|
|
|
let placeholder = _t('Find a room…');
|
2020-03-13 03:02:50 +03:00
|
|
|
if (!this.state.instanceId || this.state.instanceId === ALL_ROOMS) {
|
2021-05-19 20:40:03 +03:00
|
|
|
placeholder = _t("Find a room… (e.g. %(exampleRoom)s)", {
|
|
|
|
exampleRoom: "#example:" + this.state.roomServer,
|
|
|
|
});
|
|
|
|
} else if (instanceExpectedFieldType) {
|
|
|
|
placeholder = instanceExpectedFieldType.placeholder;
|
2019-03-27 17:17:24 +03:00
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2021-05-19 20:40:03 +03:00
|
|
|
let showJoinButton = this.stringLooksLikeId(this.state.filterString, instanceExpectedFieldType);
|
2019-03-27 17:17:24 +03:00
|
|
|
if (protocolName) {
|
|
|
|
const instance = instanceForInstanceId(this.protocols, this.state.instanceId);
|
2021-05-19 20:40:03 +03:00
|
|
|
if (this.getFieldsForThirdPartyLocation(
|
|
|
|
this.state.filterString,
|
|
|
|
this.protocols[protocolName],
|
|
|
|
instance,
|
|
|
|
) === null) {
|
2019-03-27 17:17:24 +03:00
|
|
|
showJoinButton = false;
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
2019-03-27 17:17:24 +03:00
|
|
|
|
2020-08-22 00:56:54 +03:00
|
|
|
let dropdown = (
|
|
|
|
<NetworkDropdown
|
|
|
|
protocols={this.protocols}
|
|
|
|
onOptionChange={this.onOptionChange}
|
|
|
|
selectedServerName={this.state.roomServer}
|
|
|
|
selectedInstanceId={this.state.instanceId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
if (this.state.selectedCommunityId) {
|
|
|
|
dropdown = null;
|
|
|
|
}
|
|
|
|
|
2019-03-27 17:17:24 +03:00
|
|
|
listHeader = <div className="mx_RoomDirectory_listheader">
|
|
|
|
<DirectorySearchBox
|
|
|
|
className="mx_RoomDirectory_searchbox"
|
2020-03-13 03:02:50 +03:00
|
|
|
onChange={this.onFilterChange}
|
|
|
|
onClear={this.onFilterClear}
|
|
|
|
onJoinClick={this.onJoinFromSearchClick}
|
|
|
|
placeholder={placeholder}
|
|
|
|
showJoinButton={showJoinButton}
|
2020-11-11 16:36:17 +03:00
|
|
|
initialText={this.props.initialText}
|
2020-03-13 03:02:50 +03:00
|
|
|
/>
|
2020-08-22 00:56:54 +03:00
|
|
|
{dropdown}
|
2019-03-27 17:17:24 +03:00
|
|
|
</div>;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
2019-09-11 16:36:29 +03:00
|
|
|
const explanation =
|
|
|
|
_t("If you can't find the room you're looking for, ask for an invite or <a>Create a new room</a>.", null,
|
2021-06-29 15:11:58 +03:00
|
|
|
{ a: sub => (
|
2021-05-19 20:40:03 +03:00
|
|
|
<AccessibleButton kind="secondary" onClick={this.onCreateRoomClick}>
|
|
|
|
{ sub }
|
|
|
|
</AccessibleButton>
|
2021-06-29 15:11:58 +03:00
|
|
|
) },
|
2019-09-11 16:36:29 +03:00
|
|
|
);
|
2018-04-12 01:58:04 +03:00
|
|
|
|
2020-08-22 00:56:54 +03:00
|
|
|
const title = this.state.selectedCommunityId
|
|
|
|
? _t("Explore rooms in %(communityName)s", {
|
|
|
|
communityName: this.state.communityName || this.state.selectedCommunityId,
|
|
|
|
}) : _t("Explore rooms");
|
2018-04-12 01:58:04 +03:00
|
|
|
return (
|
2019-01-29 17:34:58 +03:00
|
|
|
<BaseDialog
|
|
|
|
className={'mx_RoomDirectory_dialog'}
|
|
|
|
hasCancel={true}
|
2020-10-29 18:53:14 +03:00
|
|
|
onFinished={this.onFinished}
|
2020-08-22 00:56:54 +03:00
|
|
|
title={title}
|
2019-01-29 17:34:58 +03:00
|
|
|
>
|
|
|
|
<div className="mx_RoomDirectory">
|
2020-03-11 02:11:48 +03:00
|
|
|
{explanation}
|
2019-01-29 17:34:58 +03:00
|
|
|
<div className="mx_RoomDirectory_list">
|
2019-03-27 17:17:24 +03:00
|
|
|
{listHeader}
|
2019-01-29 17:34:58 +03:00
|
|
|
{content}
|
2018-04-12 01:58:04 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-29 17:34:58 +03:00
|
|
|
</BaseDialog>
|
2018-04-12 01:58:04 +03:00
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
// Similar to matrix-react-sdk's MatrixTools.getDisplayAliasForRoom
|
|
|
|
// but works with the objects we get from the public room list
|
2021-05-19 20:40:03 +03:00
|
|
|
function getDisplayAliasForRoom(room: IRoom) {
|
|
|
|
return room.canonical_alias || room.aliases?.[0] || "";
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|