implement pr feedback; reuse existing keyfromurl function; fix imports
This commit is contained in:
parent
7244f95fea
commit
d4cd0cb1de
6 changed files with 16 additions and 42 deletions
|
|
@ -7,6 +7,7 @@ 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';
|
||||
|
|
@ -21,7 +22,7 @@ import {getCurrentUser} from '@queries/servers/user';
|
|||
import {getThemeFromState} from '@screens/navigation';
|
||||
import EphemeralStore from '@store/ephemeral_store';
|
||||
import {deleteFileCache, deleteFileCacheByDir} from '@utils/file';
|
||||
import {createKeyFromServerUrl, isMainActivity} from '@utils/helpers';
|
||||
import {isMainActivity} from '@utils/helpers';
|
||||
import {addNewServer} from '@utils/server';
|
||||
|
||||
import type {LaunchType} from '@typings/launch';
|
||||
|
|
@ -121,7 +122,7 @@ class SessionManager {
|
|||
WebsocketManager.invalidateClient(serverUrl);
|
||||
|
||||
if (removeServer) {
|
||||
await removePushDisabledInServerAcknowledged(createKeyFromServerUrl(serverUrl));
|
||||
await removePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl));
|
||||
await DatabaseManager.destroyServerDatabase(serverUrl);
|
||||
} else {
|
||||
await DatabaseManager.deleteServerDatabase(serverUrl);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ describe('components/channel_list/header', () => {
|
|||
expect(toJSON()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('Push notifications disabled and not having ackoledge show alert icon', () => {
|
||||
it('Push notifications disabled and not having acknoledged it show alert icon', () => {
|
||||
const wrapper = renderWithIntl(
|
||||
<Header
|
||||
pushProxyStatus={PUSH_PROXY_RESPONSE_NOT_AVAILABLE}
|
||||
|
|
@ -39,7 +39,7 @@ describe('components/channel_list/header', () => {
|
|||
expect(wrapper.getByTestId('channel_list_header.push_alert')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Push notifications disabled but after ackoledging do not show alert icon', () => {
|
||||
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}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ import withObservables from '@nozbe/with-observables';
|
|||
import {combineLatest, of as of$} from 'rxjs';
|
||||
import {distinctUntilChanged, switchMap} from 'rxjs/operators';
|
||||
|
||||
import {observePushDisabledInServerAcknowledged} from '@app/queries/app/global';
|
||||
import {createKeyFromServerUrl} from '@app/utils/helpers';
|
||||
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';
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
|
|||
distinctUntilChanged(),
|
||||
),
|
||||
pushProxyStatus: observePushVerificationStatus(database),
|
||||
pushDisabledAck: observePushDisabledInServerAcknowledged(createKeyFromServerUrl(serverUrl)),
|
||||
pushDisabledAck: observePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl)),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
import withObservables from '@nozbe/with-observables';
|
||||
import {of as of$} from 'rxjs';
|
||||
|
||||
import {createKeyFromServerUrl} from '@app/utils/helpers';
|
||||
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 {observePushVerificationStatus} from '@queries/servers/system';
|
||||
import {urlSafeBase64Encode} from '@utils/security';
|
||||
|
||||
import ServerItem from './server_item';
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ const enhance = withObservables(['highlight'], ({highlight, server}: {highlight:
|
|||
server: server.observe(),
|
||||
tutorialWatched,
|
||||
pushProxyStatus: serverDatabase ? observePushVerificationStatus(serverDatabase) : of$(PUSH_PROXY_STATUS_UNKNOWN),
|
||||
pushDisabledAck: observePushDisabledInServerAcknowledged(createKeyFromServerUrl(server.url)),
|
||||
pushDisabledAck: observePushDisabledInServerAcknowledged(urlSafeBase64Encode(server.url)),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -162,29 +162,3 @@ export function isMainActivity() {
|
|||
android: ShareModule?.getCurrentActivityName() === 'MainActivity',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the serverUrl to create a key.
|
||||
*
|
||||
* @param {string} input - The serverUrl, potentially with a port and protocol.
|
||||
* @returns {string} The extracted domain name or IP address,
|
||||
* or empty if no match is found.
|
||||
*
|
||||
* // Output:
|
||||
* // Input: https://example-something.com => Result: examplesomething
|
||||
* // Input: http://192.168.1.1 => Result: 19216811
|
||||
* // Input: https://127.0.0.1:3000 => Result: 1270013000
|
||||
* // Input: https://subdomain.example.com/api => subdomainexamplecomapi
|
||||
* // Input: http://localhost:8080/app/v1 => localhost8080appv1
|
||||
*/
|
||||
export function createKeyFromServerUrl(input: string) {
|
||||
const regex = /^(https?:\/\/)?([\w.-]+)(:\d+)?(\/\S*)?/;
|
||||
const match = input.match(regex);
|
||||
|
||||
if (match) {
|
||||
const domainWithPortAndSubpath = match[2] + (match[3] || '') + (match[4] || '');
|
||||
return domainWithPortAndSubpath.replace(/[^\w]/g, '');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,17 @@
|
|||
import {Alert} from 'react-native';
|
||||
|
||||
import {storePushDisabledInServerAcknowledged} from '@actions/app/global';
|
||||
import {getPushDisabledInServerAcknowledged} from '@app/queries/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 {createKeyFromServerUrl} from './helpers';
|
||||
import {urlSafeBase64Encode} from './security';
|
||||
|
||||
import type {IntlShape} from 'react-intl';
|
||||
|
||||
export async function pushDisabledInServerAck(serverUrl: string) {
|
||||
const extractedDomain = createKeyFromServerUrl(serverUrl);
|
||||
const pushServerDisabledAck = await getPushDisabledInServerAcknowledged(extractedDomain);
|
||||
return pushServerDisabledAck;
|
||||
export function pushDisabledInServerAck(serverUrl: string) {
|
||||
const extractedDomain = urlSafeBase64Encode(serverUrl);
|
||||
return getPushDisabledInServerAcknowledged(extractedDomain);
|
||||
}
|
||||
|
||||
export async function canReceiveNotifications(serverUrl: string, verification: string, intl: IntlShape) {
|
||||
|
|
@ -40,7 +39,7 @@ export async function canReceiveNotifications(serverUrl: string, verification: s
|
|||
const handleAlertResponse = async (buttonIndex: number, serverUrl: string) => {
|
||||
if (buttonIndex === 0) {
|
||||
// User clicked "Okay" acknowledging that the push notifications are disabled on that server
|
||||
await storePushDisabledInServerAcknowledged(createKeyFromServerUrl(serverUrl));
|
||||
await storePushDisabledInServerAcknowledged(urlSafeBase64Encode(serverUrl));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue