Refactor Signal app routing

This commit is contained in:
Jamie Kyle 2023-11-02 12:42:31 -07:00 committed by GitHub
parent 86e6c2499c
commit 3ef0d221d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 1347 additions and 1044 deletions

View file

@ -35,16 +35,14 @@ import * as durations from './durations';
import type { DurationInSeconds } from './durations';
import { isPhoneNumberSharingEnabled } from './isPhoneNumberSharingEnabled';
import * as Registration from './registration';
import {
parseE164FromSignalDotMeHash,
parseUsernameBase64FromSignalDotMeHash,
} from './sgnlHref';
import { lookupConversationWithoutServiceId } from './lookupConversationWithoutServiceId';
import * as log from '../logging/log';
import { deleteAllMyStories } from './deleteAllMyStories';
import { isEnabled } from '../RemoteConfig';
import type { NotificationClickData } from '../services/notifications';
import { StoryViewModeType, StoryViewTargetType } from '../types/Stories';
import { isValidE164 } from './isValidE164';
import { fromWebSafeBase64 } from './webSafeBase64';
type SentMediaQualityType = 'standard' | 'high';
type ThemeType = 'light' | 'dark' | 'system';
@ -121,9 +119,12 @@ export type IPCEventsCallbacksType = {
resetAllChatColors: () => void;
resetDefaultChatColor: () => void;
showConversationViaNotification: (data: NotificationClickData) => void;
showConversationViaSignalDotMe: (hash: string) => Promise<void>;
showConversationViaSignalDotMe: (
kind: string,
value: string
) => Promise<void>;
showKeyboardShortcuts: () => void;
showGroupViaLink: (x: string) => Promise<void>;
showGroupViaLink: (value: string) => Promise<void>;
showReleaseNotes: () => void;
showStickerPack: (packId: string, key: string) => void;
shutdown: () => Promise<void>;
@ -497,14 +498,14 @@ export function createIPCEvents(
}
window.reduxActions.globalModals.showStickerPackPreview(packId, key);
},
showGroupViaLink: async hash => {
showGroupViaLink: async value => {
// We can get these events even if the user has never linked this instance.
if (!Registration.everDone()) {
log.warn('showGroupViaLink: Not registered, returning early');
return;
}
try {
await window.Signal.Groups.joinViaLink(hash);
await window.Signal.Groups.joinViaLink(value);
} catch (error) {
log.error(
'showGroupViaLink: Ran into an error!',
@ -532,14 +533,14 @@ export function createIPCEvents(
} else {
window.reduxActions.conversations.showConversation({
conversationId,
messageId,
messageId: messageId ?? undefined,
});
}
} else {
window.reduxActions.app.openInbox();
}
},
async showConversationViaSignalDotMe(hash: string) {
async showConversationViaSignalDotMe(kind: string, value: string) {
if (!Registration.everDone()) {
log.info(
'showConversationViaSignalDotMe: Not registered, returning early'
@ -549,45 +550,35 @@ export function createIPCEvents(
const { showUserNotFoundModal } = window.reduxActions.globalModals;
const maybeE164 = parseE164FromSignalDotMeHash(hash);
if (maybeE164) {
const convoId = await lookupConversationWithoutServiceId({
type: 'e164',
e164: maybeE164,
phoneNumber: maybeE164,
showUserNotFoundModal,
setIsFetchingUUID: noop,
});
if (convoId) {
window.reduxActions.conversations.showConversation({
conversationId: convoId,
let conversationId: string | undefined;
if (kind === 'phoneNumber') {
if (isValidE164(value, true)) {
conversationId = await lookupConversationWithoutServiceId({
type: 'e164',
e164: value,
phoneNumber: value,
showUserNotFoundModal,
setIsFetchingUUID: noop,
});
}
} else if (kind === 'encryptedUsername') {
const usernameBase64 = fromWebSafeBase64(value);
const username = await resolveUsernameByLinkBase64(usernameBase64);
if (username != null) {
conversationId = await lookupConversationWithoutServiceId({
type: 'username',
username,
showUserNotFoundModal,
setIsFetchingUUID: noop,
});
return;
}
// We will show not found modal on error
return;
}
const maybeUsernameBase64 = parseUsernameBase64FromSignalDotMeHash(hash);
let username: string | undefined;
if (maybeUsernameBase64) {
username = await resolveUsernameByLinkBase64(maybeUsernameBase64);
}
if (username) {
const convoId = await lookupConversationWithoutServiceId({
type: 'username',
username,
showUserNotFoundModal,
setIsFetchingUUID: noop,
if (conversationId != null) {
window.reduxActions.conversations.showConversation({
conversationId,
});
if (convoId) {
window.reduxActions.conversations.showConversation({
conversationId: convoId,
});
return;
}
// We will show not found modal on error
return;
}