diff --git a/src/BasePlatform.ts b/src/BasePlatform.ts index 4d06c5df73..0a1f06f0b3 100644 --- a/src/BasePlatform.ts +++ b/src/BasePlatform.ts @@ -24,6 +24,7 @@ import {ActionPayload} from "./dispatcher/payloads"; import {CheckUpdatesPayload} from "./dispatcher/payloads/CheckUpdatesPayload"; import {Action} from "./dispatcher/actions"; import {hideToast as hideUpdateToast} from "./toasts/UpdateToast"; +import {MatrixClientPeg} from "./MatrixClientPeg"; export const SSO_HOMESERVER_URL_KEY = "mx_sso_hs_url"; export const SSO_ID_SERVER_URL_KEY = "mx_sso_is_url"; @@ -105,6 +106,9 @@ export default abstract class BasePlatform { * @param newVersion the version string to check */ protected shouldShowUpdate(newVersion: string): boolean { + // If the user registered on this client in the last 24 hours then do not show them the update toast + if (MatrixClientPeg.userRegisteredWithinLastHours(24)) return false; + try { const [version, deferUntil] = JSON.parse(localStorage.getItem(UPDATE_DEFER_KEY)); return newVersion !== version || Date.now() > deferUntil; diff --git a/src/MatrixClientPeg.ts b/src/MatrixClientPeg.ts index 5bb10dfa89..2d8c2dd398 100644 --- a/src/MatrixClientPeg.ts +++ b/src/MatrixClientPeg.ts @@ -100,6 +100,12 @@ export interface IMatrixClientPeg { */ currentUserIsJustRegistered(): boolean; + /** + * If the current user has been registered by this device then this + * returns a boolean of whether it was within the last N hours given. + */ + userRegisteredWithinLastHours(hours: number): boolean; + /** * Replace this MatrixClientPeg's client with a client instance that has * homeserver / identity server URLs and active credentials @@ -150,6 +156,9 @@ class _MatrixClientPeg implements IMatrixClientPeg { public setJustRegisteredUserId(uid: string): void { this.justRegisteredUserId = uid; + if (uid) { + window.localStorage.setItem("mx_registration_time", String(new Date().getTime())); + } } public currentUserIsJustRegistered(): boolean { @@ -159,6 +168,15 @@ class _MatrixClientPeg implements IMatrixClientPeg { ); } + public userRegisteredWithinLastHours(hours: number): boolean { + try { + const date = new Date(window.localStorage.getItem("mx_registration_time")); + return ((new Date().getTime() - date.getTime()) / 36e5) <= hours; + } catch (e) { + return false; + } + } + public replaceUsingCreds(creds: IMatrixClientCreds): void { this.currentClientCreds = creds; this.createClient(creds); diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 4d154e4332..429d60e5bd 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -62,7 +62,7 @@ import DMRoomMap from '../../utils/DMRoomMap'; import ThemeWatcher from "../../settings/watchers/ThemeWatcher"; import { FontWatcher } from '../../settings/watchers/FontWatcher'; import { storeRoomAliasInCache } from '../../RoomAliasCache'; -import { defer, IDeferred } from "../../utils/promise"; +import { defer, IDeferred, sleep } from "../../utils/promise"; import ToastStore from "../../stores/ToastStore"; import * as StorageManager from "../../utils/StorageManager"; import type LoggedInViewType from "./LoggedInView"; @@ -1214,6 +1214,8 @@ export default class MatrixChat extends React.PureComponent { StorageManager.tryPersistStorage(); + // defer the following actions by 30 seconds to not throw them at the user immediately + await sleep(30); if (SettingsStore.getValue("showCookieBar") && (Analytics.canEnable() || CountlyAnalytics.instance.canEnable()) ) { @@ -1346,8 +1348,8 @@ export default class MatrixChat extends React.PureComponent { this.firstSyncComplete = true; this.firstSyncPromise.resolve(); - if (Notifier.shouldShowPrompt()) { - showNotificationsToast(); + if (Notifier.shouldShowPrompt() && !MatrixClientPeg.userRegisteredWithinLastHours(24)) { + showNotificationsToast(false); } dis.fire(Action.FocusComposer); diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 160e9c0ec6..0cb4a5d305 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -74,6 +74,8 @@ import { IThreepidInvite } from "../../stores/ThreepidInviteStore"; import { CallState, CallType, MatrixCall } from "matrix-js-sdk/lib/webrtc/call"; import WidgetStore from "../../stores/WidgetStore"; import {UPDATE_EVENT} from "../../stores/AsyncStore"; +import Notifier from "../../Notifier"; +import {showToast as showNotificationsToast} from "../../toasts/DesktopNotificationsToast"; const DEBUG = false; let debuglog = function(msg: string) {}; @@ -1050,6 +1052,11 @@ export default class RoomView extends React.Component { let joinedOrInvitedMemberCount = room.getJoinedMemberCount() + room.getInvitedMemberCount(); if (countInfluence) joinedOrInvitedMemberCount += countInfluence; this.setState({isAlone: joinedOrInvitedMemberCount === 1}); + + // if they are not alone additionally prompt the user about notifications so they don't miss replies + if (joinedOrInvitedMemberCount > 1 && Notifier.shouldShowPrompt()) { + showNotificationsToast(true); + } } private updateDMState() {