@ -1209,15 +1209,37 @@
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 ) {
const sentTo = this . get ( 'sent_to' ) || [ ] ;
le t sentTo = this . get ( 'sent_to' ) || [ ] ;
const isOurDevice = await window . libsession . Protocols . MultiDeviceProtocol . isOurDevice (
sentMessage . device
) ;
const isOpenGroupMessage =
sentMessage . group &&
sentMessage . group instanceof libsession . Types . OpenGroup ;
// 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' ) ;
// 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 ( ! isOurDevice && ! this . get ( 'synced' ) && ! this . get ( 'sentSync' ) ) {
if ( shouldTriggerSyncMessage ) {
const contentDecoded = textsecure . protobuf . Content . decode (
sentMessage . plainTextBuffer
) ;
@ -1225,14 +1247,18 @@
if ( dataMessage ) {
this . sendSyncMessage ( dataMessage ) ;
}
} else if ( isOurDevice && this . get ( 'sentSync' ) ) {
} else if ( shouldMarkMessageAsSynced ) {
this . set ( { synced : true } ) ;
}
const primaryPubKey = await libsession . Protocols . MultiDeviceProtocol . getPrimaryDevice (
sentMessage . device
) ;
if ( ! isOpenGroupMessage ) {
const primaryPubKey = await libsession . Protocols . MultiDeviceProtocol . getPrimaryDevice (
sentMessage . device
) ;
sentTo = _ . union ( sentTo , [ primaryPubKey . key ] ) ;
}
this . set ( {
sent _to : _ . union ( sentTo , [ primaryPubKey . key ] ) ,
sent _to : sentTo,
sent : true ,
expirationStartTimestamp : Date . now ( ) ,
// unidentifiedDeliveries: result.unidentifiedDeliveries,