Show the user's 3PID invite after they've reloaded the page
This is a step towards https://github.com/vector-im/element-web/issues/13430 Since we've stored the invite, we can send the user to it once they reload the page or revisit Element. We currently only support one invite at a time, but this should be fine for most cases. We only do this restoration if the next screen isn't set to avoid breaking the user out of an expected flow. As an added touch, this also ensures that the email address is pre-filled on the registration page if needed, just in case the user refreshes before getting to the submit button.
This commit is contained in:
parent
a5d7b24805
commit
803badba1b
3 changed files with 39 additions and 8 deletions
|
@ -60,23 +60,24 @@ export default class ThreepidInviteStore extends EventEmitter {
|
|||
}
|
||||
|
||||
public storeInvite(roomId: string, wireInvite: IThreepidInviteWireFormat): IThreepidInvite {
|
||||
console.log("Storing invite: ", {roomId, ...wireInvite});
|
||||
const invite = <IPersistedThreepidInvite>{roomId, ...wireInvite};
|
||||
const id = this.generateIdOf(invite);
|
||||
localStorage.setItem(`${STORAGE_PREFIX}${id}`, JSON.stringify(invite));
|
||||
return this.translateInvite(invite);
|
||||
}
|
||||
|
||||
public getInvites(): IThreepidInvite[] {
|
||||
const result: IThreepidInvite[] = [];
|
||||
public getWireInvites(): IPersistedThreepidInvite[] {
|
||||
const results: IPersistedThreepidInvite[] = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const keyName = localStorage.key(i);
|
||||
if (!keyName.startsWith(STORAGE_PREFIX)) continue;
|
||||
|
||||
const persisted = JSON.parse(localStorage.getItem(keyName)) as IPersistedThreepidInvite;
|
||||
result.push(this.translateInvite(persisted));
|
||||
results.push(JSON.parse(localStorage.getItem(keyName)) as IPersistedThreepidInvite);
|
||||
}
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
public getInvites(): IThreepidInvite[] {
|
||||
return this.getWireInvites().map(i => this.translateInvite(i));
|
||||
}
|
||||
|
||||
// Currently Element can only handle one invite at a time, so handle that
|
||||
|
@ -104,4 +105,14 @@ export default class ThreepidInviteStore extends EventEmitter {
|
|||
inviterName: persisted.inviter_name,
|
||||
};
|
||||
}
|
||||
|
||||
public translateToWireFormat(invite: IThreepidInvite): IThreepidInviteWireFormat {
|
||||
return {
|
||||
email: invite.toEmail,
|
||||
signurl: invite.signUrl,
|
||||
room_name: invite.roomName,
|
||||
room_avatar_url: invite.roomAvatarUrl,
|
||||
inviter_name: invite.inviterName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue