2017-05-24 15:56:13 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-07-03 10:16:44 +00:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2019-12-20 00:45:24 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-05-24 15:56:13 +00: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 09:14:12 +00:00
|
|
|
|
|
|
|
import React from "react";
|
2017-05-24 15:56:13 +00:00
|
|
|
import {Store} from 'flux/utils';
|
2020-09-14 14:16:29 +00:00
|
|
|
import {MatrixError} from "matrix-js-sdk/src/http-api";
|
2020-07-21 09:14:12 +00:00
|
|
|
|
|
|
|
import dis from '../dispatcher/dispatcher';
|
2019-12-20 21:13:46 +00:00
|
|
|
import {MatrixClientPeg} from '../MatrixClientPeg';
|
2019-12-20 01:19:56 +00:00
|
|
|
import * as sdk from '../index';
|
2017-06-02 10:53:10 +00:00
|
|
|
import Modal from '../Modal';
|
|
|
|
import { _t } from '../languageHandler';
|
2019-11-12 11:43:18 +00:00
|
|
|
import { getCachedRoomIDForAlias, storeRoomAliasInCache } from '../RoomAliasCache';
|
2020-07-21 09:14:12 +00:00
|
|
|
import {ActionPayload} from "../dispatcher/payloads";
|
2020-09-14 14:16:29 +00:00
|
|
|
import {retry} from "../utils/promise";
|
2020-10-29 15:53:14 +00:00
|
|
|
import CountlyAnalytics from "../CountlyAnalytics";
|
2020-09-14 14:16:29 +00:00
|
|
|
|
|
|
|
const NUM_JOIN_RETRY = 5;
|
2017-05-24 15:56:13 +00:00
|
|
|
|
|
|
|
const INITIAL_STATE = {
|
2017-09-15 14:07:09 +00:00
|
|
|
// Whether we're joining the currently viewed room (see isJoining())
|
2017-05-24 15:56:13 +00:00
|
|
|
joining: false,
|
2017-06-08 15:00:12 +00:00
|
|
|
// Any error that has occurred during joining
|
2017-05-24 15:56:13 +00:00
|
|
|
joinError: null,
|
2017-06-08 15:00:12 +00:00
|
|
|
// The room ID of the room currently being viewed
|
2017-05-24 15:56:13 +00:00
|
|
|
roomId: null,
|
2017-06-08 14:47:41 +00:00
|
|
|
|
2017-06-08 16:27:04 +00:00
|
|
|
// The event to scroll to when the room is first viewed
|
2017-06-08 14:47:41 +00:00
|
|
|
initialEventId: null,
|
2020-07-21 09:14:12 +00:00
|
|
|
initialEventPixelOffset: null,
|
2017-06-08 14:47:41 +00:00
|
|
|
// Whether to highlight the initial event
|
|
|
|
isInitialEventHighlighted: false,
|
|
|
|
|
2017-05-24 15:56:13 +00: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 15:12:52 +00:00
|
|
|
|
|
|
|
forwardingEvent: null,
|
2017-12-10 12:50:41 +00:00
|
|
|
|
|
|
|
quotingEvent: null,
|
2020-07-21 09:14:12 +00:00
|
|
|
|
|
|
|
replyingToEvent: null,
|
|
|
|
|
|
|
|
shouldPeek: false,
|
2021-04-28 08:04:02 +00:00
|
|
|
|
|
|
|
viaServers: [],
|
2021-04-29 08:37:21 +00:00
|
|
|
|
|
|
|
wasContextSwitch: false,
|
2017-05-24 15:56:13 +00: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 09:14:12 +00:00
|
|
|
class RoomViewStore extends Store<ActionPayload> {
|
|
|
|
private state = INITIAL_STATE; // initialize state
|
|
|
|
|
2019-01-17 09:29:37 +00:00
|
|
|
constructor() {
|
|
|
|
super(dis);
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:14:12 +00:00
|
|
|
setState(newState: Partial<typeof INITIAL_STATE>) {
|
2020-02-06 17:57:17 +00: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 09:14:12 +00:00
|
|
|
if (this.state[key] !== newState[key]) {
|
2020-02-06 17:57:17 +00:00
|
|
|
stateChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!stateChanged) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:14:12 +00:00
|
|
|
this.state = Object.assign(this.state, newState);
|
2017-05-24 15:56:13 +00:00
|
|
|
this.__emitChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
__onDispatch(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
// view_room:
|
2017-06-08 13:17:49 +00:00
|
|
|
// - room_alias: '#somealias:matrix.org'
|
|
|
|
// - room_id: '!roomid123:matrix.org'
|
|
|
|
// - event_id: '$213456782:matrix.org'
|
|
|
|
// - event_offset: 100
|
|
|
|
// - highlighted: true
|
2017-05-24 15:56:13 +00:00
|
|
|
case 'view_room':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.viewRoom(payload);
|
2017-05-24 15:56:13 +00:00
|
|
|
break;
|
2020-07-21 09:22:03 +00:00
|
|
|
// for these events blank out the roomId as we are no longer in the RoomView
|
2020-07-21 09:20:30 +00:00
|
|
|
case 'view_create_group':
|
|
|
|
case 'view_welcome_page':
|
|
|
|
case 'view_home_page':
|
2017-10-24 15:32:52 +00:00
|
|
|
case 'view_my_groups':
|
|
|
|
case 'view_group':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-10-24 15:32:52 +00:00
|
|
|
roomId: null,
|
|
|
|
roomAlias: null,
|
2021-04-28 08:04:02 +00:00
|
|
|
viaServers: [],
|
2021-04-29 08:37:21 +00:00
|
|
|
wasContextSwitch: false,
|
2017-10-24 15:32:52 +00:00
|
|
|
});
|
|
|
|
break;
|
2017-06-01 17:01:30 +00:00
|
|
|
case 'view_room_error':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.viewRoomError(payload);
|
2017-06-01 17:01:30 +00:00
|
|
|
break;
|
2017-05-25 16:04:42 +00:00
|
|
|
case 'will_join':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-05-25 16:04:42 +00:00
|
|
|
joining: true,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'cancel_join':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-05-25 16:04:42 +00:00
|
|
|
joining: false,
|
|
|
|
});
|
|
|
|
break;
|
2017-05-24 15:56:13 +00:00
|
|
|
// join_room:
|
|
|
|
// - opts: options for joinRoom
|
|
|
|
case 'join_room':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.joinRoom(payload);
|
2017-05-24 15:56:13 +00:00
|
|
|
break;
|
2017-06-02 10:53:10 +00:00
|
|
|
case 'join_room_error':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.joinRoomError(payload);
|
2017-06-02 10:53:10 +00:00
|
|
|
break;
|
2020-03-31 09:37:56 +00:00
|
|
|
case 'join_room_ready':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({ shouldPeek: false });
|
2020-03-31 09:37:56 +00:00
|
|
|
break;
|
2019-07-03 22:46:37 +00:00
|
|
|
case 'on_client_not_viable':
|
2017-05-25 16:16:16 +00:00
|
|
|
case 'on_logged_out':
|
|
|
|
this.reset();
|
|
|
|
break;
|
2017-06-16 15:12:52 +00:00
|
|
|
case 'forward_event':
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-06-16 15:12:52 +00:00
|
|
|
forwardingEvent: payload.event,
|
|
|
|
});
|
|
|
|
break;
|
2018-02-19 23:41:07 +00:00
|
|
|
case 'reply_to_event':
|
2019-09-09 08:34:08 +00: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 09:14:12 +00:00
|
|
|
if (payload.event && payload.event.getRoomId() !== this.state.roomId) {
|
2019-09-09 08:34:08 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_id: payload.event.getRoomId(),
|
|
|
|
replyingToEvent: payload.event,
|
|
|
|
});
|
|
|
|
} else {
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2019-09-09 08:34:08 +00:00
|
|
|
replyingToEvent: payload.event,
|
|
|
|
});
|
|
|
|
}
|
2018-02-19 23:41:07 +00:00
|
|
|
break;
|
2019-02-04 20:25:26 +00:00
|
|
|
case 'open_room_settings': {
|
|
|
|
const RoomSettingsDialog = sdk.getComponent("dialogs.RoomSettingsDialog");
|
|
|
|
Modal.createTrackedDialog('Room settings', '', RoomSettingsDialog, {
|
2020-07-21 09:14:12 +00:00
|
|
|
roomId: payload.room_id || this.state.roomId,
|
2019-04-08 18:12:04 +00:00
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
2018-05-29 12:16:39 +00:00
|
|
|
break;
|
2019-02-04 20:25:26 +00:00
|
|
|
}
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:15:05 +00:00
|
|
|
private async viewRoom(payload: ActionPayload) {
|
2017-06-01 17:01:30 +00:00
|
|
|
if (payload.room_id) {
|
2017-06-08 14:54:23 +00:00
|
|
|
const newState = {
|
2017-06-01 17:01:30 +00:00
|
|
|
roomId: payload.room_id,
|
2017-06-14 11:05:25 +00:00
|
|
|
roomAlias: payload.room_alias,
|
2017-06-08 14:47:41 +00:00
|
|
|
initialEventId: payload.event_id,
|
|
|
|
isInitialEventHighlighted: payload.highlighted,
|
2017-06-16 15:12:52 +00:00
|
|
|
forwardingEvent: null,
|
2017-06-02 08:22:48 +00:00
|
|
|
roomLoading: false,
|
|
|
|
roomLoadError: null,
|
2017-06-16 17:24:07 +00:00
|
|
|
// should peek by default
|
|
|
|
shouldPeek: payload.should_peek === undefined ? true : payload.should_peek,
|
2017-09-14 21:22:21 +00:00
|
|
|
// have we sent a join request for this room and are waiting for a response?
|
|
|
|
joining: payload.joining || false,
|
2018-02-19 23:41:07 +00:00
|
|
|
// Reset replyingToEvent because we don't want cross-room because bad UX
|
|
|
|
replyingToEvent: null,
|
2018-06-26 16:07:39 +00:00
|
|
|
// pull the user out of Room Settings
|
|
|
|
isEditingSettings: false,
|
2021-04-28 08:04:02 +00:00
|
|
|
viaServers: payload.via_servers,
|
2021-04-29 08:37:21 +00:00
|
|
|
wasContextSwitch: payload.context_switch,
|
2017-06-08 14:54:23 +00:00
|
|
|
};
|
2019-01-17 09:29:37 +00:00
|
|
|
|
2019-09-09 08:34:08 +00: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 09:14:12 +00:00
|
|
|
if (this.state.forwardingEvent) {
|
2019-01-17 09:29:37 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'send_event',
|
|
|
|
room_id: newState.roomId,
|
2020-07-21 09:14:12 +00:00
|
|
|
event: this.state.forwardingEvent,
|
2019-01-17 09:29:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState(newState);
|
2019-01-17 09:29:37 +00:00
|
|
|
|
2017-09-14 22:06:00 +00:00
|
|
|
if (payload.auto_join) {
|
2020-07-21 09:14:12 +00:00
|
|
|
this.joinRoom(payload);
|
2017-09-14 22:06:00 +00:00
|
|
|
}
|
2017-06-02 08:22:48 +00:00
|
|
|
} else if (payload.room_alias) {
|
2019-11-12 11:43:18 +00:00
|
|
|
// Try the room alias to room ID navigation cache first to avoid
|
|
|
|
// blocking room navigation on the homeserver.
|
2019-11-12 13:29:01 +00: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 09:14:12 +00:00
|
|
|
this.setState({
|
2019-11-12 13:29:01 +00:00
|
|
|
roomId: null,
|
|
|
|
initialEventId: null,
|
|
|
|
initialEventPixelOffset: null,
|
|
|
|
isInitialEventHighlighted: null,
|
|
|
|
roomAlias: payload.room_alias,
|
|
|
|
roomLoading: true,
|
|
|
|
roomLoadError: null,
|
2021-04-28 08:04:02 +00:00
|
|
|
viaServers: payload.via_servers,
|
2021-04-29 08:37:21 +00:00
|
|
|
wasContextSwitch: payload.context_switch,
|
2019-11-12 11:43:18 +00:00
|
|
|
});
|
2019-11-12 13:29:01 +00: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 10:18:14 +00:00
|
|
|
console.error("RVS failed to get room id for alias: ", err);
|
2019-11-12 13:29:01 +00:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room_error',
|
|
|
|
room_id: null,
|
|
|
|
room_alias: payload.room_alias,
|
|
|
|
err,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2019-11-12 11:43:18 +00:00
|
|
|
}
|
2019-11-12 13:29:01 +00: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,
|
2021-04-29 08:37:21 +00:00
|
|
|
viaServers: payload.via_servers,
|
|
|
|
wasContextSwitch: payload.context_switch,
|
2017-05-24 15:56:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 09:15:05 +00:00
|
|
|
private viewRoomError(payload: ActionPayload) {
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-06-01 17:01:30 +00:00
|
|
|
roomId: payload.room_id,
|
|
|
|
roomAlias: payload.room_alias,
|
|
|
|
roomLoading: false,
|
|
|
|
roomLoadError: payload.err,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-14 14:16:29 +00:00
|
|
|
private async joinRoom(payload: ActionPayload) {
|
2020-10-29 15:53:14 +00:00
|
|
|
const startTime = CountlyAnalytics.getTimestamp();
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-05-24 15:56:13 +00:00
|
|
|
joining: true,
|
|
|
|
});
|
2020-09-14 14:16:29 +00:00
|
|
|
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const address = this.state.roomAlias || this.state.roomId;
|
2021-04-28 08:07:02 +00:00
|
|
|
const viaServers = this.state.viaServers || [];
|
2020-09-14 14:16:29 +00:00
|
|
|
try {
|
2021-03-24 16:45:53 +00:00
|
|
|
await retry<void, MatrixError>(() => cli.joinRoom(address, {
|
2021-04-28 08:04:02 +00:00
|
|
|
viaServers,
|
2021-03-24 16:45:53 +00:00
|
|
|
...payload.opts,
|
|
|
|
}), NUM_JOIN_RETRY, (err) => {
|
2020-09-14 14:16:29 +00:00
|
|
|
// if we received a Gateway timeout then retry
|
|
|
|
return err.httpStatus === 504;
|
|
|
|
});
|
2020-10-29 15:53:14 +00:00
|
|
|
CountlyAnalytics.instance.trackRoomJoin(startTime, this.state.roomId, payload._type);
|
2020-09-14 14:16:29 +00:00
|
|
|
|
2020-03-31 09:37:56 +00: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 14:16:29 +00:00
|
|
|
} catch (err) {
|
2019-01-17 09:29:37 +00:00
|
|
|
dis.dispatch({
|
2017-06-02 10:53:10 +00:00
|
|
|
action: 'join_room_error',
|
|
|
|
err: err,
|
|
|
|
});
|
2020-09-14 14:16:29 +00:00
|
|
|
|
2018-08-21 17:33:25 +00:00
|
|
|
let msg = err.message ? err.message : JSON.stringify(err);
|
2020-05-26 12:58:09 +00:00
|
|
|
console.log("Failed to join room:", msg);
|
2020-09-14 14:16:29 +00:00
|
|
|
|
2020-05-26 13:20:58 +00:00
|
|
|
if (err.name === "ConnectionError") {
|
2018-11-27 21:23:28 +00:00
|
|
|
msg = _t("There was an error joining the room");
|
2020-07-30 08:33:36 +00:00
|
|
|
} else if (err.errcode === 'M_INCOMPATIBLE_ROOM_VERSION') {
|
2018-08-21 17:33:25 +00: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 08:33:36 +00:00
|
|
|
} else if (err.httpStatus === 404) {
|
2020-08-04 20:35:42 +00:00
|
|
|
const invitingUserId = this.getInvitingUserId(this.state.roomId);
|
2020-07-29 14:51:37 +00: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 17:33:25 +00:00
|
|
|
}
|
2020-09-14 14:16:29 +00:00
|
|
|
|
2017-06-02 10:53:10 +00:00
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-08-10 12:49:11 +00:00
|
|
|
Modal.createTrackedDialog('Failed to join room', '', ErrorDialog, {
|
2017-06-02 10:53:10 +00:00
|
|
|
title: _t("Failed to join room"),
|
|
|
|
description: msg,
|
|
|
|
});
|
2020-09-14 14:16:29 +00:00
|
|
|
}
|
2017-06-02 10:53:10 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 20:33:27 +00:00
|
|
|
private getInvitingUserId(roomId: string): string {
|
2020-07-29 14:51:37 +00: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 09:15:05 +00:00
|
|
|
private joinRoomError(payload: ActionPayload) {
|
2020-07-21 09:14:12 +00:00
|
|
|
this.setState({
|
2017-06-02 12:41:41 +00:00
|
|
|
joining: false,
|
|
|
|
joinError: payload.err,
|
|
|
|
});
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:14:12 +00:00
|
|
|
public reset() {
|
|
|
|
this.state = Object.assign({}, INITIAL_STATE);
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// The room ID of the room currently being viewed
|
2020-07-21 09:14:12 +00:00
|
|
|
public getRoomId() {
|
|
|
|
return this.state.roomId;
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 16:28:56 +00:00
|
|
|
// The event to scroll to when the room is first viewed
|
2020-07-21 09:14:12 +00:00
|
|
|
public getInitialEventId() {
|
|
|
|
return this.state.initialEventId;
|
2017-06-08 13:17:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// Whether to highlight the initial event
|
2020-07-21 09:14:12 +00:00
|
|
|
public isInitialEventHighlighted() {
|
|
|
|
return this.state.isInitialEventHighlighted;
|
2017-06-08 13:17:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// The room alias of the room (or null if not originally specified in view_room)
|
2020-07-21 09:14:12 +00:00
|
|
|
public getRoomAlias() {
|
|
|
|
return this.state.roomAlias;
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// Whether the current room is loading (true whilst resolving an alias)
|
2020-07-21 09:14:12 +00:00
|
|
|
public isRoomLoading() {
|
|
|
|
return this.state.roomLoading;
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// Any error that has occurred during loading
|
2020-07-21 09:14:12 +00:00
|
|
|
public getRoomLoadError() {
|
|
|
|
return this.state.roomLoadError;
|
2017-06-01 17:01:30 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 14:07:09 +00: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 09:21:20 +00:00
|
|
|
// so you should always observe the joined state from the member event
|
|
|
|
// if a room object is present.
|
2017-09-15 14:07:09 +00:00
|
|
|
// ie. The correct logic is:
|
2017-09-19 09:21:20 +00:00
|
|
|
// if (room) {
|
|
|
|
// if (myMember.membership == 'joined') {
|
|
|
|
// // user is joined to the room
|
|
|
|
// } else {
|
|
|
|
// // Not joined
|
|
|
|
// }
|
2017-09-15 14:07:09 +00:00
|
|
|
// } else {
|
|
|
|
// if (RoomViewStore.isJoining()) {
|
|
|
|
// // show spinner
|
|
|
|
// } else {
|
|
|
|
// // show join prompt
|
|
|
|
// }
|
|
|
|
// }
|
2020-07-21 09:14:12 +00:00
|
|
|
public isJoining() {
|
|
|
|
return this.state.joining;
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 15:00:12 +00:00
|
|
|
// Any error that has occurred during joining
|
2020-07-21 09:14:12 +00:00
|
|
|
public getJoinError() {
|
|
|
|
return this.state.joinError;
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
2017-06-16 15:12:52 +00:00
|
|
|
|
|
|
|
// The mxEvent if one is about to be forwarded
|
2020-07-21 09:14:12 +00:00
|
|
|
public getForwardingEvent() {
|
|
|
|
return this.state.forwardingEvent;
|
2017-06-16 15:12:52 +00:00
|
|
|
}
|
2017-06-19 00:53:35 +00:00
|
|
|
|
2017-12-10 12:50:41 +00:00
|
|
|
// The mxEvent if one is currently being replied to/quoted
|
2020-07-21 09:14:12 +00:00
|
|
|
public getQuotingEvent() {
|
|
|
|
return this.state.replyingToEvent;
|
2017-12-10 12:50:41 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 09:14:12 +00:00
|
|
|
public shouldPeek() {
|
|
|
|
return this.state.shouldPeek;
|
2017-06-16 17:24:07 +00:00
|
|
|
}
|
2021-04-29 08:37:21 +00:00
|
|
|
|
|
|
|
public getWasContextSwitch() {
|
|
|
|
return this.state.wasContextSwitch;
|
|
|
|
}
|
2017-05-24 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 09:29:37 +00:00
|
|
|
let singletonRoomViewStore = null;
|
|
|
|
if (!singletonRoomViewStore) {
|
|
|
|
singletonRoomViewStore = new RoomViewStore();
|
|
|
|
}
|
2019-12-20 00:45:24 +00:00
|
|
|
export default singletonRoomViewStore;
|