#475 usernames from WhatsApp
This commit is contained in:
@@ -32,6 +32,8 @@ type Bwhatsapp struct {
|
|||||||
// connExt *whatsappExt.ExtendedConn // https://github.com/tulir/mautrix-whatsapp/blob/master/whatsapp-ext/whatsapp.go
|
// connExt *whatsappExt.ExtendedConn // https://github.com/tulir/mautrix-whatsapp/blob/master/whatsapp-ext/whatsapp.go
|
||||||
conn *whatsapp.Conn
|
conn *whatsapp.Conn
|
||||||
startedAt uint64
|
startedAt uint64
|
||||||
|
|
||||||
|
users map[string]whatsapp.Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
@@ -48,6 +50,8 @@ func New(cfg *bridge.Config) bridge.Bridger {
|
|||||||
b := &Bwhatsapp{
|
b := &Bwhatsapp{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
|
|
||||||
|
users: make(map[string]whatsapp.Contact),
|
||||||
|
|
||||||
//uuid: xid.New().String(),
|
//uuid: xid.New().String(),
|
||||||
//users: map[string]*slack.User{},
|
//users: map[string]*slack.User{},
|
||||||
//channelsByID: map[string]*slack.Channel{},
|
//channelsByID: map[string]*slack.Channel{},
|
||||||
@@ -123,6 +127,13 @@ func (b *Bwhatsapp) Connect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for id, contact := range b.conn.Store.Contacts {
|
||||||
|
if !isGroupJid(id) && id != "status@broadcast" {
|
||||||
|
// it is user
|
||||||
|
b.users[id] = contact
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.Log.Debugln("Importing all contacts done")
|
b.Log.Debugln("Importing all contacts done")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -271,9 +282,9 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
|
|||||||
// Id: "", // TODO id
|
// Id: "", // TODO id
|
||||||
// TODO Timestamp
|
// TODO Timestamp
|
||||||
RemoteJid: msg.Channel, // which equals to group id
|
RemoteJid: msg.Channel, // which equals to group id
|
||||||
PushName: "pushname",
|
|
||||||
},
|
},
|
||||||
Text: msg.Text,
|
Text: msg.Username + msg.Text,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO adapt gitter code
|
// TODO adapt gitter code
|
||||||
@@ -380,10 +391,24 @@ func (b *Bwhatsapp) HandleTextMessage(message whatsapp.TextMessage) {
|
|||||||
senderJid = *message.Info.Source.Participant
|
senderJid = *message.Info.Source.Participant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// translate sender's Jid to the nicest username we can get
|
||||||
|
senderName := senderJid
|
||||||
|
if sender, exists := b.users[senderJid]; exists {
|
||||||
|
if sender.Name != "" {
|
||||||
|
senderName = sender.Name
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// if user is not in phone contacts
|
||||||
|
// it is the most obvious scenario unless you sync your phone contacts with some remote updated source
|
||||||
|
// users can change it in their WhatsApp settings -> profile -> click on Avatar
|
||||||
|
senderName = sender.Notify
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJid, b.Account)
|
b.Log.Debugf("<= Sending message from %s on %s to gateway", senderJid, b.Account)
|
||||||
rmsg := config.Message{
|
rmsg := config.Message{
|
||||||
UserID: senderJid,
|
UserID: senderJid,
|
||||||
Username: senderJid, // TODO mapping
|
Username: senderName,
|
||||||
Text: message.Text,
|
Text: message.Text,
|
||||||
Timestamp: messageTime,
|
Timestamp: messageTime,
|
||||||
Channel: groupJid,
|
Channel: groupJid,
|
||||||
|
|||||||
Reference in New Issue
Block a user