From fc664a2580af7ad18e073ea7241aa03f670caed9 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 6 Aug 2020 14:22:10 +1000 Subject: [PATCH] show a toast on secondary device forced unlink --- _locales/en/messages.json | 3 ++ js/background.js | 108 +++++++++++++++++++++----------------- preload.js | 4 +- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index cbc2489a9..ececbfe68 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1736,6 +1736,9 @@ "unlinked": { "message": "Unlinked" }, + "successUnlinked": { + "message": "Your device was unlinked successfully" + }, "relink": { "message": "Relink" }, diff --git a/js/background.js b/js/background.js index ff7a7357e..bece78657 100644 --- a/js/background.js +++ b/js/background.js @@ -129,6 +129,52 @@ // of preload.js processing window.setImmediate = window.nodeSetImmediate; + window.toasts = new Map(); + window.pushToast = options => { + // Setting toasts with the same ID can be used to prevent identical + // toasts from appearing at once (stacking). + // If toast already exists, it will be reloaded (updated) + + const params = { + title: options.title, + id: options.id || window.generateID(), + description: options.description || '', + type: options.type || '', + icon: options.icon || '', + shouldFade: options.shouldFade, + }; + + // Give all toasts an ID. User may define. + let currentToast; + const toastID = params.id; + const toast = !!toastID && window.toasts.get(toastID); + if (toast) { + currentToast = window.toasts.get(toastID); + currentToast.update(params); + } else { + // Make new Toast + window.toasts.set( + toastID, + new Whisper.SessionToastView({ + el: $('body'), + }) + ); + + currentToast = window.toasts.get(toastID); + currentToast.render(); + currentToast.update(params); + } + + // Remove some toasts if too many exist + const maxToasts = 6; + while (window.toasts.size > maxToasts) { + const finalToastID = window.toasts.keys().next().value; + window.toasts.get(finalToastID).fadeToast(); + } + + return toastID; + }; + const { IdleDetector, MessageDataMigrator } = Signal.Workflow; const { mandatoryMessageUpgrade, @@ -151,6 +197,20 @@ window.log.info('background page reloaded'); window.log.info('environment:', window.getEnvironment()); + const restartReason = localStorage.getItem('restart-reason'); + window.log.info('restartReason:', restartReason); + + if (restartReason === 'unlink') { + setTimeout(() => { + localStorage.removeItem('restart-reason'); + + window.pushToast({ + title: window.i18n('successUnlinked'), + type: 'info', + id: '123', + }); + }, 2000); + } let idleDetector; let initialLoadComplete = false; @@ -302,7 +362,7 @@ // 4th August 2020 - Force wipe of secondary devices as multi device is being disabled. if (storage.get('isSecondaryDevice')) { - await window.deleteAccount(); + await window.deleteAccount('unlink'); return; } @@ -760,52 +820,6 @@ .toString(36) .substring(3); - window.toasts = new Map(); - window.pushToast = options => { - // Setting toasts with the same ID can be used to prevent identical - // toasts from appearing at once (stacking). - // If toast already exists, it will be reloaded (updated) - - const params = { - title: options.title, - id: options.id || window.generateID(), - description: options.description || '', - type: options.type || '', - icon: options.icon || '', - shouldFade: options.shouldFade, - }; - - // Give all toasts an ID. User may define. - let currentToast; - const toastID = params.id; - const toast = !!toastID && window.toasts.get(toastID); - if (toast) { - currentToast = window.toasts.get(toastID); - currentToast.update(params); - } else { - // Make new Toast - window.toasts.set( - toastID, - new Whisper.SessionToastView({ - el: $('body'), - }) - ); - - currentToast = window.toasts.get(toastID); - currentToast.render(); - currentToast.update(params); - } - - // Remove some toasts if too many exist - const maxToasts = 6; - while (window.toasts.size > maxToasts) { - const finalToastID = window.toasts.keys().next().value; - window.toasts.get(finalToastID).fadeToast(); - } - - return toastID; - }; - // Get memberlist. This function is not accurate >> // window.getMemberList = window.lokiPublicChatAPI.getListOfMembers(); diff --git a/preload.js b/preload.js index 49b3ec0a9..92204da6e 100644 --- a/preload.js +++ b/preload.js @@ -505,7 +505,7 @@ const { window.BlockedNumberController = BlockedNumberController; -window.deleteAccount = async () => { +window.deleteAccount = async reason => { try { window.log.info('Deleting everything!'); @@ -517,6 +517,8 @@ window.deleteAccount = async () => { await window.Signal.Data.removeDB(); await window.Signal.Data.removeOtherData(); + // 'unlink' => toast will be shown on app restart + window.localStorage.setItem('restart-reason', reason); } catch (error) { window.log.error( 'Something went wrong deleting all data:',