Skip to content

Commit

Permalink
better handling of delivery and read receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
trek-boldly-go committed Mar 25, 2024
1 parent 26a3dec commit 5a967bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
69 changes: 53 additions & 16 deletions imessage/bluebubbles/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,34 @@ func (bb *blueBubbles) handleNewMessage(rawMessage json.RawMessage) (err error)
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
if !message.ReadAt.IsZero() && data.DateRetracted == 0 && data.DateEdited == 0 {
senderGUID := data.Chats[0].GUID
var receipt = imessage.ReadReceipt{
SenderGUID: senderGUID,
IsFromMe: false,
ChatGUID: message.ChatGUID,
ReadUpTo: message.GUID,
ReadAt: message.ReadAt,
JSONUnixReadAt: message.JSONUnixReadAt,

if message.IsEdited || message.IsRetracted {
return nil // the regular message channel should handle edits and unsends updates
} else if message.IsRead {
select {
case bb.receiptChan <- &imessage.ReadReceipt{
SenderGUID: message.ChatGUID,
IsFromMe: !message.IsFromMe,
ChatGUID: message.ChatGUID,
ReadUpTo: message.GUID,
ReadAt: message.ReadAt,
}:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
} else if message.IsDelivered {
select {
case bb.receiptChan <- &receipt:
case bb.messageStatusChan <- &imessage.SendMessageStatus{
GUID: message.GUID,
ChatGUID: message.ChatGUID,
Status: "delivered",
Service: imessage.ParseIdentifier(message.ChatGUID).Service,
}:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
}

return nil
}

Expand All @@ -336,10 +348,35 @@ func (bb *blueBubbles) handleMessageUpdated(rawMessage json.RawMessage) (err err
return err
}

select {
case bb.messageChan <- message:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
if message.IsEdited || message.IsRetracted {
select {
case bb.messageChan <- message:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
} else if message.IsRead {
select {
case bb.receiptChan <- &imessage.ReadReceipt{
SenderGUID: message.ChatGUID,
IsFromMe: !message.IsFromMe,
ChatGUID: message.ChatGUID,
ReadUpTo: message.GUID,
ReadAt: message.ReadAt,
}:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
} else if message.IsDelivered {
select {
case bb.messageStatusChan <- &imessage.SendMessageStatus{
GUID: message.GUID,
ChatGUID: message.ChatGUID,
Status: "delivered",
Service: imessage.ParseIdentifier(message.ChatGUID).Service,
}:
default:
bb.log.Warn().Msg("Incoming message buffer is full")
}
}

return nil
Expand Down Expand Up @@ -1551,8 +1588,8 @@ func (bb *blueBubbles) convertBBMessageToiMessage(bbMessage Message) (*imessage.
message.ReadAt = time.UnixMilli(bbMessage.DateRead)
}
message.IsDelivered = bbMessage.DateDelivered != 0
message.IsSent = true // assume yes because we made it to this part of the code
message.IsEmote = false // emojis seem to send either way, and BB doesn't say whether there is one or not
message.IsSent = bbMessage.DateCreated != 0 // assume yes because we made it to this part of the code
message.IsEmote = false // emojis seem to send either way, and BB doesn't say whether there is one or not
message.IsAudioMessage = bbMessage.IsAudioMessage
message.IsEdited = bbMessage.DateEdited != 0
message.IsRetracted = bbMessage.DateRetracted != 0
Expand Down
4 changes: 3 additions & 1 deletion portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,9 @@ func (portal *Portal) handleNormaliMessage(msg *imessage.Message, dbMessage *dat
}
for index, converted := range parts {
if mxID != nil {
converted.Content.SetEdit(*mxID)
if len(parts) == 1 {
converted.Content.SetEdit(*mxID)
}
}
portal.log.Debugfln("Sending iMessage attachment %s.%d", msg.GUID, index)
resp, err := portal.sendMessage(intent, converted.Type, converted.Content, converted.Extra, dbMessage.Timestamp)
Expand Down

0 comments on commit 5a967bd

Please sign in to comment.