Skip to content

Commit

Permalink
Merge pull request #170 from mautrix/166-bluebubbles-implement-handle…
Browse files Browse the repository at this point in the history
…chatreadstatuschanged

166 bluebubbles implement handlechatreadstatuschanged
  • Loading branch information
trek-boldly-go authored Jan 18, 2024
2 parents fab28d3 + ca0d7bb commit 7925b1c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 51 deletions.
62 changes: 44 additions & 18 deletions imessage/bluebubbles/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
// Ref: https://github.com/BlueBubblesApp/bluebubbles-server/blob/master/packages/server/src/server/events.ts
NewMessage string = "new-message"
MessageSendError string = "message-send-error"
MessageUpdated string = "message-updated"
MessageUpdated string = "updated-message"
ParticipantRemoved string = "participant-removed"
ParticipantAdded string = "participant-added"
ParticipantLeft string = "participant-left"
Expand Down Expand Up @@ -225,8 +225,30 @@ func (bb *blueBubbles) handleMessageSendError(data json.RawMessage) (err error)
return ErrNotImplemented
}

func (bb *blueBubbles) handleMessageUpdated(data json.RawMessage) (err error) {
bb.log.Trace().RawJSON("data", data).Msg("handleMessageUpdated")
func (bb *blueBubbles) handleMessageUpdated(rawMessage json.RawMessage) (err error) {
bb.log.Trace().RawJSON("rawMessage", rawMessage).Msg("handleMessageUpdated")

//TODO: This code words just fine, unless you send a caption with a picture. then it duplicates your message in the matrix client (not visible to the other imessage user though)
// Let's get the multipart message working before we worry about this function
// var data Message
// err = json.Unmarshal(rawMessage, &data)
// if err != nil {
// return err
// }

// message, err := bb.convertBBMessageToiMessage(data)

// if err != nil {
// return err
// }

// select {
// case bb.messageChan <- message:
// default:
// bb.log.Warn().Msg("Incoming message buffer is full")
// }

// return nil
return ErrNotImplemented
}

Expand Down Expand Up @@ -286,7 +308,7 @@ func (bb *blueBubbles) handleChatReadStatusChanged(data json.RawMessage) (err er

var receipt = imessage.ReadReceipt{
SenderGUID: lastMessage.Handle.Address, // TODO: Make sure this is the right field?
IsFromMe: true,
IsFromMe: false, // changing this to false as I believe read reciepts will always be from others
ChatGUID: rec.ChatGUID,
ReadUpTo: chatInfo.Data.LastMessage.GUID,
ReadAt: now,
Expand Down Expand Up @@ -918,20 +940,24 @@ func (bb *blueBubbles) convertBBMessageToiMessage(bbMessage Message) (*imessage.
message.Text = bbMessage.Text
message.ChatGUID = bbMessage.Chats[0].GUID

// TODO: there doesn't seem to be a "from" in the bluebubbles data
// message.JSONSenderGUID = bbMessage.Handle.Address
// message.Sender = imessage.Identifier{
// LocalID: bbMessage.Handle.Address,
// Service: bbMessage.Handle.Service,
// IsGroup: false,
// }

message.JSONTargetGUID = bbMessage.Handle.Address
message.Target = imessage.Identifier{
LocalID: bbMessage.Handle.Address,
Service: bbMessage.Handle.Service,
IsGroup: false,
// bbMessage.Handle seems to always be the other person,
// so the sender/target depends on whether the message is from you
if bbMessage.IsFromMe {
message.JSONTargetGUID = bbMessage.Handle.Address
message.Target = imessage.Identifier{
LocalID: bbMessage.Handle.Address,
Service: bbMessage.Handle.Service,
IsGroup: false,
}
} else {
message.JSONSenderGUID = bbMessage.Handle.Address
message.Sender = imessage.Identifier{
LocalID: bbMessage.Handle.Address,
Service: bbMessage.Handle.Service,
IsGroup: false,
}
}

message.Service = bbMessage.Handle.Service
message.IsFromMe = bbMessage.IsFromMe
message.IsRead = false
Expand All @@ -954,7 +980,7 @@ func (bb *blueBubbles) convertBBMessageToiMessage(bbMessage Message) (*imessage.
// message.ReplyToPart = num
// }

// Tapbacks work E2E now!
// Tapbacks
if bbMessage.AssociatedMessageGuid != "" &&
bbMessage.AssociatedMessageType != "" {
message.Tapback = &imessage.Tapback{
Expand Down
79 changes: 46 additions & 33 deletions imessage/bluebubbles/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,52 @@ type TypingNotification struct {
}

type Message struct {
AssociatedMessageGuid string `json:"associatedMessageGuid,omitempty"`
AssociatedMessageType string `json:"associatedMessageType,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
AttributedBody []interface{} `json:"attributedBody,omitempty"`
BalloonBundleId interface{} `json:"balloonBundleId,omitempty"`
Chats []Chat `json:"chats,omitempty"`
DateCreated int64 `json:"dateCreated,omitempty"`
DateDelivered int64 `json:"dateDelivered,omitempty"`
DateEdited int64 `json:"dateEdited,omitempty"`
DateRead int64 `json:"dateRead,omitempty"`
DateRetracted int64 `json:"dateRetracted,omitempty"`
Error int `json:"error,omitempty"`
ExpressiveSendStyleId interface{} `json:"expressiveSendStyleId,omitempty"`
GroupActionType int `json:"groupActionType,omitempty"`
GroupTitle string `json:"groupTitle,omitempty"`
GUID string `json:"guid,omitempty"`
Handle Handle `json:"handle,omitempty"`
HandleId int `json:"handleId,omitempty"`
HasDdResults bool `json:"hasDdResults,omitempty"`
HasPayloadData bool `json:"hasPayloadData,omitempty"`
IsAudioMessage bool `json:"isAudioMessage,omitempty"`
IsArchived bool `json:"isArchived,omitempty"`
IsFromMe bool `json:"isFromMe,omitempty"`
ItemType int `json:"itemType,omitempty"`
MessageSummaryInfo interface{} `json:"messageSummaryInfo,omitempty"`
OriginalROWID int `json:"originalROWID,omitempty"`
OtherHandle int `json:"otherHandle,omitempty"`
PartCount int `json:"partCount,omitempty"`
PayloadData interface{} `json:"payloadData,omitempty"`
Subject string `json:"subject,omitempty"`
Text string `json:"text,omitempty"`
ThreadOriginatorGuid string `json:"threadOriginatorGuid,omitempty"`
ThreadOriginatorPart string `json:"threadOriginatorPart,omitempty"`
AssociatedMessageGuid string `json:"associatedMessageGuid,omitempty"`
AssociatedMessageType string `json:"associatedMessageType,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
AttributedBody []interface{} `json:"attributedBody,omitempty"`
BalloonBundleId interface{} `json:"balloonBundleId,omitempty"`
Chats []Chat `json:"chats,omitempty"`
DateCreated int64 `json:"dateCreated,omitempty"`
DateDelivered int64 `json:"dateDelivered,omitempty"`
DateEdited int64 `json:"dateEdited,omitempty"`
DateRead int64 `json:"dateRead,omitempty"`
DateRetracted int64 `json:"dateRetracted,omitempty"`
Error int `json:"error,omitempty"`
ExpressiveSendStyleId interface{} `json:"expressiveSendStyleId,omitempty"`
GroupActionType int `json:"groupActionType,omitempty"`
GroupTitle string `json:"groupTitle,omitempty"`
GUID string `json:"guid,omitempty"`
Handle Handle `json:"handle,omitempty"`
HandleId int `json:"handleId,omitempty"`
HasDdResults bool `json:"hasDdResults,omitempty"`
HasPayloadData bool `json:"hasPayloadData,omitempty"`
IsArchived bool `json:"isArchived,omitempty"`
IsAudioMessage bool `json:"isAudioMessage,omitempty"`
IsAutoReply bool `json:"isAutoReply,omitempty"`
IsCorrupt bool `json:"isCorrupt,omitempty"`
IsDelayed bool `json:"isDelayed,omitempty"`
IsExpired bool `json:"isExpired,omitempty"`
IsForward bool `json:"isForward,omitempty"`
IsFromMe bool `json:"isFromMe,omitempty"`
IsServiceMessage bool `json:"isServiceMessage,omitempty"`
IsSpam bool `json:"isSpam,omitempty"`
IsSystemMessage bool `json:"isSystemMessage,omitempty"`
ItemType int `json:"itemType,omitempty"`
MessageSummaryInfo interface{} `json:"messageSummaryInfo,omitempty"`
OriginalROWID int `json:"originalROWID,omitempty"`
OtherHandle int `json:"otherHandle,omitempty"`
PartCount int `json:"partCount,omitempty"`
PayloadData interface{} `json:"payloadData,omitempty"`
ReplyToGuid string `json:"replyToGuid,omitempty"`
ShareDirection int `json:"shareDirection,omitempty"`
ShareStatus int `json:"shareStatus,omitempty"`
Subject string `json:"subject,omitempty"`
Text string `json:"text,omitempty"`
ThreadOriginatorGuid string `json:"threadOriginatorGuid,omitempty"`
ThreadOriginatorPart interface{} `json:"threadOriginatorPart,omitempty"`
TimeExpressiveSendStyleId interface{} `json:"timeExpressiveSendStyleId,omitempty"`
WasDeliveredQuietly bool `json:"wasDeliveredQuietly,omitempty"`
}

type Attachment struct {
Expand Down

0 comments on commit 7925b1c

Please sign in to comment.