Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-50354 - do not show push disabled notification once acknowledged #7495

Merged
merged 8 commits into from
Oct 25, 2023
8 changes: 8 additions & 0 deletions app/actions/app/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ export const removeLastViewedChannelIdAndServer = async () => {
export const removeLastViewedThreadIdAndServer = async () => {
return storeGlobal(GLOBAL_IDENTIFIERS.LAST_VIEWED_THREAD, null, false);
};

export const storePushDisabledInServerAcknowledged = async (serverUrl: string) => {
return storeGlobal(`${GLOBAL_IDENTIFIERS.PUSH_DISABLED_ACK}${serverUrl}`, 'true', false);
};

export const removePushDisabledInServerAcknowledged = async (serverUrl: string) => {
return storeGlobal(`${GLOBAL_IDENTIFIERS.PUSH_DISABLED_ACK}${serverUrl}`, null, false);
};
1 change: 1 addition & 0 deletions app/constants/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const GLOBAL_IDENTIFIERS = {
ONBOARDING: 'onboarding',
LAST_VIEWED_CHANNEL: 'lastViewedChannel',
LAST_VIEWED_THREAD: 'lastViewedThread',
PUSH_DISABLED_ACK: 'pushDisabledAck',
};

export enum OperationType {
Expand Down
4 changes: 3 additions & 1 deletion app/managers/session_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CookieManager, {type Cookie} from '@react-native-cookies/cookies';
import {AppState, type AppStateStatus, DeviceEventEmitter, Platform} from 'react-native';
import FastImage from 'react-native-fast-image';

import {storeOnboardingViewedValue} from '@actions/app/global';
import {removePushDisabledInServerAcknowledged, storeOnboardingViewedValue} from '@actions/app/global';
import {cancelSessionNotification, logout, scheduleSessionNotification} from '@actions/remote/session';
import {Events, Launch} from '@constants';
import DatabaseManager from '@database/manager';
Expand All @@ -22,6 +22,7 @@ import {getThemeFromState} from '@screens/navigation';
import EphemeralStore from '@store/ephemeral_store';
import {deleteFileCache, deleteFileCacheByDir} from '@utils/file';
import {isMainActivity} from '@utils/helpers';
import {urlSafeBase64Encode} from '@utils/security';
import {addNewServer} from '@utils/server';

import type {LaunchType} from '@typings/launch';
Expand Down Expand Up @@ -121,6 +122,7 @@ class SessionManager {
WebsocketManager.invalidateClient(serverUrl);

if (removeServer) {
await removePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl));
await DatabaseManager.destroyServerDatabase(serverUrl);
} else {
await DatabaseManager.deleteServerDatabase(serverUrl);
Expand Down
16 changes: 16 additions & 0 deletions app/queries/app/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ export const getDontAskForReview = async () => {
return Boolean(records?.[0]?.value);
};

export const getPushDisabledInServerAcknowledged = async (serverDomainString: string) => {
const records = await queryGlobalValue(`${GLOBAL_IDENTIFIERS.PUSH_DISABLED_ACK}${serverDomainString}`)?.fetch();
return Boolean(records?.[0]?.value);
};

export const observePushDisabledInServerAcknowledged = (serverDomainString: string) => {
const query = queryGlobalValue(`${GLOBAL_IDENTIFIERS.PUSH_DISABLED_ACK}${serverDomainString}`);
if (!query) {
return of$(false);
}
return query.observe().pipe(
switchMap((result) => (result.length ? result[0].observe() : of$(false))),
switchMap((v) => of$(Boolean(v))),
);
};

larkox marked this conversation as resolved.
Show resolved Hide resolved
export const getFirstLaunch = async () => {
const records = await queryGlobalValue(GLOBAL_IDENTIFIERS.FIRST_LAUNCH)?.fetch();
if (!records?.[0]?.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React from 'react';

import {PUSH_PROXY_STATUS_VERIFIED} from '@constants/push_proxy';
import {PUSH_PROXY_RESPONSE_NOT_AVAILABLE, PUSH_PROXY_STATUS_VERIFIED} from '@constants/push_proxy';
import {renderWithIntl} from '@test/intl-test-helper';

import Header from './header';
Expand All @@ -22,4 +22,18 @@ describe('components/channel_list/header', () => {

expect(toJSON()).toMatchSnapshot();
});

it('Push notifications disabled show alert icon', () => {
const wrapper = renderWithIntl(
<Header
pushProxyStatus={PUSH_PROXY_RESPONSE_NOT_AVAILABLE}
canCreateChannels={true}
canJoinChannels={true}
canInvitePeople={true}
displayName={'Test!'}
/>,
);

expect(wrapper.getByTestId('channel_list_header.push_alert')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const ChannelListHeader = ({
>
{serverDisplayName}
</Text>
{(pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED) && (
{pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED && (
<TouchableWithFeedback
onPress={onPushAlertPress}
testID='channel_list_header.push_alert'
Expand Down
29 changes: 25 additions & 4 deletions app/utils/push_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@

import {Alert} from 'react-native';

import {storePushDisabledInServerAcknowledged} from '@actions/app/global';
import {PUSH_PROXY_RESPONSE_NOT_AVAILABLE, PUSH_PROXY_RESPONSE_UNKNOWN, PUSH_PROXY_STATUS_NOT_AVAILABLE, PUSH_PROXY_STATUS_UNKNOWN, PUSH_PROXY_STATUS_VERIFIED} from '@constants/push_proxy';
import {getPushDisabledInServerAcknowledged} from '@queries/app/global';
import EphemeralStore from '@store/ephemeral_store';

import {urlSafeBase64Encode} from './security';

import type {IntlShape} from 'react-intl';

export function canReceiveNotifications(serverUrl: string, verification: string, intl: IntlShape) {
export function pushDisabledInServerAck(serverUrl: string) {
const extractedDomain = urlSafeBase64Encode(serverUrl);
return getPushDisabledInServerAcknowledged(extractedDomain);
}

export async function canReceiveNotifications(serverUrl: string, verification: string, intl: IntlShape) {
const hasAckNotification = await pushDisabledInServerAck(serverUrl);

switch (verification) {
case PUSH_PROXY_RESPONSE_NOT_AVAILABLE:
EphemeralStore.setPushProxyVerificationState(serverUrl, PUSH_PROXY_STATUS_NOT_AVAILABLE);
alertPushProxyError(intl);
if (!hasAckNotification) {
alertPushProxyError(intl, serverUrl);
}
break;
case PUSH_PROXY_RESPONSE_UNKNOWN:
EphemeralStore.setPushProxyVerificationState(serverUrl, PUSH_PROXY_STATUS_UNKNOWN);
Expand All @@ -23,18 +36,26 @@ export function canReceiveNotifications(serverUrl: string, verification: string,
}
}

export function alertPushProxyError(intl: IntlShape) {
const handleAlertResponse = async (buttonIndex: number, serverUrl?: string) => {
if (buttonIndex === 0 && serverUrl) {
// User clicked "Okay" acknowledging that the push notifications are disabled on that server
await storePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl));
}
};

export function alertPushProxyError(intl: IntlShape, serverUrl?: string) {
Alert.alert(
intl.formatMessage({
id: 'alert.push_proxy_error.title',
defaultMessage: 'Notifications cannot be received from this server',
}),
intl.formatMessage({
id: 'alert.push_proxy_error.description',
defaultMessage: 'Due to the configuration for this server, notifications cannot be received in the mobile app. Contact your system admin for more information.',
defaultMessage: 'Due to the configuration of this server, notifications cannot be received in the mobile app. Contact your system admin for more information.',
}),
[{
text: intl.formatMessage({id: 'alert.push_proxy.button', defaultMessage: 'Okay'}),
onPress: () => handleAlertResponse(0, serverUrl),
}],
);
}
Expand Down
2 changes: 1 addition & 1 deletion assets/base/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"account.your_profile": "Your Profile",
"alert.channel_deleted.description": "The channel {displayName} has been archived.",
"alert.channel_deleted.title": "Archived channel",
"alert.push_proxy_error.description": "Due to the configuration for this server, notifications cannot be received in the mobile app. Contact your system admin for more information.",
"alert.push_proxy_error.description": "Due to the configuration of this server, notifications cannot be received in the mobile app. Contact your system admin for more information.",
"alert.push_proxy_error.title": "Notifications cannot be received from this server",
"alert.push_proxy_unknown.description": "This server was unable to receive push notifications for an unknown reason. This will be attempted again next time you connect.",
"alert.push_proxy_unknown.title": "Notifications could not be received from this server",
Expand Down
2 changes: 1 addition & 1 deletion assets/base/i18n/en_AU.json
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
"alert.push_proxy.button": "Okay",
"alert.push_proxy_unknown.title": "Notifications could not be received from this server",
"alert.push_proxy_error.title": "Notifications cannot be received from this server",
"alert.push_proxy_error.description": "Due to the configuration for this server, notifications cannot be received in the mobile app. Contact your system admin for more information.",
"alert.push_proxy_error.description": "Due to the configuration of this server, notifications cannot be received in the mobile app. Contact your system admin for more information.",
"alert.channel_deleted.title": "Archived channel",
"alert.channel_deleted.description": "The channel {displayName} has been archived.",
"account.your_profile": "Your Profile",
Expand Down