Fix error shown if accepting a 3pid invite (#31735)
* Fix error shown if accepting a 3pid invite If no matrix ID was bound to the email address, the code would just throw an exception and display a very generic error. * Unused import * I hate you too, yarn. * i18n * Add test
This commit is contained in:
@@ -19,7 +19,7 @@ import { AskToJoinIcon } from "@vector-im/compound-design-tokens/assets/web/icon
|
|||||||
|
|
||||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||||
import dis from "../../../dispatcher/dispatcher";
|
import dis from "../../../dispatcher/dispatcher";
|
||||||
import { _t, UserFriendlyError } from "../../../languageHandler";
|
import { _t } from "../../../languageHandler";
|
||||||
import SdkConfig from "../../../SdkConfig";
|
import SdkConfig from "../../../SdkConfig";
|
||||||
import IdentityAuthClient from "../../../IdentityAuthClient";
|
import IdentityAuthClient from "../../../IdentityAuthClient";
|
||||||
import InviteReason from "../elements/InviteReason";
|
import InviteReason from "../elements/InviteReason";
|
||||||
@@ -112,7 +112,8 @@ interface IProps {
|
|||||||
interface IState {
|
interface IState {
|
||||||
busy: boolean;
|
busy: boolean;
|
||||||
accountEmails?: string[];
|
accountEmails?: string[];
|
||||||
invitedEmailMxid?: string;
|
// The email address that was invited. undefined === not yet loaded, null === no associated email
|
||||||
|
invitedEmailMxid?: string | null;
|
||||||
threePidFetchError?: MatrixError;
|
threePidFetchError?: MatrixError;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
}
|
}
|
||||||
@@ -165,10 +166,7 @@ class RoomPreviewBar extends React.Component<IProps, IState> {
|
|||||||
this.props.invitedEmail,
|
this.props.invitedEmail,
|
||||||
identityAccessToken!,
|
identityAccessToken!,
|
||||||
);
|
);
|
||||||
if (!("mxid" in result)) {
|
this.setState({ invitedEmailMxid: result.mxid ?? null });
|
||||||
throw new UserFriendlyError("room|error_3pid_invite_email_lookup");
|
|
||||||
}
|
|
||||||
this.setState({ invitedEmailMxid: result.mxid });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ threePidFetchError: err as MatrixError });
|
this.setState({ threePidFetchError: err as MatrixError });
|
||||||
}
|
}
|
||||||
@@ -212,7 +210,7 @@ class RoomPreviewBar extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.inviterName) {
|
if (this.props.inviterName) {
|
||||||
if (this.props.invitedEmail) {
|
if (this.props.invitedEmail !== undefined) {
|
||||||
if (this.state.threePidFetchError) {
|
if (this.state.threePidFetchError) {
|
||||||
return MessageCase.OtherThreePIDError;
|
return MessageCase.OtherThreePIDError;
|
||||||
} else if (this.state.accountEmails && !this.state.accountEmails.includes(this.props.invitedEmail)) {
|
} else if (this.state.accountEmails && !this.state.accountEmails.includes(this.props.invitedEmail)) {
|
||||||
|
|||||||
@@ -1995,7 +1995,6 @@
|
|||||||
"dm_invite_title": "Do you want to chat with %(user)s?",
|
"dm_invite_title": "Do you want to chat with %(user)s?",
|
||||||
"drop_file_prompt": "Drop file here to upload",
|
"drop_file_prompt": "Drop file here to upload",
|
||||||
"edit_topic": "Edit topic",
|
"edit_topic": "Edit topic",
|
||||||
"error_3pid_invite_email_lookup": "Unable to find user by email",
|
|
||||||
"error_cancel_knock_title": "Failed to cancel",
|
"error_cancel_knock_title": "Failed to cancel",
|
||||||
"error_join_403": "You need an invite to access this room.",
|
"error_join_403": "You need an invite to access this room.",
|
||||||
"error_join_404_1": "You attempted to join using a room ID without providing a list of servers to join through. Room IDs are internal identifiers and cannot be used to join a room without additional information.",
|
"error_join_404_1": "You attempted to join using a room ID without providing a list of servers to join through. Room IDs are internal identifiers and cannot be used to join a room without additional information.",
|
||||||
|
|||||||
@@ -423,6 +423,20 @@ describe("<RoomPreviewBar />", () => {
|
|||||||
await testJoinButton({ inviterName, invitedEmail })();
|
await testJoinButton({ inviterName, invitedEmail })();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders email mismatch message when no email bound", async () => {
|
||||||
|
MatrixClientPeg.safeGet().lookupThreePid = jest.fn().mockReturnValue({});
|
||||||
|
const component = getComponent({ inviterName, invitedEmail });
|
||||||
|
await waitForElementToBeRemoved(() => component.queryByRole("progressbar"));
|
||||||
|
|
||||||
|
expect(getMessage(component)).toMatchSnapshot();
|
||||||
|
expect(MatrixClientPeg.safeGet().lookupThreePid).toHaveBeenCalledWith(
|
||||||
|
"email",
|
||||||
|
invitedEmail,
|
||||||
|
"mock-token",
|
||||||
|
);
|
||||||
|
await testJoinButton({ inviterName, invitedEmail })();
|
||||||
|
});
|
||||||
|
|
||||||
it("renders invite message when invite email mxid match", async () => {
|
it("renders invite message when invite email mxid match", async () => {
|
||||||
MatrixClientPeg.safeGet().lookupThreePid = jest.fn().mockReturnValue({ mxid: userId });
|
MatrixClientPeg.safeGet().lookupThreePid = jest.fn().mockReturnValue({ mxid: userId });
|
||||||
const component = getComponent({ inviterName, invitedEmail });
|
const component = getComponent({ inviterName, invitedEmail });
|
||||||
|
|||||||
@@ -252,6 +252,19 @@ exports[`<RoomPreviewBar /> with an invite with an invited email when client has
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`<RoomPreviewBar /> with an invite with an invited email when client has an identity server connected renders email mismatch message when no email bound 1`] = `
|
||||||
|
<div
|
||||||
|
class="mx_RoomPreviewBar_message"
|
||||||
|
>
|
||||||
|
<h3>
|
||||||
|
This invite to RoomPreviewBar-test-room was sent to test@test.com
|
||||||
|
</h3>
|
||||||
|
<p>
|
||||||
|
Share this email in Settings to receive invites directly in Element.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`<RoomPreviewBar /> with an invite with an invited email when client has an identity server connected renders invite message when invite email mxid match 1`] = `
|
exports[`<RoomPreviewBar /> with an invite with an invited email when client has an identity server connected renders invite message when invite email mxid match 1`] = `
|
||||||
<div
|
<div
|
||||||
class="mx_RoomPreviewBar_message"
|
class="mx_RoomPreviewBar_message"
|
||||||
|
|||||||
Reference in New Issue
Block a user