From 471a381b4bd3f30ae276bbd90399de9e6fd5016d Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 30 Jul 2020 16:14:47 +1000 Subject: [PATCH] show disabled multi device message every 5 loads --- ts/components/session/ActionsPanel.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 067abaa8d..484a3b89f 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -4,6 +4,7 @@ import { Avatar } from '../Avatar'; import { PropsData as ConversationListItemPropsType } from '../ConversationListItem'; import { MultiDeviceProtocol } from '../../session/protocols'; import { UserUtil } from '../../util'; +import { createOrUpdateItem, getItemById } from '../../../js/modules/data'; export enum SectionType { Profile, @@ -59,18 +60,33 @@ export class ActionsPanel extends React.Component { 'refreshAvatarCallback' ); setTimeout(async () => { + const disabledMultiDeviceCountDb = await getItemById( + 'disabledMultiDeviceCount' + ); + const disabledMultiDeviceCount = + Number(disabledMultiDeviceCountDb?.value) || 0; + const data = { + id: 'disabledMultiDeviceCount', + value: String(disabledMultiDeviceCount + 1), + }; + await createOrUpdateItem(data); + if (disabledMultiDeviceCount % 5 !== 0) { + return; + } const currentDevice = await UserUtil.getCurrentDevicePubKey(); if (!currentDevice) { return; } - const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(currentDevice); - const isSecondary = secondaryDevices.find(s => s.key === currentDevice) || !!window.textsecure.storage.get('isSecondaryDevice'); + const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices( + currentDevice + ); + const isSecondary = + secondaryDevices.find(s => s.key === currentDevice) || + !!window.textsecure.storage.get('isSecondaryDevice'); const hasMultipleDevices = (await MultiDeviceProtocol.getOurDevices()).length > 1; - const primaryWithSecondary = - !isSecondary && - hasMultipleDevices; + const primaryWithSecondary = !isSecondary && hasMultipleDevices; if (!primaryWithSecondary && !isSecondary) { return;