Skip to content

Commit

Permalink
do not remove inside app alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
pvev committed Oct 10, 2023
1 parent 499114f commit 41ca619
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/managers/session_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import FastImage from 'react-native-fast-image';

import {removePushDisabledInServerAcknowledged, storeOnboardingViewedValue} from '@actions/app/global';
import {cancelSessionNotification, logout, scheduleSessionNotification} from '@actions/remote/session';
import {urlSafeBase64Encode} from '@app/utils/security';
import {Events, Launch} from '@constants';
import DatabaseManager from '@database/manager';
import {resetMomentLocale} from '@i18n';
Expand All @@ -23,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
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,23 @@ describe('components/channel_list/header', () => {
canJoinChannels={true}
canInvitePeople={true}
displayName={'Test!'}
pushDisabledAck={true}
/>,
);

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

it('Push notifications disabled and not having acknoledged it show alert icon', () => {
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!'}
pushDisabledAck={false}
/>,
);

expect(wrapper.getByTestId('channel_list_header.push_alert')).toBeTruthy();
});

it('Push notifications are disabled, but even after acknowledging them, the alert icon does not appear', () => {
const wrapper = renderWithIntl(
<Header
pushProxyStatus={PUSH_PROXY_RESPONSE_NOT_AVAILABLE}
canCreateChannels={true}
canJoinChannels={true}
canInvitePeople={true}
displayName={'Test!'}
pushDisabledAck={true}
/>,
);

expect(wrapper.queryByTestId('channel_list_header.push_alert')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type Props = {
iconPad?: boolean;
onHeaderPress?: () => void;
pushProxyStatus: string;
pushDisabledAck: boolean;
}

const getStyles = makeStyleSheetFromTheme((theme: Theme) => ({
Expand Down Expand Up @@ -112,7 +111,6 @@ const ChannelListHeader = ({
iconPad,
onHeaderPress,
pushProxyStatus,
pushDisabledAck,
}: Props) => {
const theme = useTheme();
const isTablet = useIsTablet();
Expand Down Expand Up @@ -168,7 +166,7 @@ const ChannelListHeader = ({

const onPushAlertPress = useCallback(() => {
if (pushProxyStatus === PUSH_PROXY_STATUS_NOT_AVAILABLE) {
alertPushProxyError(intl, serverUrl);
alertPushProxyError(intl);
} else {
alertPushProxyUnknown(intl);
}
Expand Down Expand Up @@ -208,7 +206,7 @@ const ChannelListHeader = ({
>
{serverDisplayName}
</Text>
{pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED && !pushDisabledAck && (
{pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED && (
<TouchableWithFeedback
onPress={onPushAlertPress}
testID='channel_list_header.push_alert'
Expand Down
12 changes: 2 additions & 10 deletions app/screens/home/channel_list/categories_list/header/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ import {combineLatest, of as of$} from 'rxjs';
import {distinctUntilChanged, switchMap} from 'rxjs/operators';

import {Permissions} from '@constants';
import {withServerUrl} from '@context/server';
import {observePushDisabledInServerAcknowledged} from '@queries/app/global';
import {observePermissionForTeam} from '@queries/servers/role';
import {observeConfigBooleanValue, observePushVerificationStatus} from '@queries/servers/system';
import {observeCurrentTeam} from '@queries/servers/team';
import {observeCurrentUser} from '@queries/servers/user';
import {urlSafeBase64Encode} from '@utils/security';

import ChannelListHeader from './header';

import type {WithDatabaseArgs} from '@typings/database/database';

type Props = WithDatabaseArgs & {
serverUrl: string;
}

const enhanced = withObservables([], ({serverUrl, database}: Props) => {
const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
const team = observeCurrentTeam(database);

const currentUser = observeCurrentUser(database);
Expand Down Expand Up @@ -64,8 +57,7 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
distinctUntilChanged(),
),
pushProxyStatus: observePushVerificationStatus(database),
pushDisabledAck: observePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl)),
};
});

export default withDatabase(withServerUrl(enhanced(ChannelListHeader)));
export default withDatabase(enhanced(ChannelListHeader));
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {of as of$} from 'rxjs';
import {Tutorial} from '@constants';
import {PUSH_PROXY_STATUS_UNKNOWN} from '@constants/push_proxy';
import DatabaseManager from '@database/manager';
import {observePushDisabledInServerAcknowledged, observeTutorialWatched} from '@queries/app/global';
import {observeTutorialWatched} from '@queries/app/global';
import {observePushVerificationStatus} from '@queries/servers/system';
import {urlSafeBase64Encode} from '@utils/security';

import ServerItem from './server_item';

Expand All @@ -27,7 +26,6 @@ const enhance = withObservables(['highlight'], ({highlight, server}: {highlight:
server: server.observe(),
tutorialWatched,
pushProxyStatus: serverDatabase ? observePushVerificationStatus(serverDatabase) : of$(PUSH_PROXY_STATUS_UNKNOWN),
pushDisabledAck: observePushDisabledInServerAcknowledged(urlSafeBase64Encode(server.url)),
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Props = {
server: ServersModel;
tutorialWatched: boolean;
pushProxyStatus: string;
pushDisabledAck: boolean;
}

type BadgeValues = {
Expand Down Expand Up @@ -148,7 +147,6 @@ const ServerItem = ({
server,
tutorialWatched,
pushProxyStatus,
pushDisabledAck,
}: Props) => {
const intl = useIntl();
const theme = useTheme();
Expand Down Expand Up @@ -430,7 +428,7 @@ const ServerItem = ({
>
{displayName}
</Text>
{server.lastActiveAt > 0 && pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED && !pushDisabledAck && (
{server.lastActiveAt > 0 && pushProxyStatus !== PUSH_PROXY_STATUS_VERIFIED && (
<CompassIcon
name='alert-outline'
color={theme.errorTextColor}
Expand Down
6 changes: 3 additions & 3 deletions app/utils/push_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ export async function canReceiveNotifications(serverUrl: string, verification: s
}
}

const handleAlertResponse = async (buttonIndex: number, serverUrl: string) => {
if (buttonIndex === 0) {
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) {
export function alertPushProxyError(intl: IntlShape, serverUrl?: string) {
Alert.alert(
intl.formatMessage({
id: 'alert.push_proxy_error.title',
Expand Down

0 comments on commit 41ca619

Please sign in to comment.