Don't show the prompt to enable desktop notifications immediately after registration (#8274)

* Fix MatrixClientPeg.userRegisteredWithinLastHours so that it works

* Try fixing end-to-end test + add case for New search beta

* Remove end-to-end test case for Search beta toast as it only shows up after 5 minutes

* Revert to localStorage based solution + non-inverted logic + test including time advancement
This commit is contained in:
Hugh Nimmo-Smith 2022-04-13 19:05:08 +01:00 committed by GitHub
parent d151365fd7
commit 26b771bbf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 14 deletions

View file

@ -117,7 +117,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
};
private matrixClient: MatrixClient = null;
private justRegisteredUserId: string;
private justRegisteredUserId: string | null = null;
// the credentials used to init the current client object.
// used if we tear it down & recreate it with a different store
@ -136,7 +136,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
MatrixActionCreators.stop();
}
public setJustRegisteredUserId(uid: string): void {
public setJustRegisteredUserId(uid: string | null): void {
this.justRegisteredUserId = uid;
if (uid) {
window.localStorage.setItem("mx_registration_time", String(new Date().getTime()));
@ -151,9 +151,14 @@ class MatrixClientPegClass implements IMatrixClientPeg {
}
public userRegisteredWithinLastHours(hours: number): boolean {
if (hours <= 0) {
return false;
}
try {
const date = new Date(window.localStorage.getItem("mx_registration_time"));
return ((new Date().getTime() - date.getTime()) / 36e5) <= hours;
const registrationTime = parseInt(window.localStorage.getItem("mx_registration_time"));
const diff = Date.now() - registrationTime;
return (diff / 36e5) <= hours;
} catch (e) {
return false;
}