treewide: upgrading to latest mautrix standards
Signed-off-by: Sumner Evans <sumner@beeper.com>
This commit is contained in:
parent
e843faf9b4
commit
715107f5a2
@ -10,11 +10,8 @@ insert_final_newline = true
|
|||||||
|
|
||||||
[*.{yaml,yml}]
|
[*.{yaml,yml}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 4
|
||||||
|
|
||||||
[*.sql]
|
[*.sql]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[.gitlab-ci.yml]
|
|
||||||
indent_size = 2
|
|
||||||
|
17
bridgestate.go
Normal file
17
bridgestate.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func (user *User) GetRemoteID() string {
|
||||||
|
if user == nil || !user.GMID.Valid() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return user.GMID.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetRemoteName() string {
|
||||||
|
if user == nil || !user.GMID.Valid() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("+%s", user.GMID.String())
|
||||||
|
}
|
984
commands.go
984
commands.go
File diff suppressed because it is too large
Load Diff
132
community.go
132
community.go
@ -1,132 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (user *User) inviteToCommunity() {
|
|
||||||
url := user.bridge.Bot.BuildURL("groups", user.CommunityID, "admin", "users", "invite", user.MXID)
|
|
||||||
reqBody := map[string]interface{}{}
|
|
||||||
_, err := user.bridge.Bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
|
||||||
if err != nil {
|
|
||||||
user.log.Warnfln("Failed to invite user to personal filtering community %s: %v", user.CommunityID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) updateCommunityProfile() {
|
|
||||||
url := user.bridge.Bot.BuildURL("groups", user.CommunityID, "profile")
|
|
||||||
profileReq := struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
AvatarURL string `json:"avatar_url"`
|
|
||||||
ShortDescription string `json:"short_description"`
|
|
||||||
}{"WhatsApp", user.bridge.Config.AppService.Bot.Avatar, "Your WhatsApp bridged chats"}
|
|
||||||
_, err := user.bridge.Bot.MakeRequest(http.MethodPost, url, &profileReq, nil)
|
|
||||||
if err != nil {
|
|
||||||
user.log.Warnfln("Failed to update metadata of %s: %v", user.CommunityID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) createCommunity() {
|
|
||||||
if user.IsRelaybot || !user.bridge.Config.Bridge.EnableCommunities() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
localpart, server, _ := user.MXID.Parse()
|
|
||||||
community := user.bridge.Config.Bridge.FormatCommunity(localpart, server)
|
|
||||||
user.log.Debugln("Creating personal filtering community", community)
|
|
||||||
bot := user.bridge.Bot
|
|
||||||
req := struct {
|
|
||||||
Localpart string `json:"localpart"`
|
|
||||||
}{community}
|
|
||||||
resp := struct {
|
|
||||||
GroupID string `json:"group_id"`
|
|
||||||
}{}
|
|
||||||
_, err := bot.MakeRequest(http.MethodPost, bot.BuildURL("create_group"), &req, &resp)
|
|
||||||
if err != nil {
|
|
||||||
if httpErr, ok := err.(mautrix.HTTPError); ok {
|
|
||||||
if httpErr.RespError.Err != "Group already exists" {
|
|
||||||
user.log.Warnln("Server responded with error creating personal filtering community:", err)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
user.log.Debugln("Personal filtering community", resp.GroupID, "already existed")
|
|
||||||
user.CommunityID = fmt.Sprintf("+%s:%s", req.Localpart, user.bridge.Config.Homeserver.Domain)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
user.log.Warnln("Unknown error creating personal filtering community:", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
user.log.Infoln("Created personal filtering community %s", resp.GroupID)
|
|
||||||
user.CommunityID = resp.GroupID
|
|
||||||
user.inviteToCommunity()
|
|
||||||
user.updateCommunityProfile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) addPuppetToCommunity(puppet *Puppet) bool {
|
|
||||||
if user.IsRelaybot || len(user.CommunityID) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
bot := user.bridge.Bot
|
|
||||||
url := bot.BuildURL("groups", user.CommunityID, "admin", "users", "invite", puppet.MXID)
|
|
||||||
blankReqBody := map[string]interface{}{}
|
|
||||||
_, err := bot.MakeRequest(http.MethodPut, url, &blankReqBody, nil)
|
|
||||||
if err != nil {
|
|
||||||
user.log.Warnfln("Failed to invite %s to %s: %v", puppet.MXID, user.CommunityID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
reqBody := map[string]map[string]string{
|
|
||||||
"m.visibility": {
|
|
||||||
"type": "private",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
url = bot.BuildURLWithQuery(mautrix.URLPath{"groups", user.CommunityID, "self", "accept_invite"}, map[string]string{
|
|
||||||
"user_id": puppet.MXID.String(),
|
|
||||||
})
|
|
||||||
_, err = bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
|
||||||
if err != nil {
|
|
||||||
user.log.Warnfln("Failed to join %s as %s: %v", user.CommunityID, puppet.MXID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
user.log.Debugln("Added", puppet.MXID, "to", user.CommunityID)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) addPortalToCommunity(portal *Portal) bool {
|
|
||||||
if user.IsRelaybot || len(user.CommunityID) == 0 || len(portal.MXID) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
bot := user.bridge.Bot
|
|
||||||
url := bot.BuildURL("groups", user.CommunityID, "admin", "rooms", portal.MXID)
|
|
||||||
reqBody := map[string]map[string]string{
|
|
||||||
"m.visibility": {
|
|
||||||
"type": "private",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_, err := bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
|
||||||
if err != nil {
|
|
||||||
user.log.Warnfln("Failed to add %s to %s: %v", portal.MXID, user.CommunityID, err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
user.log.Debugln("Added", portal.MXID, "to", user.CommunityID)
|
|
||||||
return true
|
|
||||||
}
|
|
336
config/bridge.go
336
config/bridge.go
@ -17,112 +17,131 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"errors"
|
||||||
"strconv"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/karmanyaahm/groupme"
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type DeferredConfig struct {
|
||||||
|
StartDaysAgo int `yaml:"start_days_ago"`
|
||||||
|
MaxBatchEvents int `yaml:"max_batch_events"`
|
||||||
|
BatchDelay int `yaml:"batch_delay"`
|
||||||
|
}
|
||||||
|
|
||||||
type BridgeConfig struct {
|
type BridgeConfig struct {
|
||||||
UsernameTemplate string `yaml:"username_template"`
|
UsernameTemplate string `yaml:"username_template"`
|
||||||
DisplaynameTemplate string `yaml:"displayname_template"`
|
DisplaynameTemplate string `yaml:"displayname_template"`
|
||||||
CommunityTemplate string `yaml:"community_template"`
|
|
||||||
|
|
||||||
ConnectionTimeout int `yaml:"connection_timeout"`
|
PersonalFilteringSpaces bool `yaml:"personal_filtering_spaces"`
|
||||||
FetchMessageOnTimeout bool `yaml:"fetch_message_on_timeout"`
|
|
||||||
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
|
||||||
LoginQRRegenCount int `yaml:"login_qr_regen_count"`
|
|
||||||
MaxConnectionAttempts int `yaml:"max_connection_attempts"`
|
|
||||||
ConnectionRetryDelay int `yaml:"connection_retry_delay"`
|
|
||||||
ReportConnectionRetry bool `yaml:"report_connection_retry"`
|
|
||||||
ChatListWait int `yaml:"chat_list_wait"`
|
|
||||||
PortalSyncWait int `yaml:"portal_sync_wait"`
|
|
||||||
UserMessageBuffer int `yaml:"user_message_buffer"`
|
|
||||||
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
|
||||||
|
|
||||||
CallNotices struct {
|
DeliveryReceipts bool `yaml:"delivery_receipts"`
|
||||||
Start bool `yaml:"start"`
|
MessageStatusEvents bool `yaml:"message_status_events"`
|
||||||
End bool `yaml:"end"`
|
MessageErrorNotices bool `yaml:"message_error_notices"`
|
||||||
} `yaml:"call_notices"`
|
PortalMessageBuffer int `yaml:"portal_message_buffer"`
|
||||||
|
|
||||||
InitialChatSync int `yaml:"initial_chat_sync_count"`
|
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
|
||||||
InitialHistoryFill int `yaml:"initial_history_fill_count"`
|
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
||||||
HistoryDisableNotifs bool `yaml:"initial_history_disable_notifications"`
|
SyncManualMarkedUnread bool `yaml:"sync_manual_marked_unread"`
|
||||||
RecoverChatSync int `yaml:"recovery_chat_sync_count"`
|
DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
|
||||||
RecoverHistory bool `yaml:"recovery_history_backfill"`
|
|
||||||
SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"`
|
|
||||||
|
|
||||||
SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"`
|
HistorySync struct {
|
||||||
SyncDirectChatList bool `yaml:"sync_direct_chat_list"`
|
CreatePortals bool `yaml:"create_portals"`
|
||||||
DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
|
Backfill bool `yaml:"backfill"`
|
||||||
DefaultBridgePresence bool `yaml:"default_bridge_presence"`
|
|
||||||
LoginSharedSecret string `yaml:"login_shared_secret"`
|
|
||||||
|
|
||||||
InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"`
|
DoublePuppetBackfill bool `yaml:"double_puppet_backfill"`
|
||||||
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
|
RequestFullSync bool `yaml:"request_full_sync"`
|
||||||
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
MaxInitialConversations int `yaml:"max_initial_conversations"`
|
||||||
|
UnreadHoursThreshold int `yaml:"unread_hours_threshold"`
|
||||||
|
|
||||||
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`
|
Immediate struct {
|
||||||
|
WorkerCount int `yaml:"worker_count"`
|
||||||
|
MaxEvents int `yaml:"max_events"`
|
||||||
|
} `yaml:"immediate"`
|
||||||
|
|
||||||
AllowUserInvite bool `yaml:"allow_user_invite"`
|
Deferred []DeferredConfig `yaml:"deferred"`
|
||||||
|
} `yaml:"history_sync"`
|
||||||
|
|
||||||
|
DoublePuppetServerMap map[string]string `yaml:"double_puppet_server_map"`
|
||||||
|
DoublePuppetAllowDiscovery bool `yaml:"double_puppet_allow_discovery"`
|
||||||
|
LoginSharedSecretMap map[string]string `yaml:"login_shared_secret_map"`
|
||||||
|
|
||||||
|
ResendBridgeInfo bool `yaml:"resend_bridge_info"`
|
||||||
|
|
||||||
|
PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"`
|
||||||
|
FederateRooms bool `yaml:"federate_rooms"`
|
||||||
|
AllowUserInvite bool `yaml:"allow_user_invite"`
|
||||||
|
|
||||||
|
MessageHandlingTimeout struct {
|
||||||
|
ErrorAfterStr string `yaml:"error_after"`
|
||||||
|
DeadlineStr string `yaml:"deadline"`
|
||||||
|
|
||||||
|
ErrorAfter time.Duration `yaml:"-"`
|
||||||
|
Deadline time.Duration `yaml:"-"`
|
||||||
|
} `yaml:"message_handling_timeout"`
|
||||||
|
|
||||||
CommandPrefix string `yaml:"command_prefix"`
|
CommandPrefix string `yaml:"command_prefix"`
|
||||||
|
|
||||||
Encryption struct {
|
ManagementRoomText bridgeconfig.ManagementRoomTexts `yaml:"management_room_text"`
|
||||||
Allow bool `yaml:"allow"`
|
|
||||||
Default bool `yaml:"default"`
|
|
||||||
|
|
||||||
KeySharing struct {
|
Encryption bridgeconfig.EncryptionConfig `yaml:"encryption"`
|
||||||
Allow bool `yaml:"allow"`
|
|
||||||
RequireCrossSigning bool `yaml:"require_cross_signing"`
|
|
||||||
RequireVerification bool `yaml:"require_verification"`
|
|
||||||
} `yaml:"key_sharing"`
|
|
||||||
} `yaml:"encryption"`
|
|
||||||
|
|
||||||
Permissions PermissionConfig `yaml:"permissions"`
|
Provisioning struct {
|
||||||
|
Prefix string `yaml:"prefix"`
|
||||||
|
SharedSecret string `yaml:"shared_secret"`
|
||||||
|
} `yaml:"provisioning"`
|
||||||
|
|
||||||
Relaybot RelaybotConfig `yaml:"relaybot"`
|
Permissions bridgeconfig.PermissionConfig `yaml:"permissions"`
|
||||||
|
|
||||||
usernameTemplate *template.Template `yaml:"-"`
|
ParsedUsernameTemplate *template.Template `yaml:"-"`
|
||||||
displaynameTemplate *template.Template `yaml:"-"`
|
displaynameTemplate *template.Template `yaml:"-"`
|
||||||
communityTemplate *template.Template `yaml:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *BridgeConfig) setDefaults() {
|
func (bc BridgeConfig) GetEncryptionConfig() bridgeconfig.EncryptionConfig {
|
||||||
bc.ConnectionTimeout = 20
|
return bc.Encryption
|
||||||
bc.FetchMessageOnTimeout = false
|
}
|
||||||
bc.DeliveryReceipts = false
|
|
||||||
bc.LoginQRRegenCount = 2
|
|
||||||
bc.MaxConnectionAttempts = 3
|
|
||||||
bc.ConnectionRetryDelay = -1
|
|
||||||
bc.ReportConnectionRetry = true
|
|
||||||
bc.ChatListWait = 30
|
|
||||||
bc.PortalSyncWait = 600
|
|
||||||
bc.UserMessageBuffer = 1024
|
|
||||||
bc.PortalMessageBuffer = 128
|
|
||||||
|
|
||||||
bc.CallNotices.Start = true
|
func (bc BridgeConfig) EnableMessageStatusEvents() bool {
|
||||||
bc.CallNotices.End = true
|
return bc.MessageStatusEvents
|
||||||
|
}
|
||||||
|
|
||||||
bc.InitialChatSync = 10
|
func (bc BridgeConfig) EnableMessageErrorNotices() bool {
|
||||||
bc.InitialHistoryFill = 20
|
return bc.MessageErrorNotices
|
||||||
bc.RecoverChatSync = -1
|
}
|
||||||
bc.RecoverHistory = true
|
|
||||||
bc.SyncChatMaxAge = 259200
|
|
||||||
|
|
||||||
bc.SyncWithCustomPuppets = true
|
func (bc BridgeConfig) GetCommandPrefix() string {
|
||||||
bc.DefaultBridgePresence = true
|
return bc.CommandPrefix
|
||||||
bc.DefaultBridgeReceipts = true
|
}
|
||||||
bc.LoginSharedSecret = ""
|
|
||||||
|
|
||||||
bc.InviteOwnPuppetForBackfilling = true
|
func (bc BridgeConfig) GetManagementRoomTexts() bridgeconfig.ManagementRoomTexts {
|
||||||
bc.PrivateChatPortalMeta = false
|
return bc.ManagementRoomText
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BridgeConfig) GetResendBridgeInfo() bool {
|
||||||
|
return bc.ResendBridgeInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func boolToInt(val bool) int {
|
||||||
|
if val {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bc BridgeConfig) Validate() error {
|
||||||
|
_, hasWildcard := bc.Permissions["*"]
|
||||||
|
_, hasExampleDomain := bc.Permissions["example.com"]
|
||||||
|
_, hasExampleUser := bc.Permissions["@admin:example.com"]
|
||||||
|
exampleLen := boolToInt(hasWildcard) + boolToInt(hasExampleUser) + boolToInt(hasExampleDomain)
|
||||||
|
if len(bc.Permissions) <= exampleLen {
|
||||||
|
return errors.New("bridge.permissions not configured")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type umBridgeConfig BridgeConfig
|
type umBridgeConfig BridgeConfig
|
||||||
@ -133,9 +152,11 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.usernameTemplate, err = template.New("username").Parse(bc.UsernameTemplate)
|
bc.ParsedUsernameTemplate, err = template.New("username").Parse(bc.UsernameTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if !strings.Contains(bc.FormatUsername("1234567890"), "1234567890") {
|
||||||
|
return fmt.Errorf("username template is missing user ID placeholder")
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.displaynameTemplate, err = template.New("displayname").Parse(bc.DisplaynameTemplate)
|
bc.displaynameTemplate, err = template.New("displayname").Parse(bc.DisplaynameTemplate)
|
||||||
@ -143,8 +164,14 @@ func (bc *BridgeConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bc.CommunityTemplate) > 0 {
|
if bc.MessageHandlingTimeout.ErrorAfterStr != "" {
|
||||||
bc.communityTemplate, err = template.New("community").Parse(bc.CommunityTemplate)
|
bc.MessageHandlingTimeout.ErrorAfter, err = time.ParseDuration(bc.MessageHandlingTimeout.ErrorAfterStr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bc.MessageHandlingTimeout.DeadlineStr != "" {
|
||||||
|
bc.MessageHandlingTimeout.Deadline, err = time.ParseDuration(bc.MessageHandlingTimeout.DeadlineStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -157,144 +184,15 @@ type UsernameTemplateArgs struct {
|
|||||||
UserID id.UserID
|
UserID id.UserID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc BridgeConfig) FormatDisplayname(contact groupme.Member) (string, int8) {
|
func (bc BridgeConfig) FormatUsername(username string) string {
|
||||||
var buf bytes.Buffer
|
var buf strings.Builder
|
||||||
if index := strings.IndexRune(contact.ID.String(), '@'); index > 0 {
|
_ = bc.ParsedUsernameTemplate.Execute(&buf, username)
|
||||||
contact.ID = groupme.ID("+" + contact.UserID.String()[:index])
|
|
||||||
}
|
|
||||||
bc.displaynameTemplate.Execute(&buf, contact)
|
|
||||||
var quality int8
|
|
||||||
switch {
|
|
||||||
case len(contact.Nickname) > 0:
|
|
||||||
quality = 3
|
|
||||||
//TODO what
|
|
||||||
case len(contact.UserID) > 0:
|
|
||||||
quality = 1
|
|
||||||
default:
|
|
||||||
quality = 0
|
|
||||||
}
|
|
||||||
return buf.String(), quality
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc BridgeConfig) FormatUsername(userID types.GroupMeID) string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
bc.usernameTemplate.Execute(&buf, userID)
|
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommunityTemplateArgs struct {
|
|
||||||
Localpart string
|
|
||||||
Server string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc BridgeConfig) EnableCommunities() bool {
|
|
||||||
return bc.communityTemplate != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc BridgeConfig) FormatCommunity(localpart, server string) string {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
bc.communityTemplate.Execute(&buf, CommunityTemplateArgs{localpart, server})
|
|
||||||
return buf.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
type PermissionConfig map[string]PermissionLevel
|
|
||||||
|
|
||||||
type PermissionLevel int
|
|
||||||
|
|
||||||
const (
|
|
||||||
PermissionLevelDefault PermissionLevel = 0
|
|
||||||
PermissionLevelRelaybot PermissionLevel = 5
|
|
||||||
PermissionLevelUser PermissionLevel = 10
|
|
||||||
PermissionLevelAdmin PermissionLevel = 100
|
|
||||||
)
|
|
||||||
|
|
||||||
func (pc *PermissionConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
||||||
rawPC := make(map[string]string)
|
|
||||||
err := unmarshal(&rawPC)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if *pc == nil {
|
|
||||||
*pc = make(map[string]PermissionLevel)
|
|
||||||
}
|
|
||||||
for key, value := range rawPC {
|
|
||||||
switch strings.ToLower(value) {
|
|
||||||
case "relaybot":
|
|
||||||
(*pc)[key] = PermissionLevelRelaybot
|
|
||||||
case "user":
|
|
||||||
(*pc)[key] = PermissionLevelUser
|
|
||||||
case "admin":
|
|
||||||
(*pc)[key] = PermissionLevelAdmin
|
|
||||||
default:
|
|
||||||
val, err := strconv.Atoi(value)
|
|
||||||
if err != nil {
|
|
||||||
(*pc)[key] = PermissionLevelDefault
|
|
||||||
} else {
|
|
||||||
(*pc)[key] = PermissionLevel(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc *PermissionConfig) MarshalYAML() (interface{}, error) {
|
|
||||||
if *pc == nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
rawPC := make(map[string]string)
|
|
||||||
for key, value := range *pc {
|
|
||||||
switch value {
|
|
||||||
case PermissionLevelRelaybot:
|
|
||||||
rawPC[key] = "relaybot"
|
|
||||||
case PermissionLevelUser:
|
|
||||||
rawPC[key] = "user"
|
|
||||||
case PermissionLevelAdmin:
|
|
||||||
rawPC[key] = "admin"
|
|
||||||
default:
|
|
||||||
rawPC[key] = strconv.Itoa(int(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rawPC, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc PermissionConfig) IsRelaybotWhitelisted(userID id.UserID) bool {
|
|
||||||
return pc.GetPermissionLevel(userID) >= PermissionLevelRelaybot
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc PermissionConfig) IsWhitelisted(userID id.UserID) bool {
|
|
||||||
return pc.GetPermissionLevel(userID) >= PermissionLevelUser
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc PermissionConfig) IsAdmin(userID id.UserID) bool {
|
|
||||||
return pc.GetPermissionLevel(userID) >= PermissionLevelAdmin
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pc PermissionConfig) GetPermissionLevel(userID id.UserID) PermissionLevel {
|
|
||||||
permissions, ok := pc[string(userID)]
|
|
||||||
if ok {
|
|
||||||
return permissions
|
|
||||||
}
|
|
||||||
|
|
||||||
_, homeserver, _ := userID.Parse()
|
|
||||||
permissions, ok = pc[homeserver]
|
|
||||||
if len(homeserver) > 0 && ok {
|
|
||||||
return permissions
|
|
||||||
}
|
|
||||||
|
|
||||||
permissions, ok = pc["*"]
|
|
||||||
if ok {
|
|
||||||
return permissions
|
|
||||||
}
|
|
||||||
|
|
||||||
return PermissionLevelDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
type RelaybotConfig struct {
|
type RelaybotConfig struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
ManagementRoom id.RoomID `yaml:"management"`
|
AdminOnly bool `yaml:"admin_only"`
|
||||||
InviteUsers []id.UserID `yaml:"invites"`
|
|
||||||
|
|
||||||
MessageFormats map[event.MessageType]string `yaml:"message_formats"`
|
MessageFormats map[event.MessageType]string `yaml:"message_formats"`
|
||||||
messageTemplates *template.Template `yaml:"-"`
|
messageTemplates *template.Template `yaml:"-"`
|
||||||
}
|
}
|
||||||
@ -319,8 +217,8 @@ func (rc *RelaybotConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sender struct {
|
type Sender struct {
|
||||||
UserID id.UserID
|
UserID string
|
||||||
*event.MemberEventContent
|
event.MemberEventContent
|
||||||
}
|
}
|
||||||
|
|
||||||
type formatData struct {
|
type formatData struct {
|
||||||
@ -329,11 +227,15 @@ type formatData struct {
|
|||||||
Content *event.MessageEventContent
|
Content *event.MessageEventContent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RelaybotConfig) FormatMessage(content *event.MessageEventContent, sender id.UserID, member *event.MemberEventContent) (string, error) {
|
func (rc *RelaybotConfig) FormatMessage(content *event.MessageEventContent, sender id.UserID, member event.MemberEventContent) (string, error) {
|
||||||
|
if len(member.Displayname) == 0 {
|
||||||
|
member.Displayname = sender.String()
|
||||||
|
}
|
||||||
|
member.Displayname = template.HTMLEscapeString(member.Displayname)
|
||||||
var output strings.Builder
|
var output strings.Builder
|
||||||
err := rc.messageTemplates.ExecuteTemplate(&output, string(content.MsgType), formatData{
|
err := rc.messageTemplates.ExecuteTemplate(&output, string(content.MsgType), formatData{
|
||||||
Sender: Sender{
|
Sender: Sender{
|
||||||
UserID: sender,
|
UserID: template.HTMLEscapeString(sender.String()),
|
||||||
MemberEventContent: member,
|
MemberEventContent: member,
|
||||||
},
|
},
|
||||||
Content: content,
|
Content: content,
|
||||||
|
@ -17,50 +17,14 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||||
|
"maunium.net/go/mautrix/id"
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Homeserver struct {
|
*bridgeconfig.BaseConfig `yaml:",inline"`
|
||||||
Address string `yaml:"address"`
|
|
||||||
Domain string `yaml:"domain"`
|
|
||||||
Asmux bool `yaml:"asmux"`
|
|
||||||
} `yaml:"homeserver"`
|
|
||||||
|
|
||||||
AppService struct {
|
SegmentKey string `yaml:"segment_key"`
|
||||||
Address string `yaml:"address"`
|
|
||||||
Hostname string `yaml:"hostname"`
|
|
||||||
Port uint16 `yaml:"port"`
|
|
||||||
|
|
||||||
Database struct {
|
|
||||||
Type string `yaml:"type"`
|
|
||||||
URI string `yaml:"uri"`
|
|
||||||
|
|
||||||
MaxOpenConns int `yaml:"max_open_conns"`
|
|
||||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
|
||||||
} `yaml:"database"`
|
|
||||||
|
|
||||||
StateStore string `yaml:"state_store_path,omitempty"`
|
|
||||||
|
|
||||||
Provisioning struct {
|
|
||||||
Prefix string `yaml:"prefix"`
|
|
||||||
SharedSecret string `yaml:"shared_secret"`
|
|
||||||
} `yaml:"provisioning"`
|
|
||||||
|
|
||||||
ID string `yaml:"id"`
|
|
||||||
Bot struct {
|
|
||||||
Username string `yaml:"username"`
|
|
||||||
Displayname string `yaml:"displayname"`
|
|
||||||
Avatar string `yaml:"avatar"`
|
|
||||||
} `yaml:"bot"`
|
|
||||||
|
|
||||||
ASToken string `yaml:"as_token"`
|
|
||||||
HSToken string `yaml:"hs_token"`
|
|
||||||
} `yaml:"appservice"`
|
|
||||||
|
|
||||||
Metrics struct {
|
Metrics struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
@ -68,50 +32,28 @@ type Config struct {
|
|||||||
} `yaml:"metrics"`
|
} `yaml:"metrics"`
|
||||||
|
|
||||||
GroupMe struct {
|
GroupMe struct {
|
||||||
OSName string `yaml:"os_name"`
|
OSName string `yaml:"os_name"`
|
||||||
BrowserName string `yaml:"browser_name"`
|
BrowserName string `yaml:"browser_name"`
|
||||||
|
ConnectionTimeout int `yaml:"connection_timeout"`
|
||||||
} `yaml:"groupme"`
|
} `yaml:"groupme"`
|
||||||
|
|
||||||
Bridge BridgeConfig `yaml:"bridge"`
|
Bridge BridgeConfig `yaml:"bridge"`
|
||||||
|
|
||||||
Logging appservice.LogConfig `yaml:"logging"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) setDefaults() {
|
func (config *Config) CanAutoDoublePuppet(userID id.UserID) bool {
|
||||||
config.AppService.Database.MaxOpenConns = 20
|
_, homeserver, _ := userID.Parse()
|
||||||
config.AppService.Database.MaxIdleConns = 2
|
_, hasSecret := config.Bridge.LoginSharedSecretMap[homeserver]
|
||||||
config.GroupMe.OSName = "Go GroupMe bridge"
|
return hasSecret
|
||||||
config.GroupMe.BrowserName = "mx-gm"
|
|
||||||
config.Bridge.setDefaults()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load(path string) (*Config, error) {
|
func (config *Config) CanDoublePuppetBackfill(userID id.UserID) bool {
|
||||||
data, err := ioutil.ReadFile(path)
|
if !config.Bridge.HistorySync.DoublePuppetBackfill {
|
||||||
if err != nil {
|
return false
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
_, homeserver, _ := userID.Parse()
|
||||||
var config = &Config{}
|
// Batch sending can only use local users, so don't allow double puppets on other servers.
|
||||||
config.setDefaults()
|
if homeserver != config.Homeserver.Domain && config.Homeserver.Software != bridgeconfig.SoftwareHungry {
|
||||||
err = yaml.Unmarshal(data, config)
|
return false
|
||||||
return config, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) Save(path string) error {
|
|
||||||
data, err := yaml.Marshal(config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return ioutil.WriteFile(path, data, 0600)
|
return true
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) MakeAppService() (*appservice.AppService, error) {
|
|
||||||
as := appservice.Create()
|
|
||||||
as.HomeserverDomain = config.Homeserver.Domain
|
|
||||||
as.HomeserverURL = config.Homeserver.Address
|
|
||||||
as.Host.Hostname = config.AppService.Hostname
|
|
||||||
as.Host.Port = config.AppService.Port
|
|
||||||
var err error
|
|
||||||
as.Registration, err = config.GetRegistration()
|
|
||||||
return as, err
|
|
||||||
}
|
}
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (config *Config) NewRegistration() (*appservice.Registration, error) {
|
|
||||||
registration := appservice.CreateRegistration()
|
|
||||||
|
|
||||||
err := config.copyToRegistration(registration)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
config.AppService.ASToken = registration.AppToken
|
|
||||||
config.AppService.HSToken = registration.ServerToken
|
|
||||||
|
|
||||||
// Workaround for https://github.com/matrix-org/synapse/pull/5758
|
|
||||||
registration.SenderLocalpart = appservice.RandomString(32)
|
|
||||||
botRegex := regexp.MustCompile(fmt.Sprintf("^@%s:%s$", config.AppService.Bot.Username, config.Homeserver.Domain))
|
|
||||||
registration.Namespaces.RegisterUserIDs(botRegex, true)
|
|
||||||
|
|
||||||
return registration, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) GetRegistration() (*appservice.Registration, error) {
|
|
||||||
registration := appservice.CreateRegistration()
|
|
||||||
|
|
||||||
err := config.copyToRegistration(registration)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
registration.AppToken = config.AppService.ASToken
|
|
||||||
registration.ServerToken = config.AppService.HSToken
|
|
||||||
return registration, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (config *Config) copyToRegistration(registration *appservice.Registration) error {
|
|
||||||
registration.ID = config.AppService.ID
|
|
||||||
registration.URL = config.AppService.Address
|
|
||||||
falseVal := false
|
|
||||||
registration.RateLimited = &falseVal
|
|
||||||
registration.SenderLocalpart = config.AppService.Bot.Username
|
|
||||||
|
|
||||||
userIDRegex, err := regexp.Compile(fmt.Sprintf("^@%s:%s$",
|
|
||||||
config.Bridge.FormatUsername("[0-9]+"),
|
|
||||||
config.Homeserver.Domain))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
registration.Namespaces.RegisterUserIDs(userIDRegex, true)
|
|
||||||
return nil
|
|
||||||
}
|
|
138
config/upgrade.go
Normal file
138
config/upgrade.go
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||||
|
"maunium.net/go/mautrix/util"
|
||||||
|
up "maunium.net/go/mautrix/util/configupgrade"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DoUpgrade(helper *up.Helper) {
|
||||||
|
bridgeconfig.Upgrader.DoUpgrade(helper)
|
||||||
|
|
||||||
|
helper.Copy(up.Str|up.Null, "segment_key")
|
||||||
|
|
||||||
|
helper.Copy(up.Bool, "metrics", "enabled")
|
||||||
|
helper.Copy(up.Str, "metrics", "listen")
|
||||||
|
|
||||||
|
helper.Copy(up.Int, "groupme", "connection_timeout")
|
||||||
|
helper.Copy(up.Bool, "groupme", "fetch_message_on_timeout")
|
||||||
|
|
||||||
|
helper.Copy(up.Str, "bridge", "username_template")
|
||||||
|
helper.Copy(up.Str, "bridge", "displayname_template")
|
||||||
|
helper.Copy(up.Bool, "bridge", "personal_filtering_spaces")
|
||||||
|
helper.Copy(up.Bool, "bridge", "delivery_receipts")
|
||||||
|
helper.Copy(up.Bool, "bridge", "message_status_events")
|
||||||
|
helper.Copy(up.Bool, "bridge", "message_error_notices")
|
||||||
|
|
||||||
|
helper.Copy(up.Int, "bridge", "portal_message_buffer")
|
||||||
|
helper.Copy(up.Bool, "bridge", "call_start_notices")
|
||||||
|
helper.Copy(up.Bool, "bridge", "identity_change_notices")
|
||||||
|
helper.Copy(up.Bool, "bridge", "user_avatar_sync")
|
||||||
|
helper.Copy(up.Bool, "bridge", "bridge_matrix_leave")
|
||||||
|
helper.Copy(up.Bool, "bridge", "sync_with_custom_puppets")
|
||||||
|
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list")
|
||||||
|
helper.Copy(up.Bool, "bridge", "default_bridge_receipts")
|
||||||
|
helper.Copy(up.Bool, "bridge", "default_bridge_presence")
|
||||||
|
helper.Copy(up.Bool, "bridge", "send_presence_on_typing")
|
||||||
|
helper.Copy(up.Bool, "bridge", "force_active_delivery_receipts")
|
||||||
|
helper.Copy(up.Map, "bridge", "double_puppet_server_map")
|
||||||
|
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
|
||||||
|
if legacySecret, ok := helper.Get(up.Str, "bridge", "login_shared_secret"); ok && len(legacySecret) > 0 {
|
||||||
|
baseNode := helper.GetBaseNode("bridge", "login_shared_secret_map")
|
||||||
|
baseNode.Map[helper.GetBase("homeserver", "domain")] = up.StringNode(legacySecret)
|
||||||
|
baseNode.UpdateContent()
|
||||||
|
} else {
|
||||||
|
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
|
||||||
|
}
|
||||||
|
helper.Copy(up.Bool, "bridge", "private_chat_portal_meta")
|
||||||
|
helper.Copy(up.Bool, "bridge", "parallel_member_sync")
|
||||||
|
helper.Copy(up.Bool, "bridge", "bridge_notices")
|
||||||
|
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
|
||||||
|
helper.Copy(up.Bool, "bridge", "mute_bridging")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "archive_tag")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "pinned_tag")
|
||||||
|
helper.Copy(up.Bool, "bridge", "tag_only_on_create")
|
||||||
|
helper.Copy(up.Bool, "bridge", "enable_status_broadcast")
|
||||||
|
helper.Copy(up.Bool, "bridge", "disable_status_broadcast_send")
|
||||||
|
helper.Copy(up.Bool, "bridge", "mute_status_broadcast")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "status_broadcast_tag")
|
||||||
|
helper.Copy(up.Bool, "bridge", "whatsapp_thumbnail")
|
||||||
|
helper.Copy(up.Bool, "bridge", "allow_user_invite")
|
||||||
|
helper.Copy(up.Str, "bridge", "command_prefix")
|
||||||
|
helper.Copy(up.Bool, "bridge", "federate_rooms")
|
||||||
|
helper.Copy(up.Bool, "bridge", "disappearing_messages_in_groups")
|
||||||
|
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
|
||||||
|
helper.Copy(up.Bool, "bridge", "crash_on_stream_replaced")
|
||||||
|
helper.Copy(up.Bool, "bridge", "url_previews")
|
||||||
|
helper.Copy(up.Bool, "bridge", "caption_in_message")
|
||||||
|
helper.Copy(up.Bool, "bridge", "send_whatsapp_edits")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline")
|
||||||
|
|
||||||
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
|
||||||
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_connected")
|
||||||
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
||||||
|
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "appservice")
|
||||||
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "receive")
|
||||||
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "send")
|
||||||
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "share")
|
||||||
|
|
||||||
|
legacyKeyShareAllow, ok := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "allow")
|
||||||
|
if ok {
|
||||||
|
helper.Set(up.Bool, legacyKeyShareAllow, "bridge", "encryption", "allow_key_sharing")
|
||||||
|
legacyKeyShareRequireCS, legacyOK1 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_cross_signing")
|
||||||
|
legacyKeyShareRequireVerification, legacyOK2 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_verification")
|
||||||
|
if legacyOK1 && legacyOK2 && legacyKeyShareRequireVerification == "false" && legacyKeyShareRequireCS == "false" {
|
||||||
|
helper.Set(up.Str, "unverified", "bridge", "encryption", "verification_levels", "share")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "allow_key_sharing")
|
||||||
|
}
|
||||||
|
|
||||||
|
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
|
||||||
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
|
||||||
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
|
||||||
|
if prefix, ok := helper.Get(up.Str, "appservice", "provisioning", "prefix"); ok {
|
||||||
|
helper.Set(up.Str, strings.TrimSuffix(prefix, "/v1"), "bridge", "provisioning", "prefix")
|
||||||
|
} else {
|
||||||
|
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
|
||||||
|
}
|
||||||
|
if secret, ok := helper.Get(up.Str, "appservice", "provisioning", "shared_secret"); ok && secret != "generate" {
|
||||||
|
helper.Set(up.Str, secret, "bridge", "provisioning", "shared_secret")
|
||||||
|
} else if secret, ok = helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
||||||
|
sharedSecret := util.RandomString(64)
|
||||||
|
helper.Set(up.Str, sharedSecret, "bridge", "provisioning", "shared_secret")
|
||||||
|
} else {
|
||||||
|
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
|
||||||
|
}
|
||||||
|
helper.Copy(up.Map, "bridge", "permissions")
|
||||||
|
helper.Copy(up.Bool, "bridge", "relay", "enabled")
|
||||||
|
helper.Copy(up.Bool, "bridge", "relay", "admin_only")
|
||||||
|
helper.Copy(up.Map, "bridge", "relay", "message_formats")
|
||||||
|
}
|
||||||
|
|
||||||
|
var SpacedBlocks = [][]string{
|
||||||
|
{"homeserver", "software"},
|
||||||
|
{"appservice"},
|
||||||
|
{"appservice", "hostname"},
|
||||||
|
{"appservice", "database"},
|
||||||
|
{"appservice", "id"},
|
||||||
|
{"appservice", "as_token"},
|
||||||
|
{"segment_key"},
|
||||||
|
{"metrics"},
|
||||||
|
{"groupme"},
|
||||||
|
{"bridge"},
|
||||||
|
{"bridge", "command_prefix"},
|
||||||
|
{"bridge", "management_room_text"},
|
||||||
|
{"bridge", "encryption"},
|
||||||
|
{"bridge", "provisioning"},
|
||||||
|
{"bridge", "permissions"},
|
||||||
|
{"bridge", "relay"},
|
||||||
|
{"logging"},
|
||||||
|
}
|
335
crypto.go
335
crypto.go
@ -1,335 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//go:build cgo && !nocrypto
|
|
||||||
// +build cgo,!nocrypto
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"runtime/debug"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"maunium.net/go/maulogger/v2"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
|
||||||
"maunium.net/go/mautrix/crypto"
|
|
||||||
"maunium.net/go/mautrix/event"
|
|
||||||
"maunium.net/go/mautrix/id"
|
|
||||||
|
|
||||||
"github.com/beeper/groupme/database"
|
|
||||||
)
|
|
||||||
|
|
||||||
var NoSessionFound = crypto.NoSessionFound
|
|
||||||
|
|
||||||
var levelTrace = maulogger.Level{
|
|
||||||
Name: "Trace",
|
|
||||||
Severity: -10,
|
|
||||||
Color: -1,
|
|
||||||
}
|
|
||||||
|
|
||||||
type CryptoHelper struct {
|
|
||||||
bridge *Bridge
|
|
||||||
client *mautrix.Client
|
|
||||||
mach *crypto.OlmMachine
|
|
||||||
store *database.SQLCryptoStore
|
|
||||||
log maulogger.Logger
|
|
||||||
baseLog maulogger.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCryptoHelper(bridge *Bridge) Crypto {
|
|
||||||
if !bridge.Config.Bridge.Encryption.Allow {
|
|
||||||
bridge.Log.Debugln("Bridge built with end-to-bridge encryption, but disabled in config")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
baseLog := bridge.Log.Sub("Crypto")
|
|
||||||
return &CryptoHelper{
|
|
||||||
bridge: bridge,
|
|
||||||
log: baseLog.Sub("Helper"),
|
|
||||||
baseLog: baseLog,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) Init() error {
|
|
||||||
helper.log.Debugln("Initializing end-to-bridge encryption...")
|
|
||||||
|
|
||||||
helper.store = database.NewSQLCryptoStore(helper.bridge.DB, helper.bridge.AS.BotMXID(),
|
|
||||||
fmt.Sprintf("@%s:%s", helper.bridge.Config.Bridge.FormatUsername("%"), helper.bridge.AS.HomeserverDomain))
|
|
||||||
|
|
||||||
var err error
|
|
||||||
helper.client, err = helper.loginBot()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.log.Debugln("Logged in as bridge bot with device ID", helper.client.DeviceID)
|
|
||||||
logger := &cryptoLogger{helper.baseLog}
|
|
||||||
stateStore := &cryptoStateStore{helper.bridge}
|
|
||||||
helper.mach = crypto.NewOlmMachine(helper.client, logger, helper.store, stateStore)
|
|
||||||
helper.mach.AllowKeyShare = helper.allowKeyShare
|
|
||||||
|
|
||||||
helper.client.Syncer = &cryptoSyncer{helper.mach}
|
|
||||||
helper.client.Store = &cryptoClientStore{helper.store}
|
|
||||||
|
|
||||||
return helper.mach.Load()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) allowKeyShare(device *crypto.DeviceIdentity, info event.RequestedKeyInfo) *crypto.KeyShareRejection {
|
|
||||||
cfg := helper.bridge.Config.Bridge.Encryption.KeySharing
|
|
||||||
if !cfg.Allow {
|
|
||||||
return &crypto.KeyShareRejectNoResponse
|
|
||||||
} else if device.Trust == crypto.TrustStateBlacklisted {
|
|
||||||
return &crypto.KeyShareRejectBlacklisted
|
|
||||||
} else if device.Trust == crypto.TrustStateVerified || !cfg.RequireVerification {
|
|
||||||
portal := helper.bridge.GetPortalByMXID(info.RoomID)
|
|
||||||
if portal == nil {
|
|
||||||
helper.log.Debugfln("Rejecting key request for %s from %s/%s: room is not a portal", info.SessionID, device.UserID, device.DeviceID)
|
|
||||||
return &crypto.KeyShareRejection{Code: event.RoomKeyWithheldUnavailable, Reason: "Requested room is not a portal room"}
|
|
||||||
}
|
|
||||||
user := helper.bridge.GetUserByMXID(device.UserID)
|
|
||||||
if !user.Admin && !user.IsInPortal(portal.Key) {
|
|
||||||
helper.log.Debugfln("Rejecting key request for %s from %s/%s: user is not in portal", info.SessionID, device.UserID, device.DeviceID)
|
|
||||||
return &crypto.KeyShareRejection{Code: event.RoomKeyWithheldUnauthorized, Reason: "You're not in that portal"}
|
|
||||||
}
|
|
||||||
helper.log.Debugfln("Accepting key request for %s from %s/%s", info.SessionID, device.UserID, device.DeviceID)
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
return &crypto.KeyShareRejectUnverified
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) loginBot() (*mautrix.Client, error) {
|
|
||||||
deviceID := helper.store.FindDeviceID()
|
|
||||||
if len(deviceID) > 0 {
|
|
||||||
helper.log.Debugln("Found existing device ID for bot in database:", deviceID)
|
|
||||||
}
|
|
||||||
client, err := mautrix.NewClient(helper.bridge.AS.HomeserverURL, "", "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to initialize client: %w", err)
|
|
||||||
}
|
|
||||||
client.Logger = helper.baseLog.Sub("Bot")
|
|
||||||
client.Client = helper.bridge.AS.HTTPClient
|
|
||||||
client.DefaultHTTPRetries = helper.bridge.AS.DefaultHTTPRetries
|
|
||||||
flows, err := client.GetLoginFlows()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get supported login flows: %w", err)
|
|
||||||
}
|
|
||||||
if !flows.HasFlow(mautrix.AuthTypeHalfyAppservice) {
|
|
||||||
return nil, fmt.Errorf("homeserver does not support appservice login")
|
|
||||||
}
|
|
||||||
// if !flows.HasFlow(mautrix.AuthTypeAppservice) {
|
|
||||||
// // TODO after synapse 1.22, turn this into an error
|
|
||||||
// helper.log.Warnln("Encryption enabled in config, but homeserver does not advertise appservice login")
|
|
||||||
// //return nil, fmt.Errorf("homeserver does not support appservice login")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// We set the API token to the AS token here to authenticate the appservice login
|
|
||||||
// It'll get overridden after the login
|
|
||||||
client.AccessToken = helper.bridge.AS.Registration.AppToken
|
|
||||||
resp, err := client.Login(&mautrix.ReqLogin{
|
|
||||||
Type: mautrix.AuthTypeHalfyAppservice,
|
|
||||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())},
|
|
||||||
DeviceID: deviceID,
|
|
||||||
InitialDeviceDisplayName: "GroupMe Bridge",
|
|
||||||
StoreCredentials: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to log in as bridge bot: %w", err)
|
|
||||||
}
|
|
||||||
helper.store.DeviceID = resp.DeviceID
|
|
||||||
return client, nil
|
|
||||||
|
|
||||||
// client.AccessToken = helper.bridge.AS.Registration.AppToken
|
|
||||||
// resp, err := client.Login(&mautrix.ReqLogin{
|
|
||||||
// Type: mautrix.AuthTypeAppservice,
|
|
||||||
// Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())},
|
|
||||||
// DeviceID: deviceID,
|
|
||||||
// InitialDeviceDisplayName: "GroupMe Bridge",
|
|
||||||
// StoreCredentials: true,
|
|
||||||
// })
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, fmt.Errorf("failed to log in as bridge bot: %w", err)
|
|
||||||
// }
|
|
||||||
// if len(deviceID) == 0 {
|
|
||||||
// helper.store.DeviceID = resp.DeviceID
|
|
||||||
// }
|
|
||||||
// return client, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) Start() {
|
|
||||||
helper.log.Debugln("Starting syncer for receiving to-device messages")
|
|
||||||
err := helper.client.Sync()
|
|
||||||
if err != nil {
|
|
||||||
helper.log.Errorln("Fatal error syncing:", err)
|
|
||||||
} else {
|
|
||||||
helper.log.Infoln("Bridge bot to-device syncer stopped without error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) Stop() {
|
|
||||||
helper.log.Debugln("CryptoHelper.Stop() called, stopping bridge bot sync")
|
|
||||||
helper.client.StopSync()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) Decrypt(evt *event.Event) (*event.Event, error) {
|
|
||||||
return helper.mach.DecryptMegolmEvent(evt)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) Encrypt(roomID id.RoomID, evtType event.Type, content event.Content) (*event.EncryptedEventContent, error) {
|
|
||||||
encrypted, err := helper.mach.EncryptMegolmEvent(roomID, evtType, &content)
|
|
||||||
if err != nil {
|
|
||||||
if err != crypto.SessionExpired && err != crypto.SessionNotShared && err != crypto.NoGroupSession {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
helper.log.Debugfln("Got %v while encrypting event for %s, sharing group session and trying again...", err, roomID)
|
|
||||||
users, err := helper.store.GetRoomMembers(roomID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get room member list: %w", err)
|
|
||||||
}
|
|
||||||
err = helper.mach.ShareGroupSession(roomID, users)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to share group session: %w", err)
|
|
||||||
}
|
|
||||||
encrypted, err = helper.mach.EncryptMegolmEvent(roomID, evtType, &content)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to encrypt event after re-sharing group session: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return encrypted, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) WaitForSession(roomID id.RoomID, senderKey id.SenderKey, sessionID id.SessionID, timeout time.Duration) bool {
|
|
||||||
return helper.mach.WaitForSession(roomID, senderKey, sessionID, timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) ResetSession(roomID id.RoomID) {
|
|
||||||
err := helper.mach.CryptoStore.RemoveOutboundGroupSession(roomID)
|
|
||||||
if err != nil {
|
|
||||||
helper.log.Debugfln("Error manually removing outbound group session in %s: %v", roomID, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (helper *CryptoHelper) HandleMemberEvent(evt *event.Event) {
|
|
||||||
helper.mach.HandleMemberEvent(evt)
|
|
||||||
}
|
|
||||||
|
|
||||||
type cryptoSyncer struct {
|
|
||||||
*crypto.OlmMachine
|
|
||||||
}
|
|
||||||
|
|
||||||
func (syncer *cryptoSyncer) ProcessResponse(resp *mautrix.RespSync, since string) error {
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
if err := recover(); err != nil {
|
|
||||||
syncer.Log.Error("Processing sync response (%s) panicked: %v\n%s", since, err, debug.Stack())
|
|
||||||
}
|
|
||||||
done <- struct{}{}
|
|
||||||
}()
|
|
||||||
syncer.Log.Trace("Starting sync response handling (%s)", since)
|
|
||||||
syncer.ProcessSyncResponse(resp, since)
|
|
||||||
syncer.Log.Trace("Successfully handled sync response (%s)", since)
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-done:
|
|
||||||
case <-time.After(30 * time.Second):
|
|
||||||
syncer.Log.Warn("Handling sync response (%s) is taking unusually long", since)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (syncer *cryptoSyncer) OnFailedSync(_ *mautrix.RespSync, err error) (time.Duration, error) {
|
|
||||||
syncer.Log.Error("Error /syncing, waiting 10 seconds: %v", err)
|
|
||||||
return 10 * time.Second, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (syncer *cryptoSyncer) GetFilterJSON(_ id.UserID) *mautrix.Filter {
|
|
||||||
everything := []event.Type{{Type: "*"}}
|
|
||||||
return &mautrix.Filter{
|
|
||||||
Presence: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
AccountData: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
Room: mautrix.RoomFilter{
|
|
||||||
IncludeLeave: false,
|
|
||||||
Ephemeral: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
AccountData: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
State: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
Timeline: mautrix.FilterPart{NotTypes: everything},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type cryptoLogger struct {
|
|
||||||
int maulogger.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Error(message string, args ...interface{}) {
|
|
||||||
c.int.Errorfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Warn(message string, args ...interface{}) {
|
|
||||||
c.int.Warnfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Debug(message string, args ...interface{}) {
|
|
||||||
c.int.Debugfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Trace(message string, args ...interface{}) {
|
|
||||||
c.int.Logfln(levelTrace, message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
type cryptoClientStore struct {
|
|
||||||
int *database.SQLCryptoStore
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cryptoClientStore) SaveFilterID(_ id.UserID, _ string) {}
|
|
||||||
func (c cryptoClientStore) LoadFilterID(_ id.UserID) string { return "" }
|
|
||||||
func (c cryptoClientStore) SaveRoom(_ *mautrix.Room) {}
|
|
||||||
func (c cryptoClientStore) LoadRoom(_ id.RoomID) *mautrix.Room { return nil }
|
|
||||||
|
|
||||||
func (c cryptoClientStore) SaveNextBatch(_ id.UserID, nextBatchToken string) {
|
|
||||||
c.int.PutNextBatch(nextBatchToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c cryptoClientStore) LoadNextBatch(_ id.UserID) string {
|
|
||||||
return c.int.GetNextBatch()
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ mautrix.Storer = (*cryptoClientStore)(nil)
|
|
||||||
|
|
||||||
type cryptoStateStore struct {
|
|
||||||
bridge *Bridge
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ crypto.StateStore = (*cryptoStateStore)(nil)
|
|
||||||
|
|
||||||
func (c *cryptoStateStore) IsEncrypted(id id.RoomID) bool {
|
|
||||||
portal := c.bridge.GetPortalByMXID(id)
|
|
||||||
if portal != nil {
|
|
||||||
return portal.Encrypted
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoStateStore) FindSharedRooms(id id.UserID) []id.RoomID {
|
|
||||||
return c.bridge.StateStore.FindSharedRooms(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoStateStore) GetEncryptionEvent(id.RoomID) *event.EncryptionEventContent {
|
|
||||||
// TODO implement
|
|
||||||
return nil
|
|
||||||
}
|
|
177
custompuppet.go
177
custompuppet.go
@ -21,6 +21,7 @@ import (
|
|||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
@ -42,7 +43,7 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
|||||||
puppet.CustomMXID = mxid
|
puppet.CustomMXID = mxid
|
||||||
puppet.AccessToken = accessToken
|
puppet.AccessToken = accessToken
|
||||||
|
|
||||||
err := puppet.StartCustomMXID()
|
err := puppet.StartCustomMXID(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -53,7 +54,6 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
|||||||
if len(puppet.CustomMXID) > 0 {
|
if len(puppet.CustomMXID) > 0 {
|
||||||
puppet.bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
puppet.bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||||
}
|
}
|
||||||
puppet.EnablePresence = puppet.bridge.Config.Bridge.DefaultBridgePresence
|
|
||||||
puppet.EnableReceipts = puppet.bridge.Config.Bridge.DefaultBridgeReceipts
|
puppet.EnableReceipts = puppet.bridge.Config.Bridge.DefaultBridgeReceipts
|
||||||
puppet.bridge.AS.StateStore.MarkRegistered(puppet.CustomMXID)
|
puppet.bridge.AS.StateStore.MarkRegistered(puppet.CustomMXID)
|
||||||
puppet.Update()
|
puppet.Update()
|
||||||
@ -62,31 +62,72 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID) (string, error) {
|
func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID) (string, error) {
|
||||||
|
_, homeserver, _ := mxid.Parse()
|
||||||
puppet.log.Debugfln("Logging into %s with shared secret", mxid)
|
puppet.log.Debugfln("Logging into %s with shared secret", mxid)
|
||||||
mac := hmac.New(sha512.New, []byte(puppet.bridge.Config.Bridge.LoginSharedSecret))
|
loginSecret := puppet.bridge.Config.Bridge.LoginSharedSecretMap[homeserver]
|
||||||
mac.Write([]byte(mxid))
|
client, err := puppet.bridge.newDoublePuppetClient(mxid, "")
|
||||||
resp, err := puppet.bridge.AS.BotClient().Login(&mautrix.ReqLogin{
|
if err != nil {
|
||||||
Type: mautrix.AuthTypePassword,
|
return "", fmt.Errorf("failed to create mautrix client to log in: %v", err)
|
||||||
|
}
|
||||||
|
req := mautrix.ReqLogin{
|
||||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(mxid)},
|
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(mxid)},
|
||||||
Password: hex.EncodeToString(mac.Sum(nil)),
|
DeviceID: "GroupMe Bridge",
|
||||||
DeviceID: "WhatsApp Bridge",
|
InitialDeviceDisplayName: "GroupMe Bridge",
|
||||||
InitialDeviceDisplayName: "WhatsApp Bridge",
|
}
|
||||||
})
|
if loginSecret == "appservice" {
|
||||||
|
client.AccessToken = puppet.bridge.AS.Registration.AppToken
|
||||||
|
req.Type = mautrix.AuthTypeAppservice
|
||||||
|
} else {
|
||||||
|
mac := hmac.New(sha512.New, []byte(loginSecret))
|
||||||
|
mac.Write([]byte(mxid))
|
||||||
|
req.Password = hex.EncodeToString(mac.Sum(nil))
|
||||||
|
req.Type = mautrix.AuthTypePassword
|
||||||
|
}
|
||||||
|
resp, err := client.Login(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return resp.AccessToken, nil
|
return resp.AccessToken, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (br *GMBridge) newDoublePuppetClient(mxid id.UserID, accessToken string) (*mautrix.Client, error) {
|
||||||
|
_, homeserver, err := mxid.Parse()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
homeserverURL, found := br.Config.Bridge.DoublePuppetServerMap[homeserver]
|
||||||
|
if !found {
|
||||||
|
if homeserver == br.AS.HomeserverDomain {
|
||||||
|
homeserverURL = br.AS.HomeserverURL
|
||||||
|
} else if br.Config.Bridge.DoublePuppetAllowDiscovery {
|
||||||
|
resp, err := mautrix.DiscoverClientAPI(homeserver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to find homeserver URL for %s: %v", homeserver, err)
|
||||||
|
}
|
||||||
|
homeserverURL = resp.Homeserver.BaseURL
|
||||||
|
br.Log.Debugfln("Discovered URL %s for %s to enable double puppeting for %s", homeserverURL, homeserver, mxid)
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("double puppeting from %s is not allowed", homeserver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client, err := mautrix.NewClient(homeserverURL, mxid, accessToken)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
client.Logger = br.AS.Log.Sub(mxid.String())
|
||||||
|
client.Client = br.AS.HTTPClient
|
||||||
|
client.DefaultHTTPRetries = br.AS.DefaultHTTPRetries
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) newCustomIntent() (*appservice.IntentAPI, error) {
|
func (puppet *Puppet) newCustomIntent() (*appservice.IntentAPI, error) {
|
||||||
if len(puppet.CustomMXID) == 0 {
|
if len(puppet.CustomMXID) == 0 {
|
||||||
return nil, ErrNoCustomMXID
|
return nil, ErrNoCustomMXID
|
||||||
}
|
}
|
||||||
client, err := mautrix.NewClient(puppet.bridge.AS.HomeserverURL, puppet.CustomMXID, puppet.AccessToken)
|
client, err := puppet.bridge.newDoublePuppetClient(puppet.CustomMXID, puppet.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client.Logger = puppet.bridge.AS.Log.Sub(string(puppet.CustomMXID))
|
|
||||||
client.Syncer = puppet
|
client.Syncer = puppet
|
||||||
client.Store = puppet
|
client.Store = puppet
|
||||||
|
|
||||||
@ -102,11 +143,10 @@ func (puppet *Puppet) clearCustomMXID() {
|
|||||||
puppet.CustomMXID = ""
|
puppet.CustomMXID = ""
|
||||||
puppet.AccessToken = ""
|
puppet.AccessToken = ""
|
||||||
puppet.customIntent = nil
|
puppet.customIntent = nil
|
||||||
puppet.customTypingIn = nil
|
|
||||||
puppet.customUser = nil
|
puppet.customUser = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) StartCustomMXID() error {
|
func (puppet *Puppet) StartCustomMXID(reloginOnFail bool) error {
|
||||||
if len(puppet.CustomMXID) == 0 {
|
if len(puppet.CustomMXID) == 0 {
|
||||||
puppet.clearCustomMXID()
|
puppet.clearCustomMXID()
|
||||||
return nil
|
return nil
|
||||||
@ -118,15 +158,16 @@ func (puppet *Puppet) StartCustomMXID() error {
|
|||||||
}
|
}
|
||||||
resp, err := intent.Whoami()
|
resp, err := intent.Whoami()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.clearCustomMXID()
|
if !reloginOnFail || (errors.Is(err, mautrix.MUnknownToken) && !puppet.tryRelogin(err, "initializing double puppeting")) {
|
||||||
return err
|
puppet.clearCustomMXID()
|
||||||
}
|
return err
|
||||||
if resp.UserID != puppet.CustomMXID {
|
}
|
||||||
|
intent.AccessToken = puppet.AccessToken
|
||||||
|
} else if resp.UserID != puppet.CustomMXID {
|
||||||
puppet.clearCustomMXID()
|
puppet.clearCustomMXID()
|
||||||
return ErrMismatchingMXID
|
return ErrMismatchingMXID
|
||||||
}
|
}
|
||||||
puppet.customIntent = intent
|
puppet.customIntent = intent
|
||||||
puppet.customTypingIn = make(map[id.RoomID]bool)
|
|
||||||
puppet.customUser = puppet.bridge.GetUserByMXID(puppet.CustomMXID)
|
puppet.customUser = puppet.bridge.GetUserByMXID(puppet.CustomMXID)
|
||||||
puppet.startSyncing()
|
puppet.startSyncing()
|
||||||
return nil
|
return nil
|
||||||
@ -154,16 +195,13 @@ func (puppet *Puppet) stopSyncing() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
||||||
if !puppet.customUser.IsConnected() {
|
if !puppet.customUser.IsLoggedIn() {
|
||||||
puppet.log.Debugln("Skipping sync processing: custom user not connected to whatsapp")
|
puppet.log.Debugln("Skipping sync processing: custom user not connected to GroupMe")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for roomID, events := range resp.Rooms.Join {
|
for roomID, events := range resp.Rooms.Join {
|
||||||
portal := puppet.bridge.GetPortalByMXID(roomID)
|
|
||||||
if portal == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, evt := range events.Ephemeral.Events {
|
for _, evt := range events.Ephemeral.Events {
|
||||||
|
evt.RoomID = roomID
|
||||||
err := evt.Content.ParseRaw(evt.Type)
|
err := evt.Content.ParseRaw(evt.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
@ -171,85 +209,40 @@ func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
|||||||
switch evt.Type {
|
switch evt.Type {
|
||||||
case event.EphemeralEventReceipt:
|
case event.EphemeralEventReceipt:
|
||||||
if puppet.EnableReceipts {
|
if puppet.EnableReceipts {
|
||||||
go puppet.handleReceiptEvent(portal, evt)
|
go puppet.bridge.MatrixHandler.HandleReceipt(evt)
|
||||||
}
|
}
|
||||||
case event.EphemeralEventTyping:
|
case event.EphemeralEventTyping:
|
||||||
go puppet.handleTypingEvent(portal, evt)
|
go puppet.bridge.MatrixHandler.HandleTyping(evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if puppet.EnablePresence {
|
|
||||||
for _, evt := range resp.Presence.Events {
|
|
||||||
if evt.Sender != puppet.CustomMXID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err := evt.Content.ParseRaw(evt.Type)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
go puppet.handlePresenceEvent(evt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) handlePresenceEvent(event *event.Event) {
|
func (puppet *Puppet) tryRelogin(cause error, action string) bool {
|
||||||
// presence := whatsapp.PresenceAvailable
|
if !puppet.bridge.Config.CanAutoDoublePuppet(puppet.CustomMXID) {
|
||||||
// if event.Content.Raw["presence"].(string) != "online" {
|
return false
|
||||||
// presence = whatsapp.PresenceUnavailable
|
}
|
||||||
// puppet.customUser.log.Debugln("Marking offline")
|
puppet.log.Debugfln("Trying to relogin after '%v' while %s", cause, action)
|
||||||
// } else {
|
accessToken, err := puppet.loginWithSharedSecret(puppet.CustomMXID)
|
||||||
// puppet.customUser.log.Debugln("Marking online")
|
if err != nil {
|
||||||
// }
|
puppet.log.Errorfln("Failed to relogin after '%v' while %s: %v", cause, action, err)
|
||||||
// _, err := puppet.customUser.Conn.Presence("", presence)
|
return false
|
||||||
// if err != nil {
|
}
|
||||||
// puppet.customUser.log.Warnln("Failed to set presence:", err)
|
puppet.log.Infofln("Successfully relogined after '%v' while %s", cause, action)
|
||||||
// }
|
puppet.AccessToken = accessToken
|
||||||
}
|
return true
|
||||||
|
|
||||||
func (puppet *Puppet) handleReceiptEvent(portal *Portal, event *event.Event) {
|
|
||||||
// for eventID, receipts := range *event.Content.AsReceipt() {
|
|
||||||
// if _, ok := receipts.Read[puppet.CustomMXID]; !ok {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// message := puppet.bridge.DB.Message.GetByMXID(eventID)
|
|
||||||
// if message == nil {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// puppet.customUser.log.Debugfln("Marking %s/%s in %s/%s as read", message.JID, message.MXID, portal.Key.JID, portal.MXID)
|
|
||||||
// _, err := puppet.customUser.Conn.Read(portal.Key.JID, message.JID)
|
|
||||||
// if err != nil {
|
|
||||||
// puppet.customUser.log.Warnln("Error marking read:", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
func (puppet *Puppet) handleTypingEvent(portal *Portal, evt *event.Event) {
|
|
||||||
// isTyping := false
|
|
||||||
// for _, userID := range evt.Content.AsTyping().UserIDs {
|
|
||||||
// if userID == puppet.CustomMXID {
|
|
||||||
// isTyping = true
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if puppet.customTypingIn[evt.RoomID] != isTyping {
|
|
||||||
// puppet.customTypingIn[evt.RoomID] = isTyping
|
|
||||||
// presence := whatsapp.PresenceComposing
|
|
||||||
// if !isTyping {
|
|
||||||
// puppet.customUser.log.Debugfln("Marking not typing in %s/%s", portal.Key.JID, portal.MXID)
|
|
||||||
// presence = whatsapp.PresencePaused
|
|
||||||
// } else {
|
|
||||||
// puppet.customUser.log.Debugfln("Marking typing in %s/%s", portal.Key.JID, portal.MXID)
|
|
||||||
// }
|
|
||||||
// _, err := puppet.customUser.Conn.Presence(portal.Key.JID, presence)
|
|
||||||
// if err != nil {
|
|
||||||
// puppet.customUser.log.Warnln("Error setting typing:", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) OnFailedSync(_ *mautrix.RespSync, err error) (time.Duration, error) {
|
func (puppet *Puppet) OnFailedSync(_ *mautrix.RespSync, err error) (time.Duration, error) {
|
||||||
puppet.log.Warnln("Sync error:", err)
|
puppet.log.Warnln("Sync error:", err)
|
||||||
|
if errors.Is(err, mautrix.MUnknownToken) {
|
||||||
|
if !puppet.tryRelogin(err, "syncing") {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
puppet.customIntent.AccessToken = puppet.AccessToken
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
return 10 * time.Second, nil
|
return 10 * time.Second, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
//go:build cgo && !nocrypto
|
|
||||||
// +build cgo,!nocrypto
|
|
||||||
|
|
||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix/crypto"
|
|
||||||
"maunium.net/go/mautrix/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SQLCryptoStore struct {
|
|
||||||
*crypto.SQLCryptoStore
|
|
||||||
UserID id.UserID
|
|
||||||
GhostIDFormat string
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ crypto.Store = (*SQLCryptoStore)(nil)
|
|
||||||
|
|
||||||
func NewSQLCryptoStore(db *Database, userID id.UserID, ghostIDFormat string) *SQLCryptoStore {
|
|
||||||
raw, _ := db.DB.DB()
|
|
||||||
return &SQLCryptoStore{
|
|
||||||
SQLCryptoStore: crypto.NewSQLCryptoStore(raw, db.dialect, "", "",
|
|
||||||
[]byte("github.com/beeper/groupme"),
|
|
||||||
&cryptoLogger{db.log.Sub("CryptoStore")}),
|
|
||||||
UserID: userID,
|
|
||||||
GhostIDFormat: ghostIDFormat,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLCryptoStore) FindDeviceID() (deviceID id.DeviceID) {
|
|
||||||
err := store.DB.QueryRow("SELECT device_id FROM crypto_account WHERE account_id=$1", store.AccountID).Scan(&deviceID)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
|
||||||
store.Log.Warn("Failed to scan device ID: %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLCryptoStore) GetRoomMembers(roomID id.RoomID) (members []id.UserID, err error) {
|
|
||||||
var rows *sql.Rows
|
|
||||||
rows, err = store.DB.Query(`
|
|
||||||
SELECT user_id FROM mx_user_profile
|
|
||||||
WHERE room_id=$1
|
|
||||||
AND (membership='join' OR membership='invite')
|
|
||||||
AND user_id<>$2
|
|
||||||
AND user_id NOT LIKE $3
|
|
||||||
`, roomID, store.UserID, store.GhostIDFormat)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for rows.Next() {
|
|
||||||
var userID id.UserID
|
|
||||||
err := rows.Scan(&userID)
|
|
||||||
if err != nil {
|
|
||||||
store.Log.Warn("Failed to scan member in %s: %v", roomID, err)
|
|
||||||
} else {
|
|
||||||
members = append(members, userID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO merge this with the one in the parent package
|
|
||||||
type cryptoLogger struct {
|
|
||||||
int log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
var levelTrace = log.Level{
|
|
||||||
Name: "Trace",
|
|
||||||
Severity: -10,
|
|
||||||
Color: -1,
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Error(message string, args ...interface{}) {
|
|
||||||
c.int.Errorfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Warn(message string, args ...interface{}) {
|
|
||||||
c.int.Warnfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Debug(message string, args ...interface{}) {
|
|
||||||
c.int.Debugfln(message, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *cryptoLogger) Trace(message string, args ...interface{}) {
|
|
||||||
c.int.Logfln(levelTrace, message, args...)
|
|
||||||
}
|
|
@ -17,26 +17,21 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"errors"
|
||||||
"strings"
|
"net"
|
||||||
|
|
||||||
|
"github.com/lib/pq"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
"maunium.net/go/maulogger/v2"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
"gorm.io/driver/postgres"
|
|
||||||
"gorm.io/driver/sqlite"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/schema"
|
|
||||||
|
|
||||||
"github.com/beeper/groupme/database/upgrades"
|
"github.com/beeper/groupme/database/upgrades"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Database struct {
|
type Database struct {
|
||||||
*gorm.DB
|
*dbutil.Database
|
||||||
log log.Logger
|
|
||||||
dialect string
|
|
||||||
|
|
||||||
User *UserQuery
|
User *UserQuery
|
||||||
Portal *PortalQuery
|
Portal *PortalQuery
|
||||||
@ -45,92 +40,42 @@ type Database struct {
|
|||||||
Reaction *ReactionQuery
|
Reaction *ReactionQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
func New(baseDB *dbutil.Database, log maulogger.Logger) *Database {
|
||||||
|
db := &Database{Database: baseDB}
|
||||||
var conn gorm.Dialector
|
db.UpgradeTable = upgrades.Table
|
||||||
|
|
||||||
if dbType == "sqlite3" {
|
|
||||||
//_, _ = conn.Exec("PRAGMA foreign_keys = ON")
|
|
||||||
log.Fatalln("no sqlite for now only postgresql")
|
|
||||||
os.Exit(1)
|
|
||||||
conn = sqlite.Open(uri)
|
|
||||||
} else {
|
|
||||||
conn = postgres.Open(uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
gdb, err := gorm.Open(conn, &gorm.Config{
|
|
||||||
// Logger: logger.Default.LogMode(logger.Info),
|
|
||||||
// Logger: baseLog,
|
|
||||||
|
|
||||||
DisableForeignKeyConstraintWhenMigrating: true,
|
|
||||||
NamingStrategy: schema.NamingStrategy{
|
|
||||||
NameReplacer: strings.NewReplacer("JID", "Jid", "MXID", "Mxid"),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
panic("failed to connect database")
|
|
||||||
}
|
|
||||||
db := &Database{
|
|
||||||
DB: gdb,
|
|
||||||
log: baseLog.Sub("Database"),
|
|
||||||
dialect: dbType,
|
|
||||||
}
|
|
||||||
db.User = &UserQuery{
|
db.User = &UserQuery{
|
||||||
db: db,
|
db: db,
|
||||||
log: db.log.Sub("User"),
|
log: log.Sub("User"),
|
||||||
}
|
}
|
||||||
db.Portal = &PortalQuery{
|
db.Portal = &PortalQuery{
|
||||||
db: db,
|
db: db,
|
||||||
log: db.log.Sub("Portal"),
|
log: log.Sub("Portal"),
|
||||||
}
|
}
|
||||||
db.Puppet = &PuppetQuery{
|
db.Puppet = &PuppetQuery{
|
||||||
db: db,
|
db: db,
|
||||||
log: db.log.Sub("Puppet"),
|
log: log.Sub("Puppet"),
|
||||||
}
|
}
|
||||||
db.Message = &MessageQuery{
|
db.Message = &MessageQuery{
|
||||||
db: db,
|
db: db,
|
||||||
log: db.log.Sub("Message"),
|
log: log.Sub("Message"),
|
||||||
}
|
}
|
||||||
db.Reaction = &ReactionQuery{
|
db.Reaction = &ReactionQuery{
|
||||||
db: db,
|
db: db,
|
||||||
log: db.log.Sub("Reaction"),
|
log: log.Sub("Reaction"),
|
||||||
}
|
}
|
||||||
|
return db
|
||||||
return db, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Database) Init() error {
|
func isRetryableError(err error) bool {
|
||||||
println("actual upgrade")
|
if pqError := (&pq.Error{}); errors.As(err, &pqError) {
|
||||||
err := db.AutoMigrate(&Portal{}, &Puppet{})
|
switch pqError.Code.Class() {
|
||||||
if err != nil {
|
case "08", // Connection Exception
|
||||||
return err
|
"53", // Insufficient Resources (e.g. too many connections)
|
||||||
|
"57": // Operator Intervention (e.g. server restart)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if netError := (&net.OpError{}); errors.As(err, &netError) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
err = db.AutoMigrate(&Message{})
|
return false
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.AutoMigrate(&Reaction{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.AutoMigrate(&mxRegistered{}, &MxUserProfile{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.AutoMigrate(&User{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = db.AutoMigrate(&UserPortal{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return upgrades.Run(db.log.Sub("Upgrade"), db.dialect, db.DB)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Scannable interface {
|
|
||||||
Scan(...interface{}) error
|
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,15 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
|
|
||||||
"github.com/beeper/groupme/groupmeExt"
|
"github.com/karmanyaahm/groupme"
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MessageQuery struct {
|
type MessageQuery struct {
|
||||||
@ -36,101 +40,106 @@ func (mq *MessageQuery) New() *Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
getAllMessagesSelect = `
|
||||||
|
SELECT chat_gmid, chat_receiver, gmid, mxid, sender, timestamp, sent
|
||||||
|
FROM messages
|
||||||
|
`
|
||||||
|
getAllMessagesQuery = getAllMessagesSelect + `
|
||||||
|
WHERE chat_gmid=$1 AND chat_receiver=$2
|
||||||
|
`
|
||||||
|
getByGMIDQuery = getAllMessagesQuery + "AND jid=$3"
|
||||||
|
getByMXIDQuery = getAllMessagesSelect + "WHERE mxid=$1"
|
||||||
|
getLastMessageInChatQuery = getAllMessagesQuery + `
|
||||||
|
AND timestamp<=$3 AND sent=true
|
||||||
|
ORDER BY timestamp DESC
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
|
getFirstMessageInChatQuery = getAllMessagesQuery + `
|
||||||
|
AND sent=true
|
||||||
|
ORDER BY timestamp ASC
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
|
getMessagesBetweenQuery = getAllMessagesQuery + `
|
||||||
|
AND timestamp>$3 AND timestamp<=$4 AND sent=true
|
||||||
|
ORDER BY timestamp ASC
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) {
|
func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) {
|
||||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Find(&messages)
|
rows, err := mq.db.Query(getAllMessagesQuery, chat.GMID, chat.Receiver)
|
||||||
if ans.Error != nil || len(messages) == 0 {
|
if err != nil || rows == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
for rows.Next() {
|
||||||
|
messages = append(messages, mq.New().Scan(rows))
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.WhatsAppMessageID) *Message {
|
func (mq *MessageQuery) GetByGMID(chat PortalKey, gmid groupme.ID) *Message {
|
||||||
var message Message
|
return mq.maybeScan(mq.db.QueryRow(getByGMIDQuery, chat.GMID, chat.Receiver, gmid))
|
||||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ? AND jid = ?", chat.JID, chat.Receiver, jid).Limit(1).Find(&message)
|
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &message
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
|
func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
|
||||||
var message Message
|
return mq.maybeScan(mq.db.QueryRow(getByMXIDQuery, mxid))
|
||||||
ans := mq.db.Where("mxid = ?", mxid).Limit(1).Find(&message)
|
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &message
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
||||||
var message Message
|
return mq.GetLastInChatBefore(chat, time.Now().Add(60*time.Second))
|
||||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Order("timestamp desc").Limit(1).Find(&message)
|
}
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
|
func (mq *MessageQuery) GetLastInChatBefore(chat PortalKey, maxTimestamp time.Time) *Message {
|
||||||
|
return mq.maybeScan(mq.db.QueryRow(getLastMessageInChatQuery, chat.GMID, chat.Receiver, maxTimestamp.Unix()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MessageQuery) GetFirstInChat(chat PortalKey) *Message {
|
||||||
|
return mq.maybeScan(mq.db.QueryRow(getFirstMessageInChatQuery, chat.GMID, chat.Receiver))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MessageQuery) GetMessagesBetween(chat PortalKey, minTimestamp, maxTimestamp time.Time) (messages []*Message) {
|
||||||
|
rows, err := mq.db.Query(getMessagesBetweenQuery, chat.GMID, chat.Receiver, minTimestamp.Unix(), maxTimestamp.Unix())
|
||||||
|
if err != nil || rows == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &message
|
for rows.Next() {
|
||||||
|
messages = append(messages, mq.New().Scan(rows))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MessageQuery) maybeScan(row *sql.Row) *Message {
|
||||||
|
if row == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return mq.New().Scan(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
Chat PortalKey `gorm:"embedded;embeddedPrefix:chat_"`
|
Chat PortalKey
|
||||||
JID types.GroupMeID `gorm:"primaryKey;unique;notNull"`
|
GMID groupme.ID
|
||||||
MXID id.EventID `gorm:"primaryKey;unique;notNull"`
|
MXID id.EventID
|
||||||
Sender types.GroupMeID `gorm:"notNull"`
|
Sender groupme.ID
|
||||||
Timestamp uint64 `gorm:"notNull;default:0"`
|
Timestamp time.Time
|
||||||
Content *groupmeExt.Message `gorm:"type:TEXT;notNull"`
|
Sent bool
|
||||||
|
|
||||||
Portal Portal `gorm:"foreignKey:chat_jid,chat_receiver;references:jid,receiver;constraint:onDelete:CASCADE;"`
|
Portal Portal
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (msg *Message) Scan(row Scannable) *Message {
|
func (msg *Message) Scan(row dbutil.Scannable) *Message {
|
||||||
// var content []byte
|
var ts int64
|
||||||
// err := row.Scan(&msg.Chat.JID, &msg.Chat.Receiver, &msg.JID, &msg.MXID, &msg.Sender, &msg.Timestamp, &content)
|
err := row.Scan(&msg.Chat.GMID, &msg.Chat.Receiver, &msg.GMID, &msg.MXID, &msg.Sender, &ts, &msg.Sent)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// if err != sql.ErrNoRows {
|
if !errors.Is(err, sql.ErrNoRows) {
|
||||||
// msg.log.Errorln("Database scan failed:", err)
|
msg.log.Errorln("Database scan failed:", err)
|
||||||
// }
|
}
|
||||||
// return nil
|
return nil
|
||||||
// }
|
|
||||||
|
|
||||||
// msg.decodeBinaryContent(content)
|
|
||||||
|
|
||||||
// return msg
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (msg *Message) decodeBinaryContent(content []byte) {
|
|
||||||
// msg.Content = &waProto.Message{}
|
|
||||||
// reader := bytes.NewReader(content)
|
|
||||||
// dec := json.NewDecoder(reader)
|
|
||||||
// err := dec.Decode(msg.Content)
|
|
||||||
// if err != nil {
|
|
||||||
// msg.log.Warnln("Failed to decode message content:", err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func (msg *Message) encodeBinaryContent() []byte {
|
|
||||||
// var buf bytes.Buffer
|
|
||||||
// enc := json.NewEncoder(&buf)
|
|
||||||
// err := enc.Encode(msg.Content)
|
|
||||||
// if err != nil {
|
|
||||||
// msg.log.Warnln("Failed to encode message content:", err)
|
|
||||||
// }
|
|
||||||
// return buf.Bytes()
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (msg *Message) Insert() {
|
|
||||||
ans := msg.db.Create(&msg)
|
|
||||||
if ans.Error != nil {
|
|
||||||
msg.log.Warnfln("Failed to insert %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
|
||||||
}
|
}
|
||||||
}
|
if ts != 0 {
|
||||||
|
msg.Timestamp = time.Unix(ts, 0)
|
||||||
func (msg *Message) Delete() {
|
|
||||||
ans := msg.db.Delete(&msg)
|
|
||||||
if ans.Error != nil {
|
|
||||||
msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
|
||||||
}
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
@ -1,158 +0,0 @@
|
|||||||
package database
|
|
||||||
|
|
||||||
// import (
|
|
||||||
// "fmt"
|
|
||||||
// "math"
|
|
||||||
// "strings"
|
|
||||||
// )
|
|
||||||
|
|
||||||
// // func countRows(db *Database, table string) (int, error) {
|
|
||||||
// // countRow := db.QueryRow(fmt.Sprintf("SELECT COUNT(*) FROM %s", table))
|
|
||||||
// // var count int
|
|
||||||
// // err := countRow.Scan(&count)
|
|
||||||
// // return count, err
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// const VariableCountLimit = 512
|
|
||||||
|
|
||||||
// func migrateTable(old *Database, new *Database, table string, columns ...string) error {
|
|
||||||
// columnNames := strings.Join(columns, ",")
|
|
||||||
// fmt.Printf("Migrating %s: ", table)
|
|
||||||
// rowCount, err := countRows(old, table)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// fmt.Print("found ", rowCount, " rows of data, ")
|
|
||||||
// rows, err := old.Query(fmt.Sprintf("SELECT %s FROM \"%s\"", columnNames, table))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// serverColNames, err := rows.Columns()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// colCount := len(serverColNames)
|
|
||||||
// valueStringFormat := strings.Repeat("$%d, ", colCount)
|
|
||||||
// valueStringFormat = fmt.Sprintf("(%s)", valueStringFormat[:len(valueStringFormat)-2])
|
|
||||||
// cols := make([]interface{}, colCount)
|
|
||||||
// colPtrs := make([]interface{}, colCount)
|
|
||||||
// for i := 0; i < colCount; i++ {
|
|
||||||
// colPtrs[i] = &cols[i]
|
|
||||||
// }
|
|
||||||
// batchSize := VariableCountLimit / colCount
|
|
||||||
// values := make([]interface{}, batchSize*colCount)
|
|
||||||
// valueStrings := make([]string, batchSize)
|
|
||||||
// var inserted int64
|
|
||||||
// batchCount := int(math.Ceil(float64(rowCount) / float64(batchSize)))
|
|
||||||
// tx, err := new.Begin()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// fmt.Printf("migrating in %d batches: ", batchCount)
|
|
||||||
// for rowCount > 0 {
|
|
||||||
// var i int
|
|
||||||
// for ; rows.Next() && i < batchSize; i++ {
|
|
||||||
// colPtrs := make([]interface{}, colCount)
|
|
||||||
// valueStringArgs := make([]interface{}, colCount)
|
|
||||||
// for j := 0; j < colCount; j++ {
|
|
||||||
// pos := i*colCount + j
|
|
||||||
// colPtrs[j] = &values[pos]
|
|
||||||
// valueStringArgs[j] = pos + 1
|
|
||||||
// }
|
|
||||||
// valueStrings[i] = fmt.Sprintf(valueStringFormat, valueStringArgs...)
|
|
||||||
// err = rows.Scan(colPtrs...)
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// slicedValues := values
|
|
||||||
// slicedValueStrings := valueStrings
|
|
||||||
// if i < len(valueStrings) {
|
|
||||||
// slicedValueStrings = slicedValueStrings[:i]
|
|
||||||
// slicedValues = slicedValues[:i*colCount]
|
|
||||||
// }
|
|
||||||
// if len(slicedValues) == 0 {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// res, err := tx.Exec(fmt.Sprintf("INSERT INTO \"%s\" (%s) VALUES %s", table, columnNames, strings.Join(slicedValueStrings, ",")), slicedValues...)
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// count, _ := res.RowsAffected()
|
|
||||||
// inserted += count
|
|
||||||
// rowCount -= batchSize
|
|
||||||
// fmt.Print("#")
|
|
||||||
// }
|
|
||||||
// err = tx.Commit()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// fmt.Println(" -- done with", inserted, "rows inserted")
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
|
|
||||||
func Migrate(old *Database, new *Database) {
|
|
||||||
print("skipping migration because test")
|
|
||||||
}
|
|
||||||
|
|
||||||
// err := migrateTable(old, new, "portal", "jid", "receiver", "mxid", "name", "topic", "avatar", "avatar_url", "encrypted")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "user", "mxid", "jid", "management_room", "client_id", "client_token", "server_token", "enc_key", "mac_key", "last_connection")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "puppet", "jid", "avatar", "displayname", "name_quality", "custom_mxid", "access_token", "next_batch", "avatar_url", "enable_presence", "enable_receipts")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "user_portal", "user_jid", "portal_jid", "portal_receiver", "in_community")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "message", "chat_jid", "chat_receiver", "jid", "mxid", "sender", "content", "timestamp")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "mx_registrations", "user_id")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "mx_user_profile", "room_id", "user_id", "membership")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "mx_room_state", "room_id", "power_levels")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_account", "account_id", "device_id", "shared", "sync_token", "account")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_message_index", "sender_key", "session_id", `"index"`, "event_id", "timestamp")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_tracked_user", "user_id")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_device", "user_id", "device_id", "identity_key", "signing_key", "trust", "deleted", "name")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_olm_session", "account_id", "session_id", "sender_key", "session", "created_at", "last_used")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_megolm_inbound_session", "account_id", "session_id", "sender_key", "signing_key", "room_id", "session", "forwarding_chains")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// err = migrateTable(old, new, "crypto_megolm_outbound_session", "account_id", "room_id", "session_id", "session", "shared", "max_messages", "message_count", "max_age", "created_at", "last_used")
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// }
|
|
@ -17,31 +17,33 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
"github.com/karmanyaahm/groupme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JID is the puppet or the group
|
// GMID is the puppet or the group
|
||||||
// Receiver is the "Other Person" in a DM or the group itself in a group
|
// Receiver is the "Other Person" in a DM or the group itself in a group
|
||||||
type PortalKey struct {
|
type PortalKey struct {
|
||||||
JID types.GroupMeID `gorm:"primaryKey"`
|
GMID groupme.ID
|
||||||
Receiver types.GroupMeID `gorm:"primaryKey"`
|
Receiver groupme.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParsePortalKey(inp types.GroupMeID) *PortalKey {
|
func ParsePortalKey(inp string) *PortalKey {
|
||||||
parts := strings.Split(inp, "+")
|
parts := strings.Split(inp, "+")
|
||||||
|
|
||||||
if len(parts) == 1 {
|
if len(parts) == 1 {
|
||||||
if i, err := strconv.Atoi(inp); i == 0 || err != nil {
|
if i, err := strconv.Atoi(inp); i == 0 || err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &PortalKey{inp, inp}
|
return &PortalKey{groupme.ID(inp), groupme.ID(inp)}
|
||||||
} else if len(parts) == 2 {
|
} else if len(parts) == 2 {
|
||||||
if i, err := strconv.Atoi(parts[0]); i == 0 || err != nil {
|
if i, err := strconv.Atoi(parts[0]); i == 0 || err != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -51,38 +53,38 @@ func ParsePortalKey(inp types.GroupMeID) *PortalKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &PortalKey{
|
return &PortalKey{
|
||||||
JID: parts[1],
|
GMID: groupme.ID(parts[1]),
|
||||||
Receiver: parts[0],
|
Receiver: groupme.ID(parts[0]),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GroupPortalKey(jid types.GroupMeID) PortalKey {
|
func GroupPortalKey(gmid groupme.ID) PortalKey {
|
||||||
return PortalKey{
|
return PortalKey{
|
||||||
JID: jid,
|
GMID: gmid,
|
||||||
Receiver: jid,
|
Receiver: gmid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPortalKey(jid, receiver types.GroupMeID) PortalKey {
|
func NewPortalKey(gmid, receiver groupme.ID) PortalKey {
|
||||||
return PortalKey{
|
return PortalKey{
|
||||||
JID: jid,
|
GMID: gmid,
|
||||||
Receiver: receiver,
|
Receiver: receiver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (key PortalKey) String() string {
|
func (key PortalKey) String() string {
|
||||||
if key.Receiver == key.JID {
|
if key.Receiver == key.GMID {
|
||||||
return key.JID
|
return key.GMID.String()
|
||||||
}
|
}
|
||||||
return key.JID + "+" + key.Receiver
|
return key.GMID.String() + "+" + key.Receiver.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (key PortalKey) IsPrivate() bool {
|
func (key PortalKey) IsPrivate() bool {
|
||||||
//also see FindPrivateChats
|
//also see FindPrivateChats
|
||||||
return key.JID != key.Receiver
|
return key.GMID != key.Receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
type PortalQuery struct {
|
type PortalQuery struct {
|
||||||
@ -97,83 +99,86 @@ func (pq *PortalQuery) New() *Portal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) GetAll() []*Portal {
|
const (
|
||||||
return pq.getAll(pq.db.DB)
|
portalColumns = "gmid, receiver, mxid, name, name_set, topic, topic_set, avatar, avatar_url, avatar_set, encrypted"
|
||||||
|
getAllPortalsQuery = "SELECT " + portalColumns + " FROM portal"
|
||||||
|
getPortalByGMIDQuery = getAllPortalsQuery + " WHERE gmid=$1 AND receiver=$2"
|
||||||
|
getPortalByMXIDQuery = getAllPortalsQuery + " WHERE mxid=$1"
|
||||||
|
getAllPortalsByGMID = getAllPortalsQuery + " WHERE gmid=$1"
|
||||||
|
getAllPrivateChats = getAllPortalsQuery + " WHERE receiver=$1 AND receiver <> gmid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (pq *PortalQuery) GetAll() []*Portal {
|
||||||
|
return pq.getAll(getAllPortalsQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) GetByJID(key PortalKey) *Portal {
|
func (pq *PortalQuery) GetByGMID(key PortalKey) *Portal {
|
||||||
return pq.get(pq.db.DB.Where("jid = ? AND receiver = ?", key.JID, key.Receiver))
|
return pq.get(getPortalByGMIDQuery, key.GMID, key.Receiver)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) GetByMXID(mxid id.RoomID) *Portal {
|
func (pq *PortalQuery) GetByMXID(mxid id.RoomID) *Portal {
|
||||||
return pq.get(pq.db.DB.Where("mxid = ?", mxid))
|
return pq.get(getPortalByMXIDQuery, mxid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) GetAllByJID(jid types.GroupMeID) []*Portal {
|
func (pq *PortalQuery) GetAllByGMID(gmid groupme.ID) []*Portal {
|
||||||
return pq.getAll(pq.db.DB.Where("jid = ?", jid))
|
return pq.getAll(getAllPortalsByGMID, gmid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) FindPrivateChats(receiver types.GroupMeID) []*Portal {
|
func (pq *PortalQuery) FindPrivateChats(receiver groupme.ID) []*Portal {
|
||||||
//also see IsPrivate
|
return pq.getAll(getAllPrivateChats, receiver)
|
||||||
return pq.getAll(pq.db.DB.Where("receiver = ? AND receiver <> jid", receiver))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) getAll(db *gorm.DB) (portals []*Portal) {
|
func (pq *PortalQuery) getAll(query string, args ...any) (portals []*Portal) {
|
||||||
ans := db.Find(&portals)
|
rows, err := pq.db.Query(query, args...)
|
||||||
if ans.Error != nil || len(portals) == 0 {
|
if err != nil || rows == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, i := range portals {
|
defer rows.Close()
|
||||||
i.db = pq.db
|
for rows.Next() {
|
||||||
i.log = pq.log
|
portals = append(portals, pq.New().Scan(rows))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PortalQuery) get(db *gorm.DB) *Portal {
|
func (pq *PortalQuery) get(query string, args ...interface{}) *Portal {
|
||||||
var portal Portal
|
row := pq.db.QueryRow(query, args...)
|
||||||
ans := db.Limit(1).Find(&portal)
|
if row == nil {
|
||||||
if ans.Error != nil || db.RowsAffected == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
portal.db = pq.db
|
return pq.New().Scan(row)
|
||||||
portal.log = pq.log
|
|
||||||
|
|
||||||
return &portal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Portal struct {
|
type Portal struct {
|
||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
Key PortalKey `gorm:"primaryKey;embedded"`
|
Key PortalKey
|
||||||
MXID id.RoomID
|
MXID id.RoomID
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
|
NameSet bool
|
||||||
Topic string
|
Topic string
|
||||||
|
TopicSet bool
|
||||||
Avatar string
|
Avatar string
|
||||||
AvatarURL id.ContentURI
|
AvatarURL id.ContentURI
|
||||||
Encrypted bool `gorm:"notNull;default:false"`
|
AvatarSet bool
|
||||||
|
Encrypted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (portal *Portal) Scan(row Scannable) *Portal {
|
func (portal *Portal) Scan(row dbutil.Scannable) *Portal {
|
||||||
// var mxid, avatarURL sql.NullString
|
var mxid, avatarURL sql.NullString
|
||||||
// err := row.Scan(&portal.Key.JID, &portal.Key.Receiver, &mxid, &portal.Name, &portal.Topic, &portal.Avatar, &avatarURL, &portal.Encrypted)
|
|
||||||
// if err != nil {
|
err := row.Scan(&portal.Key.GMID, &portal.Key.Receiver, &mxid, &portal.Name, &portal.NameSet, &portal.Topic, &portal.TopicSet, &portal.Avatar, &avatarURL, &portal.AvatarSet, &portal.Encrypted)
|
||||||
// if err != sql.ErrNoRows {
|
if err != nil {
|
||||||
// portal.log.Errorln("Database scan failed:", err)
|
if err != sql.ErrNoRows {
|
||||||
// }
|
portal.log.Errorln("Database scan failed:", err)
|
||||||
// return nil
|
}
|
||||||
// }
|
return nil
|
||||||
// portal.MXID = id.RoomID(mxid.String)
|
}
|
||||||
// portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
portal.MXID = id.RoomID(mxid.String)
|
||||||
// return portal
|
portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||||
// }
|
return portal
|
||||||
|
}
|
||||||
|
|
||||||
func (portal *Portal) mxidPtr() *id.RoomID {
|
func (portal *Portal) mxidPtr() *id.RoomID {
|
||||||
if len(portal.MXID) > 0 {
|
if len(portal.MXID) > 0 {
|
||||||
@ -183,50 +188,40 @@ func (portal *Portal) mxidPtr() *id.RoomID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) Insert() {
|
func (portal *Portal) Insert() {
|
||||||
|
_, err := portal.db.Exec(fmt.Sprintf(`
|
||||||
ans := portal.db.Create(&portal)
|
INSERT INTO portal (%s)
|
||||||
print("beware of types")
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
|
||||||
if ans.Error != nil {
|
`, portalColumns),
|
||||||
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, ans.Error)
|
portal.Key.GMID, portal.Key.Receiver, portal.mxidPtr(), portal.Name, portal.NameSet, portal.Topic, portal.TopicSet, portal.Avatar, portal.AvatarURL.String(), portal.AvatarSet, portal.Encrypted)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) Update() {
|
func (portal *Portal) Update(txn dbutil.Transaction) {
|
||||||
ans := portal.db.Where("jid = ? AND receiver = ?", portal.Key.JID, portal.Key.Receiver).Save(&portal)
|
query := `
|
||||||
print("check .model vs not")
|
UPDATE portal
|
||||||
|
SET mxid=$1, name=$2, name_set=$3, topic=$4, topic_set=$5, avatar=$6, avatar_url=$7, avatar_set=$8, encrypted=$9
|
||||||
if ans.Error != nil {
|
WHERE gmid=$10 AND receiver=$11
|
||||||
portal.log.Warnfln("Failed to update %s: %v", portal.Key, ans.Error)
|
`
|
||||||
|
args := []interface{}{
|
||||||
|
portal.mxidPtr(), portal.Name, portal.NameSet, portal.Topic, portal.TopicSet, portal.Avatar, portal.AvatarURL.String(),
|
||||||
|
portal.AvatarSet, portal.Encrypted, portal.Key.GMID, portal.Key.Receiver,
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
if txn != nil {
|
||||||
|
_, err = txn.Exec(query, args...)
|
||||||
|
} else {
|
||||||
|
_, err = portal.db.Exec(query, args...)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Warnfln("Failed to update %s: %v", portal.Key, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) Delete() {
|
func (portal *Portal) Delete() {
|
||||||
ans := portal.db.Where("jid = ? AND receiver = ?", portal.Key.JID, portal.Key.Receiver).Delete(&portal)
|
_, err := portal.db.Exec("DELETE FROM portal WHERE gmid=$1 AND receiver=$2", portal.Key.GMID, portal.Key.Receiver)
|
||||||
if ans.Error != nil {
|
|
||||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, ans.Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (portal *Portal) GetUserIDs() []id.UserID {
|
|
||||||
//TODO: gorm this
|
|
||||||
rows, err := portal.db.Raw(`SELECT "users".mxid FROM "users", user_portals
|
|
||||||
WHERE "users".jid=user_portals.user_jid
|
|
||||||
AND user_portals.portal_jid = ?
|
|
||||||
AND user_portals.portal_receiver = ?`,
|
|
||||||
portal.Key.JID, portal.Key.Receiver).Rows()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Debugln("Failed to get portal user ids:", err)
|
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
var userIDs []id.UserID
|
|
||||||
for rows.Next() {
|
|
||||||
var userID id.UserID
|
|
||||||
err = rows.Scan(&userID)
|
|
||||||
if err != nil {
|
|
||||||
portal.log.Warnln("Failed to scan row:", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
userIDs = append(userIDs, userID)
|
|
||||||
}
|
|
||||||
return userIDs
|
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
"github.com/karmanyaahm/groupme"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PuppetQuery struct {
|
type PuppetQuery struct {
|
||||||
@ -34,120 +37,126 @@ func (pq *PuppetQuery) New() *Puppet {
|
|||||||
db: pq.db,
|
db: pq.db,
|
||||||
log: pq.log,
|
log: pq.log,
|
||||||
|
|
||||||
EnablePresence: true,
|
|
||||||
EnableReceipts: true,
|
EnableReceipts: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
puppetColumns = "gmid, displayname, name_set, avatar, avatar_url, avatar_set, custom_mxid, access_token, next_batch, enable_receipts"
|
||||||
|
getAllPuppetsQuery = "SELECT " + puppetColumns + " FROM puppets"
|
||||||
|
getPuppetQuery = getAllPuppetsQuery + " WHERE gmid=$1"
|
||||||
|
getPuppetByCustomMXIDQuery = getAllPuppetsQuery + " WHERE custom_mxid=$1"
|
||||||
|
getAllPuppetsWithCustomMXIDQuery = getAllPuppetsQuery + " WHERE custom_mxid<>''"
|
||||||
|
)
|
||||||
|
|
||||||
func (pq *PuppetQuery) GetAll() (puppets []*Puppet) {
|
func (pq *PuppetQuery) GetAll() (puppets []*Puppet) {
|
||||||
ans := pq.db.Find(&puppets)
|
rows, err := pq.db.Query(getAllPuppetsQuery)
|
||||||
if ans.Error != nil || len(puppets) == 0 {
|
if err != nil || rows == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, puppet := range puppets {
|
defer rows.Close()
|
||||||
pq.initializePuppet(puppet)
|
for rows.Next() {
|
||||||
|
puppets = append(puppets, pq.New().Scan(rows))
|
||||||
}
|
}
|
||||||
// defer rows.Close()
|
|
||||||
// for rows.Next() {
|
|
||||||
// puppets = append(puppets, pq.New().Scan(rows))
|
|
||||||
// }
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PuppetQuery) Get(jid types.GroupMeID) *Puppet {
|
func (pq *PuppetQuery) Get(gmid groupme.ID) *Puppet {
|
||||||
puppet := Puppet{}
|
row := pq.db.QueryRow(getPuppetQuery, gmid)
|
||||||
ans := pq.db.Where("jid = ?", jid).Limit(1).Find(&puppet)
|
if row == nil {
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
pq.initializePuppet(&puppet)
|
return pq.New().Scan(row)
|
||||||
return &puppet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PuppetQuery) GetByCustomMXID(mxid id.UserID) *Puppet {
|
func (pq *PuppetQuery) GetByCustomMXID(mxid id.UserID) *Puppet {
|
||||||
puppet := Puppet{}
|
row := pq.db.QueryRow(getPuppetByCustomMXIDQuery, mxid)
|
||||||
ans := pq.db.Where("custom_mxid = ?", mxid).Limit(1).Find(&puppet)
|
if row == nil {
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
pq.initializePuppet(&puppet)
|
return pq.New().Scan(row)
|
||||||
return &puppet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PuppetQuery) GetAllWithCustomMXID() (puppets []*Puppet) {
|
func (pq *PuppetQuery) GetAllWithCustomMXID() (puppets []*Puppet) {
|
||||||
|
rows, err := pq.db.Query(getAllPuppetsWithCustomMXIDQuery)
|
||||||
ans := pq.db.Find(&puppets, "custom_mxid <> ''")
|
if err != nil || rows == nil {
|
||||||
if ans.Error != nil || len(puppets) != 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, puppet := range puppets {
|
defer rows.Close()
|
||||||
pq.initializePuppet(puppet)
|
for rows.Next() {
|
||||||
|
puppets = append(puppets, pq.New().Scan(rows))
|
||||||
}
|
}
|
||||||
// defer rows.Close()
|
|
||||||
// for rows.Next() {
|
|
||||||
// puppets = append(puppets, pq.New().Scan(rows))
|
|
||||||
// }
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pq *PuppetQuery) initializePuppet(p *Puppet) {
|
// Puppet is comment
|
||||||
p.db = pq.db
|
|
||||||
p.log = pq.log
|
|
||||||
}
|
|
||||||
|
|
||||||
//Puppet is comment
|
|
||||||
type Puppet struct {
|
type Puppet struct {
|
||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
JID types.GroupMeID `gorm:"primaryKey"`
|
GMID groupme.ID
|
||||||
//Avatar string
|
|
||||||
//AvatarURL types.ContentURI
|
|
||||||
//Displayname string
|
|
||||||
//NameQuality int8
|
|
||||||
|
|
||||||
CustomMXID id.UserID `gorm:"column:custom_mxid;"`
|
Displayname string
|
||||||
|
NameSet bool
|
||||||
|
|
||||||
|
Avatar string
|
||||||
|
AvatarURL id.ContentURI
|
||||||
|
AvatarSet bool
|
||||||
|
|
||||||
|
CustomMXID id.UserID
|
||||||
AccessToken string
|
AccessToken string
|
||||||
NextBatch string
|
NextBatch string
|
||||||
EnablePresence bool `gorm:"notNull;default:true"`
|
EnableReceipts bool
|
||||||
EnableReceipts bool `gorm:"notNull;default:true"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
func (puppet *Puppet) Scan(row dbutil.Scannable) *Puppet {
|
||||||
// var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
||||||
// var quality sql.NullInt64
|
var enableReceipts, nameSet, avatarSet sql.NullBool
|
||||||
// var enablePresence, enableReceipts sql.NullBool
|
var gmid string
|
||||||
// err := row.Scan(&puppet.JID, &avatar, &avatarURL, &displayname, &quality, &customMXID, &accessToken, &nextBatch, &enablePresence, &enableReceipts)
|
err := row.Scan(&gmid, &displayname, &nameSet, &avatar, &avatarURL, &avatarSet, &customMXID, &accessToken, &nextBatch, &enableReceipts)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
// puppet.log.Errorln("Database scan failed:", err)
|
puppet.log.Errorln("Database scan failed:", err)
|
||||||
// }
|
}
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
// puppet.Displayname = displayname.String
|
puppet.GMID = groupme.ID(gmid)
|
||||||
// puppet.Avatar = avatar.String
|
puppet.Displayname = displayname.String
|
||||||
// puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
puppet.NameSet = nameSet.Bool
|
||||||
// puppet.NameQuality = int8(quality.Int64)
|
puppet.Avatar = avatar.String
|
||||||
// puppet.CustomMXID = id.UserID(customMXID.String)
|
puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||||
// puppet.AccessToken = accessToken.String
|
puppet.AvatarSet = avatarSet.Bool
|
||||||
// puppet.NextBatch = nextBatch.String
|
puppet.CustomMXID = id.UserID(customMXID.String)
|
||||||
// puppet.EnablePresence = enablePresence.Bool
|
puppet.AccessToken = accessToken.String
|
||||||
// puppet.EnableReceipts = enableReceipts.Bool
|
puppet.NextBatch = nextBatch.String
|
||||||
// return puppet
|
puppet.EnableReceipts = enableReceipts.Bool
|
||||||
// }
|
return puppet
|
||||||
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) Insert() {
|
func (puppet *Puppet) Insert() {
|
||||||
// _, err := puppet.db.Exec("INSERT INTO puppet (jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
_, err := puppet.db.Exec(`
|
||||||
// puppet.JID, puppet.Avatar, puppet.AvatarURL.String(), puppet.Displayname, puppet.NameQuality, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnablePresence, puppet.EnableReceipts)
|
INSERT INTO puppet (username, avatar, avatar_url, avatar_set, displayname, name_set,
|
||||||
ans := puppet.db.Create(&puppet)
|
custom_mxid, access_token, next_batch, enable_receipts)
|
||||||
if ans.Error != nil {
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||||
puppet.log.Warnfln("Failed to insert %s: %v", puppet.JID, ans.Error)
|
`, puppet.GMID, puppet.Avatar, puppet.AvatarURL.String(), puppet.AvatarSet, puppet.Displayname,
|
||||||
|
puppet.NameSet, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch,
|
||||||
|
puppet.EnableReceipts,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
puppet.log.Warnfln("Failed to insert %s: %v", puppet.GMID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) Update() {
|
func (puppet *Puppet) Update() {
|
||||||
ans := puppet.db.Where("jid = ?", puppet.JID).Updates(&puppet)
|
_, err := puppet.db.Exec(`
|
||||||
if ans.Error != nil {
|
UPDATE puppet
|
||||||
puppet.log.Warnfln("Failed to update %s->%s: %v", puppet.JID, ans.Error)
|
SET displayname=$1, name_set=$2, avatar=$3, avatar_url=$4, avatar_set=$5, custom_mxid=$6,
|
||||||
|
access_token=$7, next_batch=$8, enable_receipts=$10
|
||||||
|
WHERE username=$11
|
||||||
|
`, puppet.Displayname, puppet.NameSet, puppet.Avatar, puppet.AvatarURL.String(), puppet.AvatarSet,
|
||||||
|
puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnableReceipts,
|
||||||
|
puppet.GMID)
|
||||||
|
if err != nil {
|
||||||
|
puppet.log.Warnfln("Failed to update %s: %v", puppet.GMID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
"github.com/karmanyaahm/groupme"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ReactionQuery struct {
|
type ReactionQuery struct {
|
||||||
@ -19,56 +23,81 @@ func (mq *ReactionQuery) New() *Reaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mq *ReactionQuery) GetByJID(jid types.GroupMeID) (reactions []*Reaction) {
|
const (
|
||||||
ans := mq.db.Model(&Reaction{}).
|
getReactionByTargetGMIDQuery = `
|
||||||
Preload("Puppet"). // TODO: Do this in seperate function?
|
SELECT chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid
|
||||||
Where("message_jid = ?", jid).
|
FROM reaction
|
||||||
Limit(1).Find(&reactions)
|
WHERE chat_gmid=$1 AND chat_receiver=$2 AND target_gmid=$3 AND sender=$4
|
||||||
|
`
|
||||||
|
getReactionByMXIDQuery = `
|
||||||
|
SELECT chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid FROM reaction
|
||||||
|
WHERE mxid=$1
|
||||||
|
`
|
||||||
|
upsertReactionQuery = `
|
||||||
|
INSERT INTO reaction (chat_gmid, chat_receiver, target_gmid, sender, mxid, gmid)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
ON CONFLICT (chat_gmid, chat_receiver, target_gmid, sender)
|
||||||
|
DO UPDATE SET mxid=excluded.mxid, gmid=excluded.gmid
|
||||||
|
`
|
||||||
|
deleteReactionQuery = `
|
||||||
|
DELETE FROM reaction WHERE chat_gmid=$1 AND chat_receiver=$2 AND target_gmid=$3 AND sender=$4 AND mxid=$5
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
func (rq *ReactionQuery) GetByTargetGMID(chat PortalKey, gmid groupme.ID, sender groupme.ID) *Reaction {
|
||||||
return nil
|
return rq.maybeScan(rq.db.QueryRow(getReactionByTargetGMIDQuery, chat.GMID, chat.Receiver, gmid, sender))
|
||||||
}
|
|
||||||
|
|
||||||
for _, reaction := range reactions {
|
|
||||||
reaction.db = mq.db
|
|
||||||
reaction.log = mq.log
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ans := mq.db.Model(&Reaction{}).
|
func (rq *ReactionQuery) GetByMXID(mxid id.EventID) *Reaction {
|
||||||
// Joins("INNER JOIN users on users.mxid = reactions.user_mxid").
|
return rq.maybeScan(rq.db.QueryRow(getReactionByMXIDQuery, mxid))
|
||||||
// Where("reactions.message_jid = ? AND users.jid = ?", jid, uid).
|
}
|
||||||
// Limit(1).Find(&reactions)
|
|
||||||
|
func (rq *ReactionQuery) maybeScan(row *sql.Row) *Reaction {
|
||||||
|
if row == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return rq.New().Scan(row)
|
||||||
|
}
|
||||||
|
|
||||||
type Reaction struct {
|
type Reaction struct {
|
||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
MXID id.EventID `gorm:"primaryKey"`
|
Chat PortalKey
|
||||||
|
TargetGMID groupme.ID
|
||||||
//Message
|
Sender groupme.ID
|
||||||
MessageJID types.GroupMeID `gorm:"notNull"`
|
MXID id.EventID
|
||||||
MessageMXID id.EventID `gorm:"notNull"`
|
GMID groupme.ID
|
||||||
|
|
||||||
Message Message `gorm:"foreignKey:MessageMXID,MessageJID;references:MXID,JID;"`
|
|
||||||
|
|
||||||
//User
|
|
||||||
PuppetJID types.GroupMeID `gorm:"notNull"`
|
|
||||||
Puppet Puppet `gorm:"foreignKey:PuppetJID;references:jid;"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reaction *Reaction) Insert() {
|
func (reaction *Reaction) Scan(row dbutil.Scannable) *Reaction {
|
||||||
ans := reaction.db.Create(&reaction)
|
err := row.Scan(&reaction.Chat.GMID, &reaction.Chat.Receiver, &reaction.TargetGMID, &reaction.Sender, &reaction.MXID, &reaction.GMID)
|
||||||
if ans.Error != nil {
|
if err != nil {
|
||||||
reaction.log.Warnfln("Failed to insert %s@%s: %v", reaction.MXID, reaction.MessageJID, ans.Error)
|
if !errors.Is(err, sql.ErrNoRows) {
|
||||||
|
reaction.log.Errorln("Database scan failed:", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
return reaction
|
||||||
|
}
|
||||||
|
|
||||||
|
func (reaction *Reaction) Upsert(txn dbutil.Execable) {
|
||||||
|
if txn == nil {
|
||||||
|
txn = reaction.db
|
||||||
|
}
|
||||||
|
_, err := txn.Exec(upsertReactionQuery, reaction.Chat.GMID, reaction.Chat.Receiver, reaction.TargetGMID, reaction.Sender, reaction.MXID, reaction.GMID)
|
||||||
|
if err != nil {
|
||||||
|
reaction.log.Warnfln("Failed to upsert reaction to %s@%s by %s: %v", reaction.Chat, reaction.TargetGMID, reaction.Sender, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (reaction *Reaction) GetTarget() *Message {
|
||||||
|
return reaction.db.Message.GetByGMID(reaction.Chat, reaction.TargetGMID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reaction *Reaction) Delete() {
|
func (reaction *Reaction) Delete() {
|
||||||
ans := reaction.db.Delete(&reaction)
|
_, err := reaction.db.Exec(deleteReactionQuery, reaction.Chat.GMID, reaction.Chat.Receiver, reaction.TargetGMID, reaction.Sender, reaction.MXID)
|
||||||
if ans.Error != nil {
|
if err != nil {
|
||||||
reaction.log.Warnfln("Failed to insert %s@%s: %v", reaction.MXID, reaction.MessageJID, ans.Error)
|
reaction.log.Warnfln("Failed to delete reaction %s: %v", reaction.MXID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,368 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
|
||||||
"maunium.net/go/mautrix/event"
|
|
||||||
"maunium.net/go/mautrix/id"
|
|
||||||
)
|
|
||||||
|
|
||||||
type SQLStateStore struct {
|
|
||||||
*appservice.TypingStateStore
|
|
||||||
|
|
||||||
db *Database
|
|
||||||
log log.Logger
|
|
||||||
|
|
||||||
Typing map[id.RoomID]map[id.UserID]int64
|
|
||||||
typingLock sync.RWMutex
|
|
||||||
}
|
|
||||||
|
|
||||||
type mxRegistered struct {
|
|
||||||
UserID string `gorm:"primaryKey"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ appservice.StateStore = (*SQLStateStore)(nil)
|
|
||||||
|
|
||||||
func NewSQLStateStore(db *Database) *SQLStateStore {
|
|
||||||
return &SQLStateStore{
|
|
||||||
TypingStateStore: appservice.NewTypingStateStore(),
|
|
||||||
db: db,
|
|
||||||
log: db.log.Sub("StateStore"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) IsRegistered(userID id.UserID) bool {
|
|
||||||
v := mxRegistered{UserID: userID.String()}
|
|
||||||
var count int64
|
|
||||||
ans := store.db.Model(&mxRegistered{}).Where(&v).Count(&count)
|
|
||||||
|
|
||||||
if errors.Is(ans.Error, gorm.ErrRecordNotFound) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to scan registration existence for %s: %v", userID, ans.Error)
|
|
||||||
}
|
|
||||||
return count >= 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) MarkRegistered(userID id.UserID) {
|
|
||||||
|
|
||||||
ans := store.db.Create(mxRegistered{userID.String()})
|
|
||||||
|
|
||||||
if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to mark %s as registered: %v", userID, ans.Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MxUserProfile struct {
|
|
||||||
RoomID string `gorm:"primaryKey"`
|
|
||||||
UserID string `gorm:"primaryKey"`
|
|
||||||
Membership string `gorm:"notNull"`
|
|
||||||
|
|
||||||
DisplayName string
|
|
||||||
AvatarURL string
|
|
||||||
Avatar string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetRoomMembers(roomID id.RoomID) map[id.UserID]*event.MemberEventContent {
|
|
||||||
members := make(map[id.UserID]*event.MemberEventContent)
|
|
||||||
var users []MxUserProfile
|
|
||||||
ans := store.db.Where("room_id = ?", roomID.String()).Find(&users)
|
|
||||||
if ans.Error != nil {
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
var userID id.UserID
|
|
||||||
var member event.MemberEventContent
|
|
||||||
for _, user := range users {
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Warnfln("Failed to scan member in %s: %v", roomID, err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
userID = id.UserID(user.UserID)
|
|
||||||
member = event.MemberEventContent{
|
|
||||||
Membership: event.Membership(user.Membership),
|
|
||||||
Displayname: user.DisplayName,
|
|
||||||
AvatarURL: id.ContentURIString(user.AvatarURL),
|
|
||||||
}
|
|
||||||
|
|
||||||
members[userID] = &member
|
|
||||||
}
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetMembership(roomID id.RoomID, userID id.UserID) event.Membership {
|
|
||||||
var user MxUserProfile
|
|
||||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
|
||||||
membership := event.MembershipLeave
|
|
||||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
|
||||||
store.log.Warnfln("Failed to scan membership of %s in %s: %v", userID, roomID, ans.Error)
|
|
||||||
}
|
|
||||||
membership = event.Membership(user.Membership)
|
|
||||||
|
|
||||||
return membership
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetMember(roomID id.RoomID, userID id.UserID) *event.MemberEventContent {
|
|
||||||
member, ok := store.TryGetMember(roomID, userID)
|
|
||||||
if !ok {
|
|
||||||
member.Membership = event.MembershipLeave
|
|
||||||
}
|
|
||||||
return member
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) TryGetMember(roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, bool) {
|
|
||||||
var user MxUserProfile
|
|
||||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Limit(1).Find(&user)
|
|
||||||
|
|
||||||
if ans.Error != nil && ans.Error != gorm.ErrRecordNotFound {
|
|
||||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
|
||||||
}
|
|
||||||
eventMember := event.MemberEventContent{
|
|
||||||
Membership: event.Membership(user.Membership),
|
|
||||||
Displayname: user.DisplayName,
|
|
||||||
AvatarURL: id.ContentURIString(user.AvatarURL),
|
|
||||||
}
|
|
||||||
|
|
||||||
return &eventMember, ans.Error != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) TryGetMemberRaw(roomID id.RoomID, userID id.UserID) (user MxUserProfile, err bool) {
|
|
||||||
user.RoomID = roomID.String()
|
|
||||||
user.UserID = userID.String()
|
|
||||||
|
|
||||||
ans := store.db.Limit(1).Find(&user)
|
|
||||||
|
|
||||||
if ans.Error == gorm.ErrRecordNotFound {
|
|
||||||
err = true
|
|
||||||
return
|
|
||||||
} else if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, ans.Error)
|
|
||||||
err = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) SetMemberRaw(member *MxUserProfile) {
|
|
||||||
ans := store.db.Clauses(clause.OnConflict{
|
|
||||||
UpdateAll: true,
|
|
||||||
}).Create(member)
|
|
||||||
|
|
||||||
if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", member.UserID, member.RoomID, member, ans.Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) FindSharedRooms(userID id.UserID) (rooms []id.RoomID) {
|
|
||||||
|
|
||||||
rows, err := store.db.Table("mx_user_profile").Select("room_id").
|
|
||||||
Joins("LEFT JOIN portal ON portal.mxid=mx_user_profile.room_id").
|
|
||||||
Where("user_id = ? AND portal.encrypted=true", userID).Rows()
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
store.log.Warnfln("Failed to query shared rooms with %s: %v", userID, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
print("running maybe maybe code f937060306")
|
|
||||||
for rows.Next() {
|
|
||||||
var roomID id.RoomID
|
|
||||||
err := rows.Scan(&roomID)
|
|
||||||
if err != nil {
|
|
||||||
store.log.Warnfln("Failed to scan room ID: %v", err)
|
|
||||||
} else {
|
|
||||||
rooms = append(rooms, roomID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) IsInRoom(roomID id.RoomID, userID id.UserID) bool {
|
|
||||||
return store.IsMembership(roomID, userID, "join")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) IsInvited(roomID id.RoomID, userID id.UserID) bool {
|
|
||||||
return store.IsMembership(roomID, userID, "join", "invite")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) IsMembership(roomID id.RoomID, userID id.UserID, allowedMemberships ...event.Membership) bool {
|
|
||||||
membership := store.GetMembership(roomID, userID)
|
|
||||||
for _, allowedMembership := range allowedMemberships {
|
|
||||||
if allowedMembership == membership {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) SetMembership(roomID id.RoomID, userID id.UserID, membership event.Membership) {
|
|
||||||
var err error
|
|
||||||
user := MxUserProfile{
|
|
||||||
RoomID: roomID.String(),
|
|
||||||
UserID: userID.String(),
|
|
||||||
Membership: string(membership),
|
|
||||||
}
|
|
||||||
print("weird thing 2 502650285")
|
|
||||||
|
|
||||||
ans := store.db.Clauses(clause.OnConflict{
|
|
||||||
Columns: []clause.Column{{Name: "room_id"}, {Name: "user_id"}},
|
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"membership"}),
|
|
||||||
}).Create(&user)
|
|
||||||
|
|
||||||
if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", userID, roomID, membership, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func (store *SQLStateStore) SetMember(roomID id.RoomID, userID id.UserID, member *event.MemberEventContent) {
|
|
||||||
|
|
||||||
user := MxUserProfile{
|
|
||||||
RoomID: roomID.String(),
|
|
||||||
UserID: userID.String(),
|
|
||||||
Membership: string(member.Membership),
|
|
||||||
DisplayName: member.Displayname,
|
|
||||||
// AvatarURL: string(member.AvatarURL),//try ignoring
|
|
||||||
}
|
|
||||||
ans := store.db.Clauses(clause.OnConflict{
|
|
||||||
Columns: []clause.Column{{Name: "room_id"}, {Name: "user_id"}},
|
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"membership", "display_name"}),
|
|
||||||
}).Create(&user)
|
|
||||||
|
|
||||||
if ans.Error != nil {
|
|
||||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", userID, roomID, member, ans.Error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) SetPowerLevels(roomID id.RoomID, levels *event.PowerLevelsEventContent) {
|
|
||||||
// levelsBytes, err := json.Marshal(levels)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorfln("Failed to marshal power levels of %s: %v", roomID, err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if store.db.dialect == "postgres" {
|
|
||||||
// _, err = store.db.Exec(`INSERT INTO mx_room_state (room_id, power_levels) VALUES ($1, $2)
|
|
||||||
// ON CONFLICT (room_id) DO UPDATE SET power_levels=$2`, roomID, levelsBytes)
|
|
||||||
// } else if store.db.dialect == "sqlite3" {
|
|
||||||
// _, err = store.db.Exec("INSERT OR REPLACE INTO mx_room_state (room_id, power_levels) VALUES ($1, $2)", roomID, levelsBytes)
|
|
||||||
// } else {
|
|
||||||
// err = fmt.Errorf("unsupported dialect %s", store.db.dialect)
|
|
||||||
// }
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Warnfln("Failed to store power levels of %s: %v", roomID, err)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetPowerLevels(roomID id.RoomID) (levels *event.PowerLevelsEventContent) {
|
|
||||||
// row := store.db.QueryRow("SELECT power_levels FROM mx_room_state WHERE room_id=$1", roomID)
|
|
||||||
// if row == nil {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// var data []byte
|
|
||||||
// err := row.Scan(&data)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorln("Failed to scan power levels of %s: %v", roomID, err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// levels = &event.PowerLevelsEventContent{}
|
|
||||||
// err = json.Unmarshal(data, levels)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorln("Failed to parse power levels of %s: %v", roomID, err)
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetPowerLevel(roomID id.RoomID, userID id.UserID) int {
|
|
||||||
// if store.db.dialect == "postgres" {
|
|
||||||
// row := store.db.QueryRow(`SELECT
|
|
||||||
// COALESCE((power_levels->'users'->$2)::int, (power_levels->'users_default')::int, 0)
|
|
||||||
// FROM mx_room_state WHERE room_id=$1`, roomID, userID)
|
|
||||||
// if row == nil {
|
|
||||||
// // Power levels not in db
|
|
||||||
// return 0
|
|
||||||
// }
|
|
||||||
// var powerLevel int
|
|
||||||
// err := row.Scan(&powerLevel)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorln("Failed to scan power level of %s in %s: %v", userID, roomID, err)
|
|
||||||
// }
|
|
||||||
// return powerLevel
|
|
||||||
// }
|
|
||||||
return store.GetPowerLevels(roomID).GetUserLevel(userID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) GetPowerLevelRequirement(roomID id.RoomID, eventType event.Type) int {
|
|
||||||
// if store.db.dialect == "postgres" {
|
|
||||||
// defaultType := "events_default"
|
|
||||||
// defaultValue := 0
|
|
||||||
// if eventType.IsState() {
|
|
||||||
// defaultType = "state_default"
|
|
||||||
// defaultValue = 50
|
|
||||||
// }
|
|
||||||
// row := store.db.QueryRow(`SELECT
|
|
||||||
// COALESCE((power_levels->'events'->$2)::int, (power_levels->'$3')::int, $4)
|
|
||||||
// FROM mx_room_state WHERE room_id=$1`, roomID, eventType.Type, defaultType, defaultValue)
|
|
||||||
// if row == nil {
|
|
||||||
// // Power levels not in db
|
|
||||||
// return defaultValue
|
|
||||||
// }
|
|
||||||
// var powerLevel int
|
|
||||||
// err := row.Scan(&powerLevel)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorln("Failed to scan power level for %s in %s: %v", eventType, roomID, err)
|
|
||||||
// }
|
|
||||||
// return powerLevel
|
|
||||||
// }
|
|
||||||
return store.GetPowerLevels(roomID).GetEventLevel(eventType)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *SQLStateStore) HasPowerLevel(roomID id.RoomID, userID id.UserID, eventType event.Type) bool {
|
|
||||||
// if store.db.dialect == "postgres" {
|
|
||||||
// defaultType := "events_default"
|
|
||||||
// defaultValue := 0
|
|
||||||
// if eventType.IsState() {
|
|
||||||
// defaultType = "state_default"
|
|
||||||
// defaultValue = 50
|
|
||||||
// }
|
|
||||||
// row := store.db.QueryRow(`SELECT
|
|
||||||
// COALESCE((power_levels->'users'->$2)::int, (power_levels->'users_default')::int, 0)
|
|
||||||
// >=
|
|
||||||
// COALESCE((power_levels->'events'->$3)::int, (power_levels->'$4')::int, $5)
|
|
||||||
// FROM mx_room_state WHERE room_id=$1`, roomID, userID, eventType.Type, defaultType, defaultValue)
|
|
||||||
// if row == nil {
|
|
||||||
// // Power levels not in db
|
|
||||||
// return defaultValue == 0
|
|
||||||
// }
|
|
||||||
// var hasPower bool
|
|
||||||
// err := row.Scan(&hasPower)
|
|
||||||
// if err != nil {
|
|
||||||
// store.log.Errorln("Failed to scan power level for %s in %s: %v", eventType, roomID, err)
|
|
||||||
// }
|
|
||||||
// return hasPower
|
|
||||||
// }
|
|
||||||
// return store.GetPowerLevel(roomID, userID) >= store.GetPowerLevelRequirement(roomID, eventType)
|
|
||||||
return false
|
|
||||||
}
|
|
83
database/upgrades/00-latest-revision.sql
Normal file
83
database/upgrades/00-latest-revision.sql
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
-- v0 -> v1: Latest revision
|
||||||
|
|
||||||
|
CREATE TABLE "user" (
|
||||||
|
mxid TEXT PRIMARY KEY,
|
||||||
|
gmid TEXT UNIQUE,
|
||||||
|
|
||||||
|
auth_token TEXT,
|
||||||
|
|
||||||
|
management_room TEXT,
|
||||||
|
space_room TEXT,
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE portal (
|
||||||
|
gmid TEXT,
|
||||||
|
receiver TEXT,
|
||||||
|
mxid TEXT UNIQUE,
|
||||||
|
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
topic TEXT NOT NULL,
|
||||||
|
topic_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
avatar TEXT NOT NULL,
|
||||||
|
avatar_url TEXT,
|
||||||
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
encrypted BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
|
PRIMARY KEY (gmid, receiver)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE puppet (
|
||||||
|
gmid TEXT PRIMARY KEY,
|
||||||
|
displayname TEXT,
|
||||||
|
name_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
avatar TEXT,
|
||||||
|
avatar_url TEXT,
|
||||||
|
avatar_set BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
|
custom_mxid TEXT,
|
||||||
|
access_token TEXT,
|
||||||
|
next_batch TEXT,
|
||||||
|
|
||||||
|
enable_presence BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
enable_receipts BOOLEAN NOT NULL DEFAULT true
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE message (
|
||||||
|
chat_gmid TEXT,
|
||||||
|
chat_receiver TEXT,
|
||||||
|
gmid TEXT,
|
||||||
|
mxid TEXT UNIQUE,
|
||||||
|
sender TEXT,
|
||||||
|
timestamp BIGINT,
|
||||||
|
sent BOOLEAN,
|
||||||
|
|
||||||
|
PRIMARY KEY (chat_gmid, chat_receiver, gmid),
|
||||||
|
FOREIGN KEY (chat_gmid, chat_receiver) REFERENCES portal(gmid, receiver) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE reaction (
|
||||||
|
chat_gmid TEXT,
|
||||||
|
chat_receiver TEXT,
|
||||||
|
target_gmid TEXT,
|
||||||
|
sender TEXT,
|
||||||
|
|
||||||
|
mxid TEXT NOT NULL,
|
||||||
|
gmid TEXT NOT NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (chat_gmid, chat_receiver, target_gmid, sender),
|
||||||
|
FOREIGN KEY (chat_gmid, chat_receiver, target_gmid) REFERENCES message(chat_gmid, chat_receiver, gmid)
|
||||||
|
ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
)
|
||||||
|
|
||||||
|
CREATE TABLE user_portal (
|
||||||
|
user_mxid TEXT,
|
||||||
|
portal_gmid TEXT,
|
||||||
|
portal_receiver TEXT,
|
||||||
|
in_space BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
|
PRIMARY KEY (user_mxid, portal_gmid, portal_receiver),
|
||||||
|
|
||||||
|
FOREIGN KEY (user_mxid) REFERENCES "user"(mxid) ON UPDATE CASCADE ON DELETE CASCADE,
|
||||||
|
FOREIGN KEY (portal_gmid, portal_receiver) REFERENCES portal(gmid, receiver) ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
|
);
|
@ -1,182 +0,0 @@
|
|||||||
package upgrades
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
upgrades[0] = upgrade{"Initial schema", func(tx *gorm.DB, ctx context) error {
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS portal (
|
|
||||||
jid VARCHAR(255),
|
|
||||||
receiver VARCHAR(255),
|
|
||||||
mxid VARCHAR(255) UNIQUE,
|
|
||||||
|
|
||||||
name VARCHAR(255) NOT NULL,
|
|
||||||
topic VARCHAR(512) NOT NULL,
|
|
||||||
avatar VARCHAR(255) NOT NULL,
|
|
||||||
avatar_url VARCHAR(255),
|
|
||||||
encrypted BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
|
|
||||||
PRIMARY KEY (jid, receiver)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS puppet (
|
|
||||||
jid VARCHAR(255) PRIMARY KEY,
|
|
||||||
avatar VARCHAR(255),
|
|
||||||
displayname VARCHAR(255),
|
|
||||||
name_quality SMALLINT,
|
|
||||||
custom_mxid VARCHAR(255),
|
|
||||||
access_token VARCHAR(1023),
|
|
||||||
next_batch VARCHAR(255),
|
|
||||||
avatar_url VARCHAR(255),
|
|
||||||
enable_presence BOOLEAN NOT NULL DEFAULT true,
|
|
||||||
enable_receipts BOOLEAN NOT NULL DEFAULT true
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS "user" (
|
|
||||||
mxid VARCHAR(255) PRIMARY KEY,
|
|
||||||
jid VARCHAR(255) UNIQUE,
|
|
||||||
|
|
||||||
management_room VARCHAR(255),
|
|
||||||
|
|
||||||
client_id VARCHAR(255),
|
|
||||||
client_token VARCHAR(255),
|
|
||||||
server_token VARCHAR(255),
|
|
||||||
enc_key bytea,
|
|
||||||
mac_key bytea,
|
|
||||||
last_connection BIGINT NOT NULL DEFAULT 0
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS "user_portal" (
|
|
||||||
user_jid VARCHAR(255),
|
|
||||||
portal_jid VARCHAR(255),
|
|
||||||
portal_receiver VARCHAR(255),
|
|
||||||
in_community BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
|
|
||||||
PRIMARY KEY (user_jid, portal_jid, portal_receiver),
|
|
||||||
|
|
||||||
FOREIGN KEY (user_jid) REFERENCES "user"(jid) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS message (
|
|
||||||
chat_jid VARCHAR(255),
|
|
||||||
chat_receiver VARCHAR(255),
|
|
||||||
jid VARCHAR(255),
|
|
||||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
|
||||||
sender VARCHAR(255) NOT NULL,
|
|
||||||
content bytea NOT NULL,
|
|
||||||
timestamp BIGINT NOT NULL DEFAULT 0,
|
|
||||||
|
|
||||||
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
|
||||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_registrations (
|
|
||||||
user_id VARCHAR(255) PRIMARY KEY
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_room_state (
|
|
||||||
room_id VARCHAR(255) PRIMARY KEY,
|
|
||||||
power_levels TEXT
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS mx_user_profile (
|
|
||||||
room_id VARCHAR(255),
|
|
||||||
user_id VARCHAR(255),
|
|
||||||
membership VARCHAR(15) NOT NULL,
|
|
||||||
PRIMARY KEY (room_id, user_id),
|
|
||||||
displayname TEXT,
|
|
||||||
avatar_url VARCHAR(255)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_olm_session (
|
|
||||||
session_id CHAR(43) NOT NULL,
|
|
||||||
sender_key CHAR(43) NOT NULL,
|
|
||||||
session bytea NOT NULL,
|
|
||||||
created_at timestamp NOT NULL,
|
|
||||||
last_used timestamp NOT NULL,
|
|
||||||
account_id TEXT NOT NULL,
|
|
||||||
PRIMARY KEY (account_id, session_id)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_megolm_inbound_session (
|
|
||||||
session_id CHAR(43) NOT NULL,
|
|
||||||
sender_key CHAR(43) NOT NULL,
|
|
||||||
signing_key CHAR(43) NOT NULL,
|
|
||||||
room_id TEXT NOT NULL,
|
|
||||||
session bytea NOT NULL,
|
|
||||||
forwarding_chains bytea NOT NULL,
|
|
||||||
account_id TEXT NOT NULL,
|
|
||||||
withheld_code TEXT,
|
|
||||||
withheld_reason TEXT,
|
|
||||||
PRIMARY KEY (session_id, account_id)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_device (
|
|
||||||
user_id VARCHAR(255),
|
|
||||||
device_id VARCHAR(255),
|
|
||||||
identity_key CHAR(43) NOT NULL,
|
|
||||||
signing_key CHAR(43) NOT NULL,
|
|
||||||
trust SMALLINT NOT NULL,
|
|
||||||
deleted BOOLEAN NOT NULL,
|
|
||||||
name VARCHAR(255) NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (user_id, device_id)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_tracked_user (
|
|
||||||
user_id VARCHAR(255) PRIMARY KEY
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_message_index (
|
|
||||||
sender_key CHAR(43),
|
|
||||||
session_id CHAR(43),
|
|
||||||
"index" INTEGER,
|
|
||||||
event_id VARCHAR(255) NOT NULL,
|
|
||||||
timestamp BIGINT NOT NULL,
|
|
||||||
|
|
||||||
PRIMARY KEY (sender_key, session_id, "index")
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_account (
|
|
||||||
device_id TEXT NOT NULL,
|
|
||||||
shared BOOLEAN NOT NULL,
|
|
||||||
sync_token TEXT NOT NULL,
|
|
||||||
account bytea NOT NULL,
|
|
||||||
account_id TEXT PRIMARY KEY
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_megolm_outbound_session (
|
|
||||||
room_id VARCHAR(255) NOT NULL,
|
|
||||||
session_id CHAR(43) NOT NULL UNIQUE,
|
|
||||||
session bytea NOT NULL,
|
|
||||||
shared BOOLEAN NOT NULL,
|
|
||||||
max_messages INTEGER NOT NULL,
|
|
||||||
message_count INTEGER NOT NULL,
|
|
||||||
max_age BIGINT NOT NULL,
|
|
||||||
created_at timestamp NOT NULL,
|
|
||||||
last_used timestamp NOT NULL,
|
|
||||||
account_id TEXT,
|
|
||||||
PRIMARY KEY (room_id, account_id)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_cross_signing_keys (
|
|
||||||
user_id TEXT NOT NULL,
|
|
||||||
usage TEXT NOT NULL,
|
|
||||||
key CHAR(43) NOT NULL,
|
|
||||||
PRIMARY KEY (user_id, usage)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_cross_signing_signatures (
|
|
||||||
signed_user_id TEXT NOT NULL,
|
|
||||||
signed_key TEXT NOT NULL,
|
|
||||||
signer_user_id TEXT NOT NULL,
|
|
||||||
signer_key TEXT NOT NULL,
|
|
||||||
signature TEXT NOT NULL,
|
|
||||||
PRIMARY KEY (signed_user_id, signed_key, signer_user_id, signer_key)
|
|
||||||
)`)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}}
|
|
||||||
}
|
|
@ -1,123 +1,36 @@
|
|||||||
|
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||||
|
// Copyright (C) 2022 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
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package upgrades
|
package upgrades
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
log "maunium.net/go/maulogger/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dialect int
|
var Table dbutil.UpgradeTable
|
||||||
|
|
||||||
const (
|
//go:embed *.sql
|
||||||
Postgres Dialect = iota
|
var rawUpgrades embed.FS
|
||||||
SQLite
|
|
||||||
)
|
|
||||||
|
|
||||||
func (dialect Dialect) String() string {
|
func init() {
|
||||||
switch dialect {
|
Table.Register(-1, 35, "Unsupported version", func(tx dbutil.Transaction, database *dbutil.Database) error {
|
||||||
case Postgres:
|
return errors.New("please upgrade to mautrix-whatsapp v0.4.0 before upgrading to a newer version")
|
||||||
return "postgres"
|
})
|
||||||
case SQLite:
|
Table.RegisterFS(rawUpgrades)
|
||||||
return "sqlite3"
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type upgradeFunc func(*gorm.DB, context) error
|
|
||||||
|
|
||||||
type context struct {
|
|
||||||
dialect Dialect
|
|
||||||
db *gorm.DB
|
|
||||||
log log.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
type upgrade struct {
|
|
||||||
message string
|
|
||||||
fn upgradeFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
type version struct {
|
|
||||||
gorm.Model
|
|
||||||
V int
|
|
||||||
}
|
|
||||||
|
|
||||||
const NumberOfUpgrades = 1
|
|
||||||
|
|
||||||
var upgrades [NumberOfUpgrades]upgrade
|
|
||||||
|
|
||||||
var UnsupportedDatabaseVersion = fmt.Errorf("unsupported database version")
|
|
||||||
|
|
||||||
func GetVersion(db *gorm.DB) (int, error) {
|
|
||||||
var ver = version{V: 0}
|
|
||||||
result := db.FirstOrCreate(&ver, &ver)
|
|
||||||
if result.Error != nil {
|
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) ||
|
|
||||||
errors.Is(result.Error, gorm.ErrInvalidField) {
|
|
||||||
db.Create(&ver)
|
|
||||||
print("create version")
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return 0, result.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return int(ver.V), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetVersion(tx *gorm.DB, newVersion int) error {
|
|
||||||
err := tx.Where("v IS NOT NULL").Delete(&version{})
|
|
||||||
if err.Error != nil {
|
|
||||||
return err.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
val := version{V: newVersion}
|
|
||||||
tx = tx.Create(&val)
|
|
||||||
return tx.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
func Run(log log.Logger, dialectName string, db *gorm.DB) error {
|
|
||||||
var dialect Dialect
|
|
||||||
switch strings.ToLower(dialectName) {
|
|
||||||
case "postgres":
|
|
||||||
dialect = Postgres
|
|
||||||
case "sqlite3":
|
|
||||||
dialect = SQLite
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unknown dialect %s", dialectName)
|
|
||||||
}
|
|
||||||
|
|
||||||
db.AutoMigrate(&version{})
|
|
||||||
version, err := GetVersion(db)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if version > NumberOfUpgrades {
|
|
||||||
return UnsupportedDatabaseVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infofln("Database currently on v%d, latest: v%d", version, NumberOfUpgrades)
|
|
||||||
for i, upgrade := range upgrades[version:] {
|
|
||||||
log.Infofln("Upgrading database to v%d: %s", version+i+1, upgrade.message)
|
|
||||||
err = db.Transaction(func(tx *gorm.DB) error {
|
|
||||||
err = upgrade.fn(tx, context{dialect, db, log})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = SetVersion(tx, version+i+1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
241
database/user.go
241
database/user.go
@ -17,14 +17,17 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/dbutil"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
"github.com/karmanyaahm/groupme"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserQuery struct {
|
type UserQuery struct {
|
||||||
@ -33,218 +36,114 @@ type UserQuery struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) New() *User {
|
func (uq *UserQuery) New() *User {
|
||||||
return &User{
|
return &User{db: uq.db, log: uq.log}
|
||||||
db: uq.db,
|
|
||||||
log: uq.log,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
userColumns = "gmid, mxid, auth_token, management_room, space_room"
|
||||||
|
getAllUsersQuery = "SELECT " + userColumns + ` FROM "user"`
|
||||||
|
getUserByMXIDQuery = getAllUsersQuery + ` WHERE mxid=$1`
|
||||||
|
getUserByGMIDQuery = getAllUsersQuery + ` WHERE gmid=$1`
|
||||||
|
insertUserQuery = `INSERT INTO "user" (` + userColumns + `) VALUES ($1, $2, $3, $4, $5)`
|
||||||
|
updateUserQurey = `
|
||||||
|
UPDATE "user"
|
||||||
|
SET gmid=$1, auth_token=$2, management_room=$3, space_room=$4
|
||||||
|
WHERE mxid=$5
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
func (uq *UserQuery) GetAll() (users []*User) {
|
func (uq *UserQuery) GetAll() (users []*User) {
|
||||||
ans := uq.db.Find(&users)
|
rows, err := uq.db.Query(getAllUsersQuery)
|
||||||
if ans.Error != nil || len(users) == 0 {
|
if err != nil || rows == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, i := range users {
|
defer rows.Close()
|
||||||
i.db = uq.db
|
for rows.Next() {
|
||||||
i.log = uq.log
|
users = append(users, uq.New().Scan(rows))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
||||||
var user User
|
row := uq.db.QueryRow(getUserByMXIDQuery, userID)
|
||||||
ans := uq.db.Where("mxid = ?", userID).Take(&user)
|
if row == nil {
|
||||||
user.db = uq.db
|
|
||||||
user.log = uq.log
|
|
||||||
if ans.Error != nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &user
|
return uq.New().Scan(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetByJID(userID types.GroupMeID) *User {
|
func (uq *UserQuery) GetByGMID(gmid groupme.ID) *User {
|
||||||
var user User
|
row := uq.db.QueryRow(getUserByGMIDQuery, gmid)
|
||||||
ans := uq.db.Where("jid = ?", userID).Limit(1).Find(&user)
|
if row == nil {
|
||||||
if ans.Error != nil || ans.RowsAffected == 0 {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
user.db = uq.db
|
return uq.New().Scan(row)
|
||||||
user.log = uq.log
|
|
||||||
|
|
||||||
return &user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
db *Database
|
db *Database
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
MXID id.UserID `gorm:"primaryKey"`
|
MXID id.UserID
|
||||||
JID types.GroupMeID `gorm:"unique"`
|
GMID groupme.ID
|
||||||
Token types.AuthToken
|
|
||||||
|
|
||||||
ManagementRoom id.RoomID
|
ManagementRoom id.RoomID
|
||||||
LastConnection uint64 `gorm:"notNull;default:0"`
|
SpaceRoom id.RoomID
|
||||||
|
|
||||||
|
Token string
|
||||||
|
|
||||||
|
lastReadCache map[PortalKey]time.Time
|
||||||
|
lastReadCacheLock sync.Mutex
|
||||||
|
inSpaceCache map[PortalKey]bool
|
||||||
|
inSpaceCacheLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (user *User) Scan(row Scannable) *User {
|
func (user *User) Scan(row dbutil.Scannable) *User {
|
||||||
// var jid, clientID, clientToken, serverToken sql.NullString
|
var gmid, authToken sql.NullString
|
||||||
// var encKey, macKey []byte
|
err := row.Scan(&gmid, &user.MXID, &authToken, &user.ManagementRoom, &user.SpaceRoom)
|
||||||
// err := row.Scan(&user.MXID, &jid, &user.ManagementRoom, &user.LastConnection, &clientID, &clientToken, &serverToken, &encKey, &macKey)
|
if err != nil {
|
||||||
// if err != nil {
|
if err != sql.ErrNoRows {
|
||||||
// if err != sql.ErrNoRows {
|
user.log.Errorln("Database scan failed:", err)
|
||||||
// user.log.Errorln("Database scan failed:", err)
|
}
|
||||||
// }
|
return nil
|
||||||
// return nil
|
}
|
||||||
// }
|
if len(gmid.String) > 0 {
|
||||||
// if len(jid.String) > 0 && len(clientID.String) > 0 {
|
user.GMID = groupme.ID(gmid.String)
|
||||||
// user.JID = jid.String + whatsappExt.NewUserSuffix
|
}
|
||||||
// // user.Session = &whatsapp.Session{
|
user.Token = authToken.String
|
||||||
// // ClientId: clientID.String,
|
return user
|
||||||
// // ClientToken: clientToken.String,
|
}
|
||||||
// // ServerToken: serverToken.String,
|
|
||||||
// // EncKey: encKey,
|
|
||||||
// // MacKey: macKey,
|
|
||||||
// // Wid: jid.String + whatsappExt.OldUserSuffix,
|
|
||||||
// // }
|
|
||||||
// } // else {
|
|
||||||
// // user.Session = nil
|
|
||||||
// // }
|
|
||||||
// return user
|
|
||||||
//}
|
|
||||||
|
|
||||||
func stripSuffix(jid types.GroupMeID) string {
|
func stripSuffix(gmid groupme.ID) string {
|
||||||
if len(jid) == 0 {
|
if len(gmid) == 0 {
|
||||||
return jid
|
return gmid.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
index := strings.IndexRune(jid, '@')
|
index := strings.IndexRune(gmid.String(), '@')
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
return jid
|
return gmid.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return jid[:index]
|
return gmid.String()[:index]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) jidPtr() *string {
|
func (user *User) gmidPtr() *string {
|
||||||
if len(user.JID) > 0 {
|
if len(user.GMID) > 0 {
|
||||||
str := stripSuffix(user.JID)
|
str := stripSuffix(user.GMID)
|
||||||
return &str
|
return &str
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
|
||||||
// // if user.Session != nil {
|
|
||||||
// // sess = *user.Session
|
|
||||||
// // }
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (user *User) Insert() {
|
func (user *User) Insert() {
|
||||||
ans := user.db.Create(&user)
|
_, err := user.db.Exec(insertUserQuery, user.gmidPtr(), user.MXID, user.Token, user.ManagementRoom, user.SpaceRoom)
|
||||||
if ans.Error != nil {
|
if err != nil {
|
||||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, ans.Error)
|
user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) UpdateLastConnection() {
|
|
||||||
user.LastConnection = uint64(time.Now().Unix())
|
|
||||||
user.Update()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) Update() {
|
func (user *User) Update() {
|
||||||
ans := user.db.Save(&user)
|
_, err := user.db.Exec(updateUserQurey, user.gmidPtr(), user.Token, user.ManagementRoom, user.SpaceRoom, user.MXID)
|
||||||
if ans.Error != nil {
|
if err != nil {
|
||||||
user.log.Warnfln("Failed to update user: %v", ans.Error)
|
user.log.Warnfln("Failed to update %s: %v", user.MXID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
type PortalKeyWithMeta struct {
|
|
||||||
PortalKey
|
|
||||||
InCommunity bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserPortal struct {
|
|
||||||
UserJID types.GroupMeID `gorm:"primaryKey;"`
|
|
||||||
|
|
||||||
PortalJID types.GroupMeID `gorm:"primaryKey;"`
|
|
||||||
PortalReceiver types.GroupMeID `gorm:"primaryKey;"`
|
|
||||||
|
|
||||||
InCommunity bool `gorm:"notNull;default:false;"`
|
|
||||||
|
|
||||||
User User `gorm:"foreignKey:UserJID;references:jid;constraint:OnDelete:CASCADE;"`
|
|
||||||
Portal Portal `gorm:"foreignKey:PortalJID,PortalReceiver;references:JID,Receiver;constraint:OnDelete:CASCADE;"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) SetPortalKeys(newKeys []PortalKeyWithMeta) error {
|
|
||||||
tx := user.db.Begin()
|
|
||||||
ans := tx.Where("user_jid = ?", *user.jidPtr()).Delete(UserPortal{})
|
|
||||||
|
|
||||||
if ans.Error != nil {
|
|
||||||
_ = tx.Rollback()
|
|
||||||
return ans.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, key := range newKeys {
|
|
||||||
ans = tx.Create(&UserPortal{
|
|
||||||
UserJID: *user.jidPtr(),
|
|
||||||
PortalJID: key.JID,
|
|
||||||
PortalReceiver: key.Receiver,
|
|
||||||
InCommunity: key.InCommunity,
|
|
||||||
})
|
|
||||||
if ans.Error != nil {
|
|
||||||
_ = tx.Rollback()
|
|
||||||
return ans.Error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println("portalkey transaction complete")
|
|
||||||
return tx.Commit().Error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) IsInPortal(key PortalKey) bool {
|
|
||||||
var count int64
|
|
||||||
user.db.Find(&UserPortal{
|
|
||||||
UserJID: *user.jidPtr(),
|
|
||||||
PortalJID: key.JID,
|
|
||||||
PortalReceiver: key.Receiver,
|
|
||||||
}).Count(&count) //TODO: efficient
|
|
||||||
return count > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) GetPortalKeys() []PortalKey {
|
|
||||||
var up []UserPortal
|
|
||||||
ans := user.db.Where("user_jid = ?", *user.jidPtr()).Find(&up)
|
|
||||||
if ans.Error != nil {
|
|
||||||
user.log.Warnln("Failed to get user portal keys:", ans.Error)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var keys []PortalKey
|
|
||||||
for _, i := range up {
|
|
||||||
key := PortalKey{
|
|
||||||
JID: i.PortalJID,
|
|
||||||
Receiver: i.PortalReceiver,
|
|
||||||
}
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) GetInCommunityMap() map[PortalKey]bool {
|
|
||||||
var up []UserPortal
|
|
||||||
ans := user.db.Where("user_jid = ?", *user.jidPtr()).Find(&up)
|
|
||||||
if ans.Error != nil {
|
|
||||||
user.log.Warnln("Failed to get user portal keys:", ans.Error)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
keys := make(map[PortalKey]bool)
|
|
||||||
for _, i := range up {
|
|
||||||
key := PortalKey{
|
|
||||||
JID: i.PortalJID,
|
|
||||||
Receiver: i.PortalReceiver,
|
|
||||||
}
|
|
||||||
keys[key] = i.InCommunity
|
|
||||||
}
|
|
||||||
return keys
|
|
||||||
}
|
}
|
||||||
|
35
database/userportal.go
Normal file
35
database/userportal.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (user *User) IsInSpace(portal PortalKey) bool {
|
||||||
|
user.inSpaceCacheLock.Lock()
|
||||||
|
defer user.inSpaceCacheLock.Unlock()
|
||||||
|
if cached, ok := user.inSpaceCache[portal]; ok {
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
var inSpace bool
|
||||||
|
err := user.db.QueryRow("SELECT in_space FROM user_portal WHERE user_mxid=$1 AND portal_gmid=$2 AND portal_receiver=$3", user.MXID, portal.GMID, portal.Receiver).Scan(&inSpace)
|
||||||
|
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||||
|
user.log.Warnfln("Failed to scan in space status from user portal table: %v", err)
|
||||||
|
}
|
||||||
|
user.inSpaceCache[portal] = inSpace
|
||||||
|
return inSpace
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) MarkInSpace(portal PortalKey) {
|
||||||
|
user.inSpaceCacheLock.Lock()
|
||||||
|
defer user.inSpaceCacheLock.Unlock()
|
||||||
|
_, err := user.db.Exec(`
|
||||||
|
INSERT INTO user_portal (user_mxid, portal_gmid, portal_receiver, in_space) VALUES ($1, $2, $3, true)
|
||||||
|
ON CONFLICT (user_mxid, portal_gmid, portal_receiver) DO UPDATE SET in_space=true
|
||||||
|
`, user.MXID, portal.GMID, portal.Receiver)
|
||||||
|
if err != nil {
|
||||||
|
user.log.Warnfln("Failed to update in space status: %v", err)
|
||||||
|
} else {
|
||||||
|
user.inSpaceCache[portal] = true
|
||||||
|
}
|
||||||
|
}
|
@ -57,6 +57,15 @@ metrics:
|
|||||||
# IP and port where the metrics listener should be. The path is always /metrics
|
# IP and port where the metrics listener should be. The path is always /metrics
|
||||||
listen: 127.0.0.1:8001
|
listen: 127.0.0.1:8001
|
||||||
|
|
||||||
|
# GroupMe configuration
|
||||||
|
groupme:
|
||||||
|
# GroupMe connection timeout in seconds.
|
||||||
|
connection_timeout: 20
|
||||||
|
# If GroupMe doesn't respond within connection_timeout, should the bridge
|
||||||
|
# try to fetch the message to see if it was actually bridged? Use this if
|
||||||
|
# you have problems with sends timing out but actually succeeding.
|
||||||
|
fetch_message_on_timeout: false
|
||||||
|
|
||||||
# Bridge config
|
# Bridge config
|
||||||
bridge:
|
bridge:
|
||||||
# Localpart template of MXIDs for WhatsApp users.
|
# Localpart template of MXIDs for WhatsApp users.
|
||||||
@ -67,26 +76,15 @@ bridge:
|
|||||||
# {{.Nickname}} - the nickname in that room
|
# {{.Nickname}} - the nickname in that room
|
||||||
# {{.ImageURL}} - User's avatar URL is available but irrelevant here
|
# {{.ImageURL}} - User's avatar URL is available but irrelevant here
|
||||||
displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .UserID.String}}{{end}} (GM)"
|
displayname_template: "{{if .Nickname}}{{.Nickname}}{{else}}{{call .UserID.String}}{{end}} (GM)"
|
||||||
# Localpart template for per-user room grouping community IDs.
|
# Should the bridge create a space for each logged-in user and add bridged rooms to it?
|
||||||
# On startup, the bridge will try to create these communities, add all of the specific user's
|
# Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time.
|
||||||
# portals to the community, and invite the Matrix user to it.
|
personal_filtering_spaces: false
|
||||||
# (Note that, by default, non-admins might not have your homeserver's permission to create
|
# Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp?
|
||||||
# communities.)
|
|
||||||
# {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user.
|
|
||||||
# whatsapp_{{.Localpart}}={{.Server}} is a good value that should work for any user.
|
|
||||||
# communities are NOT YET TESTED in the GroupMe bridge
|
|
||||||
community_template: null
|
|
||||||
|
|
||||||
# GroupMe connection timeout in seconds.
|
|
||||||
connection_timeout: 20
|
|
||||||
# If groupme doesn't respond within connection_timeout, should the bridge try to fetch the message
|
|
||||||
# to see if it was actually bridged? Use this if you have problems with sends timing out but actually
|
|
||||||
# succeeding.
|
|
||||||
fetch_message_on_timeout: false
|
|
||||||
# Whether or not the bridge should send a read receipt from the bridge bot when a message has been
|
|
||||||
# sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will
|
|
||||||
# trigger a read receipt too.
|
|
||||||
delivery_receipts: false
|
delivery_receipts: false
|
||||||
|
# Whether the bridge should send the message status as a custom com.beeper.message_send_status event.
|
||||||
|
message_status_events: false
|
||||||
|
# Whether the bridge should send error notices via m.notice events when a message fails to bridge.
|
||||||
|
message_error_notices: true
|
||||||
|
|
||||||
# Maximum number of times to retry connecting on connection error.
|
# Maximum number of times to retry connecting on connection error.
|
||||||
max_connection_attempts: 3
|
max_connection_attempts: 3
|
||||||
|
@ -21,10 +21,9 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/karmanyaahm/groupme"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)")
|
var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)")
|
||||||
@ -32,10 +31,10 @@ var boldRegex = regexp.MustCompile("([\\s>_~]|^)\\*(.+?)\\*([^a-zA-Z\\d]|$)")
|
|||||||
var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)")
|
var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)")
|
||||||
var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```")
|
var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```")
|
||||||
|
|
||||||
const mentionedJIDsContextKey = "net.maunium.groupme.mentioned_jids"
|
const mentionedGMIDsContextKey = "net.maunium.groupme.mentioned_gmids"
|
||||||
|
|
||||||
type Formatter struct {
|
type Formatter struct {
|
||||||
bridge *Bridge
|
bridge *GMBridge
|
||||||
|
|
||||||
matrixHTMLParser *format.HTMLParser
|
matrixHTMLParser *format.HTMLParser
|
||||||
|
|
||||||
@ -44,7 +43,7 @@ type Formatter struct {
|
|||||||
waReplFuncText map[*regexp.Regexp]func(string) string
|
waReplFuncText map[*regexp.Regexp]func(string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFormatter(bridge *Bridge) *Formatter {
|
func NewFormatter(bridge *GMBridge) *Formatter {
|
||||||
formatter := &Formatter{
|
formatter := &Formatter{
|
||||||
bridge: bridge,
|
bridge: bridge,
|
||||||
matrixHTMLParser: &format.HTMLParser{
|
matrixHTMLParser: &format.HTMLParser{
|
||||||
@ -55,11 +54,11 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||||||
if mxid[0] == '@' {
|
if mxid[0] == '@' {
|
||||||
puppet := bridge.GetPuppetByMXID(id.UserID(mxid))
|
puppet := bridge.GetPuppetByMXID(id.UserID(mxid))
|
||||||
if puppet != nil {
|
if puppet != nil {
|
||||||
jids, ok := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
gmids, ok := ctx[mentionedGMIDsContextKey].([]groupme.ID)
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx[mentionedJIDsContextKey] = []types.GroupMeID{puppet.JID}
|
ctx[mentionedGMIDsContextKey] = []groupme.ID{puppet.GMID}
|
||||||
} else {
|
} else {
|
||||||
ctx[mentionedJIDsContextKey] = append(jids, puppet.JID)
|
ctx[mentionedGMIDsContextKey] = append(gmids, puppet.GMID)
|
||||||
}
|
}
|
||||||
return "@" + puppet.PhoneNumber()
|
return "@" + puppet.PhoneNumber()
|
||||||
}
|
}
|
||||||
@ -101,7 +100,7 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||||||
return formatter
|
return formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (formatter *Formatter) getMatrixInfoByJID(jid types.GroupMeID) (mxid id.UserID, displayname string) {
|
//func (formatter *Formatter) getMatrixInfoByJID(jid groupme.ID) (mxid id.UserID, displayname string) {
|
||||||
// if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
// if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||||
// mxid = user.MXID
|
// mxid = user.MXID
|
||||||
// displayname = string(user.MXID)
|
// displayname = string(user.MXID)
|
||||||
@ -112,7 +111,7 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||||||
// return
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []types.GroupMeID) {
|
//func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []groupme.ID) {
|
||||||
// output := html.EscapeString(content.Body)
|
// output := html.EscapeString(content.Body)
|
||||||
// for regex, replacement := range formatter.waReplString {
|
// for regex, replacement := range formatter.waReplString {
|
||||||
// output = regex.ReplaceAllString(output, replacement)
|
// output = regex.ReplaceAllString(output, replacement)
|
||||||
@ -136,9 +135,9 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func (formatter *Formatter) ParseMatrix(html string) (string, []types.GroupMeID) {
|
func (formatter *Formatter) ParseMatrix(html string) (string, []groupme.ID) {
|
||||||
ctx := make(format.Context)
|
ctx := make(format.Context)
|
||||||
result := formatter.matrixHTMLParser.Parse(html, ctx)
|
result := formatter.matrixHTMLParser.Parse(html, ctx)
|
||||||
mentionedJIDs, _ := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
mentionedJIDs, _ := ctx[mentionedGMIDsContextKey].([]groupme.ID)
|
||||||
return result, mentionedJIDs
|
return result, mentionedJIDs
|
||||||
}
|
}
|
||||||
|
49
go.mod
49
go.mod
@ -1,28 +1,49 @@
|
|||||||
module github.com/beeper/groupme
|
module github.com/beeper/groupme
|
||||||
|
|
||||||
go 1.15
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Rhymen/go-whatsapp v0.1.1
|
github.com/Rhymen/go-whatsapp v0.1.1
|
||||||
github.com/gabriel-vasile/mimetype v1.1.2
|
github.com/gabriel-vasile/mimetype v1.1.2
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
|
|
||||||
github.com/karmanyaahm/groupme v0.0.0
|
github.com/karmanyaahm/groupme v0.0.0
|
||||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14
|
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14
|
||||||
github.com/lib/pq v1.9.0
|
github.com/lib/pq v1.10.7
|
||||||
github.com/mattn/go-sqlite3 v1.14.6
|
github.com/mattn/go-sqlite3 v1.14.15
|
||||||
github.com/prometheus/client_golang v1.9.0
|
github.com/prometheus/client_golang v1.9.0
|
||||||
github.com/prometheus/procfs v0.6.0 // indirect
|
|
||||||
golang.org/x/text v0.3.5 // indirect
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
|
||||||
google.golang.org/protobuf v1.25.0 // indirect
|
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
|
||||||
gorm.io/driver/postgres v1.0.8
|
|
||||||
gorm.io/driver/sqlite v1.1.4
|
|
||||||
gorm.io/gorm v1.20.12
|
gorm.io/gorm v1.20.12
|
||||||
maunium.net/go/mauflag v1.0.0
|
maunium.net/go/mauflag v1.0.0
|
||||||
maunium.net/go/maulogger/v2 v2.2.4
|
maunium.net/go/maulogger/v2 v2.3.2
|
||||||
maunium.net/go/mautrix v0.9.24
|
maunium.net/go/mautrix v0.12.3-0.20221020190005-d0c13d2f04a1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1 // indirect
|
||||||
|
github.com/golang/protobuf v1.4.3 // indirect
|
||||||
|
github.com/google/uuid v1.2.0 // indirect
|
||||||
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.1 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/prometheus/common v0.15.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.6.0 // indirect
|
||||||
|
github.com/rs/zerolog v1.28.0 // indirect
|
||||||
|
github.com/tidwall/gjson v1.14.3 // indirect
|
||||||
|
github.com/tidwall/match v1.1.1 // indirect
|
||||||
|
github.com/tidwall/pretty v1.2.0 // indirect
|
||||||
|
github.com/tidwall/sjson v1.2.5 // indirect
|
||||||
|
github.com/yuin/goldmark v1.5.2 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
|
||||||
|
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
|
google.golang.org/protobuf v1.25.0 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/karmanyaahm/groupme => ../groupme-lib
|
replace github.com/karmanyaahm/groupme => ../groupme-lib
|
||||||
|
201
go.sum
201
go.sum
@ -2,6 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
|||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
|
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||||
github.com/Rhymen/go-whatsapp v0.0.0/go.mod h1:rdQr95g2C1xcOfM7QGOhza58HeI3I+tZ/bbluv7VazA=
|
github.com/Rhymen/go-whatsapp v0.0.0/go.mod h1:rdQr95g2C1xcOfM7QGOhza58HeI3I+tZ/bbluv7VazA=
|
||||||
github.com/Rhymen/go-whatsapp v0.1.1 h1:OK+bCugQcr2YjyYKeDzULqCtM50TPUFM6LvQtszKfcw=
|
github.com/Rhymen/go-whatsapp v0.1.1 h1:OK+bCugQcr2YjyYKeDzULqCtM50TPUFM6LvQtszKfcw=
|
||||||
@ -13,7 +14,6 @@ github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc
|
|||||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
|
||||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
@ -35,16 +35,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
|
|||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
|
||||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
|
||||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
|
||||||
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
|
|
||||||
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
|
|
||||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
|
||||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
|
||||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
|
||||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
|
||||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
|
||||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
@ -52,18 +42,14 @@ github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+
|
|||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
|
||||||
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
|
|
||||||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
|
||||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -91,8 +77,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
|
|||||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
|
||||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
@ -139,8 +124,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
|
|||||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||||
@ -168,60 +153,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
|
|||||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||||
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
|
|
||||||
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
|
|
||||||
github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE=
|
|
||||||
github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s=
|
|
||||||
github.com/jackc/pgconn v1.4.0/go.mod h1:Y2O3ZDF0q4mMacyWV3AstPJpeHXWGEetiFttmq5lahk=
|
|
||||||
github.com/jackc/pgconn v1.5.0/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
|
||||||
github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853/go.mod h1:QeD3lBfpTFe8WUnPZWN5KY/mB8FGMIYRdd8P8Jr0fAI=
|
|
||||||
github.com/jackc/pgconn v1.8.0 h1:FmjZ0rOyXTr1wfWs45i4a9vjnjWUAGpMuQLD9OSs+lw=
|
|
||||||
github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o=
|
|
||||||
github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE=
|
|
||||||
github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2 h1:JVX6jT/XfzNqIjye4717ITLaNwV9mWbJx0dLCpcRzdA=
|
|
||||||
github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
|
||||||
github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
|
|
||||||
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.7 h1:6Pwi1b3QdY65cuv6SyVO0FgPd5J3Bl7wf/nQQjinHMA=
|
|
||||||
github.com/jackc/pgproto3/v2 v2.0.7/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
|
|
||||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc=
|
|
||||||
github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw=
|
|
||||||
github.com/jackc/pgtype v1.2.0/go.mod h1:5m2OfMh1wTK7x+Fk952IDmI4nw3nPrvtQdM0ZT4WpC0=
|
|
||||||
github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po=
|
|
||||||
github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ=
|
|
||||||
github.com/jackc/pgtype v1.6.2 h1:b3pDeuhbbzBYcg5kwNmNDun4pFUD/0AAr1kLXZLeNt8=
|
|
||||||
github.com/jackc/pgtype v1.6.2/go.mod h1:JCULISAZBFGrHaOXIIFiyfzW5VY0GRitRr8NeJsrdig=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM=
|
|
||||||
github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc=
|
|
||||||
github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXgo+kA=
|
|
||||||
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
|
|
||||||
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
|
|
||||||
github.com/jackc/pgx/v4 v4.10.1 h1:/6Q3ye4myIj6AaplUm+eRcz4OhK9HAvFf4ePsG40LJY=
|
|
||||||
github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
|
|
||||||
github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
|
|
||||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
|
||||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||||
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
|
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
|
||||||
@ -229,7 +160,6 @@ github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
|
|||||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
|
||||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
@ -242,41 +172,31 @@ github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14 h1:NrATjZKvkY+ojL
|
|||||||
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14/go.mod h1:ysD86MIEevmAkdfdg5s6Qt3I07RN6fvMAyna7jCGG2o=
|
github.com/karmanyaahm/wray v0.0.0-20210303233435-756d58657c14/go.mod h1:ysD86MIEevmAkdfdg5s6Qt3I07RN6fvMAyna7jCGG2o=
|
||||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
|
||||||
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
|
||||||
github.com/lib/pq v1.9.0 h1:L8nSXQQzAYByakOFMTwpjRoHsMJklur4Gi59b6VivR8=
|
|
||||||
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
|
||||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
|
||||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
|
||||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
@ -360,22 +280,15 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
|
|||||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
|
||||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||||
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
|
||||||
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc h1:jUIKcSPO9MoMJBbEoyE/RJoE8vz7Mb8AjvifMMwSyvY=
|
|
||||||
github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
|
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
|
||||||
@ -392,59 +305,48 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3
|
|||||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
|
||||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
|
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||||
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||||
|
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
github.com/yuin/goldmark v1.5.2 h1:ALmeCk/px5FSm1MAcFBAsVKZjDuMVj8Tm7FFIlMJnqU=
|
||||||
|
github.com/yuin/goldmark v1.5.2/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
|
||||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
|
||||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||||
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
|
||||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
|
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a h1:NmSIgad6KjE6VvHciPZuNRTKxGhlPfD6OA87W/PLkqg=
|
||||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
@ -470,8 +372,8 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU=
|
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b h1:tvrvnPFcdzp294diPnrdZZZ8XUt2Tyj7svb7X52iDuU=
|
||||||
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -491,32 +393,24 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
|
||||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
|
||||||
|
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@ -527,15 +421,11 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
|
|||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@ -581,7 +471,6 @@ gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS
|
|||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
|
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||||
@ -591,15 +480,9 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
|
||||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
|
||||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
|
||||||
gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY=
|
gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY=
|
||||||
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
@ -608,9 +491,9 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||||
maunium.net/go/maulogger/v2 v2.2.4 h1:oV2GDeM4fx1uRysdpDC0FcrPg+thFicSd9XzPcYMbVY=
|
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
||||||
maunium.net/go/maulogger/v2 v2.2.4/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||||
maunium.net/go/mautrix v0.9.24 h1:NEwWLHcJ/hPF0TBppdezfbVaxwWY9E9f2KDkG4Q6GC0=
|
maunium.net/go/mautrix v0.12.3-0.20221020190005-d0c13d2f04a1 h1:daraaP+GcSrFLgVckFpp+ciVrtQeG5s2w3Fi8AInaj8=
|
||||||
maunium.net/go/mautrix v0.9.24/go.mod h1:7IzKfWvpQtN+W2Lzxc0rLvIxFM3ryKX6Ys3S/ZoWbg8=
|
maunium.net/go/mautrix v0.12.3-0.20221020190005-d0c13d2f04a1/go.mod h1:bCw45Qx/m9qsz7eazmbe7Rzq5ZbTPzwRE1UgX2S9DXs=
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package groupmeExt
|
package groupmeext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/karmanyaahm/groupme"
|
"github.com/karmanyaahm/groupme"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -36,9 +34,9 @@ func (c Client) IndexAllChats() ([]*groupme.Chat, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFromMe bool, private bool) ([]*groupme.Message, error) {
|
func (c Client) LoadMessagesAfter(groupID groupme.ID, lastMessageID string, lastMessageFromMe bool, private bool) ([]*groupme.Message, error) {
|
||||||
if private {
|
if private {
|
||||||
ans, e := c.IndexDirectMessages(context.TODO(), groupID, &groupme.IndexDirectMessagesQuery{
|
ans, e := c.IndexDirectMessages(context.TODO(), groupID.String(), &groupme.IndexDirectMessagesQuery{
|
||||||
SinceID: groupme.ID(lastMessageID),
|
SinceID: groupme.ID(lastMessageID),
|
||||||
//Limit: num,
|
//Limit: num,
|
||||||
})
|
})
|
||||||
@ -52,7 +50,7 @@ func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFrom
|
|||||||
}
|
}
|
||||||
return ans.Messages, nil
|
return ans.Messages, nil
|
||||||
} else {
|
} else {
|
||||||
i, e := c.IndexMessages(context.TODO(), groupme.ID(groupID), &groupme.IndexMessagesQuery{
|
i, e := c.IndexMessages(context.TODO(), groupID, &groupme.IndexMessagesQuery{
|
||||||
AfterID: groupme.ID(lastMessageID),
|
AfterID: groupme.ID(lastMessageID),
|
||||||
//20 for consistency with dms
|
//20 for consistency with dms
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
@ -91,11 +89,10 @@ func (c Client) LoadMessagesBefore(groupID, lastMessageID string, private bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RemoveFromGroup(uid, groupID types.GroupMeID) error {
|
func (c *Client) RemoveFromGroup(uid, groupID groupme.ID) error {
|
||||||
|
group, err := c.ShowGroup(context.TODO(), groupID)
|
||||||
group, err := c.ShowGroup(context.TODO(), groupme.ID(groupID))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.RemoveMember(context.TODO(), groupme.ID(groupID), group.GetMemberByUserID(groupme.ID(uid)).ID)
|
return c.RemoveMember(context.TODO(), groupID, group.GetMemberByUserID(uid).ID)
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package groupmeExt
|
package groupmeext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -10,8 +10,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/karmanyaahm/groupme"
|
"github.com/karmanyaahm/groupme"
|
||||||
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message struct{ groupme.Message }
|
type Message struct{ groupme.Message }
|
||||||
@ -60,7 +58,7 @@ func DownloadImage(URL string) (bytes *[]byte, mime string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFile(RoomJID types.GroupMeID, FileID string, token string) (contents []byte, fname, mime string) {
|
func DownloadFile(RoomJID groupme.ID, FileID string, token string) (contents []byte, fname, mime string) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
b, _ := json.Marshal(struct {
|
b, _ := json.Marshal(struct {
|
||||||
FileIDS []string `json:"file_ids"`
|
FileIDS []string `json:"file_ids"`
|
@ -1,4 +1,4 @@
|
|||||||
package groupmeExt
|
package groupmeext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
@ -1,4 +1,4 @@
|
|||||||
package groupmeExt
|
package groupmeext
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OldUserSuffix = "@c.groupme.com"
|
OldUserSuffix = "@c.groupme.com"
|
441
main.go
441
main.go
@ -17,320 +17,89 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"runtime/pprof"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
flag "maunium.net/go/mauflag"
|
"maunium.net/go/mautrix/bridge"
|
||||||
log "maunium.net/go/maulogger/v2"
|
"maunium.net/go/mautrix/bridge/commands"
|
||||||
|
"maunium.net/go/mautrix/bridge/status"
|
||||||
"maunium.net/go/mautrix"
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
|
||||||
"maunium.net/go/mautrix/event"
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
"maunium.net/go/mautrix/util/configupgrade"
|
||||||
|
|
||||||
|
"github.com/karmanyaahm/groupme"
|
||||||
|
|
||||||
"github.com/beeper/groupme/config"
|
"github.com/beeper/groupme/config"
|
||||||
"github.com/beeper/groupme/database"
|
"github.com/beeper/groupme/database"
|
||||||
"github.com/beeper/groupme/database/upgrades"
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Information to find out exactly which commit the bridge was built from.
|
||||||
|
// These are filled at build time with the -X linker flag.
|
||||||
var (
|
var (
|
||||||
// These are static
|
|
||||||
Name = "go-groupme"
|
|
||||||
URL = "https://github.com/tulir/mautrix-whatsapp"
|
|
||||||
// This is changed when making a release
|
|
||||||
Version = "0.1.5"
|
|
||||||
// This is filled by init()
|
|
||||||
WAVersion = ""
|
|
||||||
// These are filled at build time with the -X linker flag
|
|
||||||
Tag = "unknown"
|
Tag = "unknown"
|
||||||
Commit = "unknown"
|
Commit = "unknown"
|
||||||
BuildTime = "unknown"
|
BuildTime = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
//go:embed example-config.yaml
|
||||||
if len(Tag) > 0 && Tag[0] == 'v' {
|
var ExampleConfig string
|
||||||
Tag = Tag[1:]
|
|
||||||
}
|
|
||||||
if Tag != Version && !strings.HasSuffix(Version, "+dev") {
|
|
||||||
Version += "+dev"
|
|
||||||
}
|
|
||||||
WAVersion = strings.FieldsFunc(Version, func(r rune) bool { return r == '-' || r == '+' })[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String()
|
type GMBridge struct {
|
||||||
|
bridge.Bridge
|
||||||
//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String()
|
Config *config.Config
|
||||||
var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String()
|
DB *database.Database
|
||||||
var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool()
|
Provisioning *ProvisioningAPI
|
||||||
var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool()
|
Formatter *Formatter
|
||||||
var ignoreUnsupportedDatabase = flag.Make().LongKey("ignore-unsupported-database").Usage("Run even if database is too new").Default("false").Bool()
|
Metrics *MetricsHandler
|
||||||
var migrateFrom = flag.Make().LongKey("migrate-db").Usage("Source database type and URI to migrate from.").Bool()
|
|
||||||
var wantHelp, _ = flag.MakeHelpFlag()
|
|
||||||
|
|
||||||
func (bridge *Bridge) GenerateRegistration() {
|
|
||||||
reg, err := bridge.Config.NewRegistration()
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to generate registration:", err)
|
|
||||||
os.Exit(20)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = reg.Save(*registrationPath)
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to save registration:", err)
|
|
||||||
os.Exit(21)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bridge.Config.Save(*configPath)
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to save config:", err)
|
|
||||||
os.Exit(22)
|
|
||||||
}
|
|
||||||
fmt.Println("Registration generated. Add the path to the registration to your Synapse config, restart it, then start the bridge.")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) MigrateDatabase() {
|
|
||||||
oldDB, err := database.New(flag.Arg(0), flag.Arg(1), bridge.Log)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to open old database:", err)
|
|
||||||
os.Exit(30)
|
|
||||||
}
|
|
||||||
err = oldDB.Init()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to upgrade old database:", err)
|
|
||||||
os.Exit(31)
|
|
||||||
}
|
|
||||||
|
|
||||||
newDB, err := database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to open new database:", err)
|
|
||||||
os.Exit(32)
|
|
||||||
}
|
|
||||||
err = newDB.Init()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Failed to upgrade new database:", err)
|
|
||||||
os.Exit(33)
|
|
||||||
}
|
|
||||||
|
|
||||||
database.Migrate(oldDB, newDB)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bridge struct {
|
|
||||||
AS *appservice.AppService
|
|
||||||
EventProcessor *appservice.EventProcessor
|
|
||||||
MatrixHandler *MatrixHandler
|
|
||||||
Config *config.Config
|
|
||||||
DB *database.Database
|
|
||||||
Log log.Logger
|
|
||||||
StateStore *database.SQLStateStore
|
|
||||||
Provisioning *ProvisioningAPI
|
|
||||||
Bot *appservice.IntentAPI
|
|
||||||
Formatter *Formatter
|
|
||||||
Relaybot *User
|
|
||||||
Crypto Crypto
|
|
||||||
Metrics *MetricsHandler
|
|
||||||
|
|
||||||
usersByMXID map[id.UserID]*User
|
usersByMXID map[id.UserID]*User
|
||||||
usersByJID map[types.GroupMeID]*User
|
usersByUsername map[string]*User
|
||||||
|
usersByGMID map[groupme.ID]*User // TODO REMOVE?
|
||||||
usersLock sync.Mutex
|
usersLock sync.Mutex
|
||||||
|
spaceRooms map[id.RoomID]*User
|
||||||
|
spaceRoomsLock sync.Mutex
|
||||||
managementRooms map[id.RoomID]*User
|
managementRooms map[id.RoomID]*User
|
||||||
managementRoomsLock sync.Mutex
|
managementRoomsLock sync.Mutex
|
||||||
portalsByMXID map[id.RoomID]*Portal
|
portalsByMXID map[id.RoomID]*Portal
|
||||||
portalsByJID map[database.PortalKey]*Portal
|
portalsByGMID map[database.PortalKey]*Portal
|
||||||
portalsLock sync.Mutex
|
portalsLock sync.Mutex
|
||||||
puppets map[types.GroupMeID]*Puppet
|
puppets map[groupme.ID]*Puppet
|
||||||
puppetsByCustomMXID map[id.UserID]*Puppet
|
puppetsByCustomMXID map[id.UserID]*Puppet
|
||||||
puppetsLock sync.Mutex
|
puppetsLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type Crypto interface {
|
func (br *GMBridge) Init() {
|
||||||
HandleMemberEvent(*event.Event)
|
br.CommandProcessor = commands.NewProcessor(&br.Bridge)
|
||||||
Decrypt(*event.Event) (*event.Event, error)
|
br.RegisterCommands()
|
||||||
Encrypt(id.RoomID, event.Type, event.Content) (*event.EncryptedEventContent, error)
|
|
||||||
WaitForSession(id.RoomID, id.SenderKey, id.SessionID, time.Duration) bool
|
|
||||||
ResetSession(id.RoomID)
|
|
||||||
Init() error
|
|
||||||
Start()
|
|
||||||
Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBridge() *Bridge {
|
Segment.log = br.Log.Sub("Segment")
|
||||||
bridge := &Bridge{
|
Segment.key = br.Config.SegmentKey
|
||||||
usersByMXID: make(map[id.UserID]*User),
|
if Segment.IsEnabled() {
|
||||||
usersByJID: make(map[types.GroupMeID]*User),
|
Segment.log.Infoln("Segment metrics are enabled")
|
||||||
managementRooms: make(map[id.RoomID]*User),
|
|
||||||
portalsByMXID: make(map[id.RoomID]*Portal),
|
|
||||||
portalsByJID: make(map[database.PortalKey]*Portal),
|
|
||||||
puppets: make(map[types.GroupMeID]*Puppet),
|
|
||||||
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
br.DB = database.New(br.Bridge.DB, br.Log.Sub("Database"))
|
||||||
bridge.Config, err = config.Load(*configPath)
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to load config:", err)
|
|
||||||
os.Exit(10)
|
|
||||||
}
|
|
||||||
return bridge
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) ensureConnection() {
|
ss := br.Config.Bridge.Provisioning.SharedSecret
|
||||||
for {
|
|
||||||
resp, err := bridge.Bot.Whoami()
|
|
||||||
if err != nil {
|
|
||||||
if httpErr, ok := err.(mautrix.HTTPError); ok && httpErr.RespError != nil && httpErr.RespError.ErrCode == "M_UNKNOWN_ACCESS_TOKEN" {
|
|
||||||
bridge.Log.Fatalln("Access token invalid. Is the registration installed in your homeserver correctly?")
|
|
||||||
os.Exit(16)
|
|
||||||
}
|
|
||||||
bridge.Log.Errorfln("Failed to connect to homeserver: %v. Retrying in 10 seconds...", err)
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
} else if resp.UserID != bridge.Bot.UserID {
|
|
||||||
bridge.Log.Fatalln("Unexpected user ID in whoami call: got %s, expected %s", resp.UserID, bridge.Bot.UserID)
|
|
||||||
os.Exit(17)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) Init() {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
bridge.AS, err = bridge.Config.MakeAppService()
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to initialize AppService:", err)
|
|
||||||
os.Exit(11)
|
|
||||||
}
|
|
||||||
_, _ = bridge.AS.Init()
|
|
||||||
bridge.Bot = bridge.AS.BotIntent()
|
|
||||||
|
|
||||||
bridge.Log = log.Create()
|
|
||||||
bridge.Config.Logging.Configure(bridge.Log)
|
|
||||||
log.DefaultLogger = bridge.Log.(*log.BasicLogger)
|
|
||||||
if len(bridge.Config.Logging.FileNameFormat) > 0 {
|
|
||||||
err = log.OpenFile()
|
|
||||||
if err != nil {
|
|
||||||
_, _ = fmt.Fprintln(os.Stderr, "Failed to open log file:", err)
|
|
||||||
os.Exit(12)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bridge.AS.Log = log.Sub("Matrix")
|
|
||||||
|
|
||||||
bridge.Log.Debugln("Initializing database connection")
|
|
||||||
print("test1")
|
|
||||||
|
|
||||||
bridge.DB, err = database.New(bridge.Config.AppService.Database.Type, bridge.Config.AppService.Database.URI, bridge.Log)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
bridge.Log.Fatalln("Failed to initialize database connection:", err)
|
|
||||||
os.Exit(14)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(bridge.Config.AppService.StateStore) > 0 && bridge.Config.AppService.StateStore != "./mx-state.json" {
|
|
||||||
version, err := upgrades.GetVersion(bridge.DB.DB)
|
|
||||||
if version < 0 && err == nil {
|
|
||||||
bridge.Log.Fatalln("Non-standard state store path. Please move the state store to ./mx-state.json " +
|
|
||||||
"and update the config. The state store will be migrated into the db on the next launch.")
|
|
||||||
os.Exit(18)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bridge.Log.Debugln("Initializing state store")
|
|
||||||
bridge.StateStore = database.NewSQLStateStore(bridge.DB)
|
|
||||||
bridge.AS.StateStore = bridge.StateStore
|
|
||||||
|
|
||||||
// bridge.DB.SetMaxOpenConns(bridge.Config.AppService.Database.MaxOpenConns)
|
|
||||||
// bridge.DB.SetMaxIdleConns(bridge.Config.AppService.Database.MaxIdleConns)
|
|
||||||
|
|
||||||
ss := bridge.Config.AppService.Provisioning.SharedSecret
|
|
||||||
if len(ss) > 0 && ss != "disable" {
|
if len(ss) > 0 && ss != "disable" {
|
||||||
bridge.Provisioning = &ProvisioningAPI{bridge: bridge}
|
br.Provisioning = &ProvisioningAPI{bridge: br}
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge.Log.Debugln("Initializing Matrix event processor")
|
br.Formatter = NewFormatter(br)
|
||||||
bridge.EventProcessor = appservice.NewEventProcessor(bridge.AS)
|
br.Metrics = NewMetricsHandler(br.Config.Metrics.Listen, br.Log.Sub("Metrics"), br.DB)
|
||||||
bridge.Log.Debugln("Initializing Matrix event handler")
|
br.MatrixHandler.TrackEventDuration = br.Metrics.TrackMatrixEvent
|
||||||
bridge.MatrixHandler = NewMatrixHandler(bridge)
|
|
||||||
bridge.Formatter = NewFormatter(bridge)
|
|
||||||
bridge.Crypto = NewCryptoHelper(bridge)
|
|
||||||
bridge.Metrics = NewMetricsHandler(bridge.Config.Metrics.Listen, bridge.Log.Sub("Metrics"), bridge.DB)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) Start() {
|
func (bridge *GMBridge) Start() {
|
||||||
bridge.Log.Debugln("Running database upgrades")
|
|
||||||
err := bridge.DB.Init()
|
|
||||||
if err != nil && (err != upgrades.UnsupportedDatabaseVersion || !*ignoreUnsupportedDatabase) {
|
|
||||||
bridge.Log.Fatalln("Failed to initialize database:", err)
|
|
||||||
os.Exit(15)
|
|
||||||
}
|
|
||||||
bridge.Log.Debugln("Checking connection to homeserver")
|
|
||||||
bridge.ensureConnection()
|
|
||||||
if bridge.Crypto != nil {
|
|
||||||
err := bridge.Crypto.Init()
|
|
||||||
if err != nil {
|
|
||||||
bridge.Log.Fatalln("Error initializing end-to-bridge encryption:", err)
|
|
||||||
os.Exit(19)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if bridge.Provisioning != nil {
|
if bridge.Provisioning != nil {
|
||||||
bridge.Log.Debugln("Initializing provisioning API")
|
bridge.Log.Debugln("Initializing provisioning API")
|
||||||
bridge.Provisioning.Init()
|
bridge.Provisioning.Init()
|
||||||
}
|
}
|
||||||
bridge.LoadRelaybot()
|
|
||||||
bridge.Log.Debugln("Starting application service HTTP server")
|
|
||||||
go bridge.AS.Start()
|
|
||||||
bridge.Log.Debugln("Starting event processor")
|
|
||||||
go bridge.EventProcessor.Start()
|
|
||||||
go bridge.UpdateBotProfile()
|
|
||||||
if bridge.Crypto != nil {
|
|
||||||
go bridge.Crypto.Start()
|
|
||||||
}
|
|
||||||
go bridge.StartUsers()
|
go bridge.StartUsers()
|
||||||
if bridge.Config.Metrics.Enabled {
|
if bridge.Config.Metrics.Enabled {
|
||||||
go bridge.Metrics.Start()
|
go bridge.Metrics.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if bridge.Config.Bridge.ResendBridgeInfo {
|
|
||||||
go bridge.ResendBridgeInfo()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) ResendBridgeInfo() {
|
func (bridge *GMBridge) UpdateBotProfile() {
|
||||||
bridge.Config.Bridge.ResendBridgeInfo = false
|
|
||||||
err := bridge.Config.Save(*configPath)
|
|
||||||
if err != nil {
|
|
||||||
bridge.Log.Errorln("Failed to save config after setting resend_bridge_info to false:", err)
|
|
||||||
}
|
|
||||||
bridge.Log.Infoln("Re-sending bridge info state event to all portals")
|
|
||||||
for _, portal := range bridge.GetAllPortals() {
|
|
||||||
portal.UpdateBridgeInfo()
|
|
||||||
}
|
|
||||||
bridge.Log.Infoln("Finished re-sending bridge info state events")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) LoadRelaybot() {
|
|
||||||
if !bridge.Config.Bridge.Relaybot.Enabled {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
bridge.Relaybot = bridge.GetUserByMXID("relaybot")
|
|
||||||
if bridge.Relaybot.HasSession() {
|
|
||||||
bridge.Log.Debugln("Relaybot is enabled")
|
|
||||||
} else {
|
|
||||||
bridge.Log.Debugln("Relaybot is enabled, but not logged in")
|
|
||||||
}
|
|
||||||
bridge.Relaybot.ManagementRoom = bridge.Config.Bridge.Relaybot.ManagementRoom
|
|
||||||
bridge.Relaybot.IsRelaybot = true
|
|
||||||
bridge.Relaybot.Connect()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) UpdateBotProfile() {
|
|
||||||
bridge.Log.Debugln("Updating bot profile")
|
bridge.Log.Debugln("Updating bot profile")
|
||||||
botConfig := bridge.Config.AppService.Bot
|
botConfig := bridge.Config.AppService.Bot
|
||||||
|
|
||||||
@ -358,16 +127,23 @@ func (bridge *Bridge) UpdateBotProfile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) StartUsers() {
|
func (br *GMBridge) StartUsers() {
|
||||||
bridge.Log.Debugln("Starting users")
|
br.Log.Debugln("Starting users")
|
||||||
for _, user := range bridge.GetAllUsers() {
|
foundAnySessions := false
|
||||||
|
for _, user := range br.GetAllUsers() {
|
||||||
|
if user.GMID.String() != "" {
|
||||||
|
foundAnySessions = true
|
||||||
|
}
|
||||||
go user.Connect()
|
go user.Connect()
|
||||||
}
|
}
|
||||||
bridge.Log.Debugln("Starting custom puppets")
|
if !foundAnySessions {
|
||||||
for _, loopuppet := range bridge.GetAllPuppetsWithCustomMXID() {
|
br.SendGlobalBridgeState(status.BridgeState{StateEvent: status.StateUnconfigured}.Fill(nil))
|
||||||
|
}
|
||||||
|
br.Log.Debugln("Starting custom puppets")
|
||||||
|
for _, loopuppet := range br.GetAllPuppetsWithCustomMXID() {
|
||||||
go func(puppet *Puppet) {
|
go func(puppet *Puppet) {
|
||||||
puppet.log.Debugln("Starting custom puppet", puppet.CustomMXID)
|
puppet.log.Debugln("Starting custom puppet", puppet.CustomMXID)
|
||||||
err := puppet.StartCustomMXID()
|
err := puppet.StartCustomMXID(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.log.Errorln("Failed to start custom puppet:", err)
|
puppet.log.Errorln("Failed to start custom puppet:", err)
|
||||||
}
|
}
|
||||||
@ -375,89 +151,58 @@ func (bridge *Bridge) StartUsers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) Stop() {
|
func (br *GMBridge) Stop() {
|
||||||
if bridge.Crypto != nil {
|
br.Metrics.Stop()
|
||||||
bridge.Crypto.Stop()
|
// TODO anything needed to disconnect the users?
|
||||||
}
|
for _, user := range br.usersByUsername {
|
||||||
bridge.AS.Stop()
|
if user.Client == nil {
|
||||||
bridge.Metrics.Stop()
|
|
||||||
bridge.EventProcessor.Stop()
|
|
||||||
for _, user := range bridge.usersByJID {
|
|
||||||
if user.Conn == nil {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bridge.Log.Debugln("Disconnecting", user.MXID)
|
br.Log.Debugln("Disconnecting", user.MXID)
|
||||||
//sess, err :=
|
|
||||||
//user.Conn.Stop(context.TODO())
|
|
||||||
// if err != nil {
|
|
||||||
// bridge.Log.Errorfln("Error while disconnecting %s: %v", user.MXID, err)
|
|
||||||
// } else if len(sess.Wid) > 0 {
|
|
||||||
// user.SetSession(&sess)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cpuprofile = flag.MakeFull("", "cpuprofile", "write cpu profile to `file`", "").String()
|
func (br *GMBridge) GetExampleConfig() string {
|
||||||
|
return ExampleConfig
|
||||||
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) Main() {
|
func (br *GMBridge) GetConfigPtr() interface{} {
|
||||||
|
br.Config = &config.Config{
|
||||||
if *generateRegistration {
|
BaseConfig: &br.Bridge.Config,
|
||||||
bridge.GenerateRegistration()
|
|
||||||
return
|
|
||||||
} else if *migrateFrom {
|
|
||||||
bridge.MigrateDatabase()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
bridge.Init()
|
br.Config.BaseConfig.Bridge = &br.Config.Bridge
|
||||||
bridge.Log.Infoln("Bridge initialization complete, starting...")
|
return br.Config
|
||||||
bridge.Start()
|
|
||||||
bridge.Log.Infoln("Bridge started!")
|
|
||||||
|
|
||||||
if *cpuprofile != "" {
|
|
||||||
println("profiling")
|
|
||||||
f, err := os.Create(*cpuprofile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("could not create CPU profile: ", err)
|
|
||||||
}
|
|
||||||
defer f.Close() // error handling omitted for example
|
|
||||||
if err := pprof.StartCPUProfile(f); err != nil {
|
|
||||||
log.Fatal("could not start CPU profile: ", err)
|
|
||||||
}
|
|
||||||
defer pprof.StopCPUProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
||||||
<-c
|
|
||||||
|
|
||||||
bridge.Log.Infoln("Interrupt received, stopping...")
|
|
||||||
bridge.Stop()
|
|
||||||
bridge.Log.Infoln("Bridge stopped.")
|
|
||||||
//os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.SetHelpTitles(
|
br := &GMBridge{
|
||||||
"go-groupme - A Matrix-GroupMe puppeting bridge.",
|
usersByMXID: make(map[id.UserID]*User),
|
||||||
"go-groupme [-h] [-c <path>] [-r <path>] [-g] [--migrate-db <source type> <source uri>]")
|
usersByUsername: make(map[string]*User),
|
||||||
err := flag.Parse()
|
spaceRooms: make(map[id.RoomID]*User),
|
||||||
if err != nil {
|
managementRooms: make(map[id.RoomID]*User),
|
||||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
portalsByMXID: make(map[id.RoomID]*Portal),
|
||||||
flag.PrintHelp()
|
portalsByGMID: make(map[database.PortalKey]*Portal),
|
||||||
os.Exit(1)
|
puppets: make(map[groupme.ID]*Puppet),
|
||||||
} else if *wantHelp {
|
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
||||||
flag.PrintHelp()
|
|
||||||
os.Exit(0)
|
|
||||||
} else if *version {
|
|
||||||
if Tag == Version {
|
|
||||||
fmt.Printf("%s %s (%s)\n", Name, Tag, BuildTime)
|
|
||||||
} else if len(Commit) > 8 {
|
|
||||||
fmt.Printf("%s %s.%s (%s)\n", Name, Version, Commit[:8], BuildTime)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("%s %s.unknown\n", Name, Version)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
br.Bridge = bridge.Bridge{
|
||||||
|
Name: "groupme-matrix",
|
||||||
|
URL: "https://github.com/beeper/groupme",
|
||||||
|
Description: "A Matrix-GroupMe puppeting bridge.",
|
||||||
|
Version: "0.1.0",
|
||||||
|
ProtocolName: "GroupMe",
|
||||||
|
|
||||||
NewBridge().Main()
|
CryptoPickleKey: "github.com/beeper/groupme",
|
||||||
|
|
||||||
|
ConfigUpgrader: &configupgrade.StructUpgrader{
|
||||||
|
SimpleUpgrader: configupgrade.SimpleUpgrader(config.DoUpgrade),
|
||||||
|
Blocks: config.SpacedBlocks,
|
||||||
|
Base: ExampleConfig,
|
||||||
|
},
|
||||||
|
|
||||||
|
Child: br,
|
||||||
|
}
|
||||||
|
br.InitVersion(Tag, Commit, BuildTime)
|
||||||
|
|
||||||
|
br.Main()
|
||||||
}
|
}
|
||||||
|
446
matrix.go
446
matrix.go
@ -17,15 +17,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"maunium.net/go/maulogger/v2"
|
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/bridge"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@ -33,433 +28,76 @@ import (
|
|||||||
"github.com/beeper/groupme/database"
|
"github.com/beeper/groupme/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MatrixHandler struct {
|
func (br *GMBridge) CreatePrivatePortal(roomID id.RoomID, brInviter bridge.User, brGhost bridge.Ghost) {
|
||||||
bridge *Bridge
|
inviter := brInviter.(*User)
|
||||||
as *appservice.AppService
|
puppet := brGhost.(*Puppet)
|
||||||
log maulogger.Logger
|
key := database.NewPortalKey(puppet.GMID, inviter.GMID)
|
||||||
cmd *CommandHandler
|
portal := br.GetPortalByGMID(key)
|
||||||
}
|
|
||||||
|
|
||||||
func NewMatrixHandler(bridge *Bridge) *MatrixHandler {
|
|
||||||
handler := &MatrixHandler{
|
|
||||||
bridge: bridge,
|
|
||||||
as: bridge.AS,
|
|
||||||
log: bridge.Log.Sub("Matrix"),
|
|
||||||
cmd: NewCommandHandler(bridge),
|
|
||||||
}
|
|
||||||
bridge.EventProcessor.On(event.EventMessage, handler.HandleMessage)
|
|
||||||
bridge.EventProcessor.On(event.EventEncrypted, handler.HandleEncrypted)
|
|
||||||
bridge.EventProcessor.On(event.EventSticker, handler.HandleMessage)
|
|
||||||
bridge.EventProcessor.On(event.EventRedaction, handler.HandleRedaction)
|
|
||||||
bridge.EventProcessor.On(event.StateMember, handler.HandleMembership)
|
|
||||||
bridge.EventProcessor.On(event.StateRoomName, handler.HandleRoomMetadata)
|
|
||||||
bridge.EventProcessor.On(event.StateRoomAvatar, handler.HandleRoomMetadata)
|
|
||||||
bridge.EventProcessor.On(event.StateTopic, handler.HandleRoomMetadata)
|
|
||||||
bridge.EventProcessor.On(event.StateEncryption, handler.HandleEncryption)
|
|
||||||
return handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleEncryption(evt *event.Event) {
|
|
||||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
if evt.Content.AsEncryption().Algorithm != id.AlgorithmMegolmV1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
|
||||||
if portal != nil && !portal.Encrypted {
|
|
||||||
mx.log.Debugfln("%s enabled encryption in %s", evt.Sender, evt.RoomID)
|
|
||||||
portal.Encrypted = true
|
|
||||||
portal.Update()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) joinAndCheckMembers(evt *event.Event, intent *appservice.IntentAPI) *mautrix.RespJoinedMembers {
|
|
||||||
resp, err := intent.JoinRoomByID(evt.RoomID)
|
|
||||||
if err != nil {
|
|
||||||
mx.log.Debugfln("Failed to join room %s as %s with invite from %s: %v", evt.RoomID, intent.UserID, evt.Sender, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
members, err := intent.JoinedMembers(resp.RoomID)
|
|
||||||
if err != nil {
|
|
||||||
mx.log.Debugfln("Failed to get members in room %s after accepting invite from %s as %s: %v", resp.RoomID, evt.Sender, intent.UserID, err)
|
|
||||||
_, _ = intent.LeaveRoom(resp.RoomID)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(members.Joined) < 2 {
|
|
||||||
mx.log.Debugln("Leaving empty room", resp.RoomID, "after accepting invite from", evt.Sender, "as", intent.UserID)
|
|
||||||
_, _ = intent.LeaveRoom(resp.RoomID)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return members
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleBotInvite(evt *event.Event) {
|
|
||||||
intent := mx.as.BotIntent()
|
|
||||||
|
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
if user == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
members := mx.joinAndCheckMembers(evt, intent)
|
|
||||||
if members == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !user.Whitelisted {
|
|
||||||
_, _ = intent.SendNotice(evt.RoomID, "You are not whitelisted to use this bridge.\n"+
|
|
||||||
"If you're the owner of this bridge, see the bridge.permissions section in your config file.")
|
|
||||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if evt.RoomID == mx.bridge.Config.Bridge.Relaybot.ManagementRoom {
|
|
||||||
_, _ = intent.SendNotice(evt.RoomID, "This is the relaybot management room. Send `!wa help` to get a list of commands.")
|
|
||||||
mx.log.Debugln("Joined relaybot management room", evt.RoomID, "after invite from", evt.Sender)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
hasPuppets := false
|
|
||||||
for mxid, _ := range members.Joined {
|
|
||||||
if mxid == intent.UserID || mxid == evt.Sender {
|
|
||||||
continue
|
|
||||||
} else if _, ok := mx.bridge.ParsePuppetMXID(mxid); ok {
|
|
||||||
hasPuppets = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
mx.log.Debugln("Leaving multi-user room", evt.RoomID, "after accepting invite from", evt.Sender)
|
|
||||||
_, _ = intent.SendNotice(evt.RoomID, "This bridge is user-specific, please don't invite me into rooms with other users.")
|
|
||||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasPuppets && (len(user.ManagementRoom) == 0 || evt.Content.AsMember().IsDirect) {
|
|
||||||
user.SetManagementRoom(evt.RoomID)
|
|
||||||
_, _ = intent.SendNotice(user.ManagementRoom, "This room has been registered as your bridge management/status room. Send `help` to get a list of commands.")
|
|
||||||
mx.log.Debugln(evt.RoomID, "registered as a management room with", evt.Sender)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) handlePrivatePortal(roomID id.RoomID, inviter *User, puppet *Puppet, key database.PortalKey) {
|
|
||||||
portal := mx.bridge.GetPortalByJID(key)
|
|
||||||
|
|
||||||
if len(portal.MXID) == 0 {
|
if len(portal.MXID) == 0 {
|
||||||
mx.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
br.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := portal.MainIntent().EnsureInvited(portal.MXID, inviter.MXID)
|
ok := portal.ensureUserInvited(inviter)
|
||||||
if err != nil {
|
if !ok {
|
||||||
mx.log.Warnfln("Failed to invite %s to existing private chat portal %s with %s: %v. Redirecting portal to new room...", inviter.MXID, portal.MXID, puppet.JID, err)
|
br.Log.Warnfln("Failed to invite %s to existing private chat portal %s with %s. Redirecting portal to new room...", inviter.MXID, portal.MXID, puppet.GMID)
|
||||||
mx.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
br.createPrivatePortalFromInvite(roomID, inviter, puppet, portal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
intent := puppet.DefaultIntent()
|
intent := puppet.DefaultIntent()
|
||||||
_, _ = intent.SendNotice(roomID, "You already have a private chat portal with me at %s")
|
errorMessage := fmt.Sprintf("You already have a private chat portal with me at [%[1]s](https://matrix.to/#/%[1]s)", portal.MXID)
|
||||||
mx.log.Debugln("Leaving private chat room", roomID, "as", puppet.MXID, "after accepting invite from", inviter.MXID, "as we already have chat with the user")
|
errorContent := format.RenderMarkdown(errorMessage, true, false)
|
||||||
|
_, _ = intent.SendMessageEvent(roomID, event.EventMessage, errorContent)
|
||||||
|
br.Log.Debugfln("Leaving private chat room %s as %s after accepting invite from %s as we already have chat with the user", roomID, puppet.MXID, inviter.MXID)
|
||||||
_, _ = intent.LeaveRoom(roomID)
|
_, _ = intent.LeaveRoom(roomID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
func (br *GMBridge) createPrivatePortalFromInvite(roomID id.RoomID, inviter *User, puppet *Puppet, portal *Portal) {
|
||||||
|
// TODO check if room is already encrypted
|
||||||
|
var existingEncryption event.EncryptionEventContent
|
||||||
|
var encryptionEnabled bool
|
||||||
|
err := portal.MainIntent().StateEvent(roomID, event.StateEncryption, "", &existingEncryption)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Warnfln("Failed to check if encryption is enabled in private chat room %s", roomID)
|
||||||
|
} else {
|
||||||
|
encryptionEnabled = existingEncryption.Algorithm == id.AlgorithmMegolmV1
|
||||||
|
}
|
||||||
portal.MXID = roomID
|
portal.MXID = roomID
|
||||||
portal.Topic = "WhatsApp private chat"
|
|
||||||
portal.Key = database.PortalKey{JID: puppet.JID, Receiver: inviter.JID}
|
|
||||||
|
|
||||||
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
_, _ = portal.MainIntent().SetRoomTopic(portal.MXID, portal.Topic)
|
||||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
if portal.bridge.Config.Bridge.PrivateChatPortalMeta || br.Config.Bridge.Encryption.Default || encryptionEnabled {
|
||||||
m, _ := mx.bridge.StateStore.TryGetMemberRaw(portal.MXID, puppet.MXID)
|
portal.Name = puppet.Displayname
|
||||||
portal.Name = m.DisplayName
|
portal.AvatarURL = puppet.AvatarURL
|
||||||
portal.AvatarURL = id.MustParseContentURI(m.AvatarURL)
|
portal.Avatar = puppet.Avatar
|
||||||
print("possible bug with pointer above")
|
|
||||||
portal.Avatar = m.Avatar
|
|
||||||
_, _ = portal.MainIntent().SetRoomName(portal.MXID, portal.Name)
|
_, _ = portal.MainIntent().SetRoomName(portal.MXID, portal.Name)
|
||||||
_, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
_, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
||||||
} else {
|
} else {
|
||||||
portal.Name = ""
|
portal.Name = ""
|
||||||
}
|
}
|
||||||
portal.log.Infoln("Created private chat portal in %s after invite from", roomID, inviter.MXID)
|
portal.log.Infofln("Created private chat portal in %s after invite from %s", roomID, inviter.MXID)
|
||||||
intent := puppet.DefaultIntent()
|
intent := puppet.DefaultIntent()
|
||||||
|
|
||||||
if mx.bridge.Config.Bridge.Encryption.Default {
|
if br.Config.Bridge.Encryption.Default || encryptionEnabled {
|
||||||
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: mx.bridge.Bot.UserID})
|
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: br.Bot.UserID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnln("Failed to invite bridge bot to enable e2be:", err)
|
portal.log.Warnln("Failed to invite bridge bot to enable e2be:", err)
|
||||||
}
|
}
|
||||||
err = mx.bridge.Bot.EnsureJoined(roomID)
|
err = br.Bot.EnsureJoined(roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Warnln("Failed to join as bridge bot to enable e2be:", err)
|
portal.log.Warnln("Failed to join as bridge bot to enable e2be:", err)
|
||||||
}
|
}
|
||||||
_, err = intent.SendStateEvent(roomID, event.StateEncryption, "", &event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1})
|
if !encryptionEnabled {
|
||||||
if err != nil {
|
_, err = intent.SendStateEvent(roomID, event.StateEncryption, "", portal.GetEncryptionEventContent())
|
||||||
portal.log.Warnln("Failed to enable e2be:", err)
|
if err != nil {
|
||||||
|
portal.log.Warnln("Failed to enable e2be:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mx.as.StateStore.SetMembership(roomID, inviter.MXID, event.MembershipJoin)
|
br.AS.StateStore.SetMembership(roomID, inviter.MXID, event.MembershipJoin)
|
||||||
mx.as.StateStore.SetMembership(roomID, puppet.MXID, event.MembershipJoin)
|
br.AS.StateStore.SetMembership(roomID, puppet.MXID, event.MembershipJoin)
|
||||||
mx.as.StateStore.SetMembership(roomID, mx.bridge.Bot.UserID, event.MembershipJoin)
|
br.AS.StateStore.SetMembership(roomID, br.Bot.UserID, event.MembershipJoin)
|
||||||
portal.Encrypted = true
|
portal.Encrypted = true
|
||||||
}
|
}
|
||||||
portal.Update()
|
portal.Update(nil)
|
||||||
portal.UpdateBridgeInfo()
|
portal.UpdateBridgeInfo()
|
||||||
_, _ = intent.SendNotice(roomID, "Private chat portal created")
|
_, _ = intent.SendNotice(roomID, "Private chat portal created")
|
||||||
|
|
||||||
err := portal.FillInitialHistory(inviter)
|
|
||||||
if err != nil {
|
|
||||||
portal.log.Errorln("Failed to fill history:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
inviter.addPortalToCommunity(portal)
|
|
||||||
inviter.addPuppetToCommunity(puppet)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandlePuppetInvite(evt *event.Event, inviter *User, puppet *Puppet) {
|
|
||||||
intent := puppet.DefaultIntent()
|
|
||||||
members := mx.joinAndCheckMembers(evt, intent)
|
|
||||||
if members == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var hasBridgeBot, hasOtherUsers bool
|
|
||||||
for mxid, _ := range members.Joined {
|
|
||||||
if mxid == intent.UserID || mxid == inviter.MXID {
|
|
||||||
continue
|
|
||||||
} else if mxid == mx.bridge.Bot.UserID {
|
|
||||||
hasBridgeBot = true
|
|
||||||
} else {
|
|
||||||
hasOtherUsers = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !hasBridgeBot && !hasOtherUsers {
|
|
||||||
key := database.NewPortalKey(puppet.JID, inviter.JID)
|
|
||||||
mx.handlePrivatePortal(evt.RoomID, inviter, puppet, key)
|
|
||||||
} else if !hasBridgeBot {
|
|
||||||
mx.log.Debugln("Leaving multi-user room", evt.RoomID, "as", puppet.MXID, "after accepting invite from", evt.Sender)
|
|
||||||
_, _ = intent.SendNotice(evt.RoomID, "Please invite the bridge bot first if you want to bridge to a WhatsApp group.")
|
|
||||||
_, _ = intent.LeaveRoom(evt.RoomID)
|
|
||||||
} else {
|
|
||||||
_, _ = intent.SendNotice(evt.RoomID, "This puppet will remain inactive until this room is bridged to a WhatsApp group.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleMembership(evt *event.Event) {
|
|
||||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
|
|
||||||
if mx.bridge.Crypto != nil {
|
|
||||||
mx.bridge.Crypto.HandleMemberEvent(evt)
|
|
||||||
}
|
|
||||||
|
|
||||||
content := evt.Content.AsMember()
|
|
||||||
if content.Membership == event.MembershipInvite && id.UserID(evt.GetStateKey()) == mx.as.BotMXID() {
|
|
||||||
mx.HandleBotInvite(evt)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
if user == nil || !user.Whitelisted || !user.IsConnected() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
|
||||||
if portal == nil {
|
|
||||||
puppet := mx.bridge.GetPuppetByMXID(id.UserID(evt.GetStateKey()))
|
|
||||||
if content.Membership == event.MembershipInvite && puppet != nil {
|
|
||||||
mx.HandlePuppetInvite(evt, user, puppet)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isSelf := id.UserID(evt.GetStateKey()) == evt.Sender
|
|
||||||
|
|
||||||
if content.Membership == event.MembershipLeave {
|
|
||||||
if isSelf {
|
|
||||||
if evt.Unsigned.PrevContent != nil {
|
|
||||||
_ = evt.Unsigned.PrevContent.ParseRaw(evt.Type)
|
|
||||||
prevContent, ok := evt.Unsigned.PrevContent.Parsed.(*event.MemberEventContent)
|
|
||||||
if ok {
|
|
||||||
if portal.IsPrivateChat() || prevContent.Membership == "join" {
|
|
||||||
portal.HandleMatrixLeave(user)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
portal.HandleMatrixKick(user, evt)
|
|
||||||
}
|
|
||||||
} else if content.Membership == event.MembershipInvite && !isSelf {
|
|
||||||
portal.HandleMatrixInvite(user, evt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleRoomMetadata(evt *event.Event) {
|
|
||||||
// defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
// user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
// if user == nil || !user.Whitelisted || !user.IsConnected() {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
|
||||||
// if portal == nil || portal.IsPrivateChat() {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var resp <-chan string
|
|
||||||
// var err error
|
|
||||||
// switch content := evt.Content.Parsed.(type) {
|
|
||||||
// case *event.RoomNameEventContent:
|
|
||||||
// resp, err = user.Conn.UpdateGroupSubject(content.Name, portal.Key.JID)
|
|
||||||
// case *event.TopicEventContent:
|
|
||||||
// resp, err = user.Conn.UpdateGroupDescription(portal.Key.JID, content.Topic)
|
|
||||||
// case *event.RoomAvatarEventContent:
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if err != nil {
|
|
||||||
// mx.log.Errorln(err)
|
|
||||||
// } else {
|
|
||||||
// out := <-resp
|
|
||||||
// mx.log.Infoln(out)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) shouldIgnoreEvent(evt *event.Event) bool {
|
|
||||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
isCustomPuppet, ok := evt.Content.Raw["net.maunium.whatsapp.puppet"].(bool)
|
|
||||||
if ok && isCustomPuppet && mx.bridge.GetPuppetByCustomMXID(evt.Sender) != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
if !user.RelaybotWhitelisted {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const sessionWaitTimeout = 5 * time.Second
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleEncrypted(evt *event.Event) {
|
|
||||||
println("IDK iF encryption works yet")
|
|
||||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
if mx.shouldIgnoreEvent(evt) || mx.bridge.Crypto == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
|
||||||
if errors.Is(err, NoSessionFound) {
|
|
||||||
content := evt.Content.AsEncrypted()
|
|
||||||
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d seconds...", content.SessionID, evt.ID, int(sessionWaitTimeout.Seconds()))
|
|
||||||
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, sessionWaitTimeout) {
|
|
||||||
mx.log.Debugfln("Got session %s after waiting, trying to decrypt %s again", content.SessionID, evt.ID)
|
|
||||||
decrypted, err = mx.bridge.Crypto.Decrypt(evt)
|
|
||||||
} else {
|
|
||||||
go mx.waitLongerForSession(evt)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
mx.log.Warnfln("Failed to decrypt %s: %v", evt.ID, err)
|
|
||||||
_, _ = mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
|
||||||
"\u26a0 Your message was not bridged: %v", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) waitLongerForSession(evt *event.Event) {
|
|
||||||
const extendedTimeout = sessionWaitTimeout * 2
|
|
||||||
|
|
||||||
content := evt.Content.AsEncrypted()
|
|
||||||
mx.log.Debugfln("Couldn't find session %s trying to decrypt %s, waiting %d more seconds...",
|
|
||||||
content.SessionID, evt.ID, int(extendedTimeout.Seconds()))
|
|
||||||
|
|
||||||
resp, err := mx.bridge.Bot.SendNotice(evt.RoomID, fmt.Sprintf(
|
|
||||||
"\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. "+
|
|
||||||
"The bridge will retry for %d seconds. If this error keeps happening, try restarting your client.",
|
|
||||||
int(extendedTimeout.Seconds())))
|
|
||||||
if err != nil {
|
|
||||||
mx.log.Errorfln("Failed to send decryption error to %s: %v", evt.RoomID, err)
|
|
||||||
}
|
|
||||||
update := event.MessageEventContent{MsgType: event.MsgNotice}
|
|
||||||
|
|
||||||
if mx.bridge.Crypto.WaitForSession(evt.RoomID, content.SenderKey, content.SessionID, extendedTimeout) {
|
|
||||||
mx.log.Debugfln("Got session %s after waiting more, trying to decrypt %s again", content.SessionID, evt.ID)
|
|
||||||
decrypted, err := mx.bridge.Crypto.Decrypt(evt)
|
|
||||||
if err == nil {
|
|
||||||
mx.bridge.EventProcessor.Dispatch(decrypted)
|
|
||||||
_, _ = mx.bridge.Bot.RedactEvent(evt.RoomID, resp.EventID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mx.log.Warnfln("Failed to decrypt %s: %v", err)
|
|
||||||
update.Body = fmt.Sprintf("\u26a0 Your message was not bridged: %v", err)
|
|
||||||
} else {
|
|
||||||
mx.log.Debugfln("Didn't get %s, giving up on %s", content.SessionID, evt.ID)
|
|
||||||
update.Body = "\u26a0 Your message was not bridged: the bridge hasn't received the decryption keys. " +
|
|
||||||
"If this keeps happening, try restarting your client."
|
|
||||||
}
|
|
||||||
|
|
||||||
newContent := update
|
|
||||||
update.NewContent = &newContent
|
|
||||||
if resp != nil {
|
|
||||||
update.RelatesTo = &event.RelatesTo{
|
|
||||||
Type: event.RelReplace,
|
|
||||||
EventID: resp.EventID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_, _ = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, &update)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleMessage(evt *event.Event) {
|
|
||||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
if mx.shouldIgnoreEvent(evt) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
content := evt.Content.AsMessage()
|
|
||||||
if user.Whitelisted && content.MsgType == event.MsgText {
|
|
||||||
commandPrefix := mx.bridge.Config.Bridge.CommandPrefix
|
|
||||||
hasCommandPrefix := strings.HasPrefix(content.Body, commandPrefix)
|
|
||||||
if hasCommandPrefix {
|
|
||||||
content.Body = strings.TrimLeft(content.Body[len(commandPrefix):], " ")
|
|
||||||
}
|
|
||||||
if hasCommandPrefix || evt.RoomID == user.ManagementRoom {
|
|
||||||
mx.cmd.Handle(evt.RoomID, user, content.Body)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
|
||||||
if portal != nil && (user.Whitelisted || portal.HasRelaybot()) {
|
|
||||||
portal.HandleMatrixMessage(user, evt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mx *MatrixHandler) HandleRedaction(evt *event.Event) {
|
|
||||||
defer mx.bridge.Metrics.TrackEvent(evt.Type)()
|
|
||||||
if _, isPuppet := mx.bridge.ParsePuppetMXID(evt.Sender); evt.Sender == mx.bridge.Bot.UserID || isPuppet {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
user := mx.bridge.GetUserByMXID(evt.Sender)
|
|
||||||
|
|
||||||
if !user.Whitelisted {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !user.HasSession() {
|
|
||||||
return
|
|
||||||
} else if !user.IsConnected() {
|
|
||||||
msg := format.RenderMarkdown(fmt.Sprintf("[%[1]s](https://matrix.to/#/%[1]s): \u26a0 "+
|
|
||||||
"You are not connected to WhatsApp, so your redaction was not bridged. "+
|
|
||||||
"Use `%[2]s reconnect` to reconnect.", user.MXID, mx.bridge.Config.Bridge.CommandPrefix), true, false)
|
|
||||||
msg.MsgType = event.MsgNotice
|
|
||||||
_, _ = mx.bridge.Bot.SendMessageEvent(evt.RoomID, event.EventMessage, msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
portal := mx.bridge.GetPortalByMXID(evt.RoomID)
|
|
||||||
if portal != nil {
|
|
||||||
portal.HandleMatrixRedaction(user, evt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
68
metrics.go
68
metrics.go
@ -22,6 +22,7 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/karmanyaahm/groupme"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -31,7 +32,6 @@ import (
|
|||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"github.com/beeper/groupme/database"
|
"github.com/beeper/groupme/database"
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MetricsHandler struct {
|
type MetricsHandler struct {
|
||||||
@ -43,7 +43,7 @@ type MetricsHandler struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
stopRecorder func()
|
stopRecorder func()
|
||||||
|
|
||||||
messageHandling *prometheus.HistogramVec
|
matrixEventHandling *prometheus.HistogramVec
|
||||||
countCollection prometheus.Histogram
|
countCollection prometheus.Histogram
|
||||||
disconnections *prometheus.CounterVec
|
disconnections *prometheus.CounterVec
|
||||||
puppetCount prometheus.Gauge
|
puppetCount prometheus.Gauge
|
||||||
@ -56,17 +56,17 @@ type MetricsHandler struct {
|
|||||||
unencryptedPrivateCount prometheus.Gauge
|
unencryptedPrivateCount prometheus.Gauge
|
||||||
|
|
||||||
connected prometheus.Gauge
|
connected prometheus.Gauge
|
||||||
connectedState map[types.GroupMeID]bool
|
connectedState map[groupme.ID]bool
|
||||||
loggedIn prometheus.Gauge
|
loggedIn prometheus.Gauge
|
||||||
loggedInState map[types.GroupMeID]bool
|
loggedInState map[groupme.ID]bool
|
||||||
syncLocked prometheus.Gauge
|
syncLocked prometheus.Gauge
|
||||||
syncLockedState map[types.GroupMeID]bool
|
syncLockedState map[groupme.ID]bool
|
||||||
bufferLength *prometheus.GaugeVec
|
bufferLength *prometheus.GaugeVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
|
func NewMetricsHandler(address string, log log.Logger, db *database.Database) *MetricsHandler {
|
||||||
portalCount := promauto.NewGaugeVec(prometheus.GaugeOpts{
|
portalCount := promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "whatsapp_portals_total",
|
Name: "groupme_portals_total",
|
||||||
Help: "Number of portal rooms on Matrix",
|
Help: "Number of portal rooms on Matrix",
|
||||||
}, []string{"type", "encrypted"})
|
}, []string{"type", "encrypted"})
|
||||||
return &MetricsHandler{
|
return &MetricsHandler{
|
||||||
@ -75,28 +75,28 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
|||||||
log: log,
|
log: log,
|
||||||
running: false,
|
running: false,
|
||||||
|
|
||||||
messageHandling: promauto.NewHistogramVec(prometheus.HistogramOpts{
|
matrixEventHandling: promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Name: "matrix_event",
|
Name: "matrix_event",
|
||||||
Help: "Time spent processing Matrix events",
|
Help: "Time spent processing Matrix events",
|
||||||
}, []string{"event_type"}),
|
}, []string{"event_type"}),
|
||||||
countCollection: promauto.NewHistogram(prometheus.HistogramOpts{
|
countCollection: promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
Name: "whatsapp_count_collection",
|
Name: "groupme_count_collection",
|
||||||
Help: "Time spent collecting the whatsapp_*_total metrics",
|
Help: "Time spent collecting the groupme_*_total metrics",
|
||||||
}),
|
}),
|
||||||
disconnections: promauto.NewCounterVec(prometheus.CounterOpts{
|
disconnections: promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Name: "whatsapp_disconnections",
|
Name: "groupme_disconnections",
|
||||||
Help: "Number of times a Matrix user has been disconnected from WhatsApp",
|
Help: "Number of times a Matrix user has been disconnected from GroupMe",
|
||||||
}, []string{"user_id"}),
|
}, []string{"user_id"}),
|
||||||
puppetCount: promauto.NewGauge(prometheus.GaugeOpts{
|
puppetCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "whatsapp_puppets_total",
|
Name: "groupme_puppets_total",
|
||||||
Help: "Number of WhatsApp users bridged into Matrix",
|
Help: "Number of GroupMe users bridged into Matrix",
|
||||||
}),
|
}),
|
||||||
userCount: promauto.NewGauge(prometheus.GaugeOpts{
|
userCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "whatsapp_users_total",
|
Name: "groupme_users_total",
|
||||||
Help: "Number of Matrix users using the bridge",
|
Help: "Number of Matrix users using the bridge",
|
||||||
}),
|
}),
|
||||||
messageCount: promauto.NewGauge(prometheus.GaugeOpts{
|
messageCount: promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "whatsapp_messages_total",
|
Name: "groupme_messages_total",
|
||||||
Help: "Number of messages bridged",
|
Help: "Number of messages bridged",
|
||||||
}),
|
}),
|
||||||
portalCount: portalCount,
|
portalCount: portalCount,
|
||||||
@ -109,17 +109,17 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
|||||||
Name: "bridge_logged_in",
|
Name: "bridge_logged_in",
|
||||||
Help: "Users logged into the bridge",
|
Help: "Users logged into the bridge",
|
||||||
}),
|
}),
|
||||||
loggedInState: make(map[types.GroupMeID]bool),
|
loggedInState: make(map[groupme.ID]bool),
|
||||||
connected: promauto.NewGauge(prometheus.GaugeOpts{
|
connected: promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "bridge_connected",
|
Name: "bridge_connected",
|
||||||
Help: "Bridge users connected to WhatsApp",
|
Help: "Bridge users connected to GroupMe",
|
||||||
}),
|
}),
|
||||||
connectedState: make(map[types.GroupMeID]bool),
|
connectedState: make(map[groupme.ID]bool),
|
||||||
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "bridge_sync_locked",
|
Name: "bridge_sync_locked",
|
||||||
Help: "Bridge users locked in post-login sync",
|
Help: "Bridge users locked in post-login sync",
|
||||||
}),
|
}),
|
||||||
syncLockedState: make(map[types.GroupMeID]bool),
|
syncLockedState: make(map[groupme.ID]bool),
|
||||||
bufferLength: promauto.NewGaugeVec(prometheus.GaugeOpts{
|
bufferLength: promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
Name: "bridge_buffer_size",
|
Name: "bridge_buffer_size",
|
||||||
Help: "Number of messages in buffer",
|
Help: "Number of messages in buffer",
|
||||||
@ -129,14 +129,14 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
|||||||
|
|
||||||
func noop() {}
|
func noop() {}
|
||||||
|
|
||||||
func (mh *MetricsHandler) TrackEvent(eventType event.Type) func() {
|
func (mh *MetricsHandler) TrackMatrixEvent(eventType event.Type) func() {
|
||||||
if !mh.running {
|
if !mh.running {
|
||||||
return noop
|
return noop
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
return func() {
|
return func() {
|
||||||
duration := time.Now().Sub(start)
|
duration := time.Now().Sub(start)
|
||||||
mh.messageHandling.
|
mh.matrixEventHandling.
|
||||||
With(prometheus.Labels{"event_type": eventType.Type}).
|
With(prometheus.Labels{"event_type": eventType.Type}).
|
||||||
Observe(duration.Seconds())
|
Observe(duration.Seconds())
|
||||||
}
|
}
|
||||||
@ -149,13 +149,13 @@ func (mh *MetricsHandler) TrackDisconnection(userID id.UserID) {
|
|||||||
mh.disconnections.With(prometheus.Labels{"user_id": string(userID)}).Inc()
|
mh.disconnections.With(prometheus.Labels{"user_id": string(userID)}).Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *MetricsHandler) TrackLoginState(jid types.GroupMeID, loggedIn bool) {
|
func (mh *MetricsHandler) TrackLoginState(gmid groupme.ID, loggedIn bool) {
|
||||||
if !mh.running {
|
if !mh.running {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentVal, ok := mh.loggedInState[jid]
|
currentVal, ok := mh.loggedInState[gmid]
|
||||||
if !ok || currentVal != loggedIn {
|
if !ok || currentVal != loggedIn {
|
||||||
mh.loggedInState[jid] = loggedIn
|
mh.loggedInState[gmid] = loggedIn
|
||||||
if loggedIn {
|
if loggedIn {
|
||||||
mh.loggedIn.Inc()
|
mh.loggedIn.Inc()
|
||||||
} else {
|
} else {
|
||||||
@ -164,13 +164,13 @@ func (mh *MetricsHandler) TrackLoginState(jid types.GroupMeID, loggedIn bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *MetricsHandler) TrackConnectionState(jid types.GroupMeID, connected bool) {
|
func (mh *MetricsHandler) TrackConnectionState(gmid groupme.ID, connected bool) {
|
||||||
if !mh.running {
|
if !mh.running {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentVal, ok := mh.connectedState[jid]
|
currentVal, ok := mh.connectedState[gmid]
|
||||||
if !ok || currentVal != connected {
|
if !ok || currentVal != connected {
|
||||||
mh.connectedState[jid] = connected
|
mh.connectedState[gmid] = connected
|
||||||
if connected {
|
if connected {
|
||||||
mh.connected.Inc()
|
mh.connected.Inc()
|
||||||
} else {
|
} else {
|
||||||
@ -179,13 +179,13 @@ func (mh *MetricsHandler) TrackConnectionState(jid types.GroupMeID, connected bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *MetricsHandler) TrackSyncLock(jid types.GroupMeID, locked bool) {
|
func (mh *MetricsHandler) TrackSyncLock(gmid groupme.ID, locked bool) {
|
||||||
if !mh.running {
|
if !mh.running {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentVal, ok := mh.syncLockedState[jid]
|
currentVal, ok := mh.syncLockedState[gmid]
|
||||||
if !ok || currentVal != locked {
|
if !ok || currentVal != locked {
|
||||||
mh.syncLockedState[jid] = locked
|
mh.syncLockedState[gmid] = locked
|
||||||
if locked {
|
if locked {
|
||||||
mh.syncLocked.Inc()
|
mh.syncLocked.Inc()
|
||||||
} else {
|
} else {
|
||||||
@ -230,10 +230,10 @@ func (mh *MetricsHandler) updateStats() {
|
|||||||
// var encryptedGroupCount, encryptedPrivateCount, unencryptedGroupCount, unencryptedPrivateCount int
|
// var encryptedGroupCount, encryptedPrivateCount, unencryptedGroupCount, unencryptedPrivateCount int
|
||||||
// err = mh.db.QueryRowContext(mh.ctx, `
|
// err = mh.db.QueryRowContext(mh.ctx, `
|
||||||
// SELECT
|
// SELECT
|
||||||
// COUNT(CASE WHEN jid LIKE '%@g.us' AND encrypted THEN 1 END) AS encrypted_group_portals,
|
// COUNT(CASE WHEN gmid LIKE '%@g.us' AND encrypted THEN 1 END) AS encrypted_group_portals,
|
||||||
// COUNT(CASE WHEN jid LIKE '%@s.whatsapp.net' AND encrypted THEN 1 END) AS encrypted_private_portals,
|
// COUNT(CASE WHEN gmid LIKE '%@s.groupme.net' AND encrypted THEN 1 END) AS encrypted_private_portals,
|
||||||
// COUNT(CASE WHEN jid LIKE '%@g.us' AND NOT encrypted THEN 1 END) AS unencrypted_group_portals,
|
// COUNT(CASE WHEN gmid LIKE '%@g.us' AND NOT encrypted THEN 1 END) AS unencrypted_group_portals,
|
||||||
// COUNT(CASE WHEN jid LIKE '%@s.whatsapp.net' AND NOT encrypted THEN 1 END) AS unencrypted_private_portals
|
// COUNT(CASE WHEN gmid LIKE '%@s.groupme.net' AND NOT encrypted THEN 1 END) AS unencrypted_private_portals
|
||||||
// FROM portal WHERE mxid<>''
|
// FROM portal WHERE mxid<>''
|
||||||
// `).Scan(&encryptedGroupCount, &encryptedPrivateCount, &unencryptedGroupCount, &unencryptedPrivateCount)
|
// `).Scan(&encryptedGroupCount, &encryptedPrivateCount, &unencryptedGroupCount, &unencryptedPrivateCount)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ProvisioningAPI struct {
|
type ProvisioningAPI struct {
|
||||||
bridge *Bridge
|
bridge *GMBridge
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
96
puppet.go
96
puppet.go
@ -26,17 +26,16 @@ import (
|
|||||||
log "maunium.net/go/maulogger/v2"
|
log "maunium.net/go/maulogger/v2"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/appservice"
|
"maunium.net/go/mautrix/appservice"
|
||||||
|
"maunium.net/go/mautrix/bridge"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
"github.com/beeper/groupme/database"
|
"github.com/beeper/groupme/database"
|
||||||
"github.com/beeper/groupme/groupmeExt"
|
"github.com/beeper/groupme/groupmeext"
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
whatsappExt "github.com/beeper/groupme/whatsapp-ext"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var userIDRegex *regexp.Regexp
|
var userIDRegex *regexp.Regexp
|
||||||
|
|
||||||
func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.GroupMeID, bool) {
|
func (bridge *GMBridge) ParsePuppetMXID(mxid id.UserID) (groupme.ID, bool) {
|
||||||
if userIDRegex == nil {
|
if userIDRegex == nil {
|
||||||
userIDRegex = regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
userIDRegex = regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
||||||
bridge.Config.Bridge.FormatUsername("([0-9]+)"),
|
bridge.Config.Bridge.FormatUsername("([0-9]+)"),
|
||||||
@ -47,32 +46,31 @@ func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.GroupMeID, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
jid := types.GroupMeID(match[1])
|
return groupme.ID(match[1]), true
|
||||||
return jid, true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
|
func (bridge *GMBridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
|
||||||
jid, ok := bridge.ParsePuppetMXID(mxid)
|
gmid, ok := bridge.ParsePuppetMXID(mxid)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return bridge.GetPuppetByJID(jid)
|
return bridge.GetPuppetByGMID(gmid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetPuppetByJID(jid types.GroupMeID) *Puppet {
|
func (bridge *GMBridge) GetPuppetByGMID(gmid groupme.ID) *Puppet {
|
||||||
bridge.puppetsLock.Lock()
|
bridge.puppetsLock.Lock()
|
||||||
defer bridge.puppetsLock.Unlock()
|
defer bridge.puppetsLock.Unlock()
|
||||||
puppet, ok := bridge.puppets[jid]
|
puppet, ok := bridge.puppets[gmid]
|
||||||
if !ok {
|
if !ok {
|
||||||
dbPuppet := bridge.DB.Puppet.Get(jid)
|
dbPuppet := bridge.DB.Puppet.Get(gmid)
|
||||||
if dbPuppet == nil {
|
if dbPuppet == nil {
|
||||||
dbPuppet = bridge.DB.Puppet.New()
|
dbPuppet = bridge.DB.Puppet.New()
|
||||||
dbPuppet.JID = jid
|
dbPuppet.GMID = gmid
|
||||||
dbPuppet.Insert()
|
dbPuppet.Insert()
|
||||||
}
|
}
|
||||||
puppet = bridge.NewPuppet(dbPuppet)
|
puppet = bridge.NewPuppet(dbPuppet)
|
||||||
bridge.puppets[puppet.JID] = puppet
|
bridge.puppets[puppet.GMID] = puppet
|
||||||
if len(puppet.CustomMXID) > 0 {
|
if len(puppet.CustomMXID) > 0 {
|
||||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||||
}
|
}
|
||||||
@ -80,7 +78,7 @@ func (bridge *Bridge) GetPuppetByJID(jid types.GroupMeID) *Puppet {
|
|||||||
return puppet
|
return puppet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
func (bridge *GMBridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
||||||
bridge.puppetsLock.Lock()
|
bridge.puppetsLock.Lock()
|
||||||
defer bridge.puppetsLock.Unlock()
|
defer bridge.puppetsLock.Unlock()
|
||||||
puppet, ok := bridge.puppetsByCustomMXID[mxid]
|
puppet, ok := bridge.puppetsByCustomMXID[mxid]
|
||||||
@ -90,21 +88,57 @@ func (bridge *Bridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
puppet = bridge.NewPuppet(dbPuppet)
|
puppet = bridge.NewPuppet(dbPuppet)
|
||||||
bridge.puppets[puppet.JID] = puppet
|
bridge.puppets[puppet.GMID] = puppet
|
||||||
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
bridge.puppetsByCustomMXID[puppet.CustomMXID] = puppet
|
||||||
}
|
}
|
||||||
return puppet
|
return puppet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetAllPuppetsWithCustomMXID() []*Puppet {
|
func (user *User) GetIDoublePuppet() bridge.DoublePuppet {
|
||||||
|
p := user.bridge.GetPuppetByCustomMXID(user.MXID)
|
||||||
|
if p == nil || p.CustomIntent() == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetIGhost() bridge.Ghost {
|
||||||
|
if user.GMID.String() == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
p := user.bridge.GetPuppetByGMID(user.GMID)
|
||||||
|
if p == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (br *GMBridge) IsGhost(id id.UserID) bool {
|
||||||
|
_, ok := br.ParsePuppetMXID(id)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (br *GMBridge) GetIGhost(id id.UserID) bridge.Ghost {
|
||||||
|
p := br.GetPuppetByMXID(id)
|
||||||
|
if p == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (puppet *Puppet) GetMXID() id.UserID {
|
||||||
|
return puppet.MXID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bridge *GMBridge) GetAllPuppetsWithCustomMXID() []*Puppet {
|
||||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAllWithCustomMXID())
|
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAllWithCustomMXID())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetAllPuppets() []*Puppet {
|
func (bridge *GMBridge) GetAllPuppets() []*Puppet {
|
||||||
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAll())
|
return bridge.dbPuppetsToPuppets(bridge.DB.Puppet.GetAll())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet {
|
func (bridge *GMBridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet {
|
||||||
bridge.puppetsLock.Lock()
|
bridge.puppetsLock.Lock()
|
||||||
defer bridge.puppetsLock.Unlock()
|
defer bridge.puppetsLock.Unlock()
|
||||||
output := make([]*Puppet, len(dbPuppets))
|
output := make([]*Puppet, len(dbPuppets))
|
||||||
@ -112,10 +146,10 @@ func (bridge *Bridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet
|
|||||||
if dbPuppet == nil {
|
if dbPuppet == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
puppet, ok := bridge.puppets[dbPuppet.JID]
|
puppet, ok := bridge.puppets[dbPuppet.GMID]
|
||||||
if !ok {
|
if !ok {
|
||||||
puppet = bridge.NewPuppet(dbPuppet)
|
puppet = bridge.NewPuppet(dbPuppet)
|
||||||
bridge.puppets[dbPuppet.JID] = puppet
|
bridge.puppets[dbPuppet.GMID] = puppet
|
||||||
if len(dbPuppet.CustomMXID) > 0 {
|
if len(dbPuppet.CustomMXID) > 0 {
|
||||||
bridge.puppetsByCustomMXID[dbPuppet.CustomMXID] = puppet
|
bridge.puppetsByCustomMXID[dbPuppet.CustomMXID] = puppet
|
||||||
}
|
}
|
||||||
@ -125,29 +159,27 @@ func (bridge *Bridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) FormatPuppetMXID(jid types.GroupMeID) id.UserID {
|
func (bridge *GMBridge) FormatPuppetMXID(gmid groupme.ID) id.UserID {
|
||||||
return id.NewUserID(
|
return id.NewUserID(
|
||||||
bridge.Config.Bridge.FormatUsername(
|
bridge.Config.Bridge.FormatUsername(
|
||||||
strings.Replace(
|
gmid),
|
||||||
jid,
|
|
||||||
whatsappExt.NewUserSuffix, "", 1)),
|
|
||||||
bridge.Config.Homeserver.Domain)
|
bridge.Config.Homeserver.Domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) NewPuppet(dbPuppet *database.Puppet) *Puppet {
|
func (bridge *GMBridge) NewPuppet(dbPuppet *database.Puppet) *Puppet {
|
||||||
return &Puppet{
|
return &Puppet{
|
||||||
Puppet: dbPuppet,
|
Puppet: dbPuppet,
|
||||||
bridge: bridge,
|
bridge: bridge,
|
||||||
log: bridge.Log.Sub(fmt.Sprintf("Puppet/%s", dbPuppet.JID)),
|
log: bridge.Log.Sub(fmt.Sprintf("Puppet/%s", dbPuppet.GMID)),
|
||||||
|
|
||||||
MXID: bridge.FormatPuppetMXID(dbPuppet.JID),
|
MXID: bridge.FormatPuppetMXID(dbPuppet.GMID),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Puppet struct {
|
type Puppet struct {
|
||||||
*database.Puppet
|
*database.Puppet
|
||||||
|
|
||||||
bridge *Bridge
|
bridge *GMBridge
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
typingIn id.RoomID
|
typingIn id.RoomID
|
||||||
@ -162,13 +194,13 @@ type Puppet struct {
|
|||||||
|
|
||||||
func (puppet *Puppet) PhoneNumber() string {
|
func (puppet *Puppet) PhoneNumber() string {
|
||||||
println("phone num")
|
println("phone num")
|
||||||
return strings.Replace(puppet.JID, whatsappExt.NewUserSuffix, "", 1)
|
return strings.Replace(puppet.GMID, whatsappExt.NewUserSuffix, "", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
|
func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI {
|
||||||
if (!portal.IsPrivateChat() && puppet.customIntent == nil) ||
|
if (!portal.IsPrivateChat() && puppet.customIntent == nil) ||
|
||||||
(portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) ||
|
(portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) ||
|
||||||
portal.Key.JID == puppet.JID {
|
portal.Key.GMID == puppet.GMID {
|
||||||
return puppet.DefaultIntent()
|
return puppet.DefaultIntent()
|
||||||
}
|
}
|
||||||
return puppet.customIntent
|
return puppet.customIntent
|
||||||
@ -211,7 +243,7 @@ func (puppet *Puppet) UpdateAvatar(source *User, portalMXID id.RoomID, avatar st
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO check its actually groupme?
|
//TODO check its actually groupme?
|
||||||
image, mime, err := groupmeExt.DownloadImage(avatar + ".large")
|
image, mime, err := groupmeext.DownloadImage(avatar + ".large")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
puppet.log.Warnln(err)
|
puppet.log.Warnln(err)
|
||||||
return false
|
return false
|
||||||
|
90
segment.go
Normal file
90
segment.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
||||||
|
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
log "maunium.net/go/maulogger/v2"
|
||||||
|
"maunium.net/go/mautrix/id"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SegmentURL = "https://api.segment.io/v1/track"
|
||||||
|
|
||||||
|
type SegmentClient struct {
|
||||||
|
key string
|
||||||
|
log log.Logger
|
||||||
|
client http.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
var Segment SegmentClient
|
||||||
|
|
||||||
|
func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err := json.NewEncoder(&buf).Encode(map[string]interface{}{
|
||||||
|
"userId": userID,
|
||||||
|
"event": event,
|
||||||
|
"properties": properties,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", SegmentURL, &buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.SetBasicAuth(sc.key, "")
|
||||||
|
resp, err := sc.client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *SegmentClient) IsEnabled() bool {
|
||||||
|
return len(sc.key) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *SegmentClient) Track(userID id.UserID, event string, properties ...map[string]interface{}) {
|
||||||
|
if !sc.IsEnabled() {
|
||||||
|
return
|
||||||
|
} else if len(properties) > 1 {
|
||||||
|
panic("Track should be called with at most one property map")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
props := map[string]interface{}{}
|
||||||
|
if len(properties) > 0 {
|
||||||
|
props = properties[0]
|
||||||
|
}
|
||||||
|
props["bridge"] = "groupme"
|
||||||
|
err := sc.trackSync(userID, event, props)
|
||||||
|
if err != nil {
|
||||||
|
sc.log.Errorfln("Error tracking %s: %v", event, err)
|
||||||
|
} else {
|
||||||
|
sc.log.Debugln("Tracked", event)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package types
|
|
||||||
|
|
||||||
// GroupMeID is a WhatsApp JID.
|
|
||||||
type GroupMeID = string
|
|
||||||
|
|
||||||
// WhatsAppMessageID is the internal ID of a WhatsApp message.
|
|
||||||
type WhatsAppMessageID = string
|
|
||||||
|
|
||||||
//AuthToken is the authentication token
|
|
||||||
type AuthToken = string
|
|
||||||
|
|
||||||
type TmpID = GroupMeID
|
|
412
user.go
412
user.go
@ -22,6 +22,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -30,6 +31,9 @@ import (
|
|||||||
"github.com/Rhymen/go-whatsapp"
|
"github.com/Rhymen/go-whatsapp"
|
||||||
|
|
||||||
"maunium.net/go/mautrix"
|
"maunium.net/go/mautrix"
|
||||||
|
"maunium.net/go/mautrix/appservice"
|
||||||
|
"maunium.net/go/mautrix/bridge"
|
||||||
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
||||||
"maunium.net/go/mautrix/event"
|
"maunium.net/go/mautrix/event"
|
||||||
"maunium.net/go/mautrix/format"
|
"maunium.net/go/mautrix/format"
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
@ -37,31 +41,29 @@ import (
|
|||||||
"github.com/karmanyaahm/groupme"
|
"github.com/karmanyaahm/groupme"
|
||||||
|
|
||||||
"github.com/beeper/groupme/database"
|
"github.com/beeper/groupme/database"
|
||||||
"github.com/beeper/groupme/groupmeExt"
|
"github.com/beeper/groupme/groupmeext"
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
whatsappExt "github.com/beeper/groupme/whatsapp-ext"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
*database.User
|
*database.User
|
||||||
Conn *groupme.PushSubscription
|
Conn *groupme.PushSubscription
|
||||||
|
|
||||||
bridge *Bridge
|
bridge *GMBridge
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
|
||||||
Admin bool
|
Admin bool
|
||||||
Whitelisted bool
|
Whitelisted bool
|
||||||
RelaybotWhitelisted bool
|
PermissionLevel bridgeconfig.PermissionLevel
|
||||||
|
|
||||||
IsRelaybot bool
|
BridgeState *bridge.BridgeStateQueue
|
||||||
|
|
||||||
Client *groupmeExt.Client
|
Client *groupmeext.Client
|
||||||
ConnectionErrors int
|
ConnectionErrors int
|
||||||
CommunityID string
|
CommunityID string
|
||||||
|
|
||||||
ChatList map[types.GroupMeID]groupme.Chat
|
ChatList map[groupme.ID]groupme.Chat
|
||||||
GroupList map[types.GroupMeID]groupme.Group
|
GroupList map[groupme.ID]groupme.Group
|
||||||
RelationList map[types.GroupMeID]groupme.User
|
RelationList map[groupme.ID]groupme.User
|
||||||
|
|
||||||
cleanDisconnection bool
|
cleanDisconnection bool
|
||||||
batteryWarningsSent int
|
batteryWarningsSent int
|
||||||
@ -73,125 +75,228 @@ type User struct {
|
|||||||
messageInput chan PortalMessage
|
messageInput chan PortalMessage
|
||||||
messageOutput chan PortalMessage
|
messageOutput chan PortalMessage
|
||||||
|
|
||||||
syncStart chan struct{}
|
|
||||||
syncWait sync.WaitGroup
|
|
||||||
|
|
||||||
mgmtCreateLock sync.Mutex
|
mgmtCreateLock sync.Mutex
|
||||||
|
|
||||||
|
spaceCreateLock sync.Mutex
|
||||||
|
spaceMembershipChecked bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetUserByMXID(userID id.UserID) *User {
|
func (br *GMBridge) getUserByMXID(userID id.UserID, onlyIfExists bool) *User {
|
||||||
_, isPuppet := bridge.ParsePuppetMXID(userID)
|
_, isPuppet := br.ParsePuppetMXID(userID)
|
||||||
if isPuppet || userID == bridge.Bot.UserID {
|
if isPuppet || userID == br.Bot.UserID {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
bridge.usersLock.Lock()
|
br.usersLock.Lock()
|
||||||
defer bridge.usersLock.Unlock()
|
defer br.usersLock.Unlock()
|
||||||
user, ok := bridge.usersByMXID[userID]
|
user, ok := br.usersByMXID[userID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return bridge.loadDBUser(bridge.DB.User.GetByMXID(userID), &userID)
|
userIDPtr := &userID
|
||||||
|
if onlyIfExists {
|
||||||
|
userIDPtr = nil
|
||||||
|
}
|
||||||
|
return br.loadDBUser(br.DB.User.GetByMXID(userID), userIDPtr)
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetUserByJID(userID types.GroupMeID) *User {
|
func (br *GMBridge) GetUserByMXID(userID id.UserID) *User {
|
||||||
|
return br.getUserByMXID(userID, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (br *GMBridge) GetIUser(userID id.UserID, create bool) bridge.User {
|
||||||
|
u := br.getUserByMXID(userID, !create)
|
||||||
|
if u == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetPermissionLevel() bridgeconfig.PermissionLevel {
|
||||||
|
return user.PermissionLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetManagementRoomID() id.RoomID {
|
||||||
|
return user.ManagementRoom
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetMXID() id.UserID {
|
||||||
|
return user.MXID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetCommandState() map[string]interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (br *GMBridge) GetUserByMXIDIfExists(userID id.UserID) *User {
|
||||||
|
return br.getUserByMXID(userID, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bridge *GMBridge) GetUserByGMID(gmid groupme.ID) *User {
|
||||||
bridge.usersLock.Lock()
|
bridge.usersLock.Lock()
|
||||||
defer bridge.usersLock.Unlock()
|
defer bridge.usersLock.Unlock()
|
||||||
user, ok := bridge.usersByJID[userID]
|
user, ok := bridge.usersByGMID[gmid]
|
||||||
if !ok {
|
if !ok {
|
||||||
return bridge.loadDBUser(bridge.DB.User.GetByJID(userID), nil)
|
return bridge.loadDBUser(bridge.DB.User.GetByGMID(gmid), nil)
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) addToJIDMap() {
|
func (user *User) addToGMIDMap() {
|
||||||
user.bridge.usersLock.Lock()
|
user.bridge.usersLock.Lock()
|
||||||
user.bridge.usersByJID[user.JID] = user
|
user.bridge.usersByGMID[user.GMID] = user
|
||||||
user.bridge.usersLock.Unlock()
|
user.bridge.usersLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) removeFromJIDMap() {
|
func (user *User) removeFromGMIDMap() {
|
||||||
user.bridge.usersLock.Lock()
|
user.bridge.usersLock.Lock()
|
||||||
jidUser, ok := user.bridge.usersByJID[user.JID]
|
jidUser, ok := user.bridge.usersByGMID[user.GMID]
|
||||||
if ok && user == jidUser {
|
if ok && user == jidUser {
|
||||||
delete(user.bridge.usersByJID, user.JID)
|
delete(user.bridge.usersByGMID, user.GMID)
|
||||||
}
|
}
|
||||||
user.bridge.usersLock.Unlock()
|
user.bridge.usersLock.Unlock()
|
||||||
user.bridge.Metrics.TrackLoginState(user.JID, false)
|
user.bridge.Metrics.TrackLoginState(user.GMID, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetAllUsers() []*User {
|
func (br *GMBridge) GetAllUsers() []*User {
|
||||||
bridge.usersLock.Lock()
|
br.usersLock.Lock()
|
||||||
defer bridge.usersLock.Unlock()
|
defer br.usersLock.Unlock()
|
||||||
dbUsers := bridge.DB.User.GetAll()
|
dbUsers := br.DB.User.GetAll()
|
||||||
output := make([]*User, len(dbUsers))
|
output := make([]*User, len(dbUsers))
|
||||||
for index, dbUser := range dbUsers {
|
for index, dbUser := range dbUsers {
|
||||||
user, ok := bridge.usersByMXID[dbUser.MXID]
|
user, ok := br.usersByMXID[dbUser.MXID]
|
||||||
if !ok {
|
if !ok {
|
||||||
user = bridge.loadDBUser(dbUser, nil)
|
user = br.loadDBUser(dbUser, nil)
|
||||||
}
|
}
|
||||||
output[index] = user
|
output[index] = user
|
||||||
}
|
}
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) loadDBUser(dbUser *database.User, mxid *id.UserID) *User {
|
func (br *GMBridge) loadDBUser(dbUser *database.User, mxid *id.UserID) *User {
|
||||||
if dbUser == nil {
|
if dbUser == nil {
|
||||||
if mxid == nil {
|
if mxid == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dbUser = bridge.DB.User.New()
|
dbUser = br.DB.User.New()
|
||||||
dbUser.MXID = *mxid
|
dbUser.MXID = *mxid
|
||||||
dbUser.Insert()
|
dbUser.Insert()
|
||||||
}
|
}
|
||||||
user := bridge.NewUser(dbUser)
|
user := br.NewUser(dbUser)
|
||||||
bridge.usersByMXID[user.MXID] = user
|
br.usersByMXID[user.MXID] = user
|
||||||
if len(user.JID) > 0 {
|
if len(user.GMID) > 0 {
|
||||||
bridge.usersByJID[user.JID] = user
|
br.usersByGMID[user.GMID] = user
|
||||||
}
|
}
|
||||||
if len(user.ManagementRoom) > 0 {
|
if len(user.ManagementRoom) > 0 {
|
||||||
bridge.managementRooms[user.ManagementRoom] = user
|
br.managementRooms[user.ManagementRoom] = user
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) GetPortals() []*Portal {
|
func (br *GMBridge) NewUser(dbUser *database.User) *User {
|
||||||
user.bridge.portalsLock.Lock()
|
|
||||||
keys := user.User.GetPortalKeys()
|
|
||||||
portals := make([]*Portal, len(keys))
|
|
||||||
|
|
||||||
for i, key := range keys {
|
|
||||||
portal, ok := user.bridge.portalsByJID[key]
|
|
||||||
if !ok {
|
|
||||||
portal = user.bridge.loadDBPortal(user.bridge.DB.Portal.GetByJID(key), &key)
|
|
||||||
}
|
|
||||||
portals[i] = portal
|
|
||||||
}
|
|
||||||
user.bridge.portalsLock.Unlock()
|
|
||||||
return portals
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bridge *Bridge) NewUser(dbUser *database.User) *User {
|
|
||||||
user := &User{
|
user := &User{
|
||||||
User: dbUser,
|
User: dbUser,
|
||||||
bridge: bridge,
|
bridge: br,
|
||||||
log: bridge.Log.Sub("User").Sub(string(dbUser.MXID)),
|
log: br.Log.Sub("User").Sub(string(dbUser.MXID)),
|
||||||
|
|
||||||
IsRelaybot: false,
|
|
||||||
|
|
||||||
chatListReceived: make(chan struct{}, 1),
|
chatListReceived: make(chan struct{}, 1),
|
||||||
syncPortalsDone: make(chan struct{}, 1),
|
syncPortalsDone: make(chan struct{}, 1),
|
||||||
syncStart: make(chan struct{}, 1),
|
syncStart: make(chan struct{}, 1),
|
||||||
messageInput: make(chan PortalMessage),
|
messageInput: make(chan PortalMessage),
|
||||||
messageOutput: make(chan PortalMessage, bridge.Config.Bridge.UserMessageBuffer),
|
messageOutput: make(chan PortalMessage, br.Config.Bridge.UserMessageBuffer),
|
||||||
}
|
}
|
||||||
user.RelaybotWhitelisted = user.bridge.Config.Bridge.Permissions.IsRelaybotWhitelisted(user.MXID)
|
|
||||||
user.Whitelisted = user.bridge.Config.Bridge.Permissions.IsWhitelisted(user.MXID)
|
user.PermissionLevel = user.bridge.Config.Bridge.Permissions.Get(user.MXID)
|
||||||
user.Admin = user.bridge.Config.Bridge.Permissions.IsAdmin(user.MXID)
|
user.Whitelisted = user.PermissionLevel >= bridgeconfig.PermissionLevelUser
|
||||||
|
user.Admin = user.PermissionLevel >= bridgeconfig.PermissionLevelAdmin
|
||||||
|
user.BridgeState = br.NewBridgeStateQueue(user, user.log)
|
||||||
go user.handleMessageLoop()
|
go user.handleMessageLoop()
|
||||||
go user.runMessageRingBuffer()
|
go user.runMessageRingBuffer()
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) ensureInvited(intent *appservice.IntentAPI, roomID id.RoomID, isDirect bool) (ok bool) {
|
||||||
|
extraContent := make(map[string]interface{})
|
||||||
|
if isDirect {
|
||||||
|
extraContent["is_direct"] = true
|
||||||
|
}
|
||||||
|
customPuppet := user.bridge.GetPuppetByCustomMXID(user.MXID)
|
||||||
|
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
||||||
|
extraContent["fi.mau.will_auto_accept"] = true
|
||||||
|
}
|
||||||
|
_, err := intent.InviteUser(roomID, &mautrix.ReqInviteUser{UserID: user.MXID}, extraContent)
|
||||||
|
var httpErr mautrix.HTTPError
|
||||||
|
if err != nil && errors.As(err, &httpErr) && httpErr.RespError != nil && strings.Contains(httpErr.RespError.Err, "is already in the room") {
|
||||||
|
user.bridge.StateStore.SetMembership(roomID, user.MXID, event.MembershipJoin)
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
|
user.log.Warnfln("Failed to invite user to %s: %v", roomID, err)
|
||||||
|
} else {
|
||||||
|
ok = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
||||||
|
err = customPuppet.CustomIntent().EnsureJoined(roomID, appservice.EnsureJoinedParams{IgnoreCache: true})
|
||||||
|
if err != nil {
|
||||||
|
user.log.Warnfln("Failed to auto-join %s: %v", roomID, err)
|
||||||
|
ok = false
|
||||||
|
} else {
|
||||||
|
ok = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) GetSpaceRoom() id.RoomID {
|
||||||
|
if !user.bridge.Config.Bridge.PersonalFilteringSpaces {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(user.SpaceRoom) == 0 {
|
||||||
|
user.spaceCreateLock.Lock()
|
||||||
|
defer user.spaceCreateLock.Unlock()
|
||||||
|
if len(user.SpaceRoom) > 0 {
|
||||||
|
return user.SpaceRoom
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
||||||
|
Visibility: "private",
|
||||||
|
Name: "GroupMe",
|
||||||
|
Topic: "Your GroupMe bridged chats",
|
||||||
|
InitialState: []*event.Event{{
|
||||||
|
Type: event.StateRoomAvatar,
|
||||||
|
Content: event.Content{
|
||||||
|
Parsed: &event.RoomAvatarEventContent{
|
||||||
|
URL: user.bridge.Config.AppService.Bot.ParsedAvatar,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
|
CreationContent: map[string]interface{}{
|
||||||
|
"type": event.RoomTypeSpace,
|
||||||
|
},
|
||||||
|
PowerLevelOverride: &event.PowerLevelsEventContent{
|
||||||
|
Users: map[id.UserID]int{
|
||||||
|
user.bridge.Bot.UserID: 9001,
|
||||||
|
user.MXID: 50,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
user.log.Errorln("Failed to auto-create space room:", err)
|
||||||
|
} else {
|
||||||
|
user.SpaceRoom = resp.RoomID
|
||||||
|
user.Update()
|
||||||
|
user.ensureInvited(user.bridge.Bot, user.SpaceRoom, false)
|
||||||
|
}
|
||||||
|
} else if !user.spaceMembershipChecked && !user.bridge.StateStore.IsInRoom(user.SpaceRoom, user.MXID) {
|
||||||
|
user.ensureInvited(user.bridge.Bot, user.SpaceRoom, false)
|
||||||
|
}
|
||||||
|
user.spaceMembershipChecked = true
|
||||||
|
|
||||||
|
return user.SpaceRoom
|
||||||
|
}
|
||||||
|
|
||||||
func (user *User) GetManagementRoom() id.RoomID {
|
func (user *User) GetManagementRoom() id.RoomID {
|
||||||
if len(user.ManagementRoom) == 0 {
|
if len(user.ManagementRoom) == 0 {
|
||||||
user.mgmtCreateLock.Lock()
|
user.mgmtCreateLock.Lock()
|
||||||
@ -199,9 +304,14 @@ func (user *User) GetManagementRoom() id.RoomID {
|
|||||||
if len(user.ManagementRoom) > 0 {
|
if len(user.ManagementRoom) > 0 {
|
||||||
return user.ManagementRoom
|
return user.ManagementRoom
|
||||||
}
|
}
|
||||||
|
creationContent := make(map[string]interface{})
|
||||||
|
if !user.bridge.Config.Bridge.FederateRooms {
|
||||||
|
creationContent["m.federate"] = false
|
||||||
|
}
|
||||||
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
resp, err := user.bridge.Bot.CreateRoom(&mautrix.ReqCreateRoom{
|
||||||
Topic: "WhatsApp bridge notices",
|
Topic: "GroupMe bridge notices",
|
||||||
IsDirect: true,
|
IsDirect: true,
|
||||||
|
CreationContent: creationContent,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
user.log.Errorln("Failed to auto-create management room:", err)
|
user.log.Errorln("Failed to auto-create management room:", err)
|
||||||
@ -240,22 +350,13 @@ func (user *User) Connect() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.log.Debugln("Connecting to WhatsApp")
|
user.log.Debugln("Connecting to WhatsApp")
|
||||||
timeout := time.Duration(user.bridge.Config.Bridge.ConnectionTimeout)
|
timeout := time.Duration(user.bridge.Config.GroupMe.ConnectionTimeout)
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
timeout = 20
|
timeout = 20
|
||||||
}
|
}
|
||||||
conn := groupme.NewPushSubscription(context.Background())
|
conn := groupme.NewPushSubscription(context.Background())
|
||||||
user.Conn = &conn
|
user.Conn = &conn
|
||||||
user.Conn.StartListening(context.TODO(), groupmeExt.NewFayeClient(user.log))
|
user.Conn.StartListening(context.TODO(), groupmeext.NewFayeClient(user.log))
|
||||||
// if err != nil {
|
|
||||||
// user.log.Errorln("Failed to connect to WhatsApp:", err)
|
|
||||||
// user.sendMarkdownBridgeAlert("\u26a0 Failed to connect to WhatsApp server. " +
|
|
||||||
// "This indicates a network problem on the bridge server. See bridge logs for more info.")
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// user.Conn = whatsappExt.ExtendConn(conn)
|
|
||||||
// _ = user.Conn.SetClientName(user.bridge.Config.WhatsApp.OSName, user.bridge.Config.WhatsApp.BrowserName, WAVersion)
|
|
||||||
// user.log.Debugln("WhatsApp connection successful")
|
|
||||||
user.Conn.AddFullHandler(user)
|
user.Conn.AddFullHandler(user)
|
||||||
|
|
||||||
//TODO: typing notification?
|
//TODO: typing notification?
|
||||||
@ -264,26 +365,7 @@ func (user *User) Connect() bool {
|
|||||||
|
|
||||||
func (user *User) RestoreSession() bool {
|
func (user *User) RestoreSession() bool {
|
||||||
if len(user.Token) > 0 {
|
if len(user.Token) > 0 {
|
||||||
// if err == whatsapp.ErrAlreadyLoggedIn {
|
err := user.Conn.SubscribeToUser(context.TODO(), groupme.ID(user.GMID), user.Token.String())
|
||||||
// return true
|
|
||||||
// } else if err != nil {
|
|
||||||
// user.log.Errorln("Failed to restore session:", err)
|
|
||||||
// if errors.Is(err, whatsapp.ErrUnpaired) {
|
|
||||||
// user.sendMarkdownBridgeAlert("\u26a0 Failed to connect to WhatsApp: unpaired from phone. " +
|
|
||||||
// "To re-pair your phone, use `delete-session` and then `login`.")
|
|
||||||
// } else {
|
|
||||||
// user.sendMarkdownBridgeAlert("\u26a0 Failed to connect to WhatsApp. Make sure WhatsApp " +
|
|
||||||
// "on your phone is reachable and use `reconnect` to try connecting again.")
|
|
||||||
// }
|
|
||||||
// user.log.Debugln("Disconnecting due to failed session restore...")
|
|
||||||
// _, err :=
|
|
||||||
// if err != nil {
|
|
||||||
// user.log.Errorln("Failed to disconnect after failed session restore:", err)
|
|
||||||
// }
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
|
|
||||||
err := user.Conn.SubscribeToUser(context.TODO(), groupme.ID(user.JID), user.Token)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
@ -304,7 +386,7 @@ func (user *User) HasSession() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) IsConnected() bool {
|
func (user *User) IsConnected() bool {
|
||||||
println("better connectoin check TODO")
|
// TODO: better connection check
|
||||||
return user.Conn != nil
|
return user.Conn != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,65 +399,27 @@ func (user *User) IsLoginInProgress() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) GetJID() types.GroupMeID {
|
func (user *User) GetGMID() groupme.ID {
|
||||||
if len(user.JID) == 0 {
|
if len(user.GMID) == 0 {
|
||||||
u, _ := user.Client.MyUser(context.TODO())
|
u, err := user.Client.MyUser(context.TODO())
|
||||||
user.JID = u.ID.String()
|
if err != nil {
|
||||||
|
user.log.Errorln("Failed to get own GroupMe ID:", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
user.GMID = u.ID
|
||||||
}
|
}
|
||||||
return user.JID
|
return user.GMID
|
||||||
}
|
}
|
||||||
func (user *User) Login(ce *CommandEvent) {
|
|
||||||
// qrChan := make(chan string, 3)
|
|
||||||
// eventIDChan := make(chan id.EventID, 1)
|
|
||||||
// go user.loginQrChannel(ce, qrChan, eventIDChan)
|
|
||||||
// session, err := user.Conn.LoginWithRetry(qrChan, user.bridge.Config.Bridge.LoginQRRegenCount)
|
|
||||||
// qrChan <- "stop"
|
|
||||||
// if err != nil {
|
|
||||||
// var eventID id.EventID
|
|
||||||
// select {
|
|
||||||
// case eventID = <-eventIDChan:
|
|
||||||
// default:
|
|
||||||
// }
|
|
||||||
// reply := event.MessageEventContent{
|
|
||||||
// MsgType: event.MsgText,
|
|
||||||
// }
|
|
||||||
// if err == whatsapp.ErrAlreadyLoggedIn {
|
|
||||||
// reply.Body = "You're already logged in"
|
|
||||||
// } else if err == whatsapp.ErrLoginInProgress {
|
|
||||||
// reply.Body = "You have a login in progress already."
|
|
||||||
// } else if err == whatsapp.ErrLoginTimedOut {
|
|
||||||
// reply.Body = "QR code scan timed out. Please try again."
|
|
||||||
// } else {
|
|
||||||
// user.log.Warnln("Failed to log in:", err)
|
|
||||||
// reply.Body = fmt.Sprintf("Unknown error while logging in: %v", err)
|
|
||||||
// }
|
|
||||||
// msg := reply
|
|
||||||
// if eventID != "" {
|
|
||||||
// msg.NewContent = &reply
|
|
||||||
// msg.RelatesTo = &event.RelatesTo{
|
|
||||||
// Type: event.RelReplace,
|
|
||||||
// EventID: eventID,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// _, _ = ce.Bot.SendMessageEvent(ce.RoomID, event.EventMessage, &msg)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// // TODO there's a bit of duplication between this and the provisioning API login method
|
|
||||||
// // Also between the two logout methods (commands.go and provisioning.go)
|
|
||||||
// user.ConnectionErrors = 0
|
|
||||||
// user.JID = strings.Replace(user.Conn.Info.Wid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, 1)
|
|
||||||
|
|
||||||
if len(ce.Args) < 1 {
|
func (user *User) Login(token string) error {
|
||||||
ce.Reply(`Get your access token from https://dev.groupme.com/ which should be the first argument to login`)
|
user.Token = token
|
||||||
return
|
|
||||||
}
|
|
||||||
user.Token = ce.Args[0]
|
|
||||||
|
|
||||||
user.addToJIDMap()
|
user.addToGMIDMap()
|
||||||
//user.SetSession(&session)
|
|
||||||
ce.Reply("Successfully logged in, synchronizing chats...")
|
|
||||||
user.PostLogin()
|
user.PostLogin()
|
||||||
user.Connect()
|
if user.Connect() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("failed to connect")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
@ -385,11 +429,6 @@ type Chat struct {
|
|||||||
DM *groupme.Chat
|
DM *groupme.Chat
|
||||||
}
|
}
|
||||||
|
|
||||||
////returns private chat assuming one of group or dm have been initialized properly
|
|
||||||
//func (c Chat) IsPrivate() bool {
|
|
||||||
// return c.Group == nil
|
|
||||||
//}
|
|
||||||
|
|
||||||
type ChatList []Chat
|
type ChatList []Chat
|
||||||
|
|
||||||
func (cl ChatList) Len() int {
|
func (cl ChatList) Len() int {
|
||||||
@ -405,12 +444,9 @@ func (cl ChatList) Swap(i, j int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) PostLogin() {
|
func (user *User) PostLogin() {
|
||||||
user.bridge.Metrics.TrackConnectionState(user.JID, true)
|
user.bridge.Metrics.TrackConnectionState(user.GMID, true)
|
||||||
user.bridge.Metrics.TrackLoginState(user.JID, true)
|
user.bridge.Metrics.TrackLoginState(user.GMID, true)
|
||||||
user.bridge.Metrics.TrackBufferLength(user.MXID, 0)
|
user.bridge.Metrics.TrackBufferLength(user.MXID, 0)
|
||||||
user.log.Debugln("Locking processing of incoming messages and starting post-login sync")
|
|
||||||
user.syncWait.Add(1)
|
|
||||||
user.syncStart <- struct{}{}
|
|
||||||
go user.intPostLogin()
|
go user.intPostLogin()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +459,7 @@ func (user *User) tryAutomaticDoublePuppeting() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.log.Debugln("Checking if double puppeting needs to be enabled")
|
user.log.Debugln("Checking if double puppeting needs to be enabled")
|
||||||
puppet := user.bridge.GetPuppetByJID(user.JID)
|
puppet := user.bridge.GetPuppetByGMID(user.JID)
|
||||||
if len(puppet.CustomMXID) > 0 {
|
if len(puppet.CustomMXID) > 0 {
|
||||||
user.log.Debugln("User already has double-puppeting enabled")
|
user.log.Debugln("User already has double-puppeting enabled")
|
||||||
// Custom puppet already enabled
|
// Custom puppet already enabled
|
||||||
@ -486,7 +522,7 @@ func (user *User) postConnPing() bool {
|
|||||||
func (user *User) intPostLogin() {
|
func (user *User) intPostLogin() {
|
||||||
defer user.syncWait.Done()
|
defer user.syncWait.Done()
|
||||||
user.lastReconnection = time.Now().Unix()
|
user.lastReconnection = time.Now().Unix()
|
||||||
user.Client = groupmeExt.NewClient(user.Token)
|
user.Client = groupmeext.NewClient(user.Token)
|
||||||
if len(user.JID) == 0 {
|
if len(user.JID) == 0 {
|
||||||
myuser, err := user.Client.MyUser(context.TODO())
|
myuser, err := user.Client.MyUser(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -525,22 +561,6 @@ func (user *User) intPostLogin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) HandleStreamEvent(evt whatsappExt.StreamEvent) {
|
|
||||||
if evt.Type == whatsappExt.StreamSleep {
|
|
||||||
if user.lastReconnection+60 > time.Now().Unix() {
|
|
||||||
user.lastReconnection = 0
|
|
||||||
user.log.Infoln("Stream went to sleep soon after reconnection, making new post-connection ping in 20 seconds")
|
|
||||||
go func() {
|
|
||||||
time.Sleep(20 * time.Second)
|
|
||||||
// TODO if this happens during the post-login sync, it can get stuck forever
|
|
||||||
user.postConnPing()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
user.log.Infofln("Stream event: %+v", evt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (user *User) HandleChatList() {
|
func (user *User) HandleChatList() {
|
||||||
chatMap := make(map[string]groupme.Group)
|
chatMap := make(map[string]groupme.Group)
|
||||||
chats, err := user.Client.IndexAllGroups()
|
chats, err := user.Client.IndexAllGroups()
|
||||||
@ -618,7 +638,7 @@ func (user *User) syncPortals(createAll bool) {
|
|||||||
if inCommunity, ok = existingKeys[chat.Portal.Key]; !ok || !inCommunity {
|
if inCommunity, ok = existingKeys[chat.Portal.Key]; !ok || !inCommunity {
|
||||||
inCommunity = user.addPortalToCommunity(chat.Portal)
|
inCommunity = user.addPortalToCommunity(chat.Portal)
|
||||||
if chat.Portal.IsPrivateChat() {
|
if chat.Portal.IsPrivateChat() {
|
||||||
puppet := user.bridge.GetPuppetByJID(chat.Portal.Key.JID)
|
puppet := user.bridge.GetPuppetByJID(chat.Portal.Key.GMID)
|
||||||
user.addPuppetToCommunity(puppet)
|
user.addPuppetToCommunity(puppet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -673,7 +693,7 @@ func (user *User) getDirectChats() map[id.UserID][]id.RoomID {
|
|||||||
privateChats := user.bridge.DB.Portal.FindPrivateChats(user.JID)
|
privateChats := user.bridge.DB.Portal.FindPrivateChats(user.JID)
|
||||||
for _, portal := range privateChats {
|
for _, portal := range privateChats {
|
||||||
if len(portal.MXID) > 0 {
|
if len(portal.MXID) > 0 {
|
||||||
res[user.bridge.FormatPuppetMXID(portal.Key.JID)] = []id.RoomID{portal.MXID}
|
res[user.bridge.FormatPuppetMXID(portal.Key.GMID)] = []id.RoomID{portal.MXID}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
@ -845,12 +865,12 @@ func (user *User) HandleJSONParseError(err error) {
|
|||||||
user.log.Errorln("WhatsApp JSON parse error:", err)
|
user.log.Errorln("WhatsApp JSON parse error:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) PortalKey(jid types.GroupMeID) database.PortalKey {
|
func (user *User) PortalKey(gmid groupme.ID) database.PortalKey {
|
||||||
return database.NewPortalKey(jid, user.JID)
|
return database.NewPortalKey(gmid, user.GMID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) GetPortalByJID(jid types.GroupMeID) *Portal {
|
func (user *User) GetPortalByJID(gmid groupme.ID) *Portal {
|
||||||
return user.bridge.GetPortalByJID(user.PortalKey(jid))
|
return user.bridge.GetPortalByGMID(user.PortalKey(gmid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) runMessageRingBuffer() {
|
func (user *User) runMessageRingBuffer() {
|
||||||
@ -871,8 +891,8 @@ func (user *User) handleMessageLoop() {
|
|||||||
select {
|
select {
|
||||||
case msg := <-user.messageOutput:
|
case msg := <-user.messageOutput:
|
||||||
user.bridge.Metrics.TrackBufferLength(user.MXID, len(user.messageOutput))
|
user.bridge.Metrics.TrackBufferLength(user.MXID, len(user.messageOutput))
|
||||||
puppet := user.bridge.GetPuppetByJID(msg.data.UserID.String())
|
puppet := user.bridge.GetPuppetByGMID(msg.data.UserID)
|
||||||
portal := user.bridge.GetPortalByJID(msg.chat)
|
portal := user.bridge.GetPortalByGMID(msg.chat)
|
||||||
if puppet != nil {
|
if puppet != nil {
|
||||||
puppet.Sync(user, portal.MXID, groupme.Member{
|
puppet.Sync(user, portal.MXID, groupme.Member{
|
||||||
UserID: msg.data.UserID,
|
UserID: msg.data.UserID,
|
||||||
@ -881,12 +901,6 @@ func (user *User) handleMessageLoop() {
|
|||||||
}) //TODO: add params or docs?
|
}) //TODO: add params or docs?
|
||||||
}
|
}
|
||||||
portal.messages <- msg
|
portal.messages <- msg
|
||||||
case <-user.syncStart:
|
|
||||||
user.log.Debugln("Processing of incoming messages is locked")
|
|
||||||
user.bridge.Metrics.TrackSyncLock(user.JID, true)
|
|
||||||
user.syncWait.Wait()
|
|
||||||
user.bridge.Metrics.TrackSyncLock(user.JID, false)
|
|
||||||
user.log.Debugln("Processing of incoming messages unlocked")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CallInfoType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
CallOffer CallInfoType = "offer"
|
|
||||||
CallOfferVideo CallInfoType = "offer_video"
|
|
||||||
CallTransport CallInfoType = "transport"
|
|
||||||
CallRelayLatency CallInfoType = "relaylatency"
|
|
||||||
CallTerminate CallInfoType = "terminate"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CallInfo struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Type CallInfoType `json:"type"`
|
|
||||||
From string `json:"from"`
|
|
||||||
|
|
||||||
Platform string `json:"platform"`
|
|
||||||
Version []int `json:"version"`
|
|
||||||
|
|
||||||
Data [][]interface{} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CallInfoHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleCallInfo(CallInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageCall(message []byte) {
|
|
||||||
var event CallInfo
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event.From = strings.Replace(event.From, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
callInfoHandler, ok := handler.(CallInfoHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(callInfoHandler) {
|
|
||||||
callInfoHandler.HandleCallInfo(event)
|
|
||||||
} else {
|
|
||||||
go callInfoHandler.HandleCallInfo(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,183 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatUpdateCommand string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatUpdateCommandAction ChatUpdateCommand = "action"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatUpdate struct {
|
|
||||||
JID string `json:"id"`
|
|
||||||
Command ChatUpdateCommand `json:"cmd"`
|
|
||||||
Data ChatUpdateData `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChatActionType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
ChatActionNameChange ChatActionType = "subject"
|
|
||||||
ChatActionAddTopic ChatActionType = "desc_add"
|
|
||||||
ChatActionRemoveTopic ChatActionType = "desc_remove"
|
|
||||||
ChatActionRestrict ChatActionType = "restrict"
|
|
||||||
ChatActionAnnounce ChatActionType = "announce"
|
|
||||||
ChatActionPromote ChatActionType = "promote"
|
|
||||||
ChatActionDemote ChatActionType = "demote"
|
|
||||||
ChatActionIntroduce ChatActionType = "introduce"
|
|
||||||
ChatActionCreate ChatActionType = "create"
|
|
||||||
ChatActionRemove ChatActionType = "remove"
|
|
||||||
ChatActionAdd ChatActionType = "add"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatUpdateData struct {
|
|
||||||
Action ChatActionType
|
|
||||||
SenderJID string
|
|
||||||
|
|
||||||
NameChange struct {
|
|
||||||
Name string `json:"subject"`
|
|
||||||
SetAt int64 `json:"s_t"`
|
|
||||||
SetBy string `json:"s_o"`
|
|
||||||
}
|
|
||||||
|
|
||||||
AddTopic struct {
|
|
||||||
Topic string `json:"desc"`
|
|
||||||
ID string `json:"descId"`
|
|
||||||
SetAt int64 `json:"descTime"`
|
|
||||||
SetBy string `json:"descOwner"`
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveTopic struct {
|
|
||||||
ID string `json:"descId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
Introduce struct {
|
|
||||||
CreationTime int64 `json:"creation"`
|
|
||||||
Admins []string `json:"admins"`
|
|
||||||
SuperAdmins []string `json:"superadmins"`
|
|
||||||
Regulars []string `json:"regulars"`
|
|
||||||
}
|
|
||||||
|
|
||||||
Restrict bool
|
|
||||||
|
|
||||||
Announce bool
|
|
||||||
|
|
||||||
UserChange struct {
|
|
||||||
JIDs []string `json:"participants"`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cud *ChatUpdateData) UnmarshalJSON(data []byte) error {
|
|
||||||
var arr []json.RawMessage
|
|
||||||
err := json.Unmarshal(data, &arr)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
} else if len(arr) < 3 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(arr[0], &cud.Action)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(arr[1], &cud.SenderJID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cud.SenderJID = strings.Replace(cud.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
|
|
||||||
var unmarshalTo interface{}
|
|
||||||
switch cud.Action {
|
|
||||||
case ChatActionIntroduce, ChatActionCreate:
|
|
||||||
err = json.Unmarshal(arr[2], &cud.NameChange)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(arr[2], &cud.AddTopic)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
unmarshalTo = &cud.Introduce
|
|
||||||
case ChatActionNameChange:
|
|
||||||
unmarshalTo = &cud.NameChange
|
|
||||||
case ChatActionAddTopic:
|
|
||||||
unmarshalTo = &cud.AddTopic
|
|
||||||
case ChatActionRemoveTopic:
|
|
||||||
unmarshalTo = &cud.RemoveTopic
|
|
||||||
case ChatActionRestrict:
|
|
||||||
unmarshalTo = &cud.Restrict
|
|
||||||
case ChatActionAnnounce:
|
|
||||||
unmarshalTo = &cud.Announce
|
|
||||||
case ChatActionPromote, ChatActionDemote, ChatActionRemove, ChatActionAdd:
|
|
||||||
unmarshalTo = &cud.UserChange
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(arr[2], unmarshalTo)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cud.NameChange.SetBy = strings.Replace(cud.NameChange.SetBy, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
for index, jid := range cud.UserChange.JIDs {
|
|
||||||
cud.UserChange.JIDs[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
for index, jid := range cud.Introduce.SuperAdmins {
|
|
||||||
cud.Introduce.SuperAdmins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
for index, jid := range cud.Introduce.Admins {
|
|
||||||
cud.Introduce.Admins[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
for index, jid := range cud.Introduce.Regulars {
|
|
||||||
cud.Introduce.Regulars[index] = strings.Replace(jid, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChatUpdateHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleChatUpdate(ChatUpdate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageChatUpdate(message []byte) {
|
|
||||||
var event ChatUpdate
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
chatUpdateHandler, ok := handler.(ChatUpdateHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(chatUpdateHandler) {
|
|
||||||
chatUpdateHandler.HandleChatUpdate(event)
|
|
||||||
} else {
|
|
||||||
go chatUpdateHandler.HandleChatUpdate(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CommandType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
CommandPicture CommandType = "picture"
|
|
||||||
CommandDisconnect CommandType = "disconnect"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Command struct {
|
|
||||||
Type CommandType `json:"type"`
|
|
||||||
JID string `json:"jid"`
|
|
||||||
|
|
||||||
*ProfilePicInfo
|
|
||||||
Kind string `json:"kind"`
|
|
||||||
|
|
||||||
Raw json.RawMessage `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommandHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleCommand(Command)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageCommand(message []byte) {
|
|
||||||
var event Command
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event.Raw = message
|
|
||||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
commandHandler, ok := handler.(CommandHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(commandHandler) {
|
|
||||||
commandHandler.HandleCommand(event)
|
|
||||||
} else {
|
|
||||||
go commandHandler.HandleCommand(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ConnInfo struct {
|
|
||||||
ProtocolVersion []int `json:"protoVersion"`
|
|
||||||
BinaryVersion int `json:"binVersion"`
|
|
||||||
Phone struct {
|
|
||||||
WhatsAppVersion string `json:"wa_version"`
|
|
||||||
MCC string `json:"mcc"`
|
|
||||||
MNC string `json:"mnc"`
|
|
||||||
OSVersion string `json:"os_version"`
|
|
||||||
DeviceManufacturer string `json:"device_manufacturer"`
|
|
||||||
DeviceModel string `json:"device_model"`
|
|
||||||
OSBuildNumber string `json:"os_build_number"`
|
|
||||||
} `json:"phone"`
|
|
||||||
Features map[string]interface{} `json:"features"`
|
|
||||||
PushName string `json:"pushname"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConnInfoHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleConnInfo(ConnInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageConn(message []byte) {
|
|
||||||
var event ConnInfo
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
connInfoHandler, ok := handler.(ConnInfoHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(connInfoHandler) {
|
|
||||||
connInfoHandler.HandleConnInfo(event)
|
|
||||||
} else {
|
|
||||||
go connInfoHandler.HandleConnInfo(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/beeper/groupme/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CreateGroupResponse struct {
|
|
||||||
Status int `json:"status"`
|
|
||||||
GroupID types.GroupMeID `json:"gid"`
|
|
||||||
Participants map[types.GroupMeID]struct {
|
|
||||||
Code string `json:"code"`
|
|
||||||
} `json:"participants"`
|
|
||||||
|
|
||||||
Source string `json:"-"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type actualCreateGroupResponse struct {
|
|
||||||
Status int `json:"status"`
|
|
||||||
GroupID types.GroupMeID `json:"gid"`
|
|
||||||
Participants []map[types.GroupMeID]struct {
|
|
||||||
Code string `json:"code"`
|
|
||||||
} `json:"participants"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) CreateGroup(subject string, participants []types.GroupMeID) (*CreateGroupResponse, error) {
|
|
||||||
// respChan, err := ext.Conn.CreateGroup(subject, participants)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// var resp CreateGroupResponse
|
|
||||||
// var actualResp actualCreateGroupResponse
|
|
||||||
// resp.Source = <-respChan
|
|
||||||
// fmt.Println(">>>>>>", resp.Source)
|
|
||||||
// err = json.Unmarshal([]byte(resp.Source), &actualResp)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// resp.Status = actualResp.Status
|
|
||||||
// resp.GroupID = actualResp.GroupID
|
|
||||||
// resp.Participants = make(map[types.GroupMeID]struct {
|
|
||||||
// Code string `json:"code"`
|
|
||||||
// })
|
|
||||||
// for _, participantMap := range actualResp.Participants {
|
|
||||||
// for jid, status := range participantMap {
|
|
||||||
// resp.Participants[jid] = status
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return &resp, nil
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type JSONMessage []json.RawMessage
|
|
||||||
|
|
||||||
type JSONMessageType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
MessageMsgInfo JSONMessageType = "MsgInfo"
|
|
||||||
MessageMsg JSONMessageType = "Msg"
|
|
||||||
MessagePresence JSONMessageType = "Presence"
|
|
||||||
MessageStream JSONMessageType = "Stream"
|
|
||||||
MessageConn JSONMessageType = "Conn"
|
|
||||||
MessageProps JSONMessageType = "Props"
|
|
||||||
MessageCmd JSONMessageType = "Cmd"
|
|
||||||
MessageChat JSONMessageType = "Chat"
|
|
||||||
MessageCall JSONMessageType = "Call"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) HandleError(error) {}
|
|
||||||
|
|
||||||
type UnhandledJSONMessageHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleUnhandledJSONMessage(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
type JSONParseErrorHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleJSONParseError(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) jsonParseError(err error) {
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
errorHandler, ok := handler.(JSONParseErrorHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
errorHandler.HandleJSONParseError(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) HandleJsonMessage(message string) {
|
|
||||||
msg := JSONMessage{}
|
|
||||||
err := json.Unmarshal([]byte(message), &msg)
|
|
||||||
if err != nil || len(msg) < 2 {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var msgType JSONMessageType
|
|
||||||
json.Unmarshal(msg[0], &msgType)
|
|
||||||
|
|
||||||
switch msgType {
|
|
||||||
case MessagePresence:
|
|
||||||
ext.handleMessagePresence(msg[1])
|
|
||||||
case MessageStream:
|
|
||||||
ext.handleMessageStream(msg[1:])
|
|
||||||
case MessageConn:
|
|
||||||
ext.handleMessageConn(msg[1])
|
|
||||||
case MessageProps:
|
|
||||||
ext.handleMessageProps(msg[1])
|
|
||||||
case MessageMsgInfo, MessageMsg:
|
|
||||||
ext.handleMessageMsgInfo(msgType, msg[1])
|
|
||||||
case MessageCmd:
|
|
||||||
ext.handleMessageCommand(msg[1])
|
|
||||||
case MessageChat:
|
|
||||||
ext.handleMessageChatUpdate(msg[1])
|
|
||||||
case MessageCall:
|
|
||||||
ext.handleMessageCall(msg[1])
|
|
||||||
default:
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
ujmHandler, ok := handler.(UnhandledJSONMessageHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(ujmHandler) {
|
|
||||||
ujmHandler.HandleUnhandledJSONMessage(message)
|
|
||||||
} else {
|
|
||||||
go ujmHandler.HandleUnhandledJSONMessage(message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MsgInfoCommand string
|
|
||||||
|
|
||||||
const (
|
|
||||||
MsgInfoCommandAck MsgInfoCommand = "ack"
|
|
||||||
MsgInfoCommandAcks MsgInfoCommand = "acks"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Acknowledgement int
|
|
||||||
|
|
||||||
const (
|
|
||||||
AckMessageSent Acknowledgement = 1
|
|
||||||
AckMessageDelivered Acknowledgement = 2
|
|
||||||
AckMessageRead Acknowledgement = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
type JSONStringOrArray []string
|
|
||||||
|
|
||||||
func (jsoa *JSONStringOrArray) UnmarshalJSON(data []byte) error {
|
|
||||||
var str string
|
|
||||||
if json.Unmarshal(data, &str) == nil {
|
|
||||||
*jsoa = []string{str}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var strs []string
|
|
||||||
json.Unmarshal(data, &strs)
|
|
||||||
*jsoa = strs
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type MsgInfo struct {
|
|
||||||
Command MsgInfoCommand `json:"cmd"`
|
|
||||||
IDs JSONStringOrArray `json:"id"`
|
|
||||||
Acknowledgement Acknowledgement `json:"ack"`
|
|
||||||
MessageFromJID string `json:"from"`
|
|
||||||
SenderJID string `json:"participant"`
|
|
||||||
ToJID string `json:"to"`
|
|
||||||
Timestamp int64 `json:"t"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MsgInfoHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleMsgInfo(MsgInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageMsgInfo(msgType JSONMessageType, message []byte) {
|
|
||||||
var event MsgInfo
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event.MessageFromJID = strings.Replace(event.MessageFromJID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
event.SenderJID = strings.Replace(event.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
event.ToJID = strings.Replace(event.ToJID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
if msgType == MessageMsg {
|
|
||||||
event.SenderJID = event.ToJID
|
|
||||||
}
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
msgInfoHandler, ok := handler.(MsgInfoHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(msgInfoHandler) {
|
|
||||||
msgInfoHandler.HandleMsgInfo(event)
|
|
||||||
} else {
|
|
||||||
go msgInfoHandler.HandleMsgInfo(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Presence struct {
|
|
||||||
JID string `json:"id"`
|
|
||||||
SenderJID string `json:"participant"`
|
|
||||||
Status whatsapp.Presence `json:"type"`
|
|
||||||
Timestamp int64 `json:"t"`
|
|
||||||
Deny bool `json:"deny"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PresenceHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandlePresence(Presence)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessagePresence(message []byte) {
|
|
||||||
var event Presence
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
event.JID = strings.Replace(event.JID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
if len(event.SenderJID) == 0 {
|
|
||||||
event.SenderJID = event.JID
|
|
||||||
} else {
|
|
||||||
event.SenderJID = strings.Replace(event.SenderJID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
presenceHandler, ok := handler.(PresenceHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(presenceHandler) {
|
|
||||||
presenceHandler.HandlePresence(event)
|
|
||||||
} else {
|
|
||||||
go presenceHandler.HandlePresence(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProtocolProps struct {
|
|
||||||
WebPresence bool `json:"webPresence"`
|
|
||||||
NotificationQuery bool `json:"notificationQuery"`
|
|
||||||
FacebookCrashLog bool `json:"fbCrashlog"`
|
|
||||||
Bucket string `json:"bucket"`
|
|
||||||
GIFSearch string `json:"gifSearch"`
|
|
||||||
Spam bool `json:"SPAM"`
|
|
||||||
SetBlock bool `json:"SET_BLOCK"`
|
|
||||||
MessageInfo bool `json:"MESSAGE_INFO"`
|
|
||||||
MaxFileSize int `json:"maxFileSize"`
|
|
||||||
Media int `json:"media"`
|
|
||||||
GroupNameLength int `json:"maxSubject"`
|
|
||||||
GroupDescriptionLength int `json:"groupDescLength"`
|
|
||||||
MaxParticipants int `json:"maxParticipants"`
|
|
||||||
VideoMaxEdge int `json:"videoMaxEdge"`
|
|
||||||
ImageMaxEdge int `json:"imageMaxEdge"`
|
|
||||||
ImageMaxKilobytes int `json:"imageMaxKBytes"`
|
|
||||||
Edit int `json:"edit"`
|
|
||||||
FwdUIStartTimestamp int `json:"fwdUiStartTs"`
|
|
||||||
GroupsV3 int `json:"groupsV3"`
|
|
||||||
RestrictGroups int `json:"restrictGroups"`
|
|
||||||
AnnounceGroups int `json:"announceGroups"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProtocolPropsHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleProtocolProps(ProtocolProps)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageProps(message []byte) {
|
|
||||||
var event ProtocolProps
|
|
||||||
err := json.Unmarshal(message, &event)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
protocolPropsHandler, ok := handler.(ProtocolPropsHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(protocolPropsHandler) {
|
|
||||||
protocolPropsHandler.HandleProtocolProps(event)
|
|
||||||
} else {
|
|
||||||
go protocolPropsHandler.HandleProtocolProps(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
"github.com/Rhymen/go-whatsapp/binary/proto"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MessageRevokeHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleMessageRevoke(key MessageRevocation)
|
|
||||||
}
|
|
||||||
|
|
||||||
type MessageRevocation struct {
|
|
||||||
Id string
|
|
||||||
RemoteJid string
|
|
||||||
FromMe bool
|
|
||||||
Participant string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
|
|
||||||
protoMsg := message.GetMessage().GetProtocolMessage()
|
|
||||||
if protoMsg != nil && protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
|
|
||||||
key := protoMsg.GetKey()
|
|
||||||
deletedMessage := MessageRevocation{
|
|
||||||
Id: key.GetId(),
|
|
||||||
RemoteJid: key.GetRemoteJid(),
|
|
||||||
FromMe: key.GetFromMe(),
|
|
||||||
Participant: key.GetParticipant(),
|
|
||||||
}
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
mrHandler, ok := handler.(MessageRevokeHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(mrHandler) {
|
|
||||||
mrHandler.HandleMessageRevoke(deletedMessage)
|
|
||||||
} else {
|
|
||||||
go mrHandler.HandleMessageRevoke(deletedMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StreamType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
StreamUpdate = "update"
|
|
||||||
StreamSleep = "asleep"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StreamEvent struct {
|
|
||||||
Type StreamType
|
|
||||||
|
|
||||||
IsOutdated bool
|
|
||||||
Version string
|
|
||||||
|
|
||||||
Extra []json.RawMessage
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamEventHandler interface {
|
|
||||||
whatsapp.Handler
|
|
||||||
HandleStreamEvent(StreamEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) handleMessageStream(message []json.RawMessage) {
|
|
||||||
var event StreamEvent
|
|
||||||
err := json.Unmarshal(message[0], &event.Type)
|
|
||||||
if err != nil {
|
|
||||||
ext.jsonParseError(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if event.Type == StreamUpdate && len(message) >= 3 {
|
|
||||||
_ = json.Unmarshal(message[1], &event.IsOutdated)
|
|
||||||
_ = json.Unmarshal(message[2], &event.Version)
|
|
||||||
if len(message) >= 4 {
|
|
||||||
event.Extra = message[3:]
|
|
||||||
}
|
|
||||||
} else if len(message) >= 2 {
|
|
||||||
event.Extra = message[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, handler := range ext.handlers {
|
|
||||||
streamHandler, ok := handler.(StreamEventHandler)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if ext.shouldCallSynchronously(streamHandler) {
|
|
||||||
streamHandler.HandleStreamEvent(event)
|
|
||||||
} else {
|
|
||||||
go streamHandler.HandleStreamEvent(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,164 +0,0 @@
|
|||||||
// mautrix-groupme - A Matrix-GroupMe puppeting bridge.
|
|
||||||
// Copyright (C) 2022 Sumner Evans, Karmanyaah Malhotra
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package whatsappExt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
OldUserSuffix = "@c.us"
|
|
||||||
NewUserSuffix = "@s.whatsapp.net"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ExtendedConn struct {
|
|
||||||
*whatsapp.Conn
|
|
||||||
|
|
||||||
handlers []whatsapp.Handler
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExtendConn(conn *whatsapp.Conn) *ExtendedConn {
|
|
||||||
ext := &ExtendedConn{
|
|
||||||
Conn: conn,
|
|
||||||
}
|
|
||||||
ext.Conn.AddHandler(ext)
|
|
||||||
return ext
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) AddHandler(handler whatsapp.Handler) {
|
|
||||||
ext.Conn.AddHandler(handler)
|
|
||||||
ext.handlers = append(ext.handlers, handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) RemoveHandler(handler whatsapp.Handler) bool {
|
|
||||||
ext.Conn.RemoveHandler(handler)
|
|
||||||
for i, v := range ext.handlers {
|
|
||||||
if v == handler {
|
|
||||||
ext.handlers = append(ext.handlers[:i], ext.handlers[i+1:]...)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) RemoveHandlers() {
|
|
||||||
ext.Conn.RemoveHandlers()
|
|
||||||
ext.handlers = make([]whatsapp.Handler, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) shouldCallSynchronously(handler whatsapp.Handler) bool {
|
|
||||||
sh, ok := handler.(whatsapp.SyncHandler)
|
|
||||||
return ok && sh.ShouldCallSynchronously()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) ShouldCallSynchronously() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
type GroupInfo struct {
|
|
||||||
JID string `json:"jid"`
|
|
||||||
OwnerJID string `json:"owner"`
|
|
||||||
|
|
||||||
Name string `json:"subject"`
|
|
||||||
NameSetTime int64 `json:"subjectTime"`
|
|
||||||
NameSetBy string `json:"subjectOwner"`
|
|
||||||
|
|
||||||
Announce bool `json:"announce"` // Can only admins send messages?
|
|
||||||
|
|
||||||
Topic string `json:"desc"`
|
|
||||||
TopicID string `json:"descId"`
|
|
||||||
TopicSetAt int64 `json:"descTime"`
|
|
||||||
TopicSetBy string `json:"descOwner"`
|
|
||||||
|
|
||||||
GroupCreated int64 `json:"creation"`
|
|
||||||
|
|
||||||
Status int16 `json:"status"`
|
|
||||||
|
|
||||||
Participants []struct {
|
|
||||||
JID string `json:"id"`
|
|
||||||
IsAdmin bool `json:"isAdmin"`
|
|
||||||
IsSuperAdmin bool `json:"isSuperAdmin"`
|
|
||||||
} `json:"participants"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) GetGroupMetaData(jid string) (*GroupInfo, error) {
|
|
||||||
data, err := ext.Conn.GetGroupMetaData(jid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get group metadata: %v", err)
|
|
||||||
}
|
|
||||||
content := <-data
|
|
||||||
|
|
||||||
info := &GroupInfo{}
|
|
||||||
err = json.Unmarshal([]byte(content), info)
|
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("failed to unmarshal group metadata: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for index, participant := range info.Participants {
|
|
||||||
info.Participants[index].JID = strings.Replace(participant.JID, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
}
|
|
||||||
info.NameSetBy = strings.Replace(info.NameSetBy, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
info.TopicSetBy = strings.Replace(info.TopicSetBy, OldUserSuffix, NewUserSuffix, 1)
|
|
||||||
|
|
||||||
return info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProfilePicInfo struct {
|
|
||||||
URL string `json:"eurl"`
|
|
||||||
Tag string `json:"tag"`
|
|
||||||
|
|
||||||
Status int `json:"status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ppi *ProfilePicInfo) Download() (io.ReadCloser, error) {
|
|
||||||
resp, err := http.Get(ppi.URL)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Body, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ppi *ProfilePicInfo) DownloadBytes() ([]byte, error) {
|
|
||||||
body, err := ppi.Download()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer body.Close()
|
|
||||||
data, err := ioutil.ReadAll(body)
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ext *ExtendedConn) GetProfilePicThumb(jid string) (*ProfilePicInfo, error) {
|
|
||||||
data, err := ext.Conn.GetProfilePicThumb(jid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get avatar: %v", err)
|
|
||||||
}
|
|
||||||
content := <-data
|
|
||||||
info := &ProfilePicInfo{}
|
|
||||||
err = json.Unmarshal([]byte(content), info)
|
|
||||||
if err != nil {
|
|
||||||
return info, fmt.Errorf("failed to unmarshal avatar info: %v", err)
|
|
||||||
}
|
|
||||||
return info, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user