Trigger join room actions properly
This commit is contained in:
parent
d6bc1861ae
commit
b5295b03ce
5 changed files with 72 additions and 44 deletions
|
@ -22,6 +22,7 @@ import SdkConfig from './SdkConfig';
|
|||
import {MatrixClientPeg} from "./MatrixClientPeg";
|
||||
import {sleep} from "./utils/promise";
|
||||
import RoomViewStore from "./stores/RoomViewStore";
|
||||
import { Action } from "./dispatcher/actions";
|
||||
|
||||
// polyfill textencoder if necessary
|
||||
import * as TextEncodingUtf8 from 'text-encoding-utf-8';
|
||||
|
@ -265,7 +266,7 @@ interface ICreateRoomEvent extends IEvent {
|
|||
}
|
||||
|
||||
interface IJoinRoomEvent extends IEvent {
|
||||
key: "join_room";
|
||||
key: Action.JoinRoom;
|
||||
dur: number; // how long it took to join (until remote echo)
|
||||
segmentation: {
|
||||
room_id: string; // hashed
|
||||
|
@ -858,7 +859,7 @@ export default class CountlyAnalytics {
|
|||
}
|
||||
|
||||
public trackRoomJoin(startTime: number, roomId: string, type: IJoinRoomEvent["segmentation"]["type"]) {
|
||||
this.track<IJoinRoomEvent>("join_room", { type }, roomId, {
|
||||
this.track<IJoinRoomEvent>(Action.JoinRoom, { type }, roomId, {
|
||||
dur: CountlyAnalytics.getTimestamp() - startTime,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1114,7 +1114,8 @@ export default class RoomView extends React.Component<IProps, IState> {
|
|||
Promise.resolve().then(() => {
|
||||
const signUrl = this.props.threepidInvite?.signUrl;
|
||||
dis.dispatch({
|
||||
action: 'join_room',
|
||||
action: Action.JoinRoom,
|
||||
roomId: this.getRoomId(),
|
||||
opts: { inviteSignUrl: signUrl },
|
||||
_type: "unknown", // TODO: instrumentation
|
||||
});
|
||||
|
|
|
@ -34,6 +34,7 @@ import { isJoinedOrNearlyJoined } from "./utils/membership";
|
|||
import { VIRTUAL_ROOM_EVENT_TYPE } from "./CallHandler";
|
||||
import SpaceStore from "./stores/SpaceStore";
|
||||
import { makeSpaceParentEvent } from "./utils/space";
|
||||
import { Action } from "./dispatcher/actions"
|
||||
|
||||
// we define a number of interfaces which take their names from the js-sdk
|
||||
/* eslint-disable camelcase */
|
||||
|
@ -243,7 +244,8 @@ export default function createRoom(opts: IOpts): Promise<string | null> {
|
|||
|
||||
// We also failed to join the room (this sets joining to false in RoomViewStore)
|
||||
dis.dispatch({
|
||||
action: 'join_room_error',
|
||||
action: Action.JoinRoomError,
|
||||
roomId,
|
||||
});
|
||||
console.error("Failed to create room " + roomId + " " + err);
|
||||
let description = _t("Server may be unavailable, overloaded, or you hit a bug.");
|
||||
|
|
|
@ -138,4 +138,19 @@ export enum Action {
|
|||
* Fired when an upload is cancelled by the user. Should be used with UploadCanceledPayload.
|
||||
*/
|
||||
UploadCanceled = "upload_canceled",
|
||||
|
||||
/**
|
||||
* Fired when requesting to join a room
|
||||
*/
|
||||
JoinRoom = "join_room",
|
||||
|
||||
/**
|
||||
* Fired when successfully joining a room
|
||||
*/
|
||||
JoinRoomReady = "join_room_ready",
|
||||
|
||||
/**
|
||||
* Fired when joining a room failed
|
||||
*/
|
||||
JoinRoomError = "join_room",
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import Modal from '../Modal';
|
|||
import { _t } from '../languageHandler';
|
||||
import { getCachedRoomIDForAlias, storeRoomAliasInCache } from '../RoomAliasCache';
|
||||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import { Action } from "../dispatcher/actions";
|
||||
import { retry } from "../utils/promise";
|
||||
import CountlyAnalytics from "../CountlyAnalytics";
|
||||
|
||||
|
@ -136,13 +137,13 @@ class RoomViewStore extends Store<ActionPayload> {
|
|||
break;
|
||||
// join_room:
|
||||
// - opts: options for joinRoom
|
||||
case 'join_room':
|
||||
case Action.JoinRoom:
|
||||
this.joinRoom(payload);
|
||||
break;
|
||||
case 'join_room_error':
|
||||
case Action.JoinRoomError:
|
||||
this.joinRoomError(payload);
|
||||
break;
|
||||
case 'join_room_ready':
|
||||
case Action.JoinRoomReady:
|
||||
this.setState({ shouldPeek: false });
|
||||
break;
|
||||
case 'on_client_not_viable':
|
||||
|
@ -217,7 +218,11 @@ class RoomViewStore extends Store<ActionPayload> {
|
|||
this.setState(newState);
|
||||
|
||||
if (payload.auto_join) {
|
||||
this.joinRoom(payload);
|
||||
dis.dispatch({
|
||||
...payload,
|
||||
action: Action.JoinRoom,
|
||||
roomId: payload.room_id,
|
||||
});
|
||||
}
|
||||
} else if (payload.room_alias) {
|
||||
// Try the room alias to room ID navigation cache first to avoid
|
||||
|
@ -298,13 +303,35 @@ class RoomViewStore extends Store<ActionPayload> {
|
|||
// 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' });
|
||||
dis.dispatch({
|
||||
action: Action.JoinRoomReady,
|
||||
roomId: this.state.roomId,
|
||||
});
|
||||
} catch (err) {
|
||||
dis.dispatch({
|
||||
action: 'join_room_error',
|
||||
action: Action.JoinRoomError,
|
||||
roomId: this.state.roomId,
|
||||
err: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private getInvitingUserId(roomId: string): string {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private joinRoomError(payload: ActionPayload) {
|
||||
this.setState({
|
||||
joining: false,
|
||||
joinError: payload.err,
|
||||
});
|
||||
const err = payload.err;
|
||||
let msg = err.message ? err.message : JSON.stringify(err);
|
||||
console.log("Failed to join room:", msg);
|
||||
|
||||
|
@ -334,24 +361,6 @@ class RoomViewStore extends Store<ActionPayload> {
|
|||
description: msg,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private getInvitingUserId(roomId: string): string {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private joinRoomError(payload: ActionPayload) {
|
||||
this.setState({
|
||||
joining: false,
|
||||
joinError: payload.err,
|
||||
});
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this.state = Object.assign({}, INITIAL_STATE);
|
||||
|
|
Loading…
Reference in a new issue