mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Convert signal.js and preload.js to Typescript
This commit is contained in:
@@ -12,6 +12,11 @@ export async function downloadAttachment(
|
||||
): Promise<DownloadedAttachmentType | null> {
|
||||
let migratedAttachment: AttachmentType;
|
||||
|
||||
const { server } = window.textsecure;
|
||||
if (!server) {
|
||||
throw new Error('window.textsecure.server is not available!');
|
||||
}
|
||||
|
||||
const { id: legacyId } = attachmentData;
|
||||
if (legacyId === undefined) {
|
||||
migratedAttachment = attachmentData;
|
||||
@@ -24,10 +29,7 @@ export async function downloadAttachment(
|
||||
|
||||
let downloaded;
|
||||
try {
|
||||
downloaded = await doDownloadAttachment(
|
||||
window.textsecure.server,
|
||||
migratedAttachment
|
||||
);
|
||||
downloaded = await doDownloadAttachment(server, migratedAttachment);
|
||||
} catch (error) {
|
||||
// Attachments on the server expire after 30 days, then start returning 404
|
||||
if (error && error.code === 404) {
|
||||
|
||||
+31
-6
@@ -32,6 +32,7 @@ import type {
|
||||
|
||||
import { SignalService as Proto } from '../protobuf';
|
||||
import * as log from '../logging/log';
|
||||
import MessageSender from '../textsecure/SendMessage';
|
||||
|
||||
const RETRY_LIMIT = 5;
|
||||
|
||||
@@ -125,6 +126,11 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
|
||||
|
||||
log.info(`onRetryRequest/${logId}: Resending message`);
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error(`onRetryRequest/${logId}: messaging is not available!`);
|
||||
}
|
||||
|
||||
const { contentHint, messageIds, proto, timestamp } = sentProto;
|
||||
|
||||
const { contentProto, groupId } = await maybeAddSenderKeyDistributionMessage({
|
||||
@@ -141,7 +147,7 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
|
||||
'private'
|
||||
);
|
||||
const sendOptions = await getSendOptions(recipientConversation.attributes);
|
||||
const promise = window.textsecure.messaging.sendMessageProtoAndWait({
|
||||
const promise = messaging.sendMessageProtoAndWait({
|
||||
timestamp,
|
||||
recipients: [requesterUuid],
|
||||
proto: new Proto.Content(contentProto),
|
||||
@@ -263,6 +269,13 @@ async function sendDistributionMessageOrNullMessage(
|
||||
let sentDistributionMessage = false;
|
||||
log.info(`sendDistributionMessageOrNullMessage/${logId}: Starting...`);
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error(
|
||||
`sendDistributionMessageOrNullMessage/${logId}: messaging is not available!`
|
||||
);
|
||||
}
|
||||
|
||||
const conversation = window.ConversationController.getOrCreate(
|
||||
requesterUuid,
|
||||
'private'
|
||||
@@ -286,7 +299,7 @@ async function sendDistributionMessageOrNullMessage(
|
||||
|
||||
try {
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging.sendSenderKeyDistributionMessage(
|
||||
messaging.sendSenderKeyDistributionMessage(
|
||||
{
|
||||
contentHint: ContentHint.RESENDABLE,
|
||||
distributionId,
|
||||
@@ -322,11 +335,11 @@ async function sendDistributionMessageOrNullMessage(
|
||||
|
||||
// Enqueue a null message using the newly-created session
|
||||
try {
|
||||
const nullMessage = window.textsecure.messaging.getNullMessage({
|
||||
const nullMessage = MessageSender.getNullMessage({
|
||||
uuid: requesterUuid,
|
||||
});
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging.sendIndividualProto({
|
||||
messaging.sendIndividualProto({
|
||||
...nullMessage,
|
||||
options: sendOptions,
|
||||
proto: Proto.Content.decode(
|
||||
@@ -397,6 +410,13 @@ async function maybeAddSenderKeyDistributionMessage({
|
||||
requestGroupId,
|
||||
});
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error(
|
||||
`maybeAddSenderKeyDistributionMessage/${logId}: messaging is not available!`
|
||||
);
|
||||
}
|
||||
|
||||
if (!conversation) {
|
||||
log.warn(
|
||||
`maybeAddSenderKeyDistributionMessage/${logId}: Unable to find conversation`
|
||||
@@ -421,7 +441,7 @@ async function maybeAddSenderKeyDistributionMessage({
|
||||
const senderKeyInfo = conversation.get('senderKeyInfo');
|
||||
if (senderKeyInfo && senderKeyInfo.distributionId) {
|
||||
const protoWithDistributionMessage =
|
||||
await window.textsecure.messaging.getSenderKeyDistributionMessage(
|
||||
await messaging.getSenderKeyDistributionMessage(
|
||||
senderKeyInfo.distributionId,
|
||||
{ throwIfNotInDatabase: true, timestamp }
|
||||
);
|
||||
@@ -463,6 +483,11 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
|
||||
groupId: groupId ? `groupv2(${groupId})` : undefined,
|
||||
});
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error(`requestResend/${logId}: messaging is not available!`);
|
||||
}
|
||||
|
||||
// 1. Find the target conversation
|
||||
|
||||
const group = groupId
|
||||
@@ -495,7 +520,7 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
|
||||
const plaintext = PlaintextContent.from(message);
|
||||
const options = await getSendOptions(conversation.attributes);
|
||||
const result = await handleMessageSend(
|
||||
window.textsecure.messaging.sendRetryRequest({
|
||||
messaging.sendRetryRequest({
|
||||
plaintext,
|
||||
options,
|
||||
groupId,
|
||||
|
||||
@@ -10,12 +10,10 @@ const NINETY_ONE_DAYS = 91 * ONE_DAY_MS;
|
||||
const THIRTY_ONE_DAYS = 31 * ONE_DAY_MS;
|
||||
|
||||
export function hasExpired(): boolean {
|
||||
const { getExpiration } = window;
|
||||
|
||||
let buildExpiration = 0;
|
||||
|
||||
try {
|
||||
buildExpiration = parseInt(getExpiration(), 10);
|
||||
buildExpiration = window.getExpiration();
|
||||
if (buildExpiration) {
|
||||
log.info('Build expires: ', new Date(buildExpiration).toISOString());
|
||||
}
|
||||
|
||||
@@ -8283,7 +8283,7 @@
|
||||
{
|
||||
"rule": "jQuery-$(",
|
||||
"path": "sticker-creator/util/i18n.tsx",
|
||||
"line": " const FIND_REPLACEMENTS = /\\$([^$]+)\\$/g;",
|
||||
"line": " const FIND_REPLACEMENTS = /\\$([^$]+)\\$/g;",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-07-21T18:34:59.251Z"
|
||||
},
|
||||
|
||||
@@ -62,12 +62,15 @@ export async function lookupConversationWithoutUuid(
|
||||
const { showUserNotFoundModal, setIsFetchingUUID } = options;
|
||||
setIsFetchingUUID(identifier, true);
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('messaging is not available!');
|
||||
}
|
||||
|
||||
try {
|
||||
let conversationId: string | undefined;
|
||||
if (options.type === 'e164') {
|
||||
const serverLookup = await window.textsecure.messaging.getUuidsForE164s([
|
||||
options.e164,
|
||||
]);
|
||||
const serverLookup = await messaging.getUuidsForE164s([options.e164]);
|
||||
|
||||
if (serverLookup[options.e164]) {
|
||||
conversationId = window.ConversationController.ensureContactIds({
|
||||
@@ -131,10 +134,13 @@ async function checkForUsername(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('messaging is not available!');
|
||||
}
|
||||
|
||||
try {
|
||||
const profile = await window.textsecure.messaging.getProfileForUsername(
|
||||
username
|
||||
);
|
||||
const profile = await messaging.getProfileForUsername(username);
|
||||
|
||||
if (!profile.uuid) {
|
||||
log.error("checkForUsername: Returned profile didn't include a uuid");
|
||||
|
||||
@@ -74,9 +74,7 @@ export type ElectronLocaleType =
|
||||
| 'zh_CN'
|
||||
| 'zh_TW';
|
||||
|
||||
export function mapToSupportLocale(
|
||||
ourLocale: ElectronLocaleType
|
||||
): SupportLocaleType {
|
||||
export function mapToSupportLocale(ourLocale: string): SupportLocaleType {
|
||||
if (ourLocale === 'ar') {
|
||||
return ourLocale;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { partition } from 'lodash';
|
||||
import type { AttachmentType } from '../types/Attachment';
|
||||
import type { EmbeddedContactType } from '../types/EmbeddedContact';
|
||||
import type {
|
||||
MessageAttributesType,
|
||||
PreviewMessageType,
|
||||
QuotedMessageType,
|
||||
StickerMessageType,
|
||||
} from '../model-types.d';
|
||||
import * as AttachmentDownloads from '../messageModifiers/AttachmentDownloads';
|
||||
import * as log from '../logging/log';
|
||||
import { isLongMessage } from '../types/MIME';
|
||||
@@ -21,13 +13,22 @@ import {
|
||||
} from '../types/Stickers';
|
||||
import dataInterface from '../sql/Client';
|
||||
|
||||
import type { AttachmentType } from '../types/Attachment';
|
||||
import type { EmbeddedContactType } from '../types/EmbeddedContact';
|
||||
import type {
|
||||
MessageAttributesType,
|
||||
QuotedMessageType,
|
||||
} from '../model-types.d';
|
||||
import type { StickerType } from '../types/Stickers';
|
||||
import type { LinkPreviewType } from '../types/message/LinkPreviews';
|
||||
|
||||
type ReturnType = {
|
||||
bodyAttachment?: AttachmentType;
|
||||
attachments: Array<AttachmentType>;
|
||||
preview: PreviewMessageType;
|
||||
preview: Array<LinkPreviewType>;
|
||||
contact: Array<EmbeddedContactType>;
|
||||
quote?: QuotedMessageType;
|
||||
sticker?: StickerMessageType;
|
||||
sticker?: StickerType;
|
||||
};
|
||||
|
||||
// Receive logic
|
||||
|
||||
@@ -45,6 +45,11 @@ export async function sendReceipts({
|
||||
throw missingCaseError(type);
|
||||
}
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('messaging is not available!');
|
||||
}
|
||||
|
||||
if (requiresUserSetting && !window.storage.get('read-receipt-setting')) {
|
||||
log.info('requires user setting. Not sending these receipts');
|
||||
return;
|
||||
@@ -119,7 +124,7 @@ export async function sendReceipts({
|
||||
const messageIds = batch.map(receipt => receipt.messageId);
|
||||
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging[methodName]({
|
||||
messaging[methodName]({
|
||||
senderE164: sender.get('e164'),
|
||||
senderUuid: sender.get('uuid'),
|
||||
timestamps,
|
||||
|
||||
Reference in New Issue
Block a user