Fix and add things

* Fix user ID reservation in registration
* Fix some database things
* Add commands
* Add basic contact syncing and portal creation
* Add better error logging
This commit is contained in:
Tulir Asokan
2018-08-18 22:57:08 +03:00
parent edd4f817e4
commit a9124b89bd
13 changed files with 455 additions and 98 deletions

View File

@ -22,6 +22,8 @@ import (
"maunium.net/go/mautrix-appservice"
"strings"
"strconv"
"github.com/Rhymen/go-whatsapp"
"maunium.net/go/mautrix-whatsapp/types"
)
type BridgeConfig struct {
@ -62,16 +64,16 @@ type UsernameTemplateArgs struct {
UserID string
}
func (bc BridgeConfig) FormatDisplayname(displayname string) string {
func (bc BridgeConfig) FormatDisplayname(contact whatsapp.Contact) string {
var buf bytes.Buffer
bc.displaynameTemplate.Execute(&buf, DisplaynameTemplateArgs{
Displayname: displayname,
})
bc.displaynameTemplate.Execute(&buf, contact)
return buf.String()
}
func (bc BridgeConfig) FormatUsername(receiver, userID string) string {
func (bc BridgeConfig) FormatUsername(receiver types.MatrixUserID, userID types.WhatsAppID) string {
var buf bytes.Buffer
receiver = strings.Replace(receiver, "@", "=40", 1)
receiver = strings.Replace(receiver, ":", "=3", 1)
bc.usernameTemplate.Execute(&buf, UsernameTemplateArgs{
Receiver: receiver,
UserID: userID,
@ -80,7 +82,12 @@ func (bc BridgeConfig) FormatUsername(receiver, userID string) string {
}
func (bc BridgeConfig) MarshalYAML() (interface{}, error) {
bc.DisplaynameTemplate = bc.FormatDisplayname("{{.Displayname}}")
bc.DisplaynameTemplate = bc.FormatDisplayname(whatsapp.Contact{
Jid: "{{.Jid}}",
Notify: "{{.Notify}}",
Name: "{{.Name}}",
Short: "{{.Short}}",
})
bc.UsernameTemplate = bc.FormatUsername("{{.Receiver}}", "{{.UserID}}")
return bc, nil
}