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);
void this.setToExpire();
autoBind(this);
@ -239,7 +246,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
public getPropsForTimerNotification() {
const timerUpdate = this.get('expirationTimerUpdate');
if (!timerUpdate) {
if (!timerUpdate || !timerUpdate.source) {
return null;
}

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

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

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

@ -194,14 +194,15 @@ export async function queueAllCached() {
export async function queueAllCachedFromSource(source: string) {
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);
});
}, Promise.resolve());
}
async function queueCached(item: any) {
const { textsecure } = window;
try {
const envelopePlaintext = StringUtils.encode(item.envelope, 'base64');
const envelopeArray = new Uint8Array(envelopePlaintext);

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

Loading…
Cancel
Save