More protobufjs migration

This commit is contained in:
Fedor Indutny 2021-07-09 12:36:10 -07:00 committed by GitHub
parent cf06e6638e
commit ddbbe3a6b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 3967 additions and 3369 deletions

View file

@ -14,7 +14,9 @@ import {
VerificationOptions,
WhatIsThis,
} from '../model-types.d';
import { AttachmentType } from '../types/Attachment';
import { CallMode, CallHistoryDetailsType } from '../types/Calling';
import * as Stickers from '../types/Stickers';
import { CallbackResultType, GroupV2InfoType } from '../textsecure/SendMessage';
import { ConversationType } from '../state/ducks/conversations';
import {
@ -3100,7 +3102,7 @@ export class ConversationModel extends window.Backbone
? [{ contentType: 'image/jpeg', fileName: null }]
: await this.getQuoteAttachment(attachments, preview, sticker),
bodyRanges: quotedMessage.get('bodyRanges'),
id: String(quotedMessage.get('sent_at')),
id: quotedMessage.get('sent_at'),
isViewOnce: isTapToView(quotedMessage.attributes),
messageId: quotedMessage.get('id'),
referencedMessageNotFound: false,
@ -3109,8 +3111,8 @@ export class ConversationModel extends window.Backbone
}
async sendStickerMessage(packId: string, stickerId: number): Promise<void> {
const packData = window.Signal.Stickers.getStickerPack(packId);
const stickerData = window.Signal.Stickers.getSticker(packId, stickerId);
const packData = Stickers.getStickerPack(packId);
const stickerData = Stickers.getSticker(packId, stickerId);
if (!stickerData || !packData) {
window.log.warn(
`Attempted to send nonexistent (${packId}, ${stickerId}) sticker!`
@ -3152,7 +3154,7 @@ export class ConversationModel extends window.Backbone
},
};
this.sendMessage(null, [], null, [], sticker);
this.sendMessage(undefined, [], undefined, [], sticker);
window.reduxActions.stickers.useSticker(packId, stickerId);
}
@ -3451,10 +3453,10 @@ export class ConversationModel extends window.Backbone
}
sendMessage(
body: string | null,
attachments: Array<WhatIsThis>,
quote: WhatIsThis,
preview: WhatIsThis,
body: string | undefined,
attachments: Array<AttachmentType>,
quote?: QuotedMessageType,
preview?: WhatIsThis,
sticker?: WhatIsThis,
mentions?: BodyRangesType,
{
@ -3503,6 +3505,7 @@ export class ConversationModel extends window.Backbone
// Here we move attachments to disk
const messageWithSchema = await upgradeMessageSchema({
timestamp: now,
type: 'outgoing',
body,
conversationId: this.id,
@ -3575,7 +3578,7 @@ export class ConversationModel extends window.Backbone
}
const attachmentsWithData = await Promise.all(
messageWithSchema.attachments.map(loadAttachmentData)
messageWithSchema.attachments?.map(loadAttachmentData) ?? []
);
const {
@ -5086,7 +5089,7 @@ export class ConversationModel extends window.Backbone
isTyping: boolean;
senderId: string;
fromMe: boolean;
senderDevice: string;
senderDevice: number;
}): void {
const { isTyping, senderId, fromMe, senderDevice } = options;

View file

@ -12,9 +12,10 @@ import {
QuotedMessageType,
WhatIsThis,
} from '../model-types.d';
import { strictAssert } from '../util/assert';
import { dropNull } from '../util/dropNull';
import { map, filter, find } from '../util/iterables';
import { isNotNil } from '../util/isNotNil';
import { DataMessageClass } from '../textsecure.d';
import { ConversationModel } from './conversations';
import { MessageStatusType } from '../components/conversation/Message';
import {
@ -23,9 +24,17 @@ import {
} from '../state/smart/MessageDetail';
import { getCallingNotificationText } from '../util/callingNotification';
import { CallbackResultType } from '../textsecure/SendMessage';
import { ProcessedDataMessage, ProcessedQuote } from '../textsecure/Types.d';
import * as expirationTimer from '../util/expirationTimer';
import { ReactionType } from '../types/Reactions';
import {
copyStickerToAttachments,
deletePackReference,
savePackMetadata,
getStickerPackStatus,
} from '../types/Stickers';
import * as Stickers from '../types/Stickers';
import { AttachmentType, isImage, isVideo } from '../types/Attachment';
import { MIMEType, IMAGE_WEBP } from '../types/MIME';
import { ourProfileKeyService } from '../services/ourProfileKey';
@ -107,12 +116,6 @@ const {
loadStickerData,
upgradeMessageSchema,
} = window.Signal.Migrations;
const {
copyStickerToAttachments,
deletePackReference,
savePackMetadata,
getStickerPackStatus,
} = window.Signal.Stickers;
const { getTextWithMentions, GoogleChrome } = window.Signal.Util;
const { addStickerPackReference, getMessageBySender } = window.Signal.Data;
@ -124,7 +127,7 @@ const includesAny = <T>(haystack: Array<T>, ...needles: Array<T>) =>
export function isQuoteAMatch(
message: MessageModel | null | undefined,
conversationId: string,
quote: QuotedMessageType | DataMessageClass.Quote
quote: QuotedMessageType
): message is MessageModel {
if (!message) {
return false;
@ -614,7 +617,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
const stickerData = this.get('sticker');
if (stickerData) {
const sticker = window.Signal.Stickers.getSticker(
const sticker = Stickers.getSticker(
stickerData.packId,
stickerData.stickerId
);
@ -624,7 +627,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}
return {
text: window.i18n('message--getNotificationText--stickers'),
emoji,
emoji: dropNull(emoji),
};
}
@ -1460,11 +1463,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
senderKeyInfo.distributionId
);
contentMessage.senderKeyDistributionMessage = window.dcodeIO.ByteBuffer.wrap(
window.Signal.Crypto.typedArrayToArrayBuffer(
senderKeyDistributionMessage.serialize()
)
);
contentMessage.senderKeyDistributionMessage = senderKeyDistributionMessage.serialize();
}
}
@ -2217,18 +2216,48 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
// eslint-disable-next-line class-methods-use-this
async copyFromQuotedMessage(
message: DataMessageClass,
quote: ProcessedQuote | undefined,
conversationId: string
): Promise<DataMessageClass> {
const { quote } = message;
): Promise<QuotedMessageType | undefined> {
if (!quote) {
return message;
return undefined;
}
const { id } = quote;
strictAssert(id, 'Quote must have an id');
const result: QuotedMessageType = {
...quote,
id,
attachments: quote.attachments.slice(),
bodyRanges: quote.bodyRanges.map(({ start, length, mentionUuid }) => {
strictAssert(
start !== undefined && start !== null,
'Received quote with a bodyRange.start == null'
);
strictAssert(
length !== undefined && length !== null,
'Received quote with a bodyRange.length == null'
);
return {
start,
length,
mentionUuid: dropNull(mentionUuid),
};
}),
// Just placeholder values for the fields
referencedMessageNotFound: false,
isViewOnce: false,
messageId: '',
};
const inMemoryMessages = window.MessageController.filterBySentAt(id);
const matchingMessage = find(inMemoryMessages, item =>
isQuoteAMatch(item, conversationId, quote)
isQuoteAMatch(item, conversationId, result)
);
let queryMessage: undefined | MessageModel;
@ -2241,35 +2270,35 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
MessageCollection: window.Whisper.MessageCollection,
});
const found = collection.find(item =>
isQuoteAMatch(item, conversationId, quote)
isQuoteAMatch(item, conversationId, result)
);
if (!found) {
quote.referencedMessageNotFound = true;
return message;
result.referencedMessageNotFound = true;
return result;
}
queryMessage = window.MessageController.register(found.id, found);
}
if (queryMessage) {
await this.copyQuoteContentFromOriginal(queryMessage, quote);
await this.copyQuoteContentFromOriginal(queryMessage, result);
}
return message;
return result;
}
// eslint-disable-next-line class-methods-use-this
async copyQuoteContentFromOriginal(
originalMessage: MessageModel,
quote: QuotedMessageType | DataMessageClass.Quote
quote: QuotedMessageType
): Promise<void> {
const { attachments } = quote;
const firstAttachment = attachments ? attachments[0] : undefined;
if (isTapToView(originalMessage.attributes)) {
// eslint-disable-next-line no-param-reassign
quote.text = null;
quote.text = undefined;
// eslint-disable-next-line no-param-reassign
quote.attachments = [
{
@ -2362,7 +2391,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}
handleDataMessage(
initialMessage: DataMessageClass,
initialMessage: ProcessedDataMessage,
confirm: () => void,
options: { data?: typeof window.WhatIsThis } = {}
): WhatIsThis {
@ -2631,16 +2660,19 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
});
}
const withQuoteReference = await this.copyFromQuotedMessage(
initialMessage,
conversation.id
);
const withQuoteReference = {
...initialMessage,
quote: await this.copyFromQuotedMessage(
initialMessage.quote,
conversation.id
),
};
const dataMessage = await upgradeMessageSchema(withQuoteReference);
try {
const now = new Date().getTime();
const urls = LinkPreview.findLinks(dataMessage.body);
const urls = LinkPreview.findLinks(dataMessage.body || '');
const incomingPreview = dataMessage.preview || [];
const preview = incomingPreview.filter(
(item: typeof window.WhatIsThis) =>