Rephrase everything to be "invite anyways" rather than "retry"
Also handle profile errors better
This commit is contained in:
parent
c351ee3d30
commit
a05c0f9214
4 changed files with 54 additions and 44 deletions
|
@ -101,13 +101,18 @@ export default class MultiInviter {
|
|||
if (addrType === 'email') {
|
||||
return MatrixClientPeg.get().inviteByEmail(roomId, addr);
|
||||
} else if (addrType === 'mx-user-id') {
|
||||
if (!ignoreProfile && !SettingsStore.getValue("alwaysRetryInvites", this.roomId)) {
|
||||
const profile = await MatrixClientPeg.get().getProfileInfo(addr);
|
||||
if (!profile) {
|
||||
return Promise.reject({
|
||||
errcode: "M_NOT_FOUND",
|
||||
error: "User does not have a profile or does not exist.",
|
||||
});
|
||||
if (!ignoreProfile && !SettingsStore.getValue("alwaysInviteUnknownUsers", this.roomId)) {
|
||||
try {
|
||||
const profile = await MatrixClientPeg.get().getProfileInfo(addr);
|
||||
if (!profile) {
|
||||
// noinspection ExceptionCaughtLocallyJS
|
||||
throw new Error("User has no profile");
|
||||
}
|
||||
} catch (e) {
|
||||
throw {
|
||||
errcode: "RIOT.USER_NOT_FOUND",
|
||||
error: "User does not have a profile or does not exist."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,6 +124,8 @@ export default class MultiInviter {
|
|||
|
||||
_doInvite(address, ignoreProfile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`Inviting ${address}`);
|
||||
|
||||
let doInvite;
|
||||
if (this.groupId !== null) {
|
||||
doInvite = GroupStore.inviteUserToGroup(this.groupId, address);
|
||||
|
@ -151,13 +158,13 @@ export default class MultiInviter {
|
|||
this._doInvite(address, ignoreProfile).then(resolve, reject);
|
||||
}, 5000);
|
||||
return;
|
||||
} else if (['M_NOT_FOUND', 'M_USER_NOT_FOUND'].includes(err.errcode)) {
|
||||
} else if (['M_NOT_FOUND', 'M_USER_NOT_FOUND', 'RIOT.USER_NOT_FOUND'].includes(err.errcode)) {
|
||||
errorText = _t("User %(user_id)s does not exist", {user_id: address});
|
||||
} else if (err.errcode === 'M_PROFILE_UNKNOWN') {
|
||||
} else if (err.errcode === 'M_PROFILE_UNDISCLOSED') {
|
||||
errorText = _t("User %(user_id)s may or may not exist", {user_id: address});
|
||||
} else if (err.errcode === 'M_PROFILE_NOT_FOUND' && !ignoreProfile) {
|
||||
// Invite without the profile check
|
||||
console.warn(`User ${address} does not have a profile - trying invite again`);
|
||||
console.warn(`User ${address} does not have a profile - inviting anyways automatically`);
|
||||
this._doInvite(address, true).then(resolve, reject);
|
||||
} else {
|
||||
errorText = _t('Unknown server error');
|
||||
|
@ -188,28 +195,28 @@ export default class MultiInviter {
|
|||
if (Object.keys(this.errors).length > 0 && !this.groupId) {
|
||||
// There were problems inviting some people - see if we can invite them
|
||||
// without caring if they exist or not.
|
||||
const reinviteErrors = ['M_NOT_FOUND', 'M_USER_NOT_FOUND', 'M_PROFILE_UNKNOWN', 'M_PROFILE_NOT_FOUND'];
|
||||
const reinvitableUsers = Object.keys(this.errors).filter(a => reinviteErrors.includes(this.errors[a].errcode));
|
||||
const unknownProfileErrors = ['M_NOT_FOUND', 'M_USER_NOT_FOUND', 'M_PROFILE_UNDISCLOSED', 'M_PROFILE_NOT_FOUND', 'RIOT.USER_NOT_FOUND'];
|
||||
const unknownProfileUsers = Object.keys(this.errors).filter(a => unknownProfileErrors.includes(this.errors[a].errcode));
|
||||
|
||||
if (reinvitableUsers.length > 0) {
|
||||
const retryInvites = () => {
|
||||
const promises = reinvitableUsers.map(u => this._doInvite(u, true));
|
||||
if (unknownProfileUsers.length > 0) {
|
||||
const inviteUnknowns = () => {
|
||||
const promises = unknownProfileUsers.map(u => this._doInvite(u, true));
|
||||
Promise.all(promises).then(() => this.deferred.resolve(this.completionStates));
|
||||
};
|
||||
|
||||
if (SettingsStore.getValue("alwaysRetryInvites", this.roomId)) {
|
||||
retryInvites();
|
||||
if (SettingsStore.getValue("alwaysInviteUnknownUsers", this.roomId)) {
|
||||
inviteUnknowns();
|
||||
return;
|
||||
}
|
||||
|
||||
const RetryInvitesDialog = sdk.getComponent("dialogs.RetryInvitesDialog");
|
||||
const AskInviteAnywayDialog = sdk.getComponent("dialogs.AskInviteAnywayDialog");
|
||||
console.log("Showing failed to invite dialog...");
|
||||
Modal.createTrackedDialog('Failed to invite the following users to the room', '', RetryInvitesDialog, {
|
||||
failedInvites: this.errors,
|
||||
onTryAgain: () => retryInvites(),
|
||||
Modal.createTrackedDialog('Failed to invite the following users to the room', '', AskInviteAnywayDialog, {
|
||||
unknownProfileUsers: unknownProfileUsers.map(u => {return {userId: u, errorText: this.errors[u].errorText};}),
|
||||
onInviteAnyways: () => inviteUnknowns(),
|
||||
onGiveUp: () => {
|
||||
// Fake all the completion states because we already warned the user
|
||||
for (const addr of Object.keys(this.completionStates)) {
|
||||
for (const addr of unknownProfileUsers) {
|
||||
this.completionStates[addr] = 'invited';
|
||||
}
|
||||
this.deferred.resolve(this.completionStates);
|
||||
|
@ -223,7 +230,6 @@ export default class MultiInviter {
|
|||
}
|
||||
|
||||
const addr = this.addrs[nextIndex];
|
||||
console.log(`Inviting ${addr}`);
|
||||
|
||||
// don't try to invite it if it's an invalid address
|
||||
// (it will already be marked as an error though,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue