From 00a69b996dd90b85fd58f18dc737128090929eff Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 2 Sep 2019 15:53:13 +0100 Subject: [PATCH 1/3] Clarify invite error text This fixes a typo in the message (valide) and also has better handling of error codes, because in some cases, we don't get one. Fixes https://github.com/vector-im/riot-web/issues/10683 --- src/components/views/rooms/RoomPreviewBar.js | 6 ++++-- src/i18n/strings/en_EN.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/RoomPreviewBar.js b/src/components/views/rooms/RoomPreviewBar.js index 7715bd9339..f2573d46b8 100644 --- a/src/components/views/rooms/RoomPreviewBar.js +++ b/src/components/views/rooms/RoomPreviewBar.js @@ -337,8 +337,10 @@ module.exports = React.createClass({ title = _t("Something went wrong with your invite to %(roomName)s", {roomName: this._roomName()}); const joinRule = this._joinRule(); - const errCodeMessage = _t("%(errcode)s was returned while trying to valide your invite. You could try to pass this information on to a room admin.", - {errcode: this.state.threePidFetchError.errcode}, + 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")}, ); switch (joinRule) { case "invite": diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d88484c283..8bfc918ada 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -892,7 +892,8 @@ "Re-join": "Re-join", "You were banned from %(roomName)s by %(memberName)s": "You were banned from %(roomName)s by %(memberName)s", "Something went wrong with your invite to %(roomName)s": "Something went wrong with your invite to %(roomName)s", - "%(errcode)s was returned while trying to valide your invite. You could try to pass this information on to a room admin.": "%(errcode)s was returned while trying to valide your invite. You could try to pass this information on to a room admin.", + "An error (%(errcode)s) was returned while trying to validate your invite. You could try to pass this information on to a room admin.": "An error (%(errcode)s) was returned while trying to validate your invite. You could try to pass this information on to a room admin.", + "unknown error code": "unknown error code", "You can only join it with a working invite.": "You can only join it with a working invite.", "You can still join it because this is a public room.": "You can still join it because this is a public room.", "Join the discussion": "Join the discussion", @@ -1399,7 +1400,6 @@ "Collapse Reply Thread": "Collapse Reply Thread", "End-to-end encryption information": "End-to-end encryption information", "Failed to set Direct Message status of room": "Failed to set Direct Message status of room", - "unknown error code": "unknown error code", "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", "All messages (noisy)": "All messages (noisy)", "All messages": "All messages", From 67299842e3b921028d65afd2c456ed62e72e8d8e Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 3 Sep 2019 15:32:15 +0100 Subject: [PATCH 2/3] Use more specific messaging for email invite preview This changes email invite previews to check more specific cases about whether the email has been added to your account, you have an IS, the email is bound, etc. In addition, it always allows you to join if you want to. Fixes https://github.com/vector-im/riot-web/issues/10669 --- src/components/views/rooms/RoomPreviewBar.js | 91 +++++++++++++++----- src/i18n/strings/en_EN.json | 9 +- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/src/components/views/rooms/RoomPreviewBar.js b/src/components/views/rooms/RoomPreviewBar.js index f2573d46b8..05cd44156f 100644 --- a/src/components/views/rooms/RoomPreviewBar.js +++ b/src/components/views/rooms/RoomPreviewBar.js @@ -35,6 +35,8 @@ const MessageCase = Object.freeze({ Kicked: "Kicked", Banned: "Banned", OtherThreePIDError: "OtherThreePIDError", + InvitedEmailNotFoundInAccount: "InvitedEmailNotFoundInAccount", + InvitedEmailNoIdentityServer: "InvitedEmailNoIdentityServer", InvitedEmailMismatch: "InvitedEmailMismatch", Invite: "Invite", ViewingRoom: "ViewingRoom", @@ -106,12 +108,24 @@ module.exports = React.createClass({ }, _checkInvitedEmail: async function() { - // If this is an invite and we've been told what email - // address was invited, fetch the user's list of Threepids - // so we can check them against the one that was invited + // 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. if (this.props.inviterName && this.props.invitedEmail) { this.setState({busy: true}); try { + // Gather the account 3PIDs + const account3pids = await MatrixClientPeg.get().getThreePids(); + this.setState({ + accountEmails: account3pids.threepids.filter(b => b.medium === 'email') + .map(b => b.address), + }); + // 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; + } const authClient = new IdentityAuthClient(); const identityAccessToken = await authClient.getAccessToken(); const result = await MatrixClientPeg.get().lookupThreePid( @@ -157,6 +171,13 @@ module.exports = React.createClass({ if (this.props.invitedEmail) { if (this.state.threePidFetchError) { return MessageCase.OtherThreePIDError; + } else if ( + this.state.accountEmails && + !this.state.accountEmails.includes(this.props.invitedEmail) + ) { + return MessageCase.InvitedEmailNotFoundInAccount; + } else if (!MatrixClientPeg.get().getIdentityServerUrl()) { + return MessageCase.InvitedEmailNoIdentityServer; } else if (this.state.invitedEmailMxid != MatrixClientPeg.get().getUserId()) { return MessageCase.InvitedEmailMismatch; } @@ -348,6 +369,8 @@ module.exports = React.createClass({ _t("You can only join it with a working invite."), errCodeMessage, ]; + primaryActionLabel = _t("Try to join anyway"); + primaryActionHandler = this.props.onJoinClick; break; case "public": subTitle = _t("You can still join it because this is a public room."); @@ -362,25 +385,51 @@ module.exports = React.createClass({ } break; } + 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; + } case MessageCase.InvitedEmailMismatch: { - title = _t("This invite to %(roomName)s wasn't sent to your account", - {roomName: this._roomName()}); - const joinRule = this._joinRule(); - if (joinRule === "public") { - subTitle = _t("You can still join it because this is a public room."); - primaryActionLabel = _t("Join the discussion"); - primaryActionHandler = this.props.onJoinClick; - } else { - subTitle = _t( - "Sign in with a different account, ask for another invite, or " + - "add the e-mail address %(email)s to this account.", - {email: this.props.invitedEmail}, - ); - if (joinRule !== "invite") { - primaryActionLabel = _t("Try to join anyway"); - primaryActionHandler = this.props.onJoinClick; - } - } + 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; break; } case MessageCase.Invite: { diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8bfc918ada..8e74402277 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -895,11 +895,14 @@ "An error (%(errcode)s) was returned while trying to validate your invite. You could try to pass this information on to a room admin.": "An error (%(errcode)s) was returned while trying to validate your invite. You could try to pass this information on to a room admin.", "unknown error code": "unknown error code", "You can only join it with a working invite.": "You can only join it with a working invite.", + "Try to join anyway": "Try to join anyway", "You can still join it because this is a public room.": "You can still join it because this is a public room.", "Join the discussion": "Join the discussion", - "Try to join anyway": "Try to join anyway", - "This invite to %(roomName)s wasn't sent to your account": "This invite to %(roomName)s wasn't sent to your account", - "Sign in with a different account, ask for another invite, or add the e-mail address %(email)s to this account.": "Sign in with a different account, ask for another invite, or add the e-mail address %(email)s to this account.", + "This invite to %(roomName)s was sent to %(email)s which is not associated with your account": "This invite to %(roomName)s was sent to %(email)s which is not associated with your account", + "Link this email with your account in Settings to receive invites directly in Riot.": "Link this email with your account in Settings to receive invites directly in Riot.", + "This invite to %(roomName)s was sent to %(email)s": "This invite to %(roomName)s was sent to %(email)s", + "Use an identity server in Settings to receive invites directly in Riot.": "Use an identity server in Settings to receive invites directly in Riot.", + "Share this email in Settings to receive invites directly in Riot.": "Share this email in Settings to receive invites directly in Riot.", "Do you want to chat with %(user)s?": "Do you want to chat with %(user)s?", "Do you want to join %(roomName)s?": "Do you want to join %(roomName)s?", " invited you": " invited you", From 261bdab156f30287138dd37ad1196f48fd59803b Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 3 Sep 2019 16:55:17 +0100 Subject: [PATCH 3/3] Fix indent --- src/components/views/rooms/RoomPreviewBar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/RoomPreviewBar.js b/src/components/views/rooms/RoomPreviewBar.js index 05cd44156f..ccd4559586 100644 --- a/src/components/views/rooms/RoomPreviewBar.js +++ b/src/components/views/rooms/RoomPreviewBar.js @@ -117,8 +117,8 @@ module.exports = React.createClass({ // Gather the account 3PIDs const account3pids = await MatrixClientPeg.get().getThreePids(); this.setState({ - accountEmails: account3pids.threepids.filter(b => b.medium === 'email') - .map(b => b.address), + accountEmails: account3pids.threepids + .filter(b => b.medium === 'email').map(b => b.address), }); // If we have an IS connected, use that to lookup the email and // check the bound MXID.