Skip to content

Commit

Permalink
Move addCallHistory into conversation queue
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and jamiebuilds-signal committed Feb 9, 2023
1 parent 5097973 commit 495114f
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions ts/models/conversations.ts
Expand Up @@ -3223,50 +3223,57 @@ export class ConversationModel extends window.Backbone
throw missingCaseError(callHistoryDetails);
}

const message = {
conversationId: this.id,
type: 'call-history',
sent_at: timestamp,
received_at:
receivedAtCounter || window.Signal.Util.incrementMessageCounter(),
received_at_ms: timestamp,
readStatus: unread ? ReadStatus.Unread : ReadStatus.Read,
seenStatus: unread ? SeenStatus.Unseen : SeenStatus.NotApplicable,
callHistoryDetails: detailsToSave,
// TODO: DESKTOP-722
} as unknown as MessageAttributesType;
// This is sometimes called inside of another conversation queue job so if
// awaited it would block on this forever.
drop(
this.queueJob('addCallHistory', async () => {
const message = {
conversationId: this.id,
type: 'call-history',
sent_at: timestamp,
received_at:
receivedAtCounter || window.Signal.Util.incrementMessageCounter(),
received_at_ms: timestamp,
readStatus: unread ? ReadStatus.Unread : ReadStatus.Read,
seenStatus: unread ? SeenStatus.Unseen : SeenStatus.NotApplicable,
callHistoryDetails: detailsToSave,
// TODO: DESKTOP-722
} as unknown as MessageAttributesType;

if (callHistoryDetails.callMode === CallMode.Direct) {
const messageId =
await window.Signal.Data.getCallHistoryMessageByCallId(
this.id,
callHistoryDetails.callId
);
if (messageId != null) {
log.info(
`addCallHistory: Found existing call history message (Call ID ${callHistoryDetails.callId}, Message ID: ${messageId})`
);
message.id = messageId;
}
}

if (callHistoryDetails.callMode === CallMode.Direct) {
const messageId = await window.Signal.Data.getCallHistoryMessageByCallId(
this.id,
callHistoryDetails.callId
);
if (messageId != null) {
log.info(
`addCallHistory: Found existing call history message (Call ID ${callHistoryDetails.callId}, Message ID: ${messageId})`
const id = await window.Signal.Data.saveMessage(message, {
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
});

const model = window.MessageController.register(
id,
new window.Whisper.Message({
...message,
id,
})
);
message.id = messageId;
}
}

const id = await window.Signal.Data.saveMessage(message, {
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
});
this.trigger('newmessage', model);
void this.updateUnread();

const model = window.MessageController.register(
id,
new window.Whisper.Message({
...message,
id,
if (canConversationBeUnarchived(this.attributes)) {
this.setArchived(false);
}
})
);

this.trigger('newmessage', model);
void this.updateUnread();

if (canConversationBeUnarchived(this.attributes)) {
this.setArchived(false);
}
}

/**
Expand Down

0 comments on commit 495114f

Please sign in to comment.