improve sent message handling by setting the correct convoId at start

pull/1495/head
Audric Ackermann 4 years ago
parent 66a6190f2b
commit 8716fbf495

@ -41,6 +41,13 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
}) })
); );
if (!this.attributes.id) {
throw new Error('A message always needs to have an id.');
}
if (!this.attributes.conversationId) {
throw new Error('A message always needs to have an conversationId.');
}
// this.on('expired', this.onExpired); // this.on('expired', this.onExpired);
void this.setToExpire(); void this.setToExpire();
autoBind(this); autoBind(this);
@ -239,7 +246,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public getPropsForTimerNotification() { public getPropsForTimerNotification() {
const timerUpdate = this.get('expirationTimerUpdate'); const timerUpdate = this.get('expirationTimerUpdate');
if (!timerUpdate) { if (!timerUpdate || !timerUpdate.source) {
return null; return null;
} }

@ -37,7 +37,7 @@ export interface MessageAttributes {
groupInvitation?: any; groupInvitation?: any;
attachments?: any; attachments?: any;
contact?: any; contact?: any;
conversationId: any; conversationId: string;
errors?: any; errors?: any;
flags?: number; flags?: number;
hasAttachments: boolean; hasAttachments: boolean;
@ -90,7 +90,7 @@ export interface MessageAttributesOptionals {
groupInvitation?: any; groupInvitation?: any;
attachments?: any; attachments?: any;
contact?: any; contact?: any;
conversationId: any; conversationId: string;
errors?: any; errors?: any;
flags?: number; flags?: number;
hasAttachments?: boolean; hasAttachments?: boolean;

@ -222,9 +222,7 @@ async function processGroupAvatar(message: MessageModel): Promise<boolean> {
export async function queueAttachmentDownloads( export async function queueAttachmentDownloads(
message: MessageModel message: MessageModel
): Promise<boolean> { ): Promise<void> {
const { Whisper } = window;
let count = 0; let count = 0;
count += await processNormalAttachments(message, message.get('attachments')); count += await processNormalAttachments(message, message.get('attachments'));
@ -241,9 +239,5 @@ export async function queueAttachmentDownloads(
if (count > 0) { if (count > 0) {
await saveMessage(message.attributes); await saveMessage(message.attributes);
return true;
} }
return false;
} }

@ -491,32 +491,28 @@ function createSentMessage(data: MessageCreationData): MessageModel {
isPublic, isPublic,
receivedAt, receivedAt,
sourceDevice, sourceDevice,
unidentifiedStatus,
expirationStartTimestamp, expirationStartTimestamp,
destination, destination,
message,
} = data; } = data;
let unidentifiedDeliveries;
if (unidentifiedStatus && unidentifiedStatus.length) {
sentTo = unidentifiedStatus.map((item: any) => item.destination);
const unidentified = _.filter(unidentifiedStatus, (item: any) =>
Boolean(item.unidentified)
);
// eslint-disable-next-line no-param-reassign
unidentifiedDeliveries = unidentified.map((item: any) => item.destination);
}
const sentSpecificFields = { const sentSpecificFields = {
sent_to: sentTo, sent_to: [],
sent: true, sent: true,
unidentifiedDeliveries: unidentifiedDeliveries || [],
expirationStartTimestamp: Math.min( expirationStartTimestamp: Math.min(
expirationStartTimestamp || data.timestamp || now, expirationStartTimestamp || data.timestamp || now,
now now
), ),
}; };
const messageGroupId = message?.group?.id;
let groupId =
messageGroupId && messageGroupId.length > 0 ? messageGroupId : null;
if (groupId) {
groupId = PubKey.removeTextSecurePrefixIfNeeded(groupId);
}
const messageData = { const messageData = {
source: UserUtils.getOurPubKeyStrFromCache(), source: UserUtils.getOurPubKeyStrFromCache(),
sourceDevice, sourceDevice,
@ -525,7 +521,7 @@ function createSentMessage(data: MessageCreationData): MessageModel {
sent_at: timestamp, sent_at: timestamp,
received_at: isPublic ? receivedAt : now, received_at: isPublic ? receivedAt : now,
isPublic, isPublic,
conversationId: destination, // conversation ID will might change later (if it is a group) conversationId: groupId ?? destination,
type: 'outgoing' as MessageModelType, type: 'outgoing' as MessageModelType,
...sentSpecificFields, ...sentSpecificFields,
}; };

@ -194,14 +194,15 @@ export async function queueAllCached() {
export async function queueAllCachedFromSource(source: string) { export async function queueAllCachedFromSource(source: string) {
const items = await getAllFromCacheForSource(source); const items = await getAllFromCacheForSource(source);
items.forEach(async item => {
// queue all cached for this source, but keep the order
await items.reduce(async (promise, item) => {
await promise;
await queueCached(item); await queueCached(item);
}); }, Promise.resolve());
} }
async function queueCached(item: any) { async function queueCached(item: any) {
const { textsecure } = window;
try { try {
const envelopePlaintext = StringUtils.encode(item.envelope, 'base64'); const envelopePlaintext = StringUtils.encode(item.envelope, 'base64');
const envelopeArray = new Uint8Array(envelopePlaintext); const envelopeArray = new Uint8Array(envelopePlaintext);

@ -116,10 +116,14 @@ export class MessageSentHandler {
// Handle the sync logic here // Handle the sync logic here
if (shouldTriggerSyncMessage) { if (shouldTriggerSyncMessage) {
if (dataMessage) { if (dataMessage) {
await fetchedMessage.sendSyncMessage( try {
dataMessage as SignalService.DataMessage, await fetchedMessage.sendSyncMessage(
sentMessage.timestamp dataMessage as SignalService.DataMessage,
); sentMessage.timestamp
);
} catch (e) {
window.log.warn('Got an error while trying to sendSyncMessage():', e);
}
} }
} else if (shouldMarkMessageAsSynced) { } else if (shouldMarkMessageAsSynced) {
fetchedMessage.set({ synced: true }); fetchedMessage.set({ synced: true });

Loading…
Cancel
Save