summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathanaƫl <contact@nathanaelhoun.fr>2020-06-25 00:35:49 +0200
committerGitHub <noreply@github.com>2020-06-25 00:35:49 +0200
commit1fee32324736a188af02e985bdc8b571e9addd55 (patch)
tree1dd2e6e429c49da6511b617140f1dbbbe1ff36ed
parenta41accd033a8d7e859a4bff89ae64e1f3500e4d2 (diff)
downloadmatterbridge-msglm-1fee32324736a188af02e985bdc8b571e9addd55.tar.gz
matterbridge-msglm-1fee32324736a188af02e985bdc8b571e9addd55.tar.bz2
matterbridge-msglm-1fee32324736a188af02e985bdc8b571e9addd55.zip
Reload user information when a new contact is detected (whatsapp) (#1160)
Before returning an empty string, we refresh the WhatsApp contacts and if we found the one we wanted, we can return a real name. Fixes #796
-rw-r--r--bridge/whatsapp/helpers.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/bridge/whatsapp/helpers.go b/bridge/whatsapp/helpers.go
index f45d6246..aa5f3188 100644
--- a/bridge/whatsapp/helpers.go
+++ b/bridge/whatsapp/helpers.go
@@ -80,8 +80,33 @@ func (b *Bwhatsapp) getSenderName(senderJid string) string {
// 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
- return sender.Notify
+ if sender.Notify != "" {
+ return sender.Notify
+ }
+
+ if sender.Short != "" {
+ return sender.Short
+ }
+ }
+
+ // try to reload this contact
+ _, err := b.conn.Contacts()
+ if err != nil {
+ b.Log.Errorf("error on update of contacts: %v", err)
}
+
+ if contact, exists := b.conn.Store.Contacts[senderJid]; exists {
+ // Add it to the user map
+ b.users[senderJid] = contact
+
+ if contact.Name != "" {
+ return contact.Name
+ }
+ // if user is not in phone contacts
+ // same as above
+ return contact.Notify
+ }
+
return ""
}