From 8e2f00f03dd8d44d9e67c09c03238f172c9ba69f Mon Sep 17 00:00:00 2001 From: Christian Nuss Date: Mon, 15 Jan 2024 10:27:30 -0500 Subject: [PATCH] apply fixes from PR comments --- imessage/bluebubbles/api.go | 14 +++++++------- imessage/bluebubbles/interface.go | 23 ++++++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/imessage/bluebubbles/api.go b/imessage/bluebubbles/api.go index b485cdf..2682535 100644 --- a/imessage/bluebubbles/api.go +++ b/imessage/bluebubbles/api.go @@ -316,11 +316,11 @@ func (bb *blueBubbles) GetChatsWithMessagesAfter(minDate time.Time) (resp []imes request := ChatQueryRequest{ Limit: limit, Offset: offset, - With: []string{ - "lastMessage", - "sms", + With: []ChatQueryWith{ + ChatQueryWithLastMessage, + ChatQueryWithSMS, }, - Sort: "lastmessage", + Sort: QuerySortLastMessage, } var response ChatQueryResponse @@ -329,10 +329,10 @@ func (bb *blueBubbles) GetChatsWithMessagesAfter(minDate time.Time) (resp []imes return nil, err } - for _, chat := range *response.Data { + for _, chat := range response.Data { resp = append(resp, imessage.ChatIdentifier{ - ChatGUID: fmt.Sprintf("%v", chat.GUID), - ThreadID: fmt.Sprintf("%v", chat.ChatIdentifier), // TODO Is this the right one to use? + ChatGUID: chat.GUID, + ThreadID: chat.GroupId, }) } diff --git a/imessage/bluebubbles/interface.go b/imessage/bluebubbles/interface.go index 6d4edc4..9698cde 100644 --- a/imessage/bluebubbles/interface.go +++ b/imessage/bluebubbles/interface.go @@ -7,18 +7,31 @@ type PageMetadata struct { Limit int64 `json:"limit"` } +type QuerySort string + +const ( + QuerySortLastMessage QuerySort = "lastmessage" +) + type ChatQueryRequest struct { // TODO Other Fields - Limit int64 `json:"limit"` - Offset int64 `json:"offset"` - With []string `json:"with"` - Sort string `json:"sort"` + Limit int64 `json:"limit"` + Offset int64 `json:"offset"` + With []ChatQueryWith `json:"with"` + Sort QuerySort `json:"sort"` } +type ChatQueryWith string + +const ( + ChatQueryWithSMS ChatQueryWith = "sms" + ChatQueryWithLastMessage ChatQueryWith = "lastMessage" +) + type ChatQueryResponse struct { Status int64 `json:"status"` Message string `json:"message"` - Data *[]Chat `json:"data"` + Data []Chat `json:"data"` Metadata PageMetadata `json:"metadata"` }