Cleanup
This commit is contained in:
@@ -52,9 +52,6 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
|
|||||||
channel := messageInfo.Chat
|
channel := messageInfo.Chat
|
||||||
|
|
||||||
senderName := b.getSenderName(messageInfo)
|
senderName := b.getSenderName(messageInfo)
|
||||||
if senderName == "" {
|
|
||||||
senderName = "Someone" // don't expose telephone number
|
|
||||||
}
|
|
||||||
|
|
||||||
if msg.GetExtendedTextMessage() == nil && msg.GetConversation() == "" {
|
if msg.GetExtendedTextMessage() == nil && msg.GetConversation() == "" {
|
||||||
b.Log.Debugf("message without text content? %#v", msg)
|
b.Log.Debugf("message without text content? %#v", msg)
|
||||||
@@ -82,9 +79,6 @@ func (b *Bwhatsapp) handleTextMessage(messageInfo types.MessageInfo, msg *proto.
|
|||||||
// mentions comes as telephone numbers and we don't want to expose it to other bridges
|
// mentions comes as telephone numbers and we don't want to expose it to other bridges
|
||||||
// replace it with something more meaninful to others
|
// replace it with something more meaninful to others
|
||||||
mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer))
|
mention := b.getSenderNotify(types.NewJID(numberAndSuffix[0], types.DefaultUserServer))
|
||||||
if mention == "" {
|
|
||||||
mention = "someone"
|
|
||||||
}
|
|
||||||
|
|
||||||
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
|
text = strings.Replace(text, "@"+numberAndSuffix[0], "@"+mention, 1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,17 +18,19 @@ type ProfilePicInfo struct {
|
|||||||
Status int16 `json:"status"`
|
Status int16 `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (b *Bwhatsapp) getSenderName(info types.MessageInfo) string {
|
func (b *Bwhatsapp) getSenderName(info types.MessageInfo) string {
|
||||||
// Parse AD JID
|
// Parse AD JID
|
||||||
var senderJid types.JID
|
var senderJid types.JID
|
||||||
senderJid.User, senderJid.Server = info.Sender.User, info.Sender.Server
|
senderJid.User, senderJid.Server = info.Sender.User, info.Sender.Server
|
||||||
|
|
||||||
|
sender, exists := b.contacts[senderJid]
|
||||||
|
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
if sender, exists := b.contacts[senderJid]; exists {
|
if exists && ( sender.FullName != "" ) {
|
||||||
if sender.FullName != "" {
|
return sender.FullName
|
||||||
return sender.FullName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user is not in phone contacts
|
// if user is not in phone contacts
|
||||||
// it is the most obvious scenario unless you sync your phone contacts with some remote updated source
|
// 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
|
// users can change it in their WhatsApp settings -> profile -> click on Avatar
|
||||||
@@ -36,10 +38,8 @@ func (b *Bwhatsapp) getSenderName(info types.MessageInfo) string {
|
|||||||
return info.PushName
|
return info.PushName
|
||||||
}
|
}
|
||||||
|
|
||||||
if sender, exists := b.contacts[senderJid]; exists {
|
if exists && ( sender.FirstName != "" ) {
|
||||||
if sender.FirstName != "" {
|
return sender.FirstName
|
||||||
return sender.FirstName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@@ -60,7 +60,6 @@ func (b *Bwhatsapp) getSenderName(info types.MessageInfo) string {
|
|||||||
b.contacts = allcontacts
|
b.contacts = allcontacts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Someone"
|
return "Someone"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +67,7 @@ func (b *Bwhatsapp) getSenderNotify(senderJid types.JID) string {
|
|||||||
if sender, exists := b.contacts[senderJid]; exists {
|
if sender, exists := b.contacts[senderJid]; exists {
|
||||||
return sender.PushName
|
return sender.PushName
|
||||||
}
|
}
|
||||||
|
return "someone"
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bwhatsapp) GetProfilePicThumb(jid string) (*types.ProfilePictureInfo, error) {
|
func (b *Bwhatsapp) GetProfilePicThumb(jid string) (*types.ProfilePictureInfo, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user