diff --git a/imessage/bluebubbles/api.go b/imessage/bluebubbles/api.go new file mode 100644 index 0000000..af0d82b --- /dev/null +++ b/imessage/bluebubbles/api.go @@ -0,0 +1,177 @@ +package bluebubbles + +import ( + "errors" + "os" + "time" + + "github.com/rs/zerolog" + "maunium.net/go/mautrix/id" + + "go.mau.fi/mautrix-imessage/imessage" +) + +type blueBubbles struct { + bridge imessage.Bridge + log zerolog.Logger + messageChan chan *imessage.Message + receiptChan chan *imessage.ReadReceipt + typingChan chan *imessage.TypingNotification + chatChan chan *imessage.ChatInfo + contactChan chan *imessage.Contact + messageStatusChan chan *imessage.SendMessageStatus + backfillTaskChan chan *imessage.BackfillTask +} + +func NewBlueBubblesConnector(bridge imessage.Bridge) (imessage.API, error) { + return &blueBubbles{bridge: bridge, log: bridge.GetZLog().With().Str("component", "bluebubbles").Logger()}, nil +} + +func init() { + imessage.Implementations["bluebubbles"] = NewBlueBubblesConnector +} + +func (bb *blueBubbles) Start(readyCallback func()) error { + readyCallback() + return nil +} + +func (bb *blueBubbles) Stop() {} + +var ErrNotImplemented = errors.New("not implemented") + +func (bb *blueBubbles) GetMessagesSinceDate(chatID string, minDate time.Time, backfillID string) ([]*imessage.Message, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetMessagesBetween(chatID string, minDate, maxDate time.Time) ([]*imessage.Message, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetMessagesBeforeWithLimit(chatID string, before time.Time, limit int) ([]*imessage.Message, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetMessagesWithLimit(chatID string, limit int, backfillID string) ([]*imessage.Message, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetMessage(guid string) (resp *imessage.Message, err error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetChatsWithMessagesAfter(minDate time.Time) (resp []imessage.ChatIdentifier, err error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) MessageChan() <-chan *imessage.Message { + return bb.messageChan +} + +func (bb *blueBubbles) ReadReceiptChan() <-chan *imessage.ReadReceipt { + return bb.receiptChan +} + +func (bb *blueBubbles) TypingNotificationChan() <-chan *imessage.TypingNotification { + return bb.typingChan +} + +func (bb *blueBubbles) ChatChan() <-chan *imessage.ChatInfo { + return bb.chatChan +} + +func (bb *blueBubbles) ContactChan() <-chan *imessage.Contact { + return bb.contactChan +} + +func (bb *blueBubbles) MessageStatusChan() <-chan *imessage.SendMessageStatus { + return bb.messageStatusChan +} + +func (bb *blueBubbles) BackfillTaskChan() <-chan *imessage.BackfillTask { + return bb.backfillTaskChan +} + +func (bb *blueBubbles) GetContactInfo(identifier string) (*imessage.Contact, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetContactList() ([]*imessage.Contact, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetChatInfo(chatID, threadID string) (*imessage.ChatInfo, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) GetGroupAvatar(chatID string) (*imessage.Attachment, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) SendMessage(chatID, text string, replyTo string, replyToPart int, richLink *imessage.RichLink, metadata imessage.MessageMetadata) (*imessage.SendResponse, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) SendFile(chatID, text, filename string, pathOnDisk string, replyTo string, replyToPart int, mimeType string, voiceMemo bool, metadata imessage.MessageMetadata) (*imessage.SendResponse, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) SendFileCleanup(sendFileDir string) { + _ = os.RemoveAll(sendFileDir) +} + +func (bb *blueBubbles) SendTapback(chatID, targetGUID string, targetPart int, tapback imessage.TapbackType, remove bool) (*imessage.SendResponse, error) { + return nil, ErrNotImplemented +} + +func (bb *blueBubbles) SendReadReceipt(chatID, readUpTo string) error { + return ErrNotImplemented +} + +func (bb *blueBubbles) SendTypingNotification(chatID string, typing bool) error { + return ErrNotImplemented +} + +func (bb *blueBubbles) ResolveIdentifier(identifier string) (string, error) { + return "", ErrNotImplemented +} + +func (bb *blueBubbles) PrepareDM(guid string) error { + return ErrNotImplemented +} + +func (bb *blueBubbles) CreateGroup(users []string) (*imessage.CreateGroupResponse, error) { + return nil, ErrNotImplemented +} + +// These functions are probably not necessary + +func (bb *blueBubbles) SendMessageBridgeResult(chatID, messageID string, eventID id.EventID, success bool) { +} +func (bb *blueBubbles) SendBackfillResult(chatID, backfillID string, success bool, idMap map[string][]id.EventID) { +} +func (bb *blueBubbles) SendChatBridgeResult(guid string, mxid id.RoomID) { +} +func (bb *blueBubbles) NotifyUpcomingMessage(eventID id.EventID) { +} +func (bb *blueBubbles) PreStartupSyncHook() (resp imessage.StartupSyncHookResponse, err error) { + return +} +func (bb *blueBubbles) PostStartupSyncHook() { +} + +func (bb *blueBubbles) Capabilities() imessage.ConnectorCapabilities { + return imessage.ConnectorCapabilities{ + MessageSendResponses: false, + SendTapbacks: false, + SendReadReceipts: false, + SendTypingNotifications: false, + SendCaptions: false, + BridgeState: false, + MessageStatusCheckpoints: false, + DeliveredStatus: false, + ContactChatMerging: false, + RichLinks: false, + ChatBridgeResult: false, + } +} diff --git a/imessage/interface.go b/imessage/interface.go index be28d48..5312553 100644 --- a/imessage/interface.go +++ b/imessage/interface.go @@ -23,6 +23,7 @@ import ( "path/filepath" "time" + "github.com/rs/zerolog" log "maunium.net/go/maulogger/v2" "maunium.net/go/mautrix/id" @@ -117,6 +118,7 @@ type BridgeStatus struct { type Bridge interface { GetIPC() *ipc.Processor GetLog() log.Logger + GetZLog() zerolog.Logger GetConnectorConfig() *PlatformConfig PingServer() (start, serverTs, end time.Time) SendBridgeStatus(state BridgeStatus) diff --git a/main.go b/main.go index 9c448e7..29cf908 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( "sync" "time" + "github.com/rs/zerolog" flag "maunium.net/go/mauflag" "maunium.net/go/maulogger/v2" @@ -241,6 +242,10 @@ func (br *IMBridge) GetLog() maulogger.Logger { return br.Log } +func (br *IMBridge) GetZLog() zerolog.Logger { + return br.ZLog +} + func (br *IMBridge) GetConnectorConfig() *imessage.PlatformConfig { return &br.Config.IMessage }