From 1d2fcde49f0147559b70ef04ff58310dab00cb28 Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Tue, 21 Sep 2021 16:45:25 -0400 Subject: [PATCH] Moves navigateTo to util --- ...NewlyCreatedGroupInvitedContactsDialog.tsx | 6 +++-- .../conversation/ConversationHero.tsx | 6 +++-- ts/util/openLinkInWebBrowser.ts | 6 +++++ ts/views/conversation_view.ts | 22 ++++++------------- ts/views/install_view.ts | 3 ++- 5 files changed, 23 insertions(+), 20 deletions(-) create mode 100644 ts/util/openLinkInWebBrowser.ts diff --git a/ts/components/NewlyCreatedGroupInvitedContactsDialog.tsx b/ts/components/NewlyCreatedGroupInvitedContactsDialog.tsx index 66229f2f3..97ea93c22 100644 --- a/ts/components/NewlyCreatedGroupInvitedContactsDialog.tsx +++ b/ts/components/NewlyCreatedGroupInvitedContactsDialog.tsx @@ -8,6 +8,7 @@ import { ConversationType } from '../state/ducks/conversations'; import { Intl } from './Intl'; import { ContactName } from './conversation/ContactName'; import { GroupDialog } from './GroupDialog'; +import { openLinkInWebBrowser } from '../util/openLinkInWebBrowser'; type PropsType = { contacts: Array; @@ -68,8 +69,9 @@ export const NewlyCreatedGroupInvitedContactsDialog: FunctionComponent { - window.location.href = - 'https://support.signal.org/hc/articles/360007319331-Group-chats'; + openLinkInWebBrowser( + 'https://support.signal.org/hc/articles/360007319331-Group-chats' + ); }} onClose={onClose} title={title} diff --git a/ts/components/conversation/ConversationHero.tsx b/ts/components/conversation/ConversationHero.tsx index cc11e5bca..2b3f5f9f1 100644 --- a/ts/components/conversation/ConversationHero.tsx +++ b/ts/components/conversation/ConversationHero.tsx @@ -12,6 +12,7 @@ import { ConfirmationDialog } from '../ConfirmationDialog'; import { Button, ButtonSize, ButtonVariant } from '../Button'; import { shouldBlurAvatar } from '../../util/shouldBlurAvatar'; import * as log from '../../logging/log'; +import { openLinkInWebBrowser } from '../../util/openLinkInWebBrowser'; export type Props = { about?: string; @@ -237,8 +238,9 @@ export const ConversationHero = ({ { text: i18n('MessageRequestWarning__dialog__learn-even-more'), action: () => { - window.location.href = - 'https://support.signal.org/hc/articles/360007459591'; + openLinkInWebBrowser( + 'https://support.signal.org/hc/articles/360007459591' + ); closeMessageRequestWarning(); }, }, diff --git a/ts/util/openLinkInWebBrowser.ts b/ts/util/openLinkInWebBrowser.ts new file mode 100644 index 000000000..343c79586 --- /dev/null +++ b/ts/util/openLinkInWebBrowser.ts @@ -0,0 +1,6 @@ +// Copyright 2021 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +export function openLinkInWebBrowser(url: string): void { + window.location.href = url; +} diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 81254a614..e19ca7f5f 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -84,6 +84,7 @@ import { isNotNil } from '../util/isNotNil'; import { dropNull } from '../util/dropNull'; import { CompositionAPIType } from '../components/CompositionArea'; import * as log from '../logging/log'; +import { openLinkInWebBrowser } from '../util/openLinkInWebBrowser'; type AttachmentOptions = { messageId: string; @@ -1046,11 +1047,9 @@ export class ConversationView extends window.Backbone.View { const showIdentity = (conversationId: string) => { this.showSafetyNumber(conversationId); }; - const openLink = (url: string) => { - this.navigateTo(url); - }; + const openLink = openLinkInWebBrowser; const downloadNewVersion = () => { - this.downloadNewVersion(); + openLinkInWebBrowser('https://signal.org/download'); }; const showSafetyNumber = (contactId: string) => { this.showSafetyNumber(contactId); @@ -1102,11 +1101,13 @@ export class ConversationView extends window.Backbone.View { const supportLocale = window.Signal.Util.mapToSupportLocale(locale); const url = baseUrl.replace('LOCALE', supportLocale); - this.navigateTo(url); + openLinkInWebBrowser(url); }; const learnMoreAboutDeliveryIssue = () => { - this.navigateTo('https://support.signal.org/hc/articles/4404859745690'); + openLinkInWebBrowser( + 'https://support.signal.org/hc/articles/4404859745690' + ); }; const scrollToQuotedMessage = async ( @@ -1721,15 +1722,6 @@ export class ConversationView extends window.Backbone.View { this.remove(); } - // eslint-disable-next-line class-methods-use-this - navigateTo(url: string): void { - window.location.href = url; - } - - downloadNewVersion(): void { - this.navigateTo('https://signal.org/download'); - } - async onDrop(e: JQuery.TriggeredEvent): Promise { if (!e.originalEvent) { return; diff --git a/ts/views/install_view.ts b/ts/views/install_view.ts index 36ecaf030..6d518a211 100644 --- a/ts/views/install_view.ts +++ b/ts/views/install_view.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only import * as log from '../logging/log'; +import { openLinkInWebBrowser } from '../util/openLinkInWebBrowser'; window.Whisper = window.Whisper || {}; const { Whisper } = window; @@ -106,7 +107,7 @@ Whisper.InstallView = Whisper.View.extend({ this.error.name === 'HTTPError' && this.error.code === TOO_OLD ) { - window.location.href = 'https://signal.org/download'; + openLinkInWebBrowser('https://signal.org/download'); return; }