Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WhatsApp "Someone" nicknaming #1363

Open
DummyThatMatters opened this issue Jan 19, 2021 · 12 comments
Open

WhatsApp "Someone" nicknaming #1363

DummyThatMatters opened this issue Jan 19, 2021 · 12 comments
Labels
enhancement New feature or request whatsapp

Comments

@DummyThatMatters
Copy link

DummyThatMatters commented Jan 19, 2021

Is your feature request related to a problem? Please describe.
WhatsApp tend to relay messages with "<Someone>" nickname in some cases (randomly) even if actual WhatsApp nickname presented. So it is completely impossible to distinguish authors of the posts on the other side of the bridge.

Describe the solution you'd like
To fix WhatsApp "<Someone>" nicknames with actual nicknames and add the option to use phone numbers as <NICK> source (if actual nickname is not set).

Describe alternatives you've considered
To generate unique random pseudonym nickname for each "anonymous" user instead of static "<Someone>" nickname.

Additional context
Group chat, WhatsApp - Mattermost bridge, ~50 users, some users have specified nickname, some of them are not.

@DummyThatMatters DummyThatMatters added the enhancement New feature or request label Jan 19, 2021
@JEK58
Copy link

JEK58 commented Jan 30, 2021

Why did you close this? Did you find a solution?

@joko2020
Copy link

joko2020 commented Feb 6, 2021

Dear Sir,
I need help to integrate Whatsapp to Nextcloud Talk, I have Installed matterbridge on Nextcloud 20.0.7 with matterbridge Running version 1.22.0... but I cannot find whatsapp channel in the talk matterbridge setting. after googling seems to manually edit the matterbridge.toml config file.. but i' cannot find that file.. where is the file path of matterbridge.toml
thanks

@42wim
Copy link
Owner

42wim commented Feb 20, 2021

@joko2020 you should look at the nextcloud forums, I don't know where they put the matterbridge.toml

@joko2020
Copy link

joko2020 commented Mar 5, 2021

@joko2020 you should look at the nextcloud forums, I don't know where they put the matterbridge.toml

Thanks for your reply.. unfortunately , I cannot get the right inormation Also

@micw
Copy link

micw commented Jun 14, 2021

Solution for this particular issue is IMO to allow to show the phone number instead of "someone". While that's not wanted in public groups, it's absolutely wanted in most private group bridging.
I'll create another issue for the fact that jid->account nick name resolution seems to be broken.

@micw
Copy link

micw commented Jun 14, 2021

When reading the code og go-whatsapp, I found:

jid := strings.Replace(contactNode.Attributes["jid"], "@c.us", "@s.whatsapp.net", 1)

May it be that the key in the contatc list is different from the actual sender jid, causing the lookup failures?

@micw
Copy link

micw commented Jun 14, 2021

It seems that if I restart matterbridge, after someone has sent a message to a WA group, this one's nick is resolved properly.

@micw
Copy link

micw commented Jun 21, 2021

There was already a related fix in #796. But it seems that this is insufficient. I have tried to analyze when someone is printed and when the nick name.
It seems that if a user posts a second message after he posts a message, the nick is resolved properly. After restart, the nick name cache seems to be re-filled but only from the recent messages. So if one posts now again and he had posted recently, the nick is resolved at the first message.

My assumption: When a message arrives and the nick is not known, it is retrieved somehow. But this happens after the nick for this first message is already resolved to someone. But it should happen before this.

Could anyone with knowledge about the code verify (and hopefully fix) this?

@micw
Copy link

micw commented Jun 21, 2021

@nathanaelhoun I ping you in this ticket since your PR #1160 seems to be related to this issue.

@nathanaelhoun
Copy link
Contributor

nathanaelhoun commented Jun 21, 2021

Hi @micw, I tried to fix this issue as you noted.

It seems that if a user posts a second message after he posts a message, the nick is resolved properly. After restart, the nick name cache seems to be re-filled but only from the recent messages. So if one posts now again and he had posted recently, the nick is resolved at the first message.

I arrived to the same conclusion and it's why I made #1160 to reload the user list if their is no nickname. Because this changes did not solve the issue (at least, not everytime), I believe your assumption may be right, from what I remember from the last time I checked the code:

My assumption: When a message arrives and the nick is not known, it is retrieved somehow. But this happens after the nick for this first message is already resolved to someone. But it should happen before this

@micw
Copy link

micw commented Jun 22, 2021

@nathanaelhoun
I'm reviewing

func (b *Bwhatsapp) getSenderName(senderJid string) string {
if sender, exists := b.users[senderJid]; exists {
if sender.Name != "" {
return sender.Name
}
// 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
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 ""
}

To avoid code duplication (which leads to diverge in code as already happened, compare L77-L89 with L102-107) I think the check should be earlier, something like:

sender, exists := b.users[senderJid]
if  !exists {
  // reload, add, set exists=true
}
if  exists {
  // code from L77-L89
}

Besides that, Contacts() looks to me like is jkust sends out the request. The response will probably asynchronous. So message processing should somehow block until the contacts are available. This might be quite complicated because another message might arrive meanwhile which also triggers a contacts reload.

@ghost
Copy link

ghost commented Aug 4, 2022

Is there a solution or workaround to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request whatsapp
Projects
None yet
Development

No branches or pull requests

6 participants