Update mautrix-go

This commit is contained in:
Tulir Asokan
2020-05-08 22:32:22 +03:00
parent e0aea74abf
commit acc25a02e4
20 changed files with 454 additions and 465 deletions

View File

@ -1,5 +1,5 @@
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
// Copyright (C) 2019 Tulir Asokan
// Copyright (C) 2020 Tulir Asokan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
@ -24,8 +24,8 @@ import (
"github.com/Rhymen/go-whatsapp"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix-appservice"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
"maunium.net/go/mautrix-whatsapp/types"
)
@ -54,8 +54,8 @@ type BridgeConfig struct {
RecoverHistory bool `yaml:"recovery_history_backfill"`
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
LoginSharedSecret string `yaml:"login_shared_secret"`
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
LoginSharedSecret string `yaml:"login_shared_secret"`
InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
@ -127,7 +127,7 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
type UsernameTemplateArgs struct {
UserID string
UserID id.UserID
}
func (bc BridgeConfig) FormatDisplayname(contact whatsapp.Contact) (string, int8) {
@ -232,25 +232,25 @@ func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
return rawPC, nil
}
func (pc PermissionConfig) IsRelaybotWhitelisted(userID string) bool {
func (pc PermissionConfig) IsRelaybotWhitelisted(userID id.UserID) bool {
return pc.GetPermissionLevel(userID) >= PermissionLevelRelaybot
}
func (pc PermissionConfig) IsWhitelisted(userID string) bool {
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
return pc.GetPermissionLevel(userID) >= PermissionLevelUser
}
func (pc PermissionConfig) IsAdmin(userID string) bool {
func (pc PermissionConfig) IsAdmin(userID id.UserID) bool {
return pc.GetPermissionLevel(userID) >= PermissionLevelAdmin
}
func (pc PermissionConfig) GetPermissionLevel(userID string) PermissionLevel {
permissions, ok := pc[userID]
func (pc PermissionConfig) GetPermissionLevel(userID id.UserID) PermissionLevel {
permissions, ok := pc[string(userID)]
if ok {
return permissions
}
_, homeserver := appservice.ParseUserID(userID)
_, homeserver, _ := userID.Parse()
permissions, ok = pc[homeserver]
if len(homeserver) > 0 && ok {
return permissions
@ -265,12 +265,12 @@ func (pc PermissionConfig) GetPermissionLevel(userID string) PermissionLevel {
}
type RelaybotConfig struct {
Enabled bool `yaml:"enabled"`
ManagementRoom string `yaml:"management"`
InviteUsers []types.MatrixUserID `yaml:"invites"`
Enabled bool `yaml:"enabled"`
ManagementRoom id.RoomID `yaml:"management"`
InviteUsers []id.UserID `yaml:"invites"`
MessageFormats map[mautrix.MessageType]string `yaml:"message_formats"`
messageTemplates *template.Template `yaml:"-"`
MessageFormats map[event.MessageType]string `yaml:"message_formats"`
messageTemplates *template.Template `yaml:"-"`
}
type umRelaybotConfig RelaybotConfig
@ -293,25 +293,25 @@ func (rc *RelaybotConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
}
type Sender struct {
UserID types.MatrixUserID
mautrix.Member
UserID id.UserID
*event.MemberEventContent
}
type formatData struct {
Sender Sender
Message string
Content mautrix.Content
Content *event.MessageEventContent
}
func (rc *RelaybotConfig) FormatMessage(evt *mautrix.Event, member mautrix.Member) (string, error) {
func (rc *RelaybotConfig) FormatMessage(content *event.MessageEventContent, sender id.UserID, member *event.MemberEventContent) (string, error) {
var output strings.Builder
err := rc.messageTemplates.ExecuteTemplate(&output, string(evt.Content.MsgType), formatData{
err := rc.messageTemplates.ExecuteTemplate(&output, string(content.MsgType), formatData{
Sender: Sender{
UserID: evt.Sender,
Member: member,
UserID: sender,
MemberEventContent: member,
},
Content: evt.Content,
Message: evt.Content.FormattedBody,
Content: content,
Message: content.FormattedBody,
})
return output.String(), err
}