2017-05-24 18:56:13 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-07-03 13:16:44 +03:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-05-24 18:56:13 +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.
|
|
|
|
*/
|
2020-07-21 12:14:12 +03:00
|
|
|
|
|
|
|
import React from "react";
|
2017-05-24 18:56:13 +03:00
|
|
|
import {Store} from 'flux/utils';
|
2020-09-14 17:16:29 +03:00
|
|
|
import {MatrixError} from "matrix-js-sdk/src/http-api";
|
2020-07-21 12:14:12 +03:00
|
|
|
|
|
|
|
import dis from '../dispatcher/dispatcher';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../MatrixClientPeg';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../index';
|
2017-06-02 13:53:10 +03:00
|
|
|
import Modal from '../Modal';
|
|
|
|
import { _t } from '../languageHandler';
|
2019-11-12 14:43:18 +03:00
|
|
|
import { getCachedRoomIDForAlias, storeRoomAliasInCache } from '../RoomAliasCache';
|
2020-07-21 12:14:12 +03:00
|
|
|
import {ActionPayload} from "../dispatcher/payloads";
|
2020-09-14 17:16:29 +03:00
|
|
|
import {retry} from "../utils/promise";
|
2020-10-29 18:53:14 +03:00
|
|
|
import CountlyAnalytics from "../CountlyAnalytics";
|
2020-09-14 17:16:29 +03:00
|
|
|
|
|
|
|
const NUM_JOIN_RETRY = 5;
|
2017-05-24 18:56:13 +03:00
|
|
|
|
|
|
|
const INITIAL_STATE = {
|
2017-09-15 17:07:09 +03:00
|
|
|
// Whether we're joining the currently viewed room (see isJoining())
|
2017-05-24 18:56:13 +03:00
|
|
|
joining: false,
|
2017-06-08 18:00:12 +03:00
|
|
|
// Any error that has occurred during joining
|
2017-05-24 18:56:13 +03:00
|
|
|
joinError: null,
|
2017-06-08 18:00:12 +03:00
|
|
|
// The room ID of the room currently being viewed
|
2017-05-24 18:56:13 +03:00
|
|
|
roomId: null,
|
2017-06-08 17:47:41 +03:00
|
|
|
|
2017-06-08 19:27:04 +03:00
|
|
|
// The event to scroll to when the room is first viewed
|
2017-06-08 17:47:41 +03:00
|
|
|
initialEventId: null,
|
2020-07-21 12:14:12 +03:00
|
|
|
initialEventPixelOffset: null,
|
2017-06-08 17:47:41 +03:00
|
|
|
// Whether to highlight the initial event
|
|
|
|
isInitialEventHighlighted: false,
|
|
|
|
|
2017-05-24 18:56:13 +03:00
|
|
|
// The room alias of the room (or null if not originally specified in view_room)
|
|
|
|
roomAlias: null,
|
|
|
|
// Whether the current room is loading
|
|
|
|
roomLoading: false,
|
|
|
|
// Any error that has occurred during loading
|
|
|
|
roomLoadError: null,
|
2017-06-16 18:12:52 +03:00
|
|
|
|
|
|
|
forwardingEvent: null,
|
2017-12-10 15:50:41 +03:00
|
|
|
|
|
|
|
quotingEvent: null,
|
2020-07-21 12:14:12 +03:00
|
|
|
|
|
|
|
replyingToEvent: null,
|
|
|
|
|
|
|
|
shouldPeek: false,
|
2021-04-28 11:04:02 +03:00
|
|
|
|
|
|
|
viaServers: [],
|
2017-05-24 18:56:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class for storing application state for RoomView. This is the RoomView's interface
|
|
|
|
* with a subset of the js-sdk.
|
|
|
|
* ```
|
|
|
|
*/
|
2020-07-21 12:14:12 +03:00
|
|
|
class RoomViewStore extends Store<ActionPayload> {
|
|
|
|
private state = INITIAL_STATE; // initialize state
|
|
|
|
|
2019-01-17 12:29:37 +03:00
|
|
|
constructor() {
|
|
|
|
super(dis);
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
setState(newState: Partial<typeof INITIAL_STATE>) {
|
2020-02-06 20:57:17 +03:00
|
|
|
// If values haven't changed, there's nothing to do.
|
|
|
|
// This only tries a shallow comparison, so unchanged objects will slip
|
|
|
|
// through, but that's probably okay for now.
|
|
|
|
let stateChanged = false;
|
|
|
|
for (const key of Object.keys(newState)) {
|
2020-07-21 12:14:12 +03:00
|
|
|
if (this.state[key] !== newState[key]) {
|
2020-02-06 20:57:17 +03:00
|
|
|
stateChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!stateChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
this.state = Object.assign(this.state, newState);
|
2017-05-24 18:56:13 +03:00
|
|
|
this.__emitChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
__onDispatch(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
// view_room:
|
2017-06-08 16:17:49 +03:00
|
|
|
// - room_alias: '#somealias:matrix.org'
|
|
|
|
// - room_id: '!roomid123:matrix.org'
|
|
|
|
// - event_id: '$213456782:matrix.org'
|
|
|
|
// - event_offset: 100
|
|
|
|
// - highlighted: true
|
2017-05-24 18:56:13 +03:00
|
|
|
case 'view_room':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.viewRoom(payload);
|
2017-05-24 18:56:13 +03:00
|
|
|
break;
|
2020-07-21 12:22:03 +03:00
|
|
|
// for these events blank out the roomId as we are no longer in the RoomView
|
2020-07-21 12:20:30 +03:00
|
|
|
case 'view_create_group':
|
|
|
|
case 'view_welcome_page':
|
|
|
|
case 'view_home_page':
|
2017-10-24 18:32:52 +03:00
|
|
|
case 'view_my_groups':
|
|
|
|
case 'view_group':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-10-24 18:32:52 +03:00
|
|
|
roomId: null,
|
|
|
|
roomAlias: null,
|
2021-04-28 11:04:02 +03:00
|
|
|
viaServers: [],
|
2017-10-24 18:32:52 +03:00
|
|
|
});
|
|
|
|
break;
|
2017-06-01 20:01:30 +03:00
|
|
|
case 'view_room_error':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.viewRoomError(payload);
|
2017-06-01 20:01:30 +03:00
|
|
|
break;
|
2017-05-25 19:04:42 +03:00
|
|
|
case 'will_join':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-05-25 19:04:42 +03:00
|
|
|
joining: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'cancel_join':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-05-25 19:04:42 +03:00
|
|
|
joining: false,
|
|
|
|
});
|
|
|
|
break;
|
2017-05-24 18:56:13 +03:00
|
|
|
// join_room:
|
|
|
|
// - opts: options for joinRoom
|
|
|
|
case 'join_room':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.joinRoom(payload);
|
2017-05-24 18:56:13 +03:00
|
|
|
break;
|
2017-06-02 13:53:10 +03:00
|
|
|
case 'join_room_error':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.joinRoomError(payload);
|
2017-06-02 13:53:10 +03:00
|
|
|
break;
|
2020-03-31 12:37:56 +03:00
|
|
|
case 'join_room_ready':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({ shouldPeek: false });
|
2020-03-31 12:37:56 +03:00
|
|
|
break;
|
2019-07-04 01:46:37 +03:00
|
|
|
case 'on_client_not_viable':
|
2017-05-25 19:16:16 +03:00
|
|
|
case 'on_logged_out':
|
|
|
|
this.reset();
|
|
|
|
break;
|
2017-06-16 18:12:52 +03:00
|
|
|
case 'forward_event':
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-06-16 18:12:52 +03:00
|
|
|
forwardingEvent: payload.event,
|
|
|
|
});
|
|
|
|
break;
|
2018-02-20 02:41:07 +03:00
|
|
|
case 'reply_to_event':
|
2019-09-09 11:34:08 +03:00
|
|
|
// If currently viewed room does not match the room in which we wish to reply then change rooms
|
|
|
|
// this can happen when performing a search across all rooms
|
2020-07-21 12:14:12 +03:00
|
|
|
if (payload.event && payload.event.getRoomId() !== this.state.roomId) {
|
2019-09-09 11:34:08 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: payload.event.getRoomId(),
|
|
|
|
replyingToEvent: payload.event,
|
|
|
|
});
|
|
|
|
} else {
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2019-09-09 11:34:08 +03:00
|
|
|
replyingToEvent: payload.event,
|
|
|
|
});
|
|
|
|
}
|
2018-02-20 02:41:07 +03:00
|
|
|
break;
|
2019-02-04 23:25:26 +03:00
|
|
|
case 'open_room_settings': {
|
|
|
|
const RoomSettingsDialog = sdk.getComponent("dialogs.RoomSettingsDialog");
|
|
|
|
Modal.createTrackedDialog('Room settings', '', RoomSettingsDialog, {
|
2020-07-21 12:14:12 +03:00
|
|
|
roomId: payload.room_id || this.state.roomId,
|
2019-04-08 21:12:04 +03:00
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
2018-05-29 15:16:39 +03:00
|
|
|
break;
|
2019-02-04 23:25:26 +03:00
|
|
|
}
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:15:05 +03:00
|
|
|
private async viewRoom(payload: ActionPayload) {
|
2017-06-01 20:01:30 +03:00
|
|
|
if (payload.room_id) {
|
2017-06-08 17:54:23 +03:00
|
|
|
const newState = {
|
2017-06-01 20:01:30 +03:00
|
|
|
roomId: payload.room_id,
|
2017-06-14 14:05:25 +03:00
|
|
|
roomAlias: payload.room_alias,
|
2017-06-08 17:47:41 +03:00
|
|
|
initialEventId: payload.event_id,
|
|
|
|
isInitialEventHighlighted: payload.highlighted,
|
2017-06-16 18:12:52 +03:00
|
|
|
forwardingEvent: null,
|
2017-06-02 11:22:48 +03:00
|
|
|
roomLoading: false,
|
|
|
|
roomLoadError: null,
|
2017-06-16 20:24:07 +03:00
|
|
|
// should peek by default
|
|
|
|
shouldPeek: payload.should_peek === undefined ? true : payload.should_peek,
|
2017-09-15 00:22:21 +03:00
|
|
|
// have we sent a join request for this room and are waiting for a response?
|
|
|
|
joining: payload.joining || false,
|
2018-02-20 02:41:07 +03:00
|
|
|
// Reset replyingToEvent because we don't want cross-room because bad UX
|
|
|
|
replyingToEvent: null,
|
2018-06-26 19:07:39 +03:00
|
|
|
// pull the user out of Room Settings
|
|
|
|
isEditingSettings: false,
|
2021-04-28 11:04:02 +03:00
|
|
|
viaServers: payload.via_servers,
|
2017-06-08 17:54:23 +03:00
|
|
|
};
|
2019-01-17 12:29:37 +03:00
|
|
|
|
2019-09-09 11:34:08 +03:00
|
|
|
// Allow being given an event to be replied to when switching rooms but sanity check its for this room
|
|
|
|
if (payload.replyingToEvent && payload.replyingToEvent.getRoomId() === payload.room_id) {
|
|
|
|
newState.replyingToEvent = payload.replyingToEvent;
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
if (this.state.forwardingEvent) {
|
2019-01-17 12:29:37 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'send_event',
|
|
|
|
room_id: newState.roomId,
|
2020-07-21 12:14:12 +03:00
|
|
|
event: this.state.forwardingEvent,
|
2019-01-17 12:29:37 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState(newState);
|
2019-01-17 12:29:37 +03:00
|
|
|
|
2017-09-15 01:06:00 +03:00
|
|
|
if (payload.auto_join) {
|
2020-07-21 12:14:12 +03:00
|
|
|
this.joinRoom(payload);
|
2017-09-15 01:06:00 +03:00
|
|
|
}
|
2017-06-02 11:22:48 +03:00
|
|
|
} else if (payload.room_alias) {
|
2019-11-12 14:43:18 +03:00
|
|
|
// Try the room alias to room ID navigation cache first to avoid
|
|
|
|
// blocking room navigation on the homeserver.
|
2019-11-12 16:29:01 +03:00
|
|
|
let roomId = getCachedRoomIDForAlias(payload.room_alias);
|
|
|
|
if (!roomId) {
|
|
|
|
// Room alias cache miss, so let's ask the homeserver. Resolve the alias
|
|
|
|
// and then do a second dispatch with the room ID acquired.
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2019-11-12 16:29:01 +03:00
|
|
|
roomId: null,
|
|
|
|
initialEventId: null,
|
|
|
|
initialEventPixelOffset: null,
|
|
|
|
isInitialEventHighlighted: null,
|
|
|
|
roomAlias: payload.room_alias,
|
|
|
|
roomLoading: true,
|
|
|
|
roomLoadError: null,
|
2021-04-28 11:04:02 +03:00
|
|
|
viaServers: payload.via_servers,
|
2019-11-12 14:43:18 +03:00
|
|
|
});
|
2019-11-12 16:29:01 +03:00
|
|
|
try {
|
|
|
|
const result = await MatrixClientPeg.get().getRoomIdForAlias(payload.room_alias);
|
|
|
|
storeRoomAliasInCache(payload.room_alias, result.room_id);
|
|
|
|
roomId = result.room_id;
|
|
|
|
} catch (err) {
|
2020-05-22 13:18:14 +03:00
|
|
|
console.error("RVS failed to get room id for alias: ", err);
|
2019-11-12 16:29:01 +03:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_error',
|
|
|
|
room_id: null,
|
|
|
|
room_alias: payload.room_alias,
|
|
|
|
err,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2019-11-12 14:43:18 +03:00
|
|
|
}
|
2019-11-12 16:29:01 +03:00
|
|
|
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: roomId,
|
|
|
|
event_id: payload.event_id,
|
|
|
|
highlighted: payload.highlighted,
|
|
|
|
room_alias: payload.room_alias,
|
|
|
|
auto_join: payload.auto_join,
|
|
|
|
oob_data: payload.oob_data,
|
2017-05-24 18:56:13 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:15:05 +03:00
|
|
|
private viewRoomError(payload: ActionPayload) {
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-06-01 20:01:30 +03:00
|
|
|
roomId: payload.room_id,
|
|
|
|
roomAlias: payload.room_alias,
|
|
|
|
roomLoading: false,
|
|
|
|
roomLoadError: payload.err,
|
2021-04-28 11:04:02 +03:00
|
|
|
viaServers: [],
|
2017-06-01 20:01:30 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:16:29 +03:00
|
|
|
private async joinRoom(payload: ActionPayload) {
|
2020-10-29 18:53:14 +03:00
|
|
|
const startTime = CountlyAnalytics.getTimestamp();
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-05-24 18:56:13 +03:00
|
|
|
joining: true,
|
|
|
|
});
|
2020-09-14 17:16:29 +03:00
|
|
|
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const address = this.state.roomAlias || this.state.roomId;
|
|
|
|
try {
|
2021-04-28 11:04:02 +03:00
|
|
|
const viaServers = this.state.viaServers || [];
|
2021-03-24 19:45:53 +03:00
|
|
|
await retry<void, MatrixError>(() => cli.joinRoom(address, {
|
2021-04-28 11:04:02 +03:00
|
|
|
viaServers,
|
2021-03-24 19:45:53 +03:00
|
|
|
...payload.opts,
|
|
|
|
}), NUM_JOIN_RETRY, (err) => {
|
2020-09-14 17:16:29 +03:00
|
|
|
// if we received a Gateway timeout then retry
|
|
|
|
return err.httpStatus === 504;
|
|
|
|
});
|
2020-10-29 18:53:14 +03:00
|
|
|
CountlyAnalytics.instance.trackRoomJoin(startTime, this.state.roomId, payload._type);
|
2020-09-14 17:16:29 +03:00
|
|
|
|
2020-03-31 12:37:56 +03:00
|
|
|
// We do *not* clear the 'joining' flag because the Room object and/or our 'joined' member event may not
|
|
|
|
// have come down the sync stream yet, and that's the point at which we'd consider the user joined to the
|
|
|
|
// room.
|
|
|
|
dis.dispatch({ action: 'join_room_ready' });
|
2020-09-14 17:16:29 +03:00
|
|
|
} catch (err) {
|
2019-01-17 12:29:37 +03:00
|
|
|
dis.dispatch({
|
2017-06-02 13:53:10 +03:00
|
|
|
action: 'join_room_error',
|
|
|
|
err: err,
|
|
|
|
});
|
2020-09-14 17:16:29 +03:00
|
|
|
|
2018-08-21 20:33:25 +03:00
|
|
|
let msg = err.message ? err.message : JSON.stringify(err);
|
2020-05-26 15:58:09 +03:00
|
|
|
console.log("Failed to join room:", msg);
|
2020-09-14 17:16:29 +03:00
|
|
|
|
2020-05-26 16:20:58 +03:00
|
|
|
if (err.name === "ConnectionError") {
|
2018-11-28 00:23:28 +03:00
|
|
|
msg = _t("There was an error joining the room");
|
2020-07-30 11:33:36 +03:00
|
|
|
} else if (err.errcode === 'M_INCOMPATIBLE_ROOM_VERSION') {
|
2018-08-21 20:33:25 +03:00
|
|
|
msg = <div>
|
|
|
|
{_t("Sorry, your homeserver is too old to participate in this room.")}<br />
|
|
|
|
{_t("Please contact your homeserver administrator.")}
|
|
|
|
</div>;
|
2020-07-30 11:33:36 +03:00
|
|
|
} else if (err.httpStatus === 404) {
|
2020-08-04 23:35:42 +03:00
|
|
|
const invitingUserId = this.getInvitingUserId(this.state.roomId);
|
2020-07-29 17:51:37 +03:00
|
|
|
// only provide a better error message for invites
|
|
|
|
if (invitingUserId) {
|
|
|
|
// if the inviting user is on the same HS, there can only be one cause: they left.
|
|
|
|
if (invitingUserId.endsWith(`:${MatrixClientPeg.get().getDomain()}`)) {
|
|
|
|
msg = _t("The person who invited you already left the room.");
|
|
|
|
} else {
|
|
|
|
msg = _t("The person who invited you already left the room, or their server is offline.");
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 20:33:25 +03:00
|
|
|
}
|
2020-09-14 17:16:29 +03:00
|
|
|
|
2017-06-02 13:53:10 +03:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-08-10 15:49:11 +03:00
|
|
|
Modal.createTrackedDialog('Failed to join room', '', ErrorDialog, {
|
2017-06-02 13:53:10 +03:00
|
|
|
title: _t("Failed to join room"),
|
|
|
|
description: msg,
|
|
|
|
});
|
2020-09-14 17:16:29 +03:00
|
|
|
}
|
2017-06-02 13:53:10 +03:00
|
|
|
}
|
|
|
|
|
2020-08-04 23:33:27 +03:00
|
|
|
private getInvitingUserId(roomId: string): string {
|
2020-07-29 17:51:37 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const room = cli.getRoom(roomId);
|
|
|
|
if (room && room.getMyMembership() === "invite") {
|
|
|
|
const myMember = room.getMember(cli.getUserId());
|
|
|
|
const inviteEvent = myMember ? myMember.events.member : null;
|
|
|
|
return inviteEvent && inviteEvent.getSender();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:15:05 +03:00
|
|
|
private joinRoomError(payload: ActionPayload) {
|
2020-07-21 12:14:12 +03:00
|
|
|
this.setState({
|
2017-06-02 15:41:41 +03:00
|
|
|
joining: false,
|
|
|
|
joinError: payload.err,
|
|
|
|
});
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
public reset() {
|
|
|
|
this.state = Object.assign({}, INITIAL_STATE);
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// The room ID of the room currently being viewed
|
2020-07-21 12:14:12 +03:00
|
|
|
public getRoomId() {
|
|
|
|
return this.state.roomId;
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 19:28:56 +03:00
|
|
|
// The event to scroll to when the room is first viewed
|
2020-07-21 12:14:12 +03:00
|
|
|
public getInitialEventId() {
|
|
|
|
return this.state.initialEventId;
|
2017-06-08 16:17:49 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// Whether to highlight the initial event
|
2020-07-21 12:14:12 +03:00
|
|
|
public isInitialEventHighlighted() {
|
|
|
|
return this.state.isInitialEventHighlighted;
|
2017-06-08 16:17:49 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// The room alias of the room (or null if not originally specified in view_room)
|
2020-07-21 12:14:12 +03:00
|
|
|
public getRoomAlias() {
|
|
|
|
return this.state.roomAlias;
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// Whether the current room is loading (true whilst resolving an alias)
|
2020-07-21 12:14:12 +03:00
|
|
|
public isRoomLoading() {
|
|
|
|
return this.state.roomLoading;
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// Any error that has occurred during loading
|
2020-07-21 12:14:12 +03:00
|
|
|
public getRoomLoadError() {
|
|
|
|
return this.state.roomLoadError;
|
2017-06-01 20:01:30 +03:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:07:09 +03:00
|
|
|
// True if we're expecting the user to be joined to the room currently being
|
|
|
|
// viewed. Note that this is left true after the join request has finished,
|
|
|
|
// since we should still consider a join to be in progress until the room
|
|
|
|
// & member events come down the sync.
|
|
|
|
//
|
|
|
|
// This flag remains true after the room has been sucessfully joined,
|
|
|
|
// (this store doesn't listen for the appropriate member events)
|
2017-09-19 12:21:20 +03:00
|
|
|
// so you should always observe the joined state from the member event
|
|
|
|
// if a room object is present.
|
2017-09-15 17:07:09 +03:00
|
|
|
// ie. The correct logic is:
|
2017-09-19 12:21:20 +03:00
|
|
|
// if (room) {
|
|
|
|
// if (myMember.membership == 'joined') {
|
|
|
|
// // user is joined to the room
|
|
|
|
// } else {
|
|
|
|
// // Not joined
|
|
|
|
// }
|
2017-09-15 17:07:09 +03:00
|
|
|
// } else {
|
|
|
|
// if (RoomViewStore.isJoining()) {
|
|
|
|
// // show spinner
|
|
|
|
// } else {
|
|
|
|
// // show join prompt
|
|
|
|
// }
|
|
|
|
// }
|
2020-07-21 12:14:12 +03:00
|
|
|
public isJoining() {
|
|
|
|
return this.state.joining;
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:00:12 +03:00
|
|
|
// Any error that has occurred during joining
|
2020-07-21 12:14:12 +03:00
|
|
|
public getJoinError() {
|
|
|
|
return this.state.joinError;
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
2017-06-16 18:12:52 +03:00
|
|
|
|
|
|
|
// The mxEvent if one is about to be forwarded
|
2020-07-21 12:14:12 +03:00
|
|
|
public getForwardingEvent() {
|
|
|
|
return this.state.forwardingEvent;
|
2017-06-16 18:12:52 +03:00
|
|
|
}
|
2017-06-19 03:53:35 +03:00
|
|
|
|
2017-12-10 15:50:41 +03:00
|
|
|
// The mxEvent if one is currently being replied to/quoted
|
2020-07-21 12:14:12 +03:00
|
|
|
public getQuotingEvent() {
|
|
|
|
return this.state.replyingToEvent;
|
2017-12-10 15:50:41 +03:00
|
|
|
}
|
|
|
|
|
2020-07-21 12:14:12 +03:00
|
|
|
public shouldPeek() {
|
|
|
|
return this.state.shouldPeek;
|
2017-06-16 20:24:07 +03:00
|
|
|
}
|
2017-05-24 18:56:13 +03:00
|
|
|
}
|
|
|
|
|
2019-01-17 12:29:37 +03:00
|
|
|
let singletonRoomViewStore = null;
|
|
|
|
if (!singletonRoomViewStore) {
|
|
|
|
singletonRoomViewStore = new RoomViewStore();
|
|
|
|
}
|
2019-12-20 03:45:24 +03:00
|
|
|
export default singletonRoomViewStore;
|