From 40f1d35415f5e3638a1972b4aa56365070d5ccb3 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 1 Jun 2019 00:53:49 +0200 Subject: Fix go mod issue by removing whatsapp-ext --- bridge/whatsapp/handlers.go | 5 +---- bridge/whatsapp/helpers.go | 23 +++++++++++++++++++++++ bridge/whatsapp/whatsapp.go | 12 +++--------- 3 files changed, 27 insertions(+), 13 deletions(-) (limited to 'bridge/whatsapp') diff --git a/bridge/whatsapp/handlers.go b/bridge/whatsapp/handlers.go index 456f2009..d61f6b24 100644 --- a/bridge/whatsapp/handlers.go +++ b/bridge/whatsapp/handlers.go @@ -5,10 +5,7 @@ import ( "time" "github.com/42wim/matterbridge/bridge/config" - "github.com/Rhymen/go-whatsapp" - - whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext" ) /* @@ -57,7 +54,7 @@ func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) { // mentions comes as telephone numbers and we don't want to expose it to other bridges // replace it with something more meaninful to others - mention := b.getSenderNotify(numberAndSuffix[0] + whatsappExt.NewUserSuffix) + mention := b.getSenderNotify(numberAndSuffix[0] + "@s.whatsapp.net") if mention == "" { mention = "someone" } diff --git a/bridge/whatsapp/helpers.go b/bridge/whatsapp/helpers.go index 5268ba3e..f45d6246 100644 --- a/bridge/whatsapp/helpers.go +++ b/bridge/whatsapp/helpers.go @@ -2,13 +2,22 @@ package bwhatsapp import ( "encoding/gob" + "encoding/json" "errors" + "fmt" "os" qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go" "github.com/Rhymen/go-whatsapp" ) +type ProfilePicInfo struct { + URL string `json:"eurl"` + Tag string `json:"tag"` + + Status int16 `json:"status"` +} + func qrFromTerminal(invert bool) chan string { qr := make(chan string) go func() { @@ -82,3 +91,17 @@ func (b *Bwhatsapp) getSenderNotify(senderJid string) string { } return "" } + +func (b *Bwhatsapp) GetProfilePicThumb(jid string) (*ProfilePicInfo, error) { + data, err := b.conn.GetProfilePicThumb(jid) + if err != nil { + return nil, fmt.Errorf("failed to get avatar: %v", err) + } + content := <-data + info := &ProfilePicInfo{} + err = json.Unmarshal([]byte(content), info) + if err != nil { + return info, fmt.Errorf("failed to unmarshal avatar info: %v", err) + } + return info, nil +} diff --git a/bridge/whatsapp/whatsapp.go b/bridge/whatsapp/whatsapp.go index c66e13ac..eb3f0d1c 100644 --- a/bridge/whatsapp/whatsapp.go +++ b/bridge/whatsapp/whatsapp.go @@ -12,8 +12,6 @@ import ( "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" "github.com/Rhymen/go-whatsapp" - - whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext" ) const ( @@ -28,10 +26,8 @@ type Bwhatsapp struct { *bridge.Config // https://github.com/Rhymen/go-whatsapp/blob/c31092027237441cffba1b9cb148eadf7c83c3d2/session.go#L18-L21 - session *whatsapp.Session - conn *whatsapp.Conn - // https://github.com/tulir/mautrix-whatsapp/blob/master/whatsapp-ext/whatsapp.go - connExt *whatsappExt.ExtendedConn + session *whatsapp.Session + conn *whatsapp.Conn startedAt uint64 users map[string]whatsapp.Contact @@ -73,8 +69,6 @@ func (b *Bwhatsapp) Connect() error { } b.conn = conn - b.connExt = whatsappExt.ExtendConn(b.conn) - // TODO do we want to use it? b.connExt.SetClientName("Matterbridge WhatsApp bridge", "mb-wa") b.conn.AddHandler(b) b.Log.Debugln("WhatsApp connection successful") @@ -129,7 +123,7 @@ func (b *Bwhatsapp) Connect() error { b.Log.Debug("Getting user avatars..") for jid := range b.users { - info, err := b.connExt.GetProfilePicThumb(jid) + info, err := b.GetProfilePicThumb(jid) if err != nil { b.Log.Warnf("Could not get profile photo of %s: %v", jid, err) -- cgit v1.2.3