Browse Source

Fix/improve minor things

Tulir Asokan 6 years ago
parent
commit
65f077c645
4 changed files with 13 additions and 2 deletions
  1. 3 0
      config/bridge.go
  2. 3 2
      example-config.yaml
  3. 4 0
      portal.go
  4. 3 0
      puppet.go

+ 3 - 0
config/bridge.go

@@ -66,6 +66,9 @@ type UsernameTemplateArgs struct {
 
 func (bc BridgeConfig) FormatDisplayname(contact whatsapp.Contact) string {
 	var buf bytes.Buffer
+	if index := strings.IndexRune(contact.Jid, '@'); index > 0 {
+		contact.Jid = "+" + contact.Jid[:index]
+	}
 	bc.displaynameTemplate.Execute(&buf, contact)
 	return buf.String()
 }

+ 3 - 2
example-config.yaml

@@ -49,8 +49,9 @@ bridge:
   # Displayname template for WhatsApp users.
   # {{.Name}}   - display name
   # {{.Short}}  - short display name (usually first name)
-  # {{.Notify}} - nickname (set by the target WhatsApp user)
-  displayname_template: "{{if .Name}}{{.Name}}{{else if .Notify}}{{.Notify}}{{else if .Short}}{{.Short}}{{else}}Unnamed user{{end}}"
+  # {{.Notify}} - nickname (maybe set by the target WhatsApp user)
+  # {{.Jid}}    - phone number (international format)
+  displayname_template: "{{if .Name}}{{.Name}}{{else if .Notify}}{{.Notify}}{{else if .Short}}{{.Short}}{{else}}{{.Jid}}{{end}}"
 
   # The prefix for commands. Only required in non-management rooms.
   command_prefix: "!wa"

+ 4 - 0
portal.go

@@ -388,6 +388,10 @@ func (portal *Portal) MarkHandled(jid types.WhatsAppMessageID, mxid types.Matrix
 
 func (portal *Portal) GetMessageIntent(info whatsapp.MessageInfo) *appservice.IntentAPI {
 	if info.FromMe {
+		if portal.IsPrivateChat() {
+			// TODO handle own messages in private chats properly
+			return nil
+		}
 		return portal.user.GetPuppetByJID(portal.user.JID()).Intent()
 	} else if portal.IsPrivateChat() {
 		return portal.MainIntent()

+ 3 - 0
puppet.go

@@ -187,6 +187,9 @@ func (puppet *Puppet) UpdateAvatar(avatar *whatsappExt.ProfilePicInfo) bool {
 func (puppet *Puppet) Sync(contact whatsapp.Contact) {
 	puppet.Intent().EnsureRegistered()
 
+	if contact.Jid == puppet.user.JID() {
+		contact.Notify = puppet.user.Conn.Info.Pushname
+	}
 	newName := puppet.bridge.Config.Bridge.FormatDisplayname(contact)
 	if puppet.Displayname != newName {
 		err := puppet.Intent().SetDisplayName(newName)