Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0c14de3

Browse files
committed
defer some toasts
1 parent 4afa610 commit 0c14de3

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/BasePlatform.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {ActionPayload} from "./dispatcher/payloads";
2424
import {CheckUpdatesPayload} from "./dispatcher/payloads/CheckUpdatesPayload";
2525
import {Action} from "./dispatcher/actions";
2626
import {hideToast as hideUpdateToast} from "./toasts/UpdateToast";
27+
import {MatrixClientPeg} from "./MatrixClientPeg";
2728

2829
export const SSO_HOMESERVER_URL_KEY = "mx_sso_hs_url";
2930
export const SSO_ID_SERVER_URL_KEY = "mx_sso_is_url";
@@ -105,6 +106,9 @@ export default abstract class BasePlatform {
105106
* @param newVersion the version string to check
106107
*/
107108
protected shouldShowUpdate(newVersion: string): boolean {
109+
// If the user registered on this client in the last 24 hours then do not show them the update toast
110+
if (MatrixClientPeg.userRegisteredWithinLastHours(24)) return false;
111+
108112
try {
109113
const [version, deferUntil] = JSON.parse(localStorage.getItem(UPDATE_DEFER_KEY));
110114
return newVersion !== version || Date.now() > deferUntil;

src/MatrixClientPeg.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ export interface IMatrixClientPeg {
100100
*/
101101
currentUserIsJustRegistered(): boolean;
102102

103+
/**
104+
* If the current user has been registered by this device then this
105+
* returns a boolean of whether it was within the last N hours given.
106+
*/
107+
userRegisteredWithinLastHours(hours: number): boolean;
108+
103109
/**
104110
* Replace this MatrixClientPeg's client with a client instance that has
105111
* homeserver / identity server URLs and active credentials
@@ -150,6 +156,9 @@ class _MatrixClientPeg implements IMatrixClientPeg {
150156

151157
public setJustRegisteredUserId(uid: string): void {
152158
this.justRegisteredUserId = uid;
159+
if (uid) {
160+
window.localStorage.setItem("mx_registration_time", String(new Date().getTime()));
161+
}
153162
}
154163

155164
public currentUserIsJustRegistered(): boolean {
@@ -159,6 +168,15 @@ class _MatrixClientPeg implements IMatrixClientPeg {
159168
);
160169
}
161170

171+
public userRegisteredWithinLastHours(hours: number): boolean {
172+
try {
173+
const date = new Date(window.localStorage.getItem("mx_registration_time"));
174+
return ((new Date().getTime() - date.getTime()) / 36e5) <= hours;
175+
} catch (e) {
176+
return false;
177+
}
178+
}
179+
162180
public replaceUsingCreds(creds: IMatrixClientCreds): void {
163181
this.currentClientCreds = creds;
164182
this.createClient(creds);

src/components/structures/MatrixChat.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import DMRoomMap from '../../utils/DMRoomMap';
6262
import ThemeWatcher from "../../settings/watchers/ThemeWatcher";
6363
import { FontWatcher } from '../../settings/watchers/FontWatcher';
6464
import { storeRoomAliasInCache } from '../../RoomAliasCache';
65-
import { defer, IDeferred } from "../../utils/promise";
65+
import { defer, IDeferred, sleep } from "../../utils/promise";
6666
import ToastStore from "../../stores/ToastStore";
6767
import * as StorageManager from "../../utils/StorageManager";
6868
import type LoggedInViewType from "./LoggedInView";
@@ -1214,6 +1214,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
12141214

12151215
StorageManager.tryPersistStorage();
12161216

1217+
// defer the following actions by 30 seconds to not throw them at the user immediately
1218+
await sleep(30);
12171219
if (SettingsStore.getValue("showCookieBar") &&
12181220
(Analytics.canEnable() || CountlyAnalytics.instance.canEnable())
12191221
) {
@@ -1346,8 +1348,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13461348
this.firstSyncComplete = true;
13471349
this.firstSyncPromise.resolve();
13481350

1349-
if (Notifier.shouldShowPrompt()) {
1350-
showNotificationsToast();
1351+
if (Notifier.shouldShowPrompt() && !MatrixClientPeg.userRegisteredWithinLastHours(24)) {
1352+
showNotificationsToast(false);
13511353
}
13521354

13531355
dis.fire(Action.FocusComposer);

src/components/structures/RoomView.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import { IThreepidInvite } from "../../stores/ThreepidInviteStore";
7474
import { CallState, CallType, MatrixCall } from "matrix-js-sdk/lib/webrtc/call";
7575
import WidgetStore from "../../stores/WidgetStore";
7676
import {UPDATE_EVENT} from "../../stores/AsyncStore";
77+
import Notifier from "../../Notifier";
78+
import {showToast as showNotificationsToast} from "../../toasts/DesktopNotificationsToast";
7779

7880
const DEBUG = false;
7981
let debuglog = function(msg: string) {};
@@ -1050,6 +1052,11 @@ export default class RoomView extends React.Component<IProps, IState> {
10501052
let joinedOrInvitedMemberCount = room.getJoinedMemberCount() + room.getInvitedMemberCount();
10511053
if (countInfluence) joinedOrInvitedMemberCount += countInfluence;
10521054
this.setState({isAlone: joinedOrInvitedMemberCount === 1});
1055+
1056+
// if they are not alone additionally prompt the user about notifications so they don't miss replies
1057+
if (joinedOrInvitedMemberCount > 1 && Notifier.shouldShowPrompt()) {
1058+
showNotificationsToast(true);
1059+
}
10531060
}
10541061

10551062
private updateDMState() {

0 commit comments

Comments
 (0)