2016-01-12 17:11:15 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-17 18:50:30 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-06-10 12:24:06 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2016-01-12 17:11:15 +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.
|
|
|
|
*/
|
|
|
|
|
2019-04-15 18:52:17 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 17:04:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
2019-04-15 18:52:17 +03:00
|
|
|
import dis from '../../../dispatcher';
|
2019-04-12 13:54:13 +03:00
|
|
|
import classNames from 'classnames';
|
2017-11-13 22:19:33 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-07-29 17:08:54 +03:00
|
|
|
import IdentityAuthClient from '../../../IdentityAuthClient';
|
2017-05-23 17:16:31 +03:00
|
|
|
|
2019-04-12 15:40:31 +03:00
|
|
|
const MessageCase = Object.freeze({
|
|
|
|
NotLoggedIn: "NotLoggedIn",
|
|
|
|
Joining: "Joining",
|
2019-04-15 19:49:00 +03:00
|
|
|
Loading: "Loading",
|
|
|
|
Rejecting: "Rejecting",
|
2019-04-12 15:40:31 +03:00
|
|
|
Kicked: "Kicked",
|
|
|
|
Banned: "Banned",
|
|
|
|
OtherThreePIDError: "OtherThreePIDError",
|
2019-09-03 17:32:15 +03:00
|
|
|
InvitedEmailNotFoundInAccount: "InvitedEmailNotFoundInAccount",
|
|
|
|
InvitedEmailNoIdentityServer: "InvitedEmailNoIdentityServer",
|
2019-04-15 15:43:37 +03:00
|
|
|
InvitedEmailMismatch: "InvitedEmailMismatch",
|
2019-04-12 15:40:31 +03:00
|
|
|
Invite: "Invite",
|
|
|
|
ViewingRoom: "ViewingRoom",
|
|
|
|
RoomNotFound: "RoomNotFound",
|
|
|
|
OtherError: "OtherError",
|
|
|
|
});
|
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default createReactClass({
|
2016-01-12 17:11:15 +03:00
|
|
|
displayName: 'RoomPreviewBar',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
onJoinClick: PropTypes.func,
|
|
|
|
onRejectClick: PropTypes.func,
|
2020-01-23 14:50:59 +03:00
|
|
|
onRejectAndIgnoreClick: PropTypes.func,
|
2017-12-26 04:03:18 +03:00
|
|
|
onForgetClick: PropTypes.func,
|
2016-03-10 20:43:20 +03:00
|
|
|
// if inviterName is specified, the preview bar will shown an invite to the room.
|
|
|
|
// You should also specify onRejectClick if specifiying inviterName
|
2017-12-26 04:03:18 +03:00
|
|
|
inviterName: PropTypes.string,
|
2016-03-17 21:38:25 +03:00
|
|
|
|
|
|
|
// If invited by 3rd party invite, the email address the invite was sent to
|
2017-12-26 04:03:18 +03:00
|
|
|
invitedEmail: PropTypes.string,
|
2016-06-24 17:34:07 +03:00
|
|
|
|
2019-06-06 16:34:57 +03:00
|
|
|
// For third party invites, information passed about the room out-of-band
|
|
|
|
oobData: PropTypes.object,
|
|
|
|
|
2019-06-10 12:24:06 +03:00
|
|
|
// For third party invites, a URL for a 3pid invite signing service
|
|
|
|
signUrl: PropTypes.string,
|
|
|
|
|
2016-06-24 17:34:07 +03:00
|
|
|
// A standard client/server API error object. If supplied, indicates that the
|
|
|
|
// caller was unable to fetch details about the room for the given reason.
|
2017-12-26 04:03:18 +03:00
|
|
|
error: PropTypes.object,
|
2016-06-24 17:34:07 +03:00
|
|
|
|
2017-12-26 04:03:18 +03:00
|
|
|
canPreview: PropTypes.bool,
|
2019-06-26 05:56:33 +03:00
|
|
|
previewLoading: PropTypes.bool,
|
2017-12-26 04:03:18 +03:00
|
|
|
room: PropTypes.object,
|
2016-06-28 16:59:45 +03:00
|
|
|
|
2018-10-17 22:53:12 +03:00
|
|
|
// When a spinner is present, a spinnerState can be specified to indicate the
|
|
|
|
// purpose of the spinner.
|
|
|
|
spinner: PropTypes.bool,
|
|
|
|
spinnerState: PropTypes.oneOf(["joining"]),
|
2019-04-17 20:05:52 +03:00
|
|
|
loading: PropTypes.bool,
|
|
|
|
joining: PropTypes.bool,
|
|
|
|
rejecting: PropTypes.bool,
|
2016-06-28 16:59:45 +03:00
|
|
|
// The alias that was used to access this room, if appropriate
|
2016-06-28 19:11:47 +03:00
|
|
|
// If given, this will be how the room is referred to (eg.
|
|
|
|
// in error messages).
|
2017-12-26 04:03:18 +03:00
|
|
|
roomAlias: PropTypes.string,
|
2016-01-12 17:11:15 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
onJoinClick: function() {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-03-18 18:30:27 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2017-10-11 19:56:17 +03:00
|
|
|
busy: false,
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2016-03-18 18:30:27 +03:00
|
|
|
},
|
|
|
|
|
2020-03-31 23:14:17 +03:00
|
|
|
componentDidMount: function() {
|
2019-06-06 16:34:57 +03:00
|
|
|
this._checkInvitedEmail();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function(prevProps, prevState) {
|
|
|
|
if (this.props.invitedEmail !== prevProps.invitedEmail || this.props.inviterName !== prevProps.inviterName) {
|
|
|
|
this._checkInvitedEmail();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-29 17:04:18 +03:00
|
|
|
_checkInvitedEmail: async function() {
|
2019-09-03 17:32:15 +03:00
|
|
|
// If this is an invite and we've been told what email address was
|
|
|
|
// invited, fetch the user's account emails and discovery bindings so we
|
|
|
|
// can check them against the email that was invited.
|
2016-03-18 18:30:27 +03:00
|
|
|
if (this.props.inviterName && this.props.invitedEmail) {
|
|
|
|
this.setState({busy: true});
|
2019-07-29 17:04:18 +03:00
|
|
|
try {
|
2019-09-03 17:32:15 +03:00
|
|
|
// Gather the account 3PIDs
|
|
|
|
const account3pids = await MatrixClientPeg.get().getThreePids();
|
|
|
|
this.setState({
|
2019-09-03 18:55:17 +03:00
|
|
|
accountEmails: account3pids.threepids
|
|
|
|
.filter(b => b.medium === 'email').map(b => b.address),
|
2019-09-03 17:32:15 +03:00
|
|
|
});
|
|
|
|
// If we have an IS connected, use that to lookup the email and
|
|
|
|
// check the bound MXID.
|
|
|
|
if (!MatrixClientPeg.get().getIdentityServerUrl()) {
|
|
|
|
this.setState({busy: false});
|
|
|
|
return;
|
|
|
|
}
|
2019-07-29 17:08:54 +03:00
|
|
|
const authClient = new IdentityAuthClient();
|
2019-07-30 12:05:57 +03:00
|
|
|
const identityAccessToken = await authClient.getAccessToken();
|
2019-07-29 17:04:18 +03:00
|
|
|
const result = await MatrixClientPeg.get().lookupThreePid(
|
2019-07-29 17:08:54 +03:00
|
|
|
'email',
|
|
|
|
this.props.invitedEmail,
|
|
|
|
undefined /* callback */,
|
2019-07-30 12:05:57 +03:00
|
|
|
identityAccessToken,
|
2019-07-29 17:04:18 +03:00
|
|
|
);
|
2016-03-18 18:30:27 +03:00
|
|
|
this.setState({invitedEmailMxid: result.mxid});
|
2019-07-29 17:04:18 +03:00
|
|
|
} catch (err) {
|
2016-03-18 18:30:27 +03:00
|
|
|
this.setState({threePidFetchError: err});
|
2019-07-29 17:04:18 +03:00
|
|
|
}
|
|
|
|
this.setState({busy: false});
|
2016-03-18 18:30:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-12 15:40:31 +03:00
|
|
|
_getMessageCase() {
|
2019-04-16 18:23:01 +03:00
|
|
|
const isGuest = MatrixClientPeg.get().isGuest();
|
|
|
|
|
|
|
|
if (isGuest) {
|
|
|
|
return MessageCase.NotLoggedIn;
|
|
|
|
}
|
|
|
|
|
2019-04-29 19:48:48 +03:00
|
|
|
const myMember = this._getMyMember();
|
2019-04-16 18:23:01 +03:00
|
|
|
|
|
|
|
if (myMember) {
|
|
|
|
if (myMember.isKicked()) {
|
|
|
|
return MessageCase.Kicked;
|
|
|
|
} else if (myMember.membership === "ban") {
|
|
|
|
return MessageCase.Banned;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 19:49:00 +03:00
|
|
|
if (this.props.joining) {
|
|
|
|
return MessageCase.Joining;
|
|
|
|
} else if (this.props.rejecting) {
|
|
|
|
return MessageCase.Rejecting;
|
2019-04-16 18:23:24 +03:00
|
|
|
} else if (this.props.loading || this.state.busy) {
|
2019-04-15 19:49:00 +03:00
|
|
|
return MessageCase.Loading;
|
2019-04-12 15:40:31 +03:00
|
|
|
}
|
|
|
|
|
2019-04-16 18:23:01 +03:00
|
|
|
if (this.props.inviterName) {
|
2019-04-12 15:40:31 +03:00
|
|
|
if (this.props.invitedEmail) {
|
|
|
|
if (this.state.threePidFetchError) {
|
|
|
|
return MessageCase.OtherThreePIDError;
|
2019-09-03 17:32:15 +03:00
|
|
|
} else if (
|
|
|
|
this.state.accountEmails &&
|
|
|
|
!this.state.accountEmails.includes(this.props.invitedEmail)
|
|
|
|
) {
|
|
|
|
return MessageCase.InvitedEmailNotFoundInAccount;
|
|
|
|
} else if (!MatrixClientPeg.get().getIdentityServerUrl()) {
|
|
|
|
return MessageCase.InvitedEmailNoIdentityServer;
|
2019-04-16 19:48:47 +03:00
|
|
|
} else if (this.state.invitedEmailMxid != MatrixClientPeg.get().getUserId()) {
|
2019-04-15 15:43:37 +03:00
|
|
|
return MessageCase.InvitedEmailMismatch;
|
2019-04-12 15:40:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return MessageCase.Invite;
|
|
|
|
} else if (this.props.error) {
|
|
|
|
if (this.props.error.errcode == 'M_NOT_FOUND') {
|
|
|
|
return MessageCase.RoomNotFound;
|
|
|
|
} else {
|
|
|
|
return MessageCase.OtherError;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return MessageCase.ViewingRoom;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getKickOrBanInfo() {
|
2019-04-29 19:48:48 +03:00
|
|
|
const myMember = this._getMyMember();
|
2019-04-12 15:40:31 +03:00
|
|
|
if (!myMember) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
const kickerMember = this.props.room.currentState.getMember(
|
|
|
|
myMember.events.member.getSender(),
|
|
|
|
);
|
|
|
|
const memberName = kickerMember ?
|
|
|
|
kickerMember.name : myMember.events.member.getSender();
|
|
|
|
const reason = myMember.events.member.getContent().reason;
|
|
|
|
return {memberName, reason};
|
|
|
|
},
|
|
|
|
|
2019-04-15 16:16:50 +03:00
|
|
|
_joinRule: function() {
|
|
|
|
const room = this.props.room;
|
|
|
|
if (room) {
|
|
|
|
const joinRules = room.currentState.getStateEvents('m.room.join_rules', '');
|
|
|
|
if (joinRules) {
|
|
|
|
return joinRules.getContent().join_rule;
|
|
|
|
}
|
|
|
|
}
|
2017-02-17 18:50:30 +03:00
|
|
|
},
|
|
|
|
|
2019-04-16 18:50:20 +03:00
|
|
|
_roomName: function(atStart = false) {
|
2019-04-17 20:05:52 +03:00
|
|
|
const name = this.props.room ? this.props.room.name : this.props.roomAlias;
|
2019-04-16 18:50:20 +03:00
|
|
|
if (name) {
|
|
|
|
return name;
|
|
|
|
} else if (atStart) {
|
|
|
|
return _t("This room");
|
|
|
|
} else {
|
|
|
|
return _t("this room");
|
|
|
|
}
|
2019-04-15 16:16:50 +03:00
|
|
|
},
|
2019-04-15 15:43:37 +03:00
|
|
|
|
2019-04-29 19:48:48 +03:00
|
|
|
_getMyMember() {
|
|
|
|
return (
|
|
|
|
this.props.room &&
|
|
|
|
this.props.room.getMember(MatrixClientPeg.get().getUserId())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-04-16 19:48:47 +03:00
|
|
|
_getInviteMember: function() {
|
|
|
|
const {room} = this.props;
|
|
|
|
if (!room) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const myUserId = MatrixClientPeg.get().getUserId();
|
|
|
|
const inviteEvent = room.currentState.getMember(myUserId);
|
|
|
|
if (!inviteEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const inviterUserId = inviteEvent.events.member.getSender();
|
|
|
|
return room.currentState.getMember(inviterUserId);
|
|
|
|
},
|
|
|
|
|
2019-04-29 19:48:48 +03:00
|
|
|
_isDMInvite() {
|
|
|
|
const myMember = this._getMyMember();
|
|
|
|
if (!myMember) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const memberEvent = myMember.events.member;
|
|
|
|
const memberContent = memberEvent.getContent();
|
|
|
|
return memberContent.membership === "invite" && memberContent.is_direct;
|
|
|
|
},
|
|
|
|
|
2019-06-10 12:24:06 +03:00
|
|
|
_makeScreenAfterLogin() {
|
|
|
|
return {
|
|
|
|
screen: 'room',
|
|
|
|
params: {
|
|
|
|
email: this.props.invitedEmail,
|
|
|
|
signurl: this.props.signUrl,
|
|
|
|
room_name: this.props.oobData.room_name,
|
|
|
|
room_avatar_url: this.props.oobData.avatarUrl,
|
|
|
|
inviter_name: this.props.oobData.inviterName,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-04-15 18:52:17 +03:00
|
|
|
onLoginClick: function() {
|
2019-06-10 12:24:06 +03:00
|
|
|
dis.dispatch({ action: 'start_login', screenAfterLogin: this._makeScreenAfterLogin() });
|
2019-04-15 18:52:17 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onRegisterClick: function() {
|
2019-06-10 12:24:06 +03:00
|
|
|
dis.dispatch({ action: 'start_registration', screenAfterLogin: this._makeScreenAfterLogin() });
|
2019-04-15 18:52:17 +03:00
|
|
|
},
|
|
|
|
|
2019-04-15 16:16:50 +03:00
|
|
|
render: function() {
|
2019-06-26 05:56:33 +03:00
|
|
|
const Spinner = sdk.getComponent('elements.Spinner');
|
2020-01-23 14:50:59 +03:00
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2019-06-26 05:56:33 +03:00
|
|
|
|
2019-04-12 15:40:31 +03:00
|
|
|
let showSpinner = false;
|
|
|
|
let darkStyle = false;
|
|
|
|
let title;
|
|
|
|
let subTitle;
|
|
|
|
let primaryActionHandler;
|
|
|
|
let primaryActionLabel;
|
|
|
|
let secondaryActionHandler;
|
|
|
|
let secondaryActionLabel;
|
2019-06-26 05:56:33 +03:00
|
|
|
let footer;
|
2020-01-23 14:50:59 +03:00
|
|
|
const extraComponents = [];
|
2019-04-12 15:40:31 +03:00
|
|
|
|
2019-04-17 12:46:04 +03:00
|
|
|
const messageCase = this._getMessageCase();
|
|
|
|
switch (messageCase) {
|
2019-04-12 15:40:31 +03:00
|
|
|
case MessageCase.Joining: {
|
2019-04-15 19:49:00 +03:00
|
|
|
title = _t("Joining room …");
|
|
|
|
showSpinner = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.Loading: {
|
|
|
|
title = _t("Loading …");
|
2019-04-12 15:40:31 +03:00
|
|
|
showSpinner = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-15 19:49:00 +03:00
|
|
|
case MessageCase.Rejecting: {
|
|
|
|
title = _t("Rejecting invite …");
|
2019-04-12 15:40:31 +03:00
|
|
|
showSpinner = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.NotLoggedIn: {
|
|
|
|
darkStyle = true;
|
|
|
|
title = _t("Join the conversation with an account");
|
|
|
|
primaryActionLabel = _t("Sign Up");
|
2019-04-15 18:52:17 +03:00
|
|
|
primaryActionHandler = this.onRegisterClick;
|
2019-04-12 15:40:31 +03:00
|
|
|
secondaryActionLabel = _t("Sign In");
|
2019-04-15 18:52:17 +03:00
|
|
|
secondaryActionHandler = this.onLoginClick;
|
2019-06-26 05:56:33 +03:00
|
|
|
if (this.props.previewLoading) {
|
|
|
|
footer = (
|
|
|
|
<div>
|
|
|
|
<Spinner w={20} h={20}/>
|
|
|
|
{_t("Loading room preview")}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.Kicked: {
|
2019-04-15 15:43:37 +03:00
|
|
|
const {memberName, reason} = this._getKickOrBanInfo();
|
2019-04-16 18:50:20 +03:00
|
|
|
title = _t("You were kicked from %(roomName)s by %(memberName)s",
|
|
|
|
{memberName, roomName: this._roomName()});
|
2019-07-15 08:31:38 +03:00
|
|
|
subTitle = reason ? _t("Reason: %(reason)s", {reason}) : null;
|
2019-04-16 18:23:45 +03:00
|
|
|
|
|
|
|
if (this._joinRule() === "invite") {
|
|
|
|
primaryActionLabel = _t("Forget this room");
|
|
|
|
primaryActionHandler = this.props.onForgetClick;
|
|
|
|
} else {
|
|
|
|
primaryActionLabel = _t("Re-join");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
|
|
|
secondaryActionLabel = _t("Forget this room");
|
|
|
|
secondaryActionHandler = this.props.onForgetClick;
|
|
|
|
}
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.Banned: {
|
2019-04-15 15:43:37 +03:00
|
|
|
const {memberName, reason} = this._getKickOrBanInfo();
|
2019-04-16 18:50:20 +03:00
|
|
|
title = _t("You were banned from %(roomName)s by %(memberName)s",
|
|
|
|
{memberName, roomName: this._roomName()});
|
2019-07-15 08:31:38 +03:00
|
|
|
subTitle = reason ? _t("Reason: %(reason)s", {reason}) : null;
|
2019-04-12 15:40:31 +03:00
|
|
|
primaryActionLabel = _t("Forget this room");
|
2019-04-15 15:43:37 +03:00
|
|
|
primaryActionHandler = this.props.onForgetClick;
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.OtherThreePIDError: {
|
2019-04-29 18:34:57 +03:00
|
|
|
title = _t("Something went wrong with your invite to %(roomName)s",
|
|
|
|
{roomName: this._roomName()});
|
2019-04-15 16:16:50 +03:00
|
|
|
const joinRule = this._joinRule();
|
2019-09-02 17:53:13 +03:00
|
|
|
const errCodeMessage = _t(
|
|
|
|
"An error (%(errcode)s) was returned while trying to validate your " +
|
|
|
|
"invite. You could try to pass this information on to a room admin.",
|
|
|
|
{errcode: this.state.threePidFetchError.errcode || _t("unknown error code")},
|
2019-04-15 16:25:34 +03:00
|
|
|
);
|
2019-04-15 16:16:50 +03:00
|
|
|
switch (joinRule) {
|
|
|
|
case "invite":
|
|
|
|
subTitle = [
|
2019-04-15 18:11:17 +03:00
|
|
|
_t("You can only join it with a working invite."),
|
2019-04-15 16:22:08 +03:00
|
|
|
errCodeMessage,
|
2019-04-15 16:16:50 +03:00
|
|
|
];
|
2019-09-03 17:32:15 +03:00
|
|
|
primaryActionLabel = _t("Try to join anyway");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
2019-04-15 16:16:50 +03:00
|
|
|
break;
|
|
|
|
case "public":
|
2019-04-15 18:11:17 +03:00
|
|
|
subTitle = _t("You can still join it because this is a public room.");
|
2019-04-15 16:16:50 +03:00
|
|
|
primaryActionLabel = _t("Join the discussion");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
subTitle = errCodeMessage;
|
|
|
|
primaryActionLabel = _t("Try to join anyway");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-09-03 17:32:15 +03:00
|
|
|
case MessageCase.InvitedEmailNotFoundInAccount: {
|
|
|
|
title = _t(
|
|
|
|
"This invite to %(roomName)s was sent to %(email)s which is not " +
|
|
|
|
"associated with your account",
|
|
|
|
{
|
|
|
|
roomName: this._roomName(),
|
|
|
|
email: this.props.invitedEmail,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
subTitle = _t(
|
|
|
|
"Link this email with your account in Settings to receive invites " +
|
|
|
|
"directly in Riot.",
|
|
|
|
);
|
|
|
|
primaryActionLabel = _t("Join the discussion");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.InvitedEmailNoIdentityServer: {
|
|
|
|
title = _t(
|
|
|
|
"This invite to %(roomName)s was sent to %(email)s",
|
|
|
|
{
|
|
|
|
roomName: this._roomName(),
|
|
|
|
email: this.props.invitedEmail,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
subTitle = _t(
|
|
|
|
"Use an identity server in Settings to receive invites directly in Riot.",
|
|
|
|
);
|
|
|
|
primaryActionLabel = _t("Join the discussion");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-15 15:43:37 +03:00
|
|
|
case MessageCase.InvitedEmailMismatch: {
|
2019-09-03 17:32:15 +03:00
|
|
|
title = _t(
|
|
|
|
"This invite to %(roomName)s was sent to %(email)s",
|
|
|
|
{
|
|
|
|
roomName: this._roomName(),
|
|
|
|
email: this.props.invitedEmail,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
subTitle = _t(
|
|
|
|
"Share this email in Settings to receive invites directly in Riot.",
|
|
|
|
);
|
|
|
|
primaryActionLabel = _t("Join the discussion");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.Invite: {
|
2019-04-30 11:30:36 +03:00
|
|
|
const RoomAvatar = sdk.getComponent("views.avatars.RoomAvatar");
|
2019-06-06 16:34:57 +03:00
|
|
|
const avatar = <RoomAvatar room={this.props.room} oobData={this.props.oobData} />;
|
2019-04-30 11:30:36 +03:00
|
|
|
|
2019-04-16 19:48:47 +03:00
|
|
|
const inviteMember = this._getInviteMember();
|
2019-04-17 11:22:35 +03:00
|
|
|
let inviterElement;
|
2019-04-16 19:48:47 +03:00
|
|
|
if (inviteMember) {
|
2019-04-30 11:22:41 +03:00
|
|
|
inviterElement = <span>
|
|
|
|
<span className="mx_RoomPreviewBar_inviter">
|
|
|
|
{inviteMember.rawDisplayName}
|
|
|
|
</span> ({inviteMember.userId})
|
|
|
|
</span>;
|
2019-04-16 19:48:47 +03:00
|
|
|
} else {
|
2019-04-17 12:02:58 +03:00
|
|
|
inviterElement = (<span className="mx_RoomPreviewBar_inviter">{this.props.inviterName}</span>);
|
2019-04-16 19:48:47 +03:00
|
|
|
}
|
|
|
|
|
2019-04-29 19:48:48 +03:00
|
|
|
const isDM = this._isDMInvite();
|
|
|
|
if (isDM) {
|
|
|
|
title = _t("Do you want to chat with %(user)s?",
|
|
|
|
{ user: inviteMember.name });
|
2019-12-07 03:08:24 +03:00
|
|
|
subTitle = [
|
|
|
|
avatar,
|
|
|
|
_t("<userName/> wants to chat", {}, {userName: () => inviterElement}),
|
|
|
|
];
|
|
|
|
primaryActionLabel = _t("Start chatting");
|
2019-04-29 19:48:48 +03:00
|
|
|
} else {
|
|
|
|
title = _t("Do you want to join %(roomName)s?",
|
|
|
|
{ roomName: this._roomName() });
|
2019-12-07 03:08:24 +03:00
|
|
|
subTitle = [
|
|
|
|
avatar,
|
|
|
|
_t("<userName/> invited you", {}, {userName: () => inviterElement}),
|
|
|
|
];
|
|
|
|
primaryActionLabel = _t("Accept");
|
2019-04-29 19:48:48 +03:00
|
|
|
}
|
2019-04-16 19:48:47 +03:00
|
|
|
|
2019-04-15 15:43:37 +03:00
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
2019-04-12 15:40:31 +03:00
|
|
|
secondaryActionLabel = _t("Reject");
|
2019-04-15 15:43:37 +03:00
|
|
|
secondaryActionHandler = this.props.onRejectClick;
|
2020-01-23 14:50:59 +03:00
|
|
|
|
|
|
|
if (this.props.onRejectAndIgnoreClick) {
|
|
|
|
extraComponents.push(
|
|
|
|
<AccessibleButton kind="secondary" onClick={this.props.onRejectAndIgnoreClick} key="ignore">
|
|
|
|
{ _t("Reject & Ignore user") }
|
2020-01-23 14:51:31 +03:00
|
|
|
</AccessibleButton>,
|
2020-01-23 14:50:59 +03:00
|
|
|
);
|
|
|
|
}
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.ViewingRoom: {
|
|
|
|
if (this.props.canPreview) {
|
2019-04-29 18:34:57 +03:00
|
|
|
title = _t("You're previewing %(roomName)s. Want to join it?",
|
|
|
|
{roomName: this._roomName()});
|
2019-04-12 15:40:31 +03:00
|
|
|
} else {
|
2019-04-16 18:50:20 +03:00
|
|
|
title = _t("%(roomName)s can't be previewed. Do you want to join it?",
|
|
|
|
{roomName: this._roomName(true)});
|
2019-04-12 15:40:31 +03:00
|
|
|
}
|
2019-04-15 15:43:37 +03:00
|
|
|
primaryActionLabel = _t("Join the discussion");
|
|
|
|
primaryActionHandler = this.props.onJoinClick;
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.RoomNotFound: {
|
2019-04-16 18:50:20 +03:00
|
|
|
title = _t("%(roomName)s does not exist.", {roomName: this._roomName(true)});
|
2019-04-15 15:43:37 +03:00
|
|
|
subTitle = _t("This room doesn't exist. Are you sure you're at the right place?");
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageCase.OtherError: {
|
2019-04-16 18:50:20 +03:00
|
|
|
title = _t("%(roomName)s is not accessible at this time.", {roomName: this._roomName(true)});
|
2019-04-15 18:11:17 +03:00
|
|
|
subTitle = [
|
2019-04-15 16:22:08 +03:00
|
|
|
_t("Try again later, or ask a room admin to check if you have access."),
|
2019-04-29 18:34:57 +03:00
|
|
|
_t(
|
|
|
|
"%(errcode)s was returned while trying to access the room. " +
|
|
|
|
"If you think you're seeing this message in error, please " +
|
|
|
|
"<issueLink>submit a bug report</issueLink>.",
|
2019-04-15 18:11:17 +03:00
|
|
|
{ errcode: this.props.error.errcode },
|
|
|
|
{ issueLink: label => <a href="https://github.com/vector-im/riot-web/issues/new/choose"
|
2020-02-24 01:14:29 +03:00
|
|
|
target="_blank" rel="noreferrer noopener">{ label }</a> },
|
2019-04-15 18:11:17 +03:00
|
|
|
),
|
|
|
|
];
|
2019-04-12 15:40:31 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 15:43:37 +03:00
|
|
|
let subTitleElements;
|
|
|
|
if (subTitle) {
|
2019-04-15 16:22:08 +03:00
|
|
|
if (!Array.isArray(subTitle)) {
|
|
|
|
subTitle = [subTitle];
|
2016-06-24 17:34:07 +03:00
|
|
|
}
|
2019-04-15 16:22:08 +03:00
|
|
|
subTitleElements = subTitle.map((t, i) => <p key={`subTitle${i}`}>{t}</p>);
|
2016-01-18 20:39:23 +03:00
|
|
|
}
|
|
|
|
|
2019-04-15 18:11:17 +03:00
|
|
|
let titleElement;
|
|
|
|
if (showSpinner) {
|
|
|
|
titleElement = <h3 className="mx_RoomPreviewBar_spinnerTitle"><Spinner />{ title }</h3>;
|
|
|
|
} else {
|
|
|
|
titleElement = <h3>{ title }</h3>;
|
|
|
|
}
|
|
|
|
|
2019-04-15 18:56:36 +03:00
|
|
|
let primaryButton;
|
|
|
|
if (primaryActionHandler) {
|
|
|
|
primaryButton = (
|
|
|
|
<AccessibleButton kind="primary" onClick={primaryActionHandler}>
|
|
|
|
{ primaryActionLabel }
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let secondaryButton;
|
|
|
|
if (secondaryActionHandler) {
|
|
|
|
secondaryButton = (
|
|
|
|
<AccessibleButton kind="secondary" onClick={secondaryActionHandler}>
|
|
|
|
{ secondaryActionLabel }
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:46:04 +03:00
|
|
|
const classes = classNames("mx_RoomPreviewBar", "dark-panel", `mx_RoomPreviewBar_${messageCase}`, {
|
2019-04-15 18:56:36 +03:00
|
|
|
"mx_RoomPreviewBar_panel": this.props.canPreview,
|
|
|
|
"mx_RoomPreviewBar_dialog": !this.props.canPreview,
|
|
|
|
"mx_RoomPreviewBar_dark": darkStyle,
|
|
|
|
});
|
|
|
|
|
2016-01-18 20:39:23 +03:00
|
|
|
return (
|
2019-04-12 13:54:13 +03:00
|
|
|
<div className={classes}>
|
2019-04-15 15:43:37 +03:00
|
|
|
<div className="mx_RoomPreviewBar_message">
|
2019-04-15 18:11:17 +03:00
|
|
|
{ titleElement }
|
2019-04-15 15:43:37 +03:00
|
|
|
{ subTitleElements }
|
|
|
|
</div>
|
|
|
|
<div className="mx_RoomPreviewBar_actions">
|
2019-04-15 18:56:36 +03:00
|
|
|
{ secondaryButton }
|
2020-01-23 14:50:59 +03:00
|
|
|
{ extraComponents }
|
2019-04-15 18:56:36 +03:00
|
|
|
{ primaryButton }
|
2016-01-18 22:56:56 +03:00
|
|
|
</div>
|
2019-06-26 05:56:33 +03:00
|
|
|
<div className="mx_RoomPreviewBar_footer">
|
|
|
|
{ footer }
|
|
|
|
</div>
|
2016-01-12 17:11:15 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2016-01-12 17:11:15 +03:00
|
|
|
});
|