Skip to content

Commit

Permalink
Fix send sync message bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Jul 28, 2021
1 parent a2e4577 commit 3cc799c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3221,7 +3221,7 @@ export async function startApp(): Promise<void> {
return {
...result,
[conversationId]: {
status: SendStatus.Pending,
status: SendStatus.Sent,
updatedAt: timestamp,
},
};
Expand Down
85 changes: 40 additions & 45 deletions ts/messageModifiers/MessageReceipts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { isOutgoing } from '../state/selectors/message';
import { isDirectConversation } from '../util/whatTypeOfConversation';
import { getOwn } from '../util/getOwn';
import { missingCaseError } from '../util/missingCaseError';
import { SendActionType, sendStateReducer } from '../messages/MessageSendState';
import {
SendActionType,
SendStatus,
sendStateReducer,
} from '../messages/MessageSendState';
import dataInterface from '../sql/Client';

const { deleteSentProtoRecipient } = dataInterface;
Expand Down Expand Up @@ -106,7 +110,7 @@ export class MessageReceipts extends Collection<MessageReceiptModel> {
ids.includes(receipt.get('sourceConversationId'))
);
if (receipts.length) {
window.log.info('Found early read receipts for message');
window.log.info('Found early receipts for message');
this.remove(receipts);
}
return receipts;
Expand Down Expand Up @@ -141,54 +145,45 @@ export class MessageReceipts extends Collection<MessageReceiptModel> {
const oldSendState = getOwn(
oldSendStateByConversationId,
sourceConversationId
);
if (oldSendState) {
let sendActionType: SendActionType;
switch (type) {
case MessageReceiptType.Delivery:
sendActionType = SendActionType.GotDeliveryReceipt;
break;
case MessageReceiptType.Read:
sendActionType = SendActionType.GotReadReceipt;
break;
default:
throw missingCaseError(type);
}
) ?? { status: SendStatus.Sent, updatedAt: undefined };

let sendActionType: SendActionType;
switch (type) {
case MessageReceiptType.Delivery:
sendActionType = SendActionType.GotDeliveryReceipt;
break;
case MessageReceiptType.Read:
sendActionType = SendActionType.GotReadReceipt;
break;
default:
throw missingCaseError(type);
}

const newSendState = sendStateReducer(oldSendState, {
type: sendActionType,
updatedAt: messageSentAt,
const newSendState = sendStateReducer(oldSendState, {
type: sendActionType,
updatedAt: messageSentAt,
});

// The send state may not change. For example, this can happen if we get a read
// receipt before a delivery receipt.
if (!isEqual(oldSendState, newSendState)) {
message.set('sendStateByConversationId', {
...oldSendStateByConversationId,
[sourceConversationId]: newSendState,
});

// The send state may not change. For example, this can happen if we get a read
// receipt before a delivery receipt.
if (!isEqual(oldSendState, newSendState)) {
message.set('sendStateByConversationId', {
...oldSendStateByConversationId,
[sourceConversationId]: newSendState,
});

window.Signal.Util.queueUpdateMessage(message.attributes);
window.Signal.Util.queueUpdateMessage(message.attributes);

// notify frontend listeners
const conversation = window.ConversationController.get(
message.get('conversationId')
);
const updateLeftPane = conversation
? conversation.debouncedUpdateLastMessage
: undefined;
if (updateLeftPane) {
updateLeftPane();
}
}
} else {
window.log.warn(
`Got a receipt from someone (${sourceConversationId}), but the message (sent at ${message.get(
'sent_at'
)}) wasn't sent to them. It was sent to ${
Object.keys(oldSendStateByConversationId).length
} recipients`
// notify frontend listeners
const conversation = window.ConversationController.get(
message.get('conversationId')
);
const updateLeftPane = conversation
? conversation.debouncedUpdateLastMessage
: undefined;
if (updateLeftPane) {
updateLeftPane();
}
}

if (
Expand Down
25 changes: 15 additions & 10 deletions ts/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2579,20 +2579,25 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
return;
}

const updatedAt: number = isNormalNumber(data.timestamp)
? data.timestamp
: Date.now();

const previousSendState = getOwn(
sendStateByConversationId,
destinationConversationId
);
if (previousSendState) {
sendStateByConversationId[
destinationConversationId
] = sendStateReducer(previousSendState, {
type: SendActionType.Sent,
updatedAt: isNormalNumber(data.timestamp)
? data.timestamp
: Date.now(),
});
}
sendStateByConversationId[
destinationConversationId
] = previousSendState
? sendStateReducer(previousSendState, {
type: SendActionType.Sent,
updatedAt,
})
: {
status: SendStatus.Sent,
updatedAt,
};

if (unidentified) {
unidentifiedDeliveriesSet.add(identifier);
Expand Down

0 comments on commit 3cc799c

Please sign in to comment.