clean code and add comments

pull/1229/head
Audric Ackermann 5 years ago
parent 8019bce372
commit b502fcc3f9
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1209,6 +1209,10 @@
return errors[0][0];
},
/**
* This function is called by inbox_view.js when a message was successfully sent for one device.
* So it might be called several times for the same message
*/
async handleMessageSentSuccess(sentMessage) {
let sentTo = this.get('sent_to') || [];
@ -1220,13 +1224,22 @@
sentMessage.group &&
sentMessage.group instanceof libsession.Types.OpenGroup;
// Handle the sync logic here
if (
// We trigger a sync message only when the message is not to one of our devices, AND
// the message is not for an open group (there is no sync for opengroups, each device pulls all messages), AND
// if we did not sync or trigger a sync message for this specific message already
const shouldTriggerSyncMessage =
!isOurDevice &&
!isOpenGroupMessage &&
!this.get('synced') &&
!this.get('sentSync')
) {
!this.get('sentSync');
// A message is synced if we triggered a sync message (sentSync)
// and the current message was sent to our device (so a sync message)
const shouldMarkMessageAsSynced =
isOurDevice && !isOpenGroupMessage && this.get('sentSync');
// Handle the sync logic here
if (shouldTriggerSyncMessage) {
const contentDecoded = textsecure.protobuf.Content.decode(
sentMessage.plainTextBuffer
);
@ -1234,7 +1247,7 @@
if (dataMessage) {
this.sendSyncMessage(dataMessage);
}
} else if (isOurDevice && this.get('sentSync')) {
} else if (shouldMarkMessageAsSynced) {
this.set({ synced: true });
}
if (!isOpenGroupMessage) {

@ -111,4 +111,8 @@ export class MockConversation {
return this.isPrimary ? this.id : generateFakePubKey().key;
}
public get(obj: string) {
return (this.attributes as any)[obj];
}
}

Loading…
Cancel
Save