#475 WA users' avatars!
This commit is contained in:
@@ -13,9 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Baozisoftware/qrcode-terminal-go"
|
"github.com/Baozisoftware/qrcode-terminal-go"
|
||||||
"github.com/Rhymen/go-whatsapp"
|
"github.com/Rhymen/go-whatsapp"
|
||||||
// "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||||
// "@c.us" -> "@s.whatsapp.net"
|
|
||||||
// "github.com/tulir/mautrix-whatsapp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -29,11 +27,13 @@ type Bwhatsapp struct {
|
|||||||
|
|
||||||
// https://github.com/Rhymen/go-whatsapp/blob/c31092027237441cffba1b9cb148eadf7c83c3d2/session.go#L18-L21
|
// https://github.com/Rhymen/go-whatsapp/blob/c31092027237441cffba1b9cb148eadf7c83c3d2/session.go#L18-L21
|
||||||
session *whatsapp.Session
|
session *whatsapp.Session
|
||||||
// connExt *whatsappExt.ExtendedConn // https://github.com/tulir/mautrix-whatsapp/blob/master/whatsapp-ext/whatsapp.go
|
conn *whatsapp.Conn
|
||||||
conn *whatsapp.Conn
|
// https://github.com/tulir/mautrix-whatsapp/blob/master/whatsapp-ext/whatsapp.go
|
||||||
|
connExt *whatsappExt.ExtendedConn
|
||||||
startedAt uint64
|
startedAt uint64
|
||||||
|
|
||||||
users map[string]whatsapp.Contact
|
users map[string]whatsapp.Contact
|
||||||
|
userAvatars map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
@@ -50,7 +50,8 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
b := &Bwhatsapp{
|
b := &Bwhatsapp{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
|
|
||||||
users: make(map[string]whatsapp.Contact),
|
users: make(map[string]whatsapp.Contact),
|
||||||
|
userAvatars: make(map[string]string),
|
||||||
|
|
||||||
//uuid: xid.New().String(),
|
//uuid: xid.New().String(),
|
||||||
//users: map[string]*slack.User{},
|
//users: map[string]*slack.User{},
|
||||||
@@ -85,8 +86,9 @@ func (b *Bwhatsapp) Connect() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.conn = conn
|
b.conn = conn
|
||||||
//b.connExt = whatsappExt.ExtendConn(b.conn)
|
b.connExt = whatsappExt.ExtendConn(b.conn)
|
||||||
//b.connExt.SetClientName("Matterbridge WhatsApp bridge", "mb-wa")
|
// TODO do we want to use it? b.connExt.SetClientName("Matterbridge WhatsApp bridge", "mb-wa")
|
||||||
|
|
||||||
b.conn.AddHandler(b)
|
b.conn.AddHandler(b)
|
||||||
b.Log.Debugln("WhatsApp connection successful")
|
b.Log.Debugln("WhatsApp connection successful")
|
||||||
|
|
||||||
@@ -133,18 +135,21 @@ func (b *Bwhatsapp) Connect() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get avatar URLs
|
// get user avatar asynchronously
|
||||||
// https://web.whatsapp.com/pp
|
go func() {
|
||||||
// ?e=https%3A%2F%2Fpps.whatsapp.net%2Fv%2Ft61.11540-24%2F16489067_255781518198245_6804985813445640192_n.jpg%3Foe%3D5C66A1FA%26oh%3D20cd213793de891d1e256b27a1cf1075
|
b.Log.Debug("Getting user avatars..")
|
||||||
// &t=s
|
|
||||||
// &u=remotenumber%40c.us
|
for jid := range b.users {
|
||||||
// &i=1485652465
|
info, err := b.connExt.GetProfilePicThumb(jid)
|
||||||
// https://web.whatsapp.com/pp
|
if err != nil {
|
||||||
// ?e=https://pps.whatsapp.net/v/t61.11540-24/16489067_255781518198245_6804985813445640192_n.jpg?oe=5C66A1FA&oh=20cd213793de891d1e256b27a1cf1075 (the actual photo)
|
b.Log.Warnf("Could not get profile photo of %s: %v", jid, err)
|
||||||
// &t=s
|
|
||||||
// &u=remotenumber@c.us
|
} else {
|
||||||
// &i=1485652465
|
b.userAvatars[jid] = info.URL
|
||||||
GetProfilePicThumb
|
}
|
||||||
|
}
|
||||||
|
b.Log.Debug("Finished getting avatars..")
|
||||||
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -412,12 +417,15 @@ func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) {
|
|||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
Protocol: b.Protocol,
|
Protocol: b.Protocol,
|
||||||
Extra: make(map[string][]interface{}),
|
Extra: make(map[string][]interface{}),
|
||||||
// Avatar: b.getAvatar(ev.Message.From.Username), // TODO get avatar
|
|
||||||
// ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string
|
// ParentID: TODO, // TODO handle thread replies // map from Info.QuotedMessageID string
|
||||||
// Event string `json:"event"`
|
// Event string `json:"event"`
|
||||||
// Gateway string // will be added during message processing
|
// Gateway string // will be added during message processing
|
||||||
ID: message.Info.Id}
|
ID: message.Info.Id}
|
||||||
|
|
||||||
|
if avatarUrl, exists := b.userAvatars[senderJid]; exists {
|
||||||
|
rmsg.Avatar = avatarUrl
|
||||||
|
}
|
||||||
|
|
||||||
b.Log.Debugf("<= Message is %#v", rmsg)
|
b.Log.Debugf("<= Message is %#v", rmsg)
|
||||||
b.Remote <- rmsg
|
b.Remote <- rmsg
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user