Skip to content

Commit

Permalink
Add stub bluebubbles connector
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 14, 2024
1 parent 1b5c459 commit c314edf
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
177 changes: 177 additions & 0 deletions imessage/bluebubbles/api.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
2 changes: 2 additions & 0 deletions imessage/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"time"

"github.com/rs/zerolog"
log "maunium.net/go/maulogger/v2"

"maunium.net/go/mautrix/id"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sync"
"time"

"github.com/rs/zerolog"
flag "maunium.net/go/mauflag"
"maunium.net/go/maulogger/v2"

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c314edf

Please sign in to comment.