Convert signal.js and preload.js to Typescript
This commit is contained in:
parent
e18510e41c
commit
2464e0a9c1
94 changed files with 2113 additions and 1848 deletions
|
@ -38,6 +38,7 @@ import type {
|
|||
StickerType,
|
||||
} from '../textsecure/SendMessage';
|
||||
import createTaskWithTimeout from '../textsecure/TaskWithTimeout';
|
||||
import MessageSender from '../textsecure/SendMessage';
|
||||
import type { CallbackResultType } from '../textsecure/Types.d';
|
||||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import type {
|
||||
|
@ -1249,7 +1250,9 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
async sendTypingMessage(isTyping: boolean): Promise<void> {
|
||||
if (!window.textsecure.messaging) {
|
||||
const { messaging } = window.textsecure;
|
||||
|
||||
if (!messaging) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1298,8 +1301,7 @@ export class ConversationModel extends window.Backbone
|
|||
`sendTypingMessage(${this.idForLogging()}): sending ${content.isTyping}`
|
||||
);
|
||||
|
||||
const contentMessage =
|
||||
window.textsecure.messaging.getTypingContentMessage(content);
|
||||
const contentMessage = messaging.getTypingContentMessage(content);
|
||||
|
||||
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
|
||||
|
||||
|
@ -1309,7 +1311,7 @@ export class ConversationModel extends window.Backbone
|
|||
};
|
||||
if (isDirectConversation(this.attributes)) {
|
||||
await handleMessageSend(
|
||||
window.textsecure.messaging.sendMessageProtoAndWait({
|
||||
messaging.sendMessageProtoAndWait({
|
||||
timestamp,
|
||||
recipients: groupMembers,
|
||||
proto: contentMessage,
|
||||
|
@ -2504,7 +2506,7 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
try {
|
||||
await singleProtoJobQueue.add(
|
||||
window.textsecure.messaging.getMessageRequestResponseSync({
|
||||
MessageSender.getMessageRequestResponseSync({
|
||||
threadE164: this.get('e164'),
|
||||
threadUuid: this.get('uuid'),
|
||||
groupId,
|
||||
|
@ -2696,12 +2698,7 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
try {
|
||||
await singleProtoJobQueue.add(
|
||||
window.textsecure.messaging.getVerificationSync(
|
||||
e164,
|
||||
uuid.toString(),
|
||||
state,
|
||||
key
|
||||
)
|
||||
MessageSender.getVerificationSync(e164, uuid.toString(), state, key)
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(
|
||||
|
@ -3987,15 +3984,11 @@ export class ConversationModel extends window.Backbone
|
|||
'desktop.mandatoryProfileSharing'
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const destination = this.getSendTarget()!;
|
||||
const recipients = this.getRecipients();
|
||||
|
||||
await this.maybeApplyUniversalTimer();
|
||||
|
||||
const expireTimer = this.get('expireTimer');
|
||||
|
||||
const recipientMaybeConversations = map(recipients, identifier =>
|
||||
const recipientMaybeConversations = map(this.getRecipients(), identifier =>
|
||||
window.ConversationController.get(identifier)
|
||||
);
|
||||
const recipientConversations = filter(
|
||||
|
@ -4020,7 +4013,8 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
// Here we move attachments to disk
|
||||
const messageWithSchema = await upgradeMessageSchema({
|
||||
const attributes = await upgradeMessageSchema({
|
||||
id: UUID.generate().toString(),
|
||||
timestamp: now,
|
||||
type: 'outgoing',
|
||||
body,
|
||||
|
@ -4033,7 +4027,6 @@ export class ConversationModel extends window.Backbone
|
|||
received_at: window.Signal.Util.incrementMessageCounter(),
|
||||
received_at_ms: now,
|
||||
expireTimer,
|
||||
recipients,
|
||||
readStatus: ReadStatus.Read,
|
||||
seenStatus: SeenStatus.NotApplicable,
|
||||
sticker,
|
||||
|
@ -4049,14 +4042,6 @@ export class ConversationModel extends window.Backbone
|
|||
storyId,
|
||||
});
|
||||
|
||||
if (isDirectConversation(this.attributes)) {
|
||||
messageWithSchema.destination = destination;
|
||||
}
|
||||
const attributes: MessageAttributesType = {
|
||||
...messageWithSchema,
|
||||
id: UUID.generate().toString(),
|
||||
};
|
||||
|
||||
const model = new window.Whisper.Message(attributes);
|
||||
const message = window.MessageController.register(model.id, model);
|
||||
message.cachedOutgoingContactData = contact;
|
||||
|
@ -4588,6 +4573,11 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
// Deprecated: only applies to GroupV1
|
||||
async leaveGroup(): Promise<void> {
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('leaveGroup: Cannot leave v1 group when offline!');
|
||||
}
|
||||
|
||||
if (!isGroupV1(this.attributes)) {
|
||||
throw new Error(
|
||||
`leaveGroup: Group ${this.idForLogging()} is not GroupV1!`
|
||||
|
@ -4628,11 +4618,7 @@ export class ConversationModel extends window.Backbone
|
|||
const options = await getSendOptions(this.attributes);
|
||||
message.send(
|
||||
handleMessageSend(
|
||||
window.textsecure.messaging.leaveGroup(
|
||||
groupId,
|
||||
groupIdentifiers,
|
||||
options
|
||||
),
|
||||
messaging.leaveGroup(groupId, groupIdentifiers, options),
|
||||
{ messageIds: [], sendType: 'legacyGroupChange' }
|
||||
)
|
||||
);
|
||||
|
@ -4797,7 +4783,11 @@ export class ConversationModel extends window.Backbone
|
|||
return;
|
||||
}
|
||||
|
||||
const avatar = await window.textsecure.messaging.getAvatar(avatarPath);
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('setProfileAvatar: Cannot fetch avatar when offline!');
|
||||
}
|
||||
const avatar = await messaging.getAvatar(avatarPath);
|
||||
|
||||
// decrypt
|
||||
const decrypted = decryptProfile(avatar, decryptionKey);
|
||||
|
@ -5017,17 +5007,17 @@ export class ConversationModel extends window.Backbone
|
|||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const number = this.get('e164')!;
|
||||
try {
|
||||
const parsedNumber = window.libphonenumber.parse(number);
|
||||
const regionCode = getRegionCodeForNumber(parsedNumber);
|
||||
const parsedNumber = window.libphonenumberInstance.parse(number);
|
||||
const regionCode = getRegionCodeForNumber(number);
|
||||
if (regionCode === window.storage.get('regionCode')) {
|
||||
return window.libphonenumber.format(
|
||||
return window.libphonenumberInstance.format(
|
||||
parsedNumber,
|
||||
window.libphonenumber.PhoneNumberFormat.NATIONAL
|
||||
window.libphonenumberFormat.NATIONAL
|
||||
);
|
||||
}
|
||||
return window.libphonenumber.format(
|
||||
return window.libphonenumberInstance.format(
|
||||
parsedNumber,
|
||||
window.libphonenumber.PhoneNumberFormat.INTERNATIONAL
|
||||
window.libphonenumberFormat.INTERNATIONAL
|
||||
);
|
||||
} catch (e) {
|
||||
return number;
|
||||
|
|
|
@ -205,7 +205,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
if (_.isObject(attributes)) {
|
||||
this.set(
|
||||
TypedMessage.initializeSchemaVersion({
|
||||
message: attributes,
|
||||
message: attributes as MessageAttributesType,
|
||||
logger: log,
|
||||
})
|
||||
);
|
||||
|
@ -1638,6 +1638,11 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
return;
|
||||
}
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('sendSyncMessage: messaging not available!');
|
||||
}
|
||||
|
||||
this.syncPromise = this.syncPromise || Promise.resolve();
|
||||
const next = async () => {
|
||||
const dataMessage = this.get('dataMessage');
|
||||
|
@ -1677,7 +1682,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
);
|
||||
|
||||
return handleMessageSend(
|
||||
window.textsecure.messaging.sendSyncMessage({
|
||||
messaging.sendSyncMessage({
|
||||
encodedDataMessage: dataMessage,
|
||||
timestamp: this.get('sent_at'),
|
||||
destination: conv.get('e164'),
|
||||
|
@ -2347,6 +2352,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
]);
|
||||
|
||||
const withQuoteReference = {
|
||||
...message.attributes,
|
||||
...initialMessage,
|
||||
quote,
|
||||
storyId: storyQuote?.id,
|
||||
|
@ -2410,12 +2416,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
};
|
||||
|
||||
// GroupV1
|
||||
if (!hasGroupV2Prop && dataMessage.group) {
|
||||
if (!hasGroupV2Prop && initialMessage.group) {
|
||||
const pendingGroupUpdate: GroupV1Update = {};
|
||||
|
||||
const memberConversations: Array<ConversationModel> =
|
||||
await Promise.all(
|
||||
dataMessage.group.membersE164.map((e164: string) =>
|
||||
initialMessage.group.membersE164.map((e164: string) =>
|
||||
window.ConversationController.getOrCreateAndWait(
|
||||
e164,
|
||||
'private'
|
||||
|
@ -2426,20 +2432,20 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
attributes = {
|
||||
...attributes,
|
||||
type: 'group',
|
||||
groupId: dataMessage.group.id,
|
||||
groupId: initialMessage.group.id,
|
||||
};
|
||||
if (dataMessage.group.type === GROUP_TYPES.UPDATE) {
|
||||
if (initialMessage.group.type === GROUP_TYPES.UPDATE) {
|
||||
attributes = {
|
||||
...attributes,
|
||||
name: dataMessage.group.name,
|
||||
name: initialMessage.group.name,
|
||||
members: _.union(members, conversation.get('members')),
|
||||
};
|
||||
|
||||
if (dataMessage.group.name !== conversation.get('name')) {
|
||||
pendingGroupUpdate.name = dataMessage.group.name;
|
||||
if (initialMessage.group.name !== conversation.get('name')) {
|
||||
pendingGroupUpdate.name = initialMessage.group.name;
|
||||
}
|
||||
|
||||
const avatarAttachment = dataMessage.group.avatar;
|
||||
const avatarAttachment = initialMessage.group.avatar;
|
||||
|
||||
let downloadedAvatar;
|
||||
let hash;
|
||||
|
@ -2520,7 +2526,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
attributes.left = false;
|
||||
conversation.set({ addedBy: getContactId(message.attributes) });
|
||||
}
|
||||
} else if (dataMessage.group.type === GROUP_TYPES.QUIT) {
|
||||
} else if (initialMessage.group.type === GROUP_TYPES.QUIT) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const sender = window.ConversationController.get(senderId)!;
|
||||
const inGroup = Boolean(
|
||||
|
@ -2584,7 +2590,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
expirationTimerUpdate: {
|
||||
source,
|
||||
sourceUuid,
|
||||
expireTimer: dataMessage.expireTimer,
|
||||
expireTimer: initialMessage.expireTimer,
|
||||
},
|
||||
});
|
||||
conversation.set({ expireTimer: dataMessage.expireTimer });
|
||||
|
@ -2626,8 +2632,8 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
}
|
||||
|
||||
if (dataMessage.profileKey) {
|
||||
const { profileKey } = dataMessage;
|
||||
if (initialMessage.profileKey) {
|
||||
const { profileKey } = initialMessage;
|
||||
if (
|
||||
source === window.textsecure.storage.user.getNumber() ||
|
||||
sourceUuid ===
|
||||
|
@ -2700,10 +2706,13 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
navigator.languages,
|
||||
window.getLocale()
|
||||
);
|
||||
const response =
|
||||
await window.textsecure.messaging.server.getBoostBadgesFromServer(
|
||||
userLanguages
|
||||
);
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('handleDataMessage: messaging is not available');
|
||||
}
|
||||
const response = await messaging.server.getBoostBadgesFromServer(
|
||||
userLanguages
|
||||
);
|
||||
const boostBadgesByLevel = parseBoostBadgeListFromServer(
|
||||
response,
|
||||
updatesUrl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue