BIG ASS COMMIT
This commit is contained in:
parent
95f6487912
commit
eafc18099d
104
ROADMAP.md
104
ROADMAP.md
@ -1,67 +1,67 @@
|
||||
# Features & roadmap
|
||||
* Matrix → WhatsApp
|
||||
* [x] Message content
|
||||
* [x] Plain text
|
||||
* [x] Formatted messages
|
||||
* [x] Media/files
|
||||
* [x] Replies
|
||||
* [x] Message redactions
|
||||
* [x] Presence
|
||||
* [x] Typing notifications
|
||||
* [x] Read receipts
|
||||
* Matrix → GroupMe
|
||||
* [ ] Message content
|
||||
* [ ] Plain text
|
||||
* [ ] Formatted messages
|
||||
* [ ] Media/files
|
||||
* [ ] Replies
|
||||
* [ ] Message redactions
|
||||
* [ ] Presence
|
||||
* [ ] Typing notifications
|
||||
* [ ] Read receipts
|
||||
* [ ] Power level
|
||||
* [ ] Membership actions
|
||||
* [x] Invite
|
||||
* [ ] Invite
|
||||
* [ ] Join
|
||||
* [x] Leave
|
||||
* [x] Kick
|
||||
* [ ] Leave
|
||||
* [ ] Kick
|
||||
* [ ] Room metadata changes
|
||||
* [x] Name
|
||||
* [ ] Name
|
||||
* [ ] Avatar<sup>[1]</sup>
|
||||
* [x] Topic
|
||||
* [ ] Topic
|
||||
* [ ] Initial room metadata
|
||||
* WhatsApp → Matrix
|
||||
* [x] Message content
|
||||
* [x] Plain text
|
||||
* [x] Formatted messages
|
||||
* [x] Media/files
|
||||
* [x] Location messages
|
||||
* [x] Contact messages
|
||||
* [x] Replies
|
||||
* GroupMe → Matrix
|
||||
* [ ] Message content
|
||||
* [ ] Plain text
|
||||
* [ ] Formatted messages
|
||||
* [ ] Media/files
|
||||
* [ ] Location messages
|
||||
* [ ] Contact messages
|
||||
* [ ] Replies
|
||||
* [ ] Chat types
|
||||
* [x] Private chat
|
||||
* [x] Group chat
|
||||
* [ ] Private chat
|
||||
* [ ] Group chat
|
||||
* [ ] Broadcast list<sup>[2]</sup>
|
||||
* [x] Message deletions
|
||||
* [x] Avatars
|
||||
* [x] Presence
|
||||
* [x] Typing notifications
|
||||
* [x] Read receipts
|
||||
* [x] Admin/superadmin status
|
||||
* [x] Membership actions
|
||||
* [x] Invite
|
||||
* [x] Join
|
||||
* [x] Leave
|
||||
* [x] Kick
|
||||
* [x] Group metadata changes
|
||||
* [x] Title
|
||||
* [x] Avatar
|
||||
* [x] Description
|
||||
* [x] Initial group metadata
|
||||
* [ ] Message deletions
|
||||
* [ ] Avatars
|
||||
* [ ] Presence
|
||||
* [ ] Typing notifications
|
||||
* [ ] Read receipts
|
||||
* [ ] Admin/superadmin status
|
||||
* [ ] Membership actions
|
||||
* [ ] Invite
|
||||
* [ ] Join
|
||||
* [ ] Leave
|
||||
* [ ] Kick
|
||||
* [ ] Group metadata changes
|
||||
* [ ] Title
|
||||
* [ ] Avatar
|
||||
* [ ] Description
|
||||
* [ ] Initial group metadata
|
||||
* [ ] User metadata changes
|
||||
* [ ] Display name<sup>[3]</sup>
|
||||
* [x] Avatar
|
||||
* [x] Initial user metadata
|
||||
* [x] Display name
|
||||
* [x] Avatar
|
||||
* [ ] Avatar
|
||||
* [ ] Initial user metadata
|
||||
* [ ] Display name
|
||||
* [ ] Avatar
|
||||
* Misc
|
||||
* [x] Automatic portal creation
|
||||
* [x] At startup
|
||||
* [x] When receiving invite
|
||||
* [x] When receiving message
|
||||
* [x] Private chat creation by inviting Matrix puppet of WhatsApp user to new room
|
||||
* [x] Option to use own Matrix account for messages sent from WhatsApp mobile/other web clients
|
||||
* [x] Shared group chat portals
|
||||
* [ ] Automatic portal creation
|
||||
* [ ] At startup
|
||||
* [ ] When receiving invite
|
||||
* [ ] When receiving message
|
||||
* [ ] Private chat creation by inviting Matrix puppet of WhatsApp user to new room
|
||||
* [ ] Option to use own Matrix account for messages sent from WhatsApp mobile/other web clients
|
||||
* [ ] Shared group chat portals
|
||||
|
||||
<sup>[1]</sup> May involve reverse-engineering the WhatsApp Web API and/or editing go-whatsapp
|
||||
<sup>[2]</sup> May already work
|
||||
|
859
commands.go
859
commands.go
@ -17,9 +17,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
// "errors"
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
// "math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -34,7 +35,7 @@ import (
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/database"
|
||||
// "maunium.net/go/mautrix-whatsapp/database"
|
||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
)
|
||||
|
||||
@ -218,123 +219,123 @@ func (handler *CommandHandler) CommandVersion(ce *CommandEvent) {
|
||||
const cmdInviteLinkHelp = `invite-link - Get an invite link to the current group chat.`
|
||||
|
||||
func (handler *CommandHandler) CommandInviteLink(ce *CommandEvent) {
|
||||
if ce.Portal == nil {
|
||||
ce.Reply("Not a portal room")
|
||||
return
|
||||
} else if ce.Portal.IsPrivateChat() {
|
||||
ce.Reply("Can't get invite link to private chat")
|
||||
return
|
||||
}
|
||||
// if ce.Portal == nil {
|
||||
// ce.Reply("Not a portal room")
|
||||
// return
|
||||
// } else if ce.Portal.IsPrivateChat() {
|
||||
// ce.Reply("Can't get invite link to private chat")
|
||||
// return
|
||||
// }
|
||||
|
||||
link, err := ce.User.Conn.GroupInviteLink(ce.Portal.Key.JID)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to get invite link: %v", err)
|
||||
return
|
||||
}
|
||||
ce.Reply("%s%s", inviteLinkPrefix, link)
|
||||
// link, err := ce.User.Conn.GroupInviteLink(ce.Portal.Key.JID)
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to get invite link: %v", err)
|
||||
// return
|
||||
// }
|
||||
// ce.Reply("%s%s", inviteLinkPrefix, link)
|
||||
}
|
||||
|
||||
const cmdJoinHelp = `join <invite link> - Join a group chat with an invite link.`
|
||||
const inviteLinkPrefix = "https://chat.whatsapp.com/"
|
||||
|
||||
func (handler *CommandHandler) CommandJoin(ce *CommandEvent) {
|
||||
if len(ce.Args) == 0 {
|
||||
ce.Reply("**Usage:** `join <invite link>`")
|
||||
return
|
||||
} else if len(ce.Args[0]) <= len(inviteLinkPrefix) || ce.Args[0][:len(inviteLinkPrefix)] != inviteLinkPrefix {
|
||||
ce.Reply("That doesn't look like a WhatsApp invite link")
|
||||
return
|
||||
}
|
||||
// if len(ce.Args) == 0 {
|
||||
// ce.Reply("**Usage:** `join <invite link>`")
|
||||
// return
|
||||
// } else if len(ce.Args[0]) <= len(inviteLinkPrefix) || ce.Args[0][:len(inviteLinkPrefix)] != inviteLinkPrefix {
|
||||
// ce.Reply("That doesn't look like a WhatsApp invite link")
|
||||
// return
|
||||
// }
|
||||
|
||||
jid, err := ce.User.Conn.GroupAcceptInviteCode(ce.Args[0][len(inviteLinkPrefix):])
|
||||
if err != nil {
|
||||
ce.Reply("Failed to join group: %v", err)
|
||||
return
|
||||
}
|
||||
// jid, err := ce.User.Conn.GroupAcceptInviteCode(ce.Args[0][len(inviteLinkPrefix):])
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to join group: %v", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
handler.log.Debugln("%s successfully joined group %s", ce.User.MXID, jid)
|
||||
portal := handler.bridge.GetPortalByJID(database.GroupPortalKey(jid))
|
||||
if len(portal.MXID) > 0 {
|
||||
portal.Sync(ce.User, whatsapp.Contact{Jid: portal.Key.JID})
|
||||
ce.Reply("Successfully joined group \"%s\" and synced portal room: [%s](https://matrix.to/#/%s)", portal.Name, portal.Name, portal.MXID)
|
||||
} else {
|
||||
err = portal.CreateMatrixRoom(ce.User)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to create portal room: %v", err)
|
||||
return
|
||||
}
|
||||
// handler.log.Debugln("%s successfully joined group %s", ce.User.MXID, jid)
|
||||
// portal := handler.bridge.GetPortalByJID(database.GroupPortalKey(jid))
|
||||
// if len(portal.MXID) > 0 {
|
||||
// portal.Sync(ce.User, whatsapp.Contact{Jid: portal.Key.JID})
|
||||
// ce.Reply("Successfully joined group \"%s\" and synced portal room: [%s](https://matrix.to/#/%s)", portal.Name, portal.Name, portal.MXID)
|
||||
// } else {
|
||||
// err = portal.CreateMatrixRoom(ce.User)
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to create portal room: %v", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
ce.Reply("Successfully joined group \"%s\" and created portal room: [%s](https://matrix.to/#/%s)", portal.Name, portal.Name, portal.MXID)
|
||||
}
|
||||
// ce.Reply("Successfully joined group \"%s\" and created portal room: [%s](https://matrix.to/#/%s)", portal.Name, portal.Name, portal.MXID)
|
||||
// }
|
||||
}
|
||||
|
||||
const cmdCreateHelp = `create - Create a group chat.`
|
||||
|
||||
func (handler *CommandHandler) CommandCreate(ce *CommandEvent) {
|
||||
if ce.Portal != nil {
|
||||
ce.Reply("This is already a portal room")
|
||||
return
|
||||
}
|
||||
// if ce.Portal != nil {
|
||||
// ce.Reply("This is already a portal room")
|
||||
// return
|
||||
// }
|
||||
|
||||
members, err := ce.Bot.JoinedMembers(ce.RoomID)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to get room members: %v", err)
|
||||
return
|
||||
}
|
||||
// members, err := ce.Bot.JoinedMembers(ce.RoomID)
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to get room members: %v", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
var roomNameEvent event.RoomNameEventContent
|
||||
err = ce.Bot.StateEvent(ce.RoomID, event.StateRoomName, "", &roomNameEvent)
|
||||
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||
ce.Reply("Failed to get room name")
|
||||
return
|
||||
} else if len(roomNameEvent.Name) == 0 {
|
||||
ce.Reply("Please set a name for the room first")
|
||||
return
|
||||
}
|
||||
// var roomNameEvent event.RoomNameEventContent
|
||||
// err = ce.Bot.StateEvent(ce.RoomID, event.StateRoomName, "", &roomNameEvent)
|
||||
// if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||
// ce.Reply("Failed to get room name")
|
||||
// return
|
||||
// } else if len(roomNameEvent.Name) == 0 {
|
||||
// ce.Reply("Please set a name for the room first")
|
||||
// return
|
||||
// }
|
||||
|
||||
var encryptionEvent event.EncryptionEventContent
|
||||
err = ce.Bot.StateEvent(ce.RoomID, event.StateEncryption, "", &encryptionEvent)
|
||||
if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||
ce.Reply("Failed to get room encryption status")
|
||||
return
|
||||
}
|
||||
// var encryptionEvent event.EncryptionEventContent
|
||||
// err = ce.Bot.StateEvent(ce.RoomID, event.StateEncryption, "", &encryptionEvent)
|
||||
// if err != nil && !errors.Is(err, mautrix.MNotFound) {
|
||||
// ce.Reply("Failed to get room encryption status")
|
||||
// return
|
||||
// }
|
||||
|
||||
participants := []string{ce.User.JID}
|
||||
for userID := range members.Joined {
|
||||
jid, ok := handler.bridge.ParsePuppetMXID(userID)
|
||||
if ok && jid != ce.User.JID {
|
||||
participants = append(participants, jid)
|
||||
}
|
||||
}
|
||||
// participants := []string{ce.User.JID}
|
||||
// for userID := range members.Joined {
|
||||
// jid, ok := handler.bridge.ParsePuppetMXID(userID)
|
||||
// if ok && jid != ce.User.JID {
|
||||
// participants = append(participants, jid)
|
||||
// }
|
||||
// }
|
||||
|
||||
resp, err := ce.User.Conn.CreateGroup(roomNameEvent.Name, participants)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to create group: %v", err)
|
||||
return
|
||||
}
|
||||
portal := handler.bridge.GetPortalByJID(database.GroupPortalKey(resp.GroupID))
|
||||
portal.roomCreateLock.Lock()
|
||||
defer portal.roomCreateLock.Unlock()
|
||||
if len(portal.MXID) != 0 {
|
||||
portal.log.Warnln("Detected race condition in room creation")
|
||||
// TODO race condition, clean up the old room
|
||||
}
|
||||
portal.MXID = ce.RoomID
|
||||
portal.Name = roomNameEvent.Name
|
||||
portal.Encrypted = encryptionEvent.Algorithm == id.AlgorithmMegolmV1
|
||||
if !portal.Encrypted && handler.bridge.Config.Bridge.Encryption.Default {
|
||||
_, err = portal.MainIntent().SendStateEvent(portal.MXID, event.StateEncryption, "", &event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1})
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to enable e2be:", err)
|
||||
}
|
||||
portal.Encrypted = true
|
||||
}
|
||||
// resp, err := ce.User.Conn.CreateGroup(roomNameEvent.Name, participants)
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to create group: %v", err)
|
||||
// return
|
||||
// }
|
||||
// portal := handler.bridge.GetPortalByJID(database.GroupPortalKey(resp.GroupID))
|
||||
// portal.roomCreateLock.Lock()
|
||||
// defer portal.roomCreateLock.Unlock()
|
||||
// if len(portal.MXID) != 0 {
|
||||
// portal.log.Warnln("Detected race condition in room creation")
|
||||
// // TODO race condition, clean up the old room
|
||||
// }
|
||||
// portal.MXID = ce.RoomID
|
||||
// portal.Name = roomNameEvent.Name
|
||||
// portal.Encrypted = encryptionEvent.Algorithm == id.AlgorithmMegolmV1
|
||||
// if !portal.Encrypted && handler.bridge.Config.Bridge.Encryption.Default {
|
||||
// _, err = portal.MainIntent().SendStateEvent(portal.MXID, event.StateEncryption, "", &event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1})
|
||||
// if err != nil {
|
||||
// portal.log.Warnln("Failed to enable e2be:", err)
|
||||
// }
|
||||
// portal.Encrypted = true
|
||||
// }
|
||||
|
||||
portal.Update()
|
||||
portal.UpdateBridgeInfo()
|
||||
// portal.Update()
|
||||
// portal.UpdateBridgeInfo()
|
||||
|
||||
ce.Reply("Successfully created WhatsApp group %s", portal.Key.JID)
|
||||
ce.User.addPortalToCommunity(portal)
|
||||
// ce.Reply("Successfully created WhatsApp group %s", portal.Key.JID)
|
||||
// ce.User.addPortalToCommunity(portal)
|
||||
}
|
||||
|
||||
const cmdSetPowerLevelHelp = `set-pl [user ID] <power level> - Change the power level in a portal room. Only for bridge admins.`
|
||||
@ -392,185 +393,185 @@ const cmdLogoutHelp = `logout - Logout from WhatsApp`
|
||||
|
||||
// CommandLogout handles !logout command
|
||||
func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
|
||||
if ce.User.Session == nil {
|
||||
ce.Reply("You're not logged in.")
|
||||
return
|
||||
} else if !ce.User.IsConnected() {
|
||||
ce.Reply("You are not connected to WhatsApp. Use the `reconnect` command to reconnect, or `delete-session` to forget all login information.")
|
||||
return
|
||||
}
|
||||
puppet := handler.bridge.GetPuppetByJID(ce.User.JID)
|
||||
if puppet.CustomMXID != "" {
|
||||
err := puppet.SwitchCustomMXID("", "")
|
||||
if err != nil {
|
||||
ce.User.log.Warnln("Failed to logout-matrix while logging out of WhatsApp:", err)
|
||||
}
|
||||
}
|
||||
err := ce.User.Conn.Logout()
|
||||
if err != nil {
|
||||
ce.User.log.Warnln("Error while logging out:", err)
|
||||
ce.Reply("Unknown error while logging out: %v", err)
|
||||
return
|
||||
}
|
||||
_, err = ce.User.Conn.Disconnect()
|
||||
if err != nil {
|
||||
ce.User.log.Warnln("Error while disconnecting after logout:", err)
|
||||
}
|
||||
ce.User.Conn.RemoveHandlers()
|
||||
ce.User.Conn = nil
|
||||
ce.User.removeFromJIDMap()
|
||||
// TODO this causes a foreign key violation, which should be fixed
|
||||
//ce.User.JID = ""
|
||||
ce.User.SetSession(nil)
|
||||
ce.Reply("Logged out successfully.")
|
||||
// if ce.User.Session == nil {
|
||||
// ce.Reply("You're not logged in.")
|
||||
// return
|
||||
// } else if !ce.User.IsConnected() {
|
||||
// ce.Reply("You are not connected to WhatsApp. Use the `reconnect` command to reconnect, or `delete-session` to forget all login information.")
|
||||
// return
|
||||
// }
|
||||
// puppet := handler.bridge.GetPuppetByJID(ce.User.JID)
|
||||
// if puppet.CustomMXID != "" {
|
||||
// err := puppet.SwitchCustomMXID("", "")
|
||||
// if err != nil {
|
||||
// ce.User.log.Warnln("Failed to logout-matrix while logging out of WhatsApp:", err)
|
||||
// }
|
||||
// }
|
||||
// err := ce.User.Conn.Logout()
|
||||
// if err != nil {
|
||||
// ce.User.log.Warnln("Error while logging out:", err)
|
||||
// ce.Reply("Unknown error while logging out: %v", err)
|
||||
// return
|
||||
// }
|
||||
// _, err = ce.User.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// ce.User.log.Warnln("Error while disconnecting after logout:", err)
|
||||
// }
|
||||
// ce.User.Conn.RemoveHandlers()
|
||||
// ce.User.Conn = nil
|
||||
// ce.User.removeFromJIDMap()
|
||||
// // TODO this causes a foreign key violation, which should be fixed
|
||||
// //ce.User.JID = ""
|
||||
// ce.User.SetSession(nil)
|
||||
// ce.Reply("Logged out successfully.")
|
||||
}
|
||||
|
||||
const cmdToggleHelp = `toggle <presence|receipts> - Toggle bridging of presence or read receipts`
|
||||
|
||||
func (handler *CommandHandler) CommandToggle(ce *CommandEvent) {
|
||||
if len(ce.Args) == 0 || (ce.Args[0] != "presence" && ce.Args[0] != "receipts") {
|
||||
ce.Reply("**Usage:** `toggle <presence|receipts>`")
|
||||
return
|
||||
}
|
||||
if ce.User.Session == nil {
|
||||
ce.Reply("You're not logged in.")
|
||||
return
|
||||
}
|
||||
customPuppet := handler.bridge.GetPuppetByCustomMXID(ce.User.MXID)
|
||||
if customPuppet == nil {
|
||||
ce.Reply("You're not logged in with your Matrix account.")
|
||||
return
|
||||
}
|
||||
if ce.Args[0] == "presence" {
|
||||
customPuppet.EnablePresence = !customPuppet.EnablePresence
|
||||
var newPresence whatsapp.Presence
|
||||
if customPuppet.EnablePresence {
|
||||
newPresence = whatsapp.PresenceAvailable
|
||||
ce.Reply("Enabled presence bridging")
|
||||
} else {
|
||||
newPresence = whatsapp.PresenceUnavailable
|
||||
ce.Reply("Disabled presence bridging")
|
||||
}
|
||||
if ce.User.IsConnected() {
|
||||
_, err := ce.User.Conn.Presence("", newPresence)
|
||||
if err != nil {
|
||||
ce.User.log.Warnln("Failed to set presence:", err)
|
||||
}
|
||||
}
|
||||
} else if ce.Args[0] == "receipts" {
|
||||
customPuppet.EnableReceipts = !customPuppet.EnableReceipts
|
||||
if customPuppet.EnableReceipts {
|
||||
ce.Reply("Enabled read receipt bridging")
|
||||
} else {
|
||||
ce.Reply("Disabled read receipt bridging")
|
||||
}
|
||||
}
|
||||
customPuppet.Update()
|
||||
// if len(ce.Args) == 0 || (ce.Args[0] != "presence" && ce.Args[0] != "receipts") {
|
||||
// ce.Reply("**Usage:** `toggle <presence|receipts>`")
|
||||
// return
|
||||
// }
|
||||
// if ce.User.Session == nil {
|
||||
// ce.Reply("You're not logged in.")
|
||||
// return
|
||||
// }
|
||||
// customPuppet := handler.bridge.GetPuppetByCustomMXID(ce.User.MXID)
|
||||
// if customPuppet == nil {
|
||||
// ce.Reply("You're not logged in with your Matrix account.")
|
||||
// return
|
||||
// }
|
||||
// if ce.Args[0] == "presence" {
|
||||
// customPuppet.EnablePresence = !customPuppet.EnablePresence
|
||||
// var newPresence whatsapp.Presence
|
||||
// if customPuppet.EnablePresence {
|
||||
// newPresence = whatsapp.PresenceAvailable
|
||||
// ce.Reply("Enabled presence bridging")
|
||||
// } else {
|
||||
// newPresence = whatsapp.PresenceUnavailable
|
||||
// ce.Reply("Disabled presence bridging")
|
||||
// }
|
||||
// if ce.User.IsConnected() {
|
||||
// _, err := ce.User.Conn.Presence("", newPresence)
|
||||
// if err != nil {
|
||||
// ce.User.log.Warnln("Failed to set presence:", err)
|
||||
// }
|
||||
// }
|
||||
// } else if ce.Args[0] == "receipts" {
|
||||
// customPuppet.EnableReceipts = !customPuppet.EnableReceipts
|
||||
// if customPuppet.EnableReceipts {
|
||||
// ce.Reply("Enabled read receipt bridging")
|
||||
// } else {
|
||||
// ce.Reply("Disabled read receipt bridging")
|
||||
// }
|
||||
// }
|
||||
// customPuppet.Update()
|
||||
}
|
||||
|
||||
const cmdDeleteSessionHelp = `delete-session - Delete session information and disconnect from WhatsApp without sending a logout request`
|
||||
|
||||
func (handler *CommandHandler) CommandDeleteSession(ce *CommandEvent) {
|
||||
if ce.User.Session == nil && ce.User.Conn == nil {
|
||||
ce.Reply("Nothing to purge: no session information stored and no active connection.")
|
||||
return
|
||||
}
|
||||
ce.User.removeFromJIDMap()
|
||||
ce.User.SetSession(nil)
|
||||
if ce.User.Conn != nil {
|
||||
_, _ = ce.User.Conn.Disconnect()
|
||||
ce.User.Conn.RemoveHandlers()
|
||||
ce.User.Conn = nil
|
||||
}
|
||||
ce.Reply("Session information purged")
|
||||
// if ce.User.Session == nil && ce.User.Conn == nil {
|
||||
// ce.Reply("Nothing to purge: no session information stored and no active connection.")
|
||||
// return
|
||||
// }
|
||||
// ce.User.removeFromJIDMap()
|
||||
// ce.User.SetSession(nil)
|
||||
// if ce.User.Conn != nil {
|
||||
// _, _ = ce.User.Conn.Disconnect()
|
||||
// ce.User.Conn.RemoveHandlers()
|
||||
// ce.User.Conn = nil
|
||||
// }
|
||||
// ce.Reply("Session information purged")
|
||||
}
|
||||
|
||||
const cmdReconnectHelp = `reconnect - Reconnect to WhatsApp`
|
||||
|
||||
func (handler *CommandHandler) CommandReconnect(ce *CommandEvent) {
|
||||
if ce.User.Conn == nil {
|
||||
if ce.User.Session == nil {
|
||||
ce.Reply("No existing connection and no session. Did you mean `login`?")
|
||||
} else {
|
||||
ce.Reply("No existing connection, creating one...")
|
||||
ce.User.Connect(false)
|
||||
}
|
||||
return
|
||||
}
|
||||
// if ce.User.Conn == nil {
|
||||
// if ce.User.Session == nil {
|
||||
// ce.Reply("No existing connection and no session. Did you mean `login`?")
|
||||
// } else {
|
||||
// ce.Reply("No existing connection, creating one...")
|
||||
// ce.User.Connect(false)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
wasConnected := true
|
||||
sess, err := ce.User.Conn.Disconnect()
|
||||
if err == whatsapp.ErrNotConnected {
|
||||
wasConnected = false
|
||||
} else if err != nil {
|
||||
ce.User.log.Warnln("Error while disconnecting:", err)
|
||||
} else if len(sess.Wid) > 0 {
|
||||
ce.User.SetSession(&sess)
|
||||
}
|
||||
// wasConnected := true
|
||||
// sess, err := ce.User.Conn.Disconnect()
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// wasConnected = false
|
||||
// } else if err != nil {
|
||||
// ce.User.log.Warnln("Error while disconnecting:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// ce.User.SetSession(&sess)
|
||||
// }
|
||||
|
||||
err = ce.User.Conn.Restore()
|
||||
if err == whatsapp.ErrInvalidSession {
|
||||
if ce.User.Session != nil {
|
||||
ce.User.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
|
||||
var sess whatsapp.Session
|
||||
sess, err = ce.User.Conn.RestoreWithSession(*ce.User.Session)
|
||||
if err == nil {
|
||||
ce.User.SetSession(&sess)
|
||||
}
|
||||
} else {
|
||||
ce.Reply("You are not logged in.")
|
||||
return
|
||||
}
|
||||
} else if err == whatsapp.ErrLoginInProgress {
|
||||
ce.Reply("A login or reconnection is already in progress.")
|
||||
return
|
||||
} else if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
ce.Reply("You were already connected.")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
ce.User.log.Warnln("Error while reconnecting:", err)
|
||||
if err.Error() == "restore session connection timed out" {
|
||||
ce.Reply("Reconnection timed out. Is WhatsApp on your phone reachable?")
|
||||
} else {
|
||||
ce.Reply("Unknown error while reconnecting: %v", err)
|
||||
}
|
||||
ce.User.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
|
||||
sess, err := ce.User.Conn.Disconnect()
|
||||
if err != nil {
|
||||
ce.User.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
|
||||
} else if len(sess.Wid) > 0 {
|
||||
ce.User.SetSession(&sess)
|
||||
}
|
||||
return
|
||||
}
|
||||
ce.User.ConnectionErrors = 0
|
||||
// err = ce.User.Conn.Restore()
|
||||
// if err == whatsapp.ErrInvalidSession {
|
||||
// if ce.User.Session != nil {
|
||||
// ce.User.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
|
||||
// var sess whatsapp.Session
|
||||
// sess, err = ce.User.Conn.RestoreWithSession(*ce.User.Session)
|
||||
// if err == nil {
|
||||
// ce.User.SetSession(&sess)
|
||||
// }
|
||||
// } else {
|
||||
// ce.Reply("You are not logged in.")
|
||||
// return
|
||||
// }
|
||||
// } else if err == whatsapp.ErrLoginInProgress {
|
||||
// ce.Reply("A login or reconnection is already in progress.")
|
||||
// return
|
||||
// } else if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// ce.Reply("You were already connected.")
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// ce.User.log.Warnln("Error while reconnecting:", err)
|
||||
// if err.Error() == "restore session connection timed out" {
|
||||
// ce.Reply("Reconnection timed out. Is WhatsApp on your phone reachable?")
|
||||
// } else {
|
||||
// ce.Reply("Unknown error while reconnecting: %v", err)
|
||||
// }
|
||||
// ce.User.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
|
||||
// sess, err := ce.User.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// ce.User.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// ce.User.SetSession(&sess)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// ce.User.ConnectionErrors = 0
|
||||
|
||||
var msg string
|
||||
if wasConnected {
|
||||
msg = "Reconnected successfully."
|
||||
} else {
|
||||
msg = "Connected successfully."
|
||||
}
|
||||
ce.Reply(msg)
|
||||
ce.User.PostLogin()
|
||||
// var msg string
|
||||
// if wasConnected {
|
||||
// msg = "Reconnected successfully."
|
||||
// } else {
|
||||
// msg = "Connected successfully."
|
||||
// }
|
||||
// ce.Reply(msg)
|
||||
// ce.User.PostLogin()
|
||||
}
|
||||
|
||||
const cmdDeleteConnectionHelp = `delete-connection - Disconnect ignoring errors and delete internal connection state.`
|
||||
|
||||
func (handler *CommandHandler) CommandDeleteConnection(ce *CommandEvent) {
|
||||
if ce.User.Conn == nil {
|
||||
ce.Reply("You don't have a WhatsApp connection.")
|
||||
return
|
||||
}
|
||||
sess, err := ce.User.Conn.Disconnect()
|
||||
if err == nil && len(sess.Wid) > 0 {
|
||||
ce.User.SetSession(&sess)
|
||||
}
|
||||
ce.User.Conn.RemoveHandlers()
|
||||
ce.User.Conn = nil
|
||||
ce.User.bridge.Metrics.TrackConnectionState(ce.User.JID, false)
|
||||
ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
|
||||
// if ce.User.Conn == nil {
|
||||
// ce.Reply("You don't have a WhatsApp connection.")
|
||||
// return
|
||||
// }
|
||||
// sess, err := ce.User.Conn.Disconnect()
|
||||
// if err == nil && len(sess.Wid) > 0 {
|
||||
// ce.User.SetSession(&sess)
|
||||
// }
|
||||
// ce.User.Conn.RemoveHandlers()
|
||||
// ce.User.Conn = nil
|
||||
// ce.User.bridge.Metrics.TrackConnectionState(ce.User.JID, false)
|
||||
// ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
|
||||
}
|
||||
|
||||
const cmdDisconnectHelp = `disconnect - Disconnect from WhatsApp (without logging out)`
|
||||
@ -580,17 +581,15 @@ func (handler *CommandHandler) CommandDisconnect(ce *CommandEvent) {
|
||||
ce.Reply("You don't have a WhatsApp connection.")
|
||||
return
|
||||
}
|
||||
sess, err := ce.User.Conn.Disconnect()
|
||||
if err == whatsapp.ErrNotConnected {
|
||||
ce.Reply("You were not connected.")
|
||||
return
|
||||
} else if err != nil {
|
||||
ce.User.log.Warnln("Error while disconnecting:", err)
|
||||
ce.Reply("Unknown error while disconnecting: %v", err)
|
||||
return
|
||||
} else if len(sess.Wid) > 0 {
|
||||
ce.User.SetSession(&sess)
|
||||
}
|
||||
ce.User.Conn.Stop(context.TODO())
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// ce.Reply("You were not connected.")
|
||||
// return
|
||||
// } else if err != nil {
|
||||
// ce.User.log.Warnln("Error while disconnecting:", err)
|
||||
// ce.Reply("Unknown error while disconnecting: %v", err)
|
||||
// return
|
||||
// }
|
||||
ce.User.bridge.Metrics.TrackConnectionState(ce.User.JID, false)
|
||||
ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
|
||||
}
|
||||
@ -598,23 +597,23 @@ func (handler *CommandHandler) CommandDisconnect(ce *CommandEvent) {
|
||||
const cmdPingHelp = `ping - Check your connection to WhatsApp.`
|
||||
|
||||
func (handler *CommandHandler) CommandPing(ce *CommandEvent) {
|
||||
if ce.User.Session == nil {
|
||||
if ce.User.IsLoginInProgress() {
|
||||
ce.Reply("You're not logged into WhatsApp, but there's a login in progress.")
|
||||
} else {
|
||||
ce.Reply("You're not logged into WhatsApp.")
|
||||
}
|
||||
} else if ce.User.Conn == nil {
|
||||
ce.Reply("You don't have a WhatsApp connection.")
|
||||
} else if err := ce.User.Conn.AdminTest(); err != nil {
|
||||
if ce.User.IsLoginInProgress() {
|
||||
ce.Reply("Connection not OK: %v, but login in progress", err)
|
||||
} else {
|
||||
ce.Reply("Connection not OK: %v", err)
|
||||
}
|
||||
} else {
|
||||
ce.Reply("Connection to WhatsApp OK")
|
||||
}
|
||||
// if ce.User.Session == nil {
|
||||
// if ce.User.IsLoginInProgress() {
|
||||
// ce.Reply("You're not logged into WhatsApp, but there's a login in progress.")
|
||||
// } else {
|
||||
// ce.Reply("You're not logged into WhatsApp.")
|
||||
// }
|
||||
// } else if ce.User.Conn == nil {
|
||||
// ce.Reply("You don't have a WhatsApp connection.")
|
||||
// } else if err := ce.User.Conn.AdminTest(); err != nil {
|
||||
// if ce.User.IsLoginInProgress() {
|
||||
// ce.Reply("Connection not OK: %v, but login in progress", err)
|
||||
// } else {
|
||||
// ce.Reply("Connection not OK: %v", err)
|
||||
// }
|
||||
// } else {
|
||||
// ce.Reply("Connection to WhatsApp OK")
|
||||
// }
|
||||
}
|
||||
|
||||
const cmdHelpHelp = `help - Prints this help`
|
||||
@ -655,31 +654,31 @@ const cmdSyncHelp = `sync [--create-all] - Synchronize contacts from phone and o
|
||||
|
||||
// CommandSync handles sync command
|
||||
func (handler *CommandHandler) CommandSync(ce *CommandEvent) {
|
||||
user := ce.User
|
||||
create := len(ce.Args) > 0 && ce.Args[0] == "--create-all"
|
||||
// user := ce.User
|
||||
// create := len(ce.Args) > 0 && ce.Args[0] == "--create-all"
|
||||
|
||||
ce.Reply("Updating contact and chat list...")
|
||||
handler.log.Debugln("Importing contacts of", user.MXID)
|
||||
_, err := user.Conn.Contacts()
|
||||
if err != nil {
|
||||
user.log.Errorln("Error updating contacts:", err)
|
||||
ce.Reply("Failed to sync contact list (see logs for details)")
|
||||
return
|
||||
}
|
||||
handler.log.Debugln("Importing chats of", user.MXID)
|
||||
_, err = user.Conn.Chats()
|
||||
if err != nil {
|
||||
user.log.Errorln("Error updating chats:", err)
|
||||
ce.Reply("Failed to sync chat list (see logs for details)")
|
||||
return
|
||||
}
|
||||
// ce.Reply("Updating contact and chat list...")
|
||||
// handler.log.Debugln("Importing contacts of", user.MXID)
|
||||
// _, err := user.Conn.Contacts()
|
||||
// if err != nil {
|
||||
// user.log.Errorln("Error updating contacts:", err)
|
||||
// ce.Reply("Failed to sync contact list (see logs for details)")
|
||||
// return
|
||||
// }
|
||||
// handler.log.Debugln("Importing chats of", user.MXID)
|
||||
// _, err = user.Conn.Chats()
|
||||
// if err != nil {
|
||||
// user.log.Errorln("Error updating chats:", err)
|
||||
// ce.Reply("Failed to sync chat list (see logs for details)")
|
||||
// return
|
||||
// }
|
||||
|
||||
ce.Reply("Syncing contacts...")
|
||||
user.syncPuppets(nil)
|
||||
ce.Reply("Syncing chats...")
|
||||
user.syncPortals(nil, create)
|
||||
// ce.Reply("Syncing contacts...")
|
||||
// user.syncPuppets(nil)
|
||||
// ce.Reply("Syncing chats...")
|
||||
// user.syncPortals(nil, create)
|
||||
|
||||
ce.Reply("Sync complete.")
|
||||
// ce.Reply("Sync complete.")
|
||||
}
|
||||
|
||||
const cmdDeletePortalHelp = `delete-portal - Delete the current portal. If the portal is used by other people, this is limited to bridge admins.`
|
||||
@ -767,150 +766,150 @@ func formatContacts(contacts bool, input map[string]whatsapp.Contact) (result []
|
||||
}
|
||||
|
||||
func (handler *CommandHandler) CommandList(ce *CommandEvent) {
|
||||
if len(ce.Args) == 0 {
|
||||
ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
|
||||
return
|
||||
}
|
||||
mode := strings.ToLower(ce.Args[0])
|
||||
if mode[0] != 'g' && mode[0] != 'c' {
|
||||
ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
|
||||
return
|
||||
}
|
||||
var err error
|
||||
page := 1
|
||||
max := 100
|
||||
if len(ce.Args) > 1 {
|
||||
page, err = strconv.Atoi(ce.Args[1])
|
||||
if err != nil || page <= 0 {
|
||||
ce.Reply("\"%s\" isn't a valid page number", ce.Args[1])
|
||||
return
|
||||
}
|
||||
}
|
||||
if len(ce.Args) > 2 {
|
||||
max, err = strconv.Atoi(ce.Args[2])
|
||||
if err != nil || max <= 0 {
|
||||
ce.Reply("\"%s\" isn't a valid number of items per page", ce.Args[2])
|
||||
return
|
||||
} else if max > 400 {
|
||||
ce.Reply("Warning: a high number of items per page may fail to send a reply")
|
||||
}
|
||||
}
|
||||
contacts := mode[0] == 'c'
|
||||
typeName := "Groups"
|
||||
if contacts {
|
||||
typeName = "Contacts"
|
||||
}
|
||||
result := formatContacts(contacts, ce.User.Conn.Store.Contacts)
|
||||
if len(result) == 0 {
|
||||
ce.Reply("No %s found", strings.ToLower(typeName))
|
||||
return
|
||||
}
|
||||
pages := int(math.Ceil(float64(len(result)) / float64(max)))
|
||||
if (page-1)*max >= len(result) {
|
||||
if pages == 1 {
|
||||
ce.Reply("There is only 1 page of %s", strings.ToLower(typeName))
|
||||
} else {
|
||||
ce.Reply("There are only %d pages of %s", pages, strings.ToLower(typeName))
|
||||
}
|
||||
return
|
||||
}
|
||||
lastIndex := page * max
|
||||
if lastIndex > len(result) {
|
||||
lastIndex = len(result)
|
||||
}
|
||||
result = result[(page-1)*max : lastIndex]
|
||||
ce.Reply("### %s (page %d of %d)\n\n%s", typeName, page, pages, strings.Join(result, "\n"))
|
||||
// if len(ce.Args) == 0 {
|
||||
// ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
|
||||
// return
|
||||
// }
|
||||
// mode := strings.ToLower(ce.Args[0])
|
||||
// if mode[0] != 'g' && mode[0] != 'c' {
|
||||
// ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
|
||||
// return
|
||||
// }
|
||||
// var err error
|
||||
// page := 1
|
||||
// max := 100
|
||||
// if len(ce.Args) > 1 {
|
||||
// page, err = strconv.Atoi(ce.Args[1])
|
||||
// if err != nil || page <= 0 {
|
||||
// ce.Reply("\"%s\" isn't a valid page number", ce.Args[1])
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// if len(ce.Args) > 2 {
|
||||
// max, err = strconv.Atoi(ce.Args[2])
|
||||
// if err != nil || max <= 0 {
|
||||
// ce.Reply("\"%s\" isn't a valid number of items per page", ce.Args[2])
|
||||
// return
|
||||
// } else if max > 400 {
|
||||
// ce.Reply("Warning: a high number of items per page may fail to send a reply")
|
||||
// }
|
||||
// }
|
||||
// contacts := mode[0] == 'c'
|
||||
// typeName := "Groups"
|
||||
// if contacts {
|
||||
// typeName = "Contacts"
|
||||
// }
|
||||
// result := formatContacts(contacts, ce.User.Conn.Store.Contacts)
|
||||
// if len(result) == 0 {
|
||||
// ce.Reply("No %s found", strings.ToLower(typeName))
|
||||
// return
|
||||
// }
|
||||
// pages := int(math.Ceil(float64(len(result)) / float64(max)))
|
||||
// if (page-1)*max >= len(result) {
|
||||
// if pages == 1 {
|
||||
// ce.Reply("There is only 1 page of %s", strings.ToLower(typeName))
|
||||
// } else {
|
||||
// ce.Reply("There are only %d pages of %s", pages, strings.ToLower(typeName))
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// lastIndex := page * max
|
||||
// if lastIndex > len(result) {
|
||||
// lastIndex = len(result)
|
||||
// }
|
||||
// result = result[(page-1)*max : lastIndex]
|
||||
// ce.Reply("### %s (page %d of %d)\n\n%s", typeName, page, pages, strings.Join(result, "\n"))
|
||||
}
|
||||
|
||||
const cmdOpenHelp = `open <_group JID_> - Open a group chat portal.`
|
||||
|
||||
func (handler *CommandHandler) CommandOpen(ce *CommandEvent) {
|
||||
if len(ce.Args) == 0 {
|
||||
ce.Reply("**Usage:** `open <group JID>`")
|
||||
return
|
||||
}
|
||||
// if len(ce.Args) == 0 {
|
||||
// ce.Reply("**Usage:** `open <group JID>`")
|
||||
// return
|
||||
// }
|
||||
|
||||
user := ce.User
|
||||
jid := ce.Args[0]
|
||||
// user := ce.User
|
||||
// jid := ce.Args[0]
|
||||
|
||||
if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
|
||||
ce.Reply("That looks like a user JID. Did you mean `pm %s`?", jid[:len(jid)-len(whatsappExt.NewUserSuffix)])
|
||||
return
|
||||
}
|
||||
// if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
|
||||
// ce.Reply("That looks like a user JID. Did you mean `pm %s`?", jid[:len(jid)-len(whatsappExt.NewUserSuffix)])
|
||||
// return
|
||||
// }
|
||||
|
||||
contact, ok := user.Conn.Store.Contacts[jid]
|
||||
if !ok {
|
||||
ce.Reply("Group JID not found in contacts. Try syncing contacts with `sync` first.")
|
||||
return
|
||||
}
|
||||
handler.log.Debugln("Importing", jid, "for", user)
|
||||
portal := user.bridge.GetPortalByJID(database.GroupPortalKey(jid))
|
||||
if len(portal.MXID) > 0 {
|
||||
portal.Sync(user, contact)
|
||||
ce.Reply("Portal room synced.")
|
||||
} else {
|
||||
portal.Sync(user, contact)
|
||||
ce.Reply("Portal room created.")
|
||||
}
|
||||
_, _ = portal.MainIntent().InviteUser(portal.MXID, &mautrix.ReqInviteUser{UserID: user.MXID})
|
||||
// contact, ok := user.Conn.Store.Contacts[jid]
|
||||
// if !ok {
|
||||
// ce.Reply("Group JID not found in contacts. Try syncing contacts with `sync` first.")
|
||||
// return
|
||||
// }
|
||||
// handler.log.Debugln("Importing", jid, "for", user)
|
||||
// portal := user.bridge.GetPortalByJID(database.GroupPortalKey(jid))
|
||||
// if len(portal.MXID) > 0 {
|
||||
// portal.Sync(user, contact)
|
||||
// ce.Reply("Portal room synced.")
|
||||
// } else {
|
||||
// portal.Sync(user, contact)
|
||||
// ce.Reply("Portal room created.")
|
||||
// }
|
||||
// _, _ = portal.MainIntent().InviteUser(portal.MXID, &mautrix.ReqInviteUser{UserID: user.MXID})
|
||||
}
|
||||
|
||||
const cmdPMHelp = `pm [--force] <_international phone number_> - Open a private chat with the given phone number.`
|
||||
|
||||
func (handler *CommandHandler) CommandPM(ce *CommandEvent) {
|
||||
if len(ce.Args) == 0 {
|
||||
ce.Reply("**Usage:** `pm [--force] <international phone number>`")
|
||||
return
|
||||
}
|
||||
// if len(ce.Args) == 0 {
|
||||
// ce.Reply("**Usage:** `pm [--force] <international phone number>`")
|
||||
// return
|
||||
// }
|
||||
|
||||
force := ce.Args[0] == "--force"
|
||||
if force {
|
||||
ce.Args = ce.Args[1:]
|
||||
}
|
||||
// force := ce.Args[0] == "--force"
|
||||
// if force {
|
||||
// ce.Args = ce.Args[1:]
|
||||
// }
|
||||
|
||||
user := ce.User
|
||||
// user := ce.User
|
||||
|
||||
number := strings.Join(ce.Args, "")
|
||||
if number[0] == '+' {
|
||||
number = number[1:]
|
||||
}
|
||||
for _, char := range number {
|
||||
if char < '0' || char > '9' {
|
||||
ce.Reply("Invalid phone number.")
|
||||
return
|
||||
}
|
||||
}
|
||||
jid := number + whatsappExt.NewUserSuffix
|
||||
// number := strings.Join(ce.Args, "")
|
||||
// if number[0] == '+' {
|
||||
// number = number[1:]
|
||||
// }
|
||||
// for _, char := range number {
|
||||
// if char < '0' || char > '9' {
|
||||
// ce.Reply("Invalid phone number.")
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// jid := number + whatsappExt.NewUserSuffix
|
||||
|
||||
handler.log.Debugln("Importing", jid, "for", user)
|
||||
// handler.log.Debugln("Importing", jid, "for", user)
|
||||
|
||||
contact, ok := user.Conn.Store.Contacts[jid]
|
||||
if !ok {
|
||||
if !force {
|
||||
ce.Reply("Phone number not found in contacts. Try syncing contacts with `sync` first. " +
|
||||
"To create a portal anyway, use `pm --force <number>`.")
|
||||
return
|
||||
}
|
||||
contact = whatsapp.Contact{Jid: jid}
|
||||
}
|
||||
puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
||||
puppet.Sync(user, contact)
|
||||
portal := user.bridge.GetPortalByJID(database.NewPortalKey(contact.Jid, user.JID))
|
||||
if len(portal.MXID) > 0 {
|
||||
err := portal.MainIntent().EnsureInvited(portal.MXID, user.MXID)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to invite %s to portal: %v. Creating new portal", user.MXID, err)
|
||||
} else {
|
||||
ce.Reply("You already have a private chat portal with that user at [%s](https://matrix.to/#/%s)", puppet.Displayname, portal.MXID)
|
||||
return
|
||||
}
|
||||
}
|
||||
err := portal.CreateMatrixRoom(user)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to create portal room: %v", err)
|
||||
return
|
||||
}
|
||||
ce.Reply("Created portal room and invited you to it.")
|
||||
// contact, ok := user.Conn.Store.Contacts[jid]
|
||||
// if !ok {
|
||||
// if !force {
|
||||
// ce.Reply("Phone number not found in contacts. Try syncing contacts with `sync` first. " +
|
||||
// "To create a portal anyway, use `pm --force <number>`.")
|
||||
// return
|
||||
// }
|
||||
// contact = whatsapp.Contact{Jid: jid}
|
||||
// }
|
||||
// puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
||||
// puppet.Sync(user, contact)
|
||||
// portal := user.bridge.GetPortalByJID(database.NewPortalKey(contact.Jid, user.JID))
|
||||
// if len(portal.MXID) > 0 {
|
||||
// err := portal.MainIntent().EnsureInvited(portal.MXID, user.MXID)
|
||||
// if err != nil {
|
||||
// portal.log.Warnfln("Failed to invite %s to portal: %v. Creating new portal", user.MXID, err)
|
||||
// } else {
|
||||
// ce.Reply("You already have a private chat portal with that user at [%s](https://matrix.to/#/%s)", puppet.Displayname, portal.MXID)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// err := portal.CreateMatrixRoom(user)
|
||||
// if err != nil {
|
||||
// ce.Reply("Failed to create portal room: %v", err)
|
||||
// return
|
||||
// }
|
||||
// ce.Reply("Created portal room and invited you to it.")
|
||||
}
|
||||
|
||||
const cmdLoginMatrixHelp = `login-matrix <_access token_> - Replace your WhatsApp account's Matrix puppet with your real Matrix account.'`
|
||||
|
@ -178,7 +178,7 @@ func (bc BridgeConfig) FormatDisplayname(contact whatsapp.Contact) (string, int8
|
||||
return buf.String(), quality
|
||||
}
|
||||
|
||||
func (bc BridgeConfig) FormatUsername(userID types.WhatsAppID) string {
|
||||
func (bc BridgeConfig) FormatUsername(userID types.GroupMeID) string {
|
||||
var buf bytes.Buffer
|
||||
bc.usernameTemplate.Execute(&buf, userID)
|
||||
return buf.String()
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
// "github.com/Rhymen/go-whatsapp"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
@ -196,58 +196,58 @@ func (puppet *Puppet) ProcessResponse(resp *mautrix.RespSync, _ string) error {
|
||||
}
|
||||
|
||||
func (puppet *Puppet) handlePresenceEvent(event *event.Event) {
|
||||
presence := whatsapp.PresenceAvailable
|
||||
if event.Content.Raw["presence"].(string) != "online" {
|
||||
presence = whatsapp.PresenceUnavailable
|
||||
puppet.customUser.log.Debugln("Marking offline")
|
||||
} else {
|
||||
puppet.customUser.log.Debugln("Marking online")
|
||||
}
|
||||
_, err := puppet.customUser.Conn.Presence("", presence)
|
||||
if err != nil {
|
||||
puppet.customUser.log.Warnln("Failed to set presence:", err)
|
||||
}
|
||||
// presence := whatsapp.PresenceAvailable
|
||||
// if event.Content.Raw["presence"].(string) != "online" {
|
||||
// presence = whatsapp.PresenceUnavailable
|
||||
// puppet.customUser.log.Debugln("Marking offline")
|
||||
// } else {
|
||||
// puppet.customUser.log.Debugln("Marking online")
|
||||
// }
|
||||
// _, err := puppet.customUser.Conn.Presence("", presence)
|
||||
// if err != nil {
|
||||
// puppet.customUser.log.Warnln("Failed to set presence:", err)
|
||||
// }
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
|
@ -36,8 +36,9 @@ type SQLCryptoStore struct {
|
||||
var _ crypto.Store = (*SQLCryptoStore)(nil)
|
||||
|
||||
func NewSQLCryptoStore(db *Database, userID id.UserID, ghostIDFormat string) *SQLCryptoStore {
|
||||
raw, _ := db.DB.DB()
|
||||
return &SQLCryptoStore{
|
||||
SQLCryptoStore: crypto.NewSQLCryptoStore(db.DB, db.dialect, "", "",
|
||||
SQLCryptoStore: crypto.NewSQLCryptoStore(raw, db.dialect, "", "",
|
||||
[]byte("maunium.net/go/mautrix-whatsapp"),
|
||||
&cryptoLogger{db.log.Sub("CryptoStore")}),
|
||||
UserID: userID,
|
||||
|
@ -17,18 +17,19 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/database/upgrades"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
*sql.DB
|
||||
*gorm.DB
|
||||
log log.Logger
|
||||
dialect string
|
||||
|
||||
@ -39,17 +40,24 @@ type Database struct {
|
||||
}
|
||||
|
||||
func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
||||
conn, err := sql.Open(dbType, uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var conn gorm.Dialector
|
||||
|
||||
if dbType == "sqlite3" {
|
||||
_, _ = conn.Exec("PRAGMA foreign_keys = ON")
|
||||
//_, _ = conn.Exec("PRAGMA foreign_keys = ON")
|
||||
conn = sqlite.Open(uri)
|
||||
} else {
|
||||
conn = postgres.Open(uri)
|
||||
}
|
||||
print("no")
|
||||
gdb, err := gorm.Open(conn, &gorm.Config{
|
||||
// Logger: baseLog,
|
||||
})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
|
||||
db := &Database{
|
||||
DB: conn,
|
||||
DB: gdb,
|
||||
log: baseLog.Sub("Database"),
|
||||
dialect: dbType,
|
||||
}
|
||||
@ -73,6 +81,29 @@ func New(dbType string, uri string, baseLog log.Logger) (*Database, error) {
|
||||
}
|
||||
|
||||
func (db *Database) Init() error {
|
||||
err := db.AutoMigrate(&Portal{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(&Puppet{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = db.AutoMigrate(&Message{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AutoMigrate(&mxRegistered{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.AutoMigrate(&mxUserProfile{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return upgrades.Run(db.log.Sub("Upgrade"), db.dialect, db.DB)
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,7 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
waProto "github.com/Rhymen/go-whatsapp/binary/proto"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
@ -42,104 +37,100 @@ func (mq *MessageQuery) New() *Message {
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) {
|
||||
rows, err := mq.db.Query("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, content FROM message WHERE chat_jid=$1 AND chat_receiver=$2", chat.JID, chat.Receiver)
|
||||
if err != nil || rows == nil {
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Find(&messages)
|
||||
if ans.Error != nil || len(messages) == 0 {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
messages = append(messages, mq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.WhatsAppMessageID) *Message {
|
||||
return mq.get("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " +
|
||||
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", chat.JID, chat.Receiver, jid)
|
||||
var message Message
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ? AND jid = ?", chat.JID, chat.Receiver, jid).Take(&message)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return &message
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message {
|
||||
return mq.get("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " +
|
||||
"FROM message WHERE mxid=$1", mxid)
|
||||
var message Message
|
||||
ans := mq.db.Where("mxid = ?", mxid).Take(&message)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return &message
|
||||
}
|
||||
|
||||
func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message {
|
||||
msg := mq.get("SELECT chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " +
|
||||
"FROM message WHERE chat_jid=$1 AND chat_receiver=$2 ORDER BY timestamp DESC LIMIT 1", chat.JID, chat.Receiver)
|
||||
if msg == nil || msg.Timestamp == 0 {
|
||||
// Old db, we don't know what the last message is.
|
||||
var message Message
|
||||
ans := mq.db.Where("chat_jid = ? AND chat_receiver = ?", chat.JID, chat.Receiver).Order("timestamp desc").First(&message)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return msg
|
||||
}
|
||||
return &message
|
||||
|
||||
func (mq *MessageQuery) get(query string, args ...interface{}) *Message {
|
||||
row := mq.db.QueryRow(query, args...)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return mq.New().Scan(row)
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
Chat PortalKey
|
||||
JID types.WhatsAppMessageID
|
||||
MXID id.EventID
|
||||
Sender types.WhatsAppID
|
||||
Timestamp uint64
|
||||
Content *waProto.Message
|
||||
Chat PortalKey `gorm:"primaryKey;embedded;embeddedPrefix:chat_"`
|
||||
JID types.WhatsAppMessageID `gorm:"primaryKey"`
|
||||
MXID id.EventID `gorm:"unique;notNull"`
|
||||
Sender types.GroupMeID `gorm:"notNull"`
|
||||
Timestamp uint64 `gorm:"notNull;default:0"`
|
||||
Content *groupme.Message `gorm:"type:TEXT;notNull"`
|
||||
|
||||
// Portal Portal `gorm:"foreignKey:JID;"` //`gorm:"foreignKey:Chat.Receiver,Chat.JID;references:jid,receiver;constraint:onDelete:CASCADE;"`TODO
|
||||
}
|
||||
|
||||
func (msg *Message) Scan(row Scannable) *Message {
|
||||
var content []byte
|
||||
err := row.Scan(&msg.Chat.JID, &msg.Chat.Receiver, &msg.JID, &msg.MXID, &msg.Sender, &msg.Timestamp, &content)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
msg.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// func (msg *Message) Scan(row Scannable) *Message {
|
||||
// var content []byte
|
||||
// err := row.Scan(&msg.Chat.JID, &msg.Chat.Receiver, &msg.JID, &msg.MXID, &msg.Sender, &msg.Timestamp, &content)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// msg.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
msg.decodeBinaryContent(content)
|
||||
// msg.decodeBinaryContent(content)
|
||||
|
||||
return msg
|
||||
}
|
||||
// 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) 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) 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() {
|
||||
_, err := msg.db.Exec("INSERT INTO message (chat_jid, chat_receiver, jid, mxid, sender, timestamp, content) " +
|
||||
"VALUES ($1, $2, $3, $4, $5, $6, $7)",
|
||||
msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID, msg.Sender, msg.Timestamp, msg.encodeBinaryContent())
|
||||
if err != nil {
|
||||
msg.log.Warnfln("Failed to insert %s@%s: %v", msg.Chat, msg.JID, err)
|
||||
ans := msg.db.Create(&msg)
|
||||
if ans.Error != nil {
|
||||
// msg.log.Warnfln("Failed to insert %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (msg *Message) Delete() {
|
||||
_, err := msg.db.Exec("DELETE FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", msg.Chat.JID, msg.Chat.Receiver, msg.JID)
|
||||
if err != nil {
|
||||
msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, err)
|
||||
ans := msg.db.Delete(&msg)
|
||||
if ans.Error != nil {
|
||||
// msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
|
||||
}
|
||||
}
|
||||
|
@ -1,155 +1,157 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
// 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
|
||||
}
|
||||
// // 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
|
||||
// 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 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) {
|
||||
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)
|
||||
}
|
||||
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,29 +17,28 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
)
|
||||
|
||||
type PortalKey struct {
|
||||
JID types.WhatsAppID
|
||||
Receiver types.WhatsAppID
|
||||
JID types.GroupMeID
|
||||
Receiver types.GroupMeID
|
||||
}
|
||||
|
||||
func GroupPortalKey(jid types.WhatsAppID) PortalKey {
|
||||
func GroupPortalKey(jid types.GroupMeID) PortalKey {
|
||||
return PortalKey{
|
||||
JID: jid,
|
||||
Receiver: jid,
|
||||
}
|
||||
}
|
||||
|
||||
func NewPortalKey(jid, receiver types.WhatsAppID) PortalKey {
|
||||
func NewPortalKey(jid, receiver types.GroupMeID) PortalKey {
|
||||
if strings.HasSuffix(jid, "@g.us") {
|
||||
receiver = jid
|
||||
}
|
||||
@ -69,72 +68,75 @@ func (pq *PortalQuery) New() *Portal {
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetAll() []*Portal {
|
||||
return pq.getAll("SELECT * FROM portal")
|
||||
return pq.getAll(pq.db.DB)
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetByJID(key PortalKey) *Portal {
|
||||
return pq.get("SELECT * FROM portal WHERE jid=$1 AND receiver=$2", key.JID, key.Receiver)
|
||||
return pq.get(pq.db.DB.Where("jit = ? AND receiver = ?", key.JID, key.Receiver))
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetByMXID(mxid id.RoomID) *Portal {
|
||||
return pq.get("SELECT * FROM portal WHERE mxid=$1", mxid)
|
||||
return pq.get(pq.db.DB.Where("mxid = ?", mxid))
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) GetAllByJID(jid types.WhatsAppID) []*Portal {
|
||||
return pq.getAll("SELECT * FROM portal WHERE jid=$1", jid)
|
||||
func (pq *PortalQuery) GetAllByJID(jid types.GroupMeID) []*Portal {
|
||||
return pq.getAll(pq.db.DB.Where("jid = ?", jid))
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) FindPrivateChats(receiver types.WhatsAppID) []*Portal {
|
||||
return pq.getAll("SELECT * FROM portal WHERE receiver=$1 AND jid LIKE '%@s.whatsapp.net'", receiver)
|
||||
func (pq *PortalQuery) FindPrivateChats(receiver types.GroupMeID) []*Portal {
|
||||
print("aaaaaaaaaaaaaaaaaa wrong portal stuff")
|
||||
return pq.getAll(pq.db.DB.Where("receiver = ? AND jid LIKE '%@s.whatsapp.net'", receiver))
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) getAll(query string, args ...interface{}) (portals []*Portal) {
|
||||
rows, err := pq.db.Query(query, args...)
|
||||
if err != nil || rows == nil {
|
||||
func (pq *PortalQuery) getAll(db *gorm.DB) (portals []*Portal) {
|
||||
ans := db.Find(&portals)
|
||||
if ans.Error != nil || len(portals) == 0 {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
portals = append(portals, pq.New().Scan(rows))
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (pq *PortalQuery) get(query string, args ...interface{}) *Portal {
|
||||
row := pq.db.QueryRow(query, args...)
|
||||
if row == nil {
|
||||
func (pq *PortalQuery) get(db *gorm.DB) *Portal {
|
||||
var portal Portal
|
||||
ans := db.Take(&portal)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return pq.New().Scan(row)
|
||||
return &portal
|
||||
}
|
||||
|
||||
type Portal struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
Key PortalKey
|
||||
Key PortalKey `gorm:"primaryKey;embedded"`
|
||||
MXID id.RoomID
|
||||
|
||||
Name string
|
||||
Topic string
|
||||
Avatar string
|
||||
AvatarURL id.ContentURI
|
||||
Encrypted bool
|
||||
AvatarURL id.ContentURI //`gorm:"-"` //TODO:STORE AVATAR
|
||||
Encrypted bool `gorm:"notNull;default:false"`
|
||||
}
|
||||
|
||||
func (portal *Portal) Scan(row Scannable) *Portal {
|
||||
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 {
|
||||
if err != sql.ErrNoRows {
|
||||
portal.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
portal.MXID = id.RoomID(mxid.String)
|
||||
portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
return portal
|
||||
}
|
||||
// func (portal *Portal) Scan(row Scannable) *Portal {
|
||||
// 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 {
|
||||
// if err != sql.ErrNoRows {
|
||||
// portal.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// portal.MXID = id.RoomID(mxid.String)
|
||||
// portal.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
// return portal
|
||||
// }
|
||||
|
||||
func (portal *Portal) mxidPtr() *id.RoomID {
|
||||
if len(portal.MXID) > 0 {
|
||||
@ -144,38 +146,38 @@ func (portal *Portal) mxidPtr() *id.RoomID {
|
||||
}
|
||||
|
||||
func (portal *Portal) Insert() {
|
||||
_, err := portal.db.Exec("INSERT INTO portal (jid, receiver, mxid, name, topic, avatar, avatar_url, encrypted) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
|
||||
portal.Key.JID, portal.Key.Receiver, portal.mxidPtr(), portal.Name, portal.Topic, portal.Avatar, portal.AvatarURL.String(), portal.Encrypted)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, err)
|
||||
|
||||
ans := portal.db.Create(&portal)
|
||||
print("beware of types")
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to insert %s: %v", portal.Key, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) Update() {
|
||||
var mxid *id.RoomID
|
||||
if len(portal.MXID) > 0 {
|
||||
mxid = &portal.MXID
|
||||
}
|
||||
_, err := portal.db.Exec("UPDATE portal SET mxid=$1, name=$2, topic=$3, avatar=$4, avatar_url=$5, encrypted=$6 WHERE jid=$7 AND receiver=$8",
|
||||
mxid, portal.Name, portal.Topic, portal.Avatar, portal.AvatarURL.String(), portal.Encrypted, portal.Key.JID, portal.Key.Receiver)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to update %s: %v", portal.Key, err)
|
||||
|
||||
ans := portal.db.Model(&portal).Updates(portal)
|
||||
print("check .model vs not")
|
||||
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to update %s: %v", portal.Key, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) Delete() {
|
||||
_, err := portal.db.Exec("DELETE FROM portal WHERE jid=$1 AND receiver=$2", portal.Key.JID, portal.Key.Receiver)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, err)
|
||||
ans := portal.db.Delete(&portal)
|
||||
if ans.Error != nil {
|
||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) GetUserIDs() []id.UserID {
|
||||
rows, err := portal.db.Query(`SELECT "user".mxid FROM "user", user_portal
|
||||
rows, err := portal.db.Raw(`SELECT "user".mxid FROM "user", user_portal
|
||||
WHERE "user".jid=user_portal.user_jid
|
||||
AND user_portal.portal_jid=$1
|
||||
AND user_portal.portal_receiver=$2`,
|
||||
portal.Key.JID, portal.Key.Receiver)
|
||||
portal.Key.JID, portal.Key.Receiver).Rows()
|
||||
print("maybe maybe sql 760476084")
|
||||
if err != nil {
|
||||
portal.log.Debugln("Failed to get portal user ids:", err)
|
||||
return nil
|
||||
|
@ -17,8 +17,6 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
@ -42,50 +40,54 @@ func (pq *PuppetQuery) New() *Puppet {
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) GetAll() (puppets []*Puppet) {
|
||||
rows, err := pq.db.Query("SELECT jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts FROM puppet")
|
||||
if err != nil || rows == nil {
|
||||
ans := pq.db.Find(&puppets)
|
||||
if ans.Error != nil || len(puppets) == 0 {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
puppets = append(puppets, pq.New().Scan(rows))
|
||||
}
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// puppets = append(puppets, pq.New().Scan(rows))
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) Get(jid types.WhatsAppID) *Puppet {
|
||||
row := pq.db.QueryRow("SELECT jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts FROM puppet WHERE jid=$1", jid)
|
||||
if row == nil {
|
||||
func (pq *PuppetQuery) Get(jid types.GroupMeID) *Puppet {
|
||||
puppet := Puppet{}
|
||||
ans := pq.db.Where("jid = ?", jid).Take(puppet)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return pq.New().Scan(row)
|
||||
return &puppet
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) GetByCustomMXID(mxid id.UserID) *Puppet {
|
||||
row := pq.db.QueryRow("SELECT jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts FROM puppet WHERE custom_mxid=$1", mxid)
|
||||
if row == nil {
|
||||
puppet := Puppet{}
|
||||
ans := pq.db.Where("custom_mxid = ?", mxid).Take(puppet)
|
||||
if ans.Error != nil {
|
||||
return nil
|
||||
}
|
||||
return pq.New().Scan(row)
|
||||
return &puppet
|
||||
}
|
||||
|
||||
func (pq *PuppetQuery) GetAllWithCustomMXID() (puppets []*Puppet) {
|
||||
rows, err := pq.db.Query("SELECT jid, avatar, avatar_url, displayname, name_quality, custom_mxid, access_token, next_batch, enable_presence, enable_receipts FROM puppet WHERE custom_mxid<>''")
|
||||
if err != nil || rows == nil {
|
||||
|
||||
ans := pq.db.Find(&puppets, "custom_mxid <> ''")
|
||||
if ans.Error != nil || len(puppets) != 0 {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
puppets = append(puppets, pq.New().Scan(rows))
|
||||
}
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// puppets = append(puppets, pq.New().Scan(rows))
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
//Puppet is comment
|
||||
type Puppet struct {
|
||||
db *Database
|
||||
log log.Logger
|
||||
|
||||
JID types.WhatsAppID
|
||||
JID types.GroupMeID `gorm:"primaryKey"`
|
||||
Avatar string
|
||||
AvatarURL id.ContentURI
|
||||
Displayname string
|
||||
@ -94,45 +96,45 @@ type Puppet struct {
|
||||
CustomMXID id.UserID
|
||||
AccessToken string
|
||||
NextBatch string
|
||||
EnablePresence bool
|
||||
EnableReceipts bool
|
||||
EnablePresence bool `gorm:"notNull;default:true"`
|
||||
EnableReceipts bool `gorm:"notNull;default:true"`
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
||||
var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
||||
var quality sql.NullInt64
|
||||
var enablePresence, enableReceipts sql.NullBool
|
||||
err := row.Scan(&puppet.JID, &avatar, &avatarURL, &displayname, &quality, &customMXID, &accessToken, &nextBatch, &enablePresence, &enableReceipts)
|
||||
if err != nil {
|
||||
if err != sql.ErrNoRows {
|
||||
puppet.log.Errorln("Database scan failed:", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
puppet.Displayname = displayname.String
|
||||
puppet.Avatar = avatar.String
|
||||
puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
puppet.NameQuality = int8(quality.Int64)
|
||||
puppet.CustomMXID = id.UserID(customMXID.String)
|
||||
puppet.AccessToken = accessToken.String
|
||||
puppet.NextBatch = nextBatch.String
|
||||
puppet.EnablePresence = enablePresence.Bool
|
||||
puppet.EnableReceipts = enableReceipts.Bool
|
||||
return puppet
|
||||
}
|
||||
// func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
||||
// var displayname, avatar, avatarURL, customMXID, accessToken, nextBatch sql.NullString
|
||||
// var quality sql.NullInt64
|
||||
// var enablePresence, enableReceipts sql.NullBool
|
||||
// err := row.Scan(&puppet.JID, &avatar, &avatarURL, &displayname, &quality, &customMXID, &accessToken, &nextBatch, &enablePresence, &enableReceipts)
|
||||
// if err != nil {
|
||||
// if err != sql.ErrNoRows {
|
||||
// puppet.log.Errorln("Database scan failed:", err)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
// puppet.Displayname = displayname.String
|
||||
// puppet.Avatar = avatar.String
|
||||
// puppet.AvatarURL, _ = id.ParseContentURI(avatarURL.String)
|
||||
// puppet.NameQuality = int8(quality.Int64)
|
||||
// puppet.CustomMXID = id.UserID(customMXID.String)
|
||||
// puppet.AccessToken = accessToken.String
|
||||
// puppet.NextBatch = nextBatch.String
|
||||
// puppet.EnablePresence = enablePresence.Bool
|
||||
// puppet.EnableReceipts = enableReceipts.Bool
|
||||
// return puppet
|
||||
// }
|
||||
|
||||
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)",
|
||||
puppet.JID, puppet.Avatar, puppet.AvatarURL.String(), puppet.Displayname, puppet.NameQuality, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnablePresence, puppet.EnableReceipts)
|
||||
if err != nil {
|
||||
puppet.log.Warnfln("Failed to insert %s: %v", puppet.JID, err)
|
||||
// _, 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)",
|
||||
// puppet.JID, puppet.Avatar, puppet.AvatarURL.String(), puppet.Displayname, puppet.NameQuality, puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnablePresence, puppet.EnableReceipts)
|
||||
ans := puppet.db.Create(&puppet)
|
||||
if ans.Error != nil {
|
||||
puppet.log.Warnfln("Failed to insert %s: %v", puppet.JID, ans.Error)
|
||||
}
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Update() {
|
||||
_, err := puppet.db.Exec("UPDATE puppet SET displayname=$1, name_quality=$2, avatar=$3, avatar_url=$4, custom_mxid=$5, access_token=$6, next_batch=$7, enable_presence=$8, enable_receipts=$9 WHERE jid=$10",
|
||||
puppet.Displayname, puppet.NameQuality, puppet.Avatar, puppet.AvatarURL.String(), puppet.CustomMXID, puppet.AccessToken, puppet.NextBatch, puppet.EnablePresence, puppet.EnableReceipts, puppet.JID)
|
||||
if err != nil {
|
||||
puppet.log.Warnfln("Failed to update %s->%s: %v", puppet.JID, err)
|
||||
ans := puppet.db.Where("jid = ?", puppet.JID).Updates(&puppet)
|
||||
if ans.Error != nil {
|
||||
puppet.log.Warnfln("Failed to update %s->%s: %v", puppet.JID, ans.Error)
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/appservice"
|
||||
@ -39,6 +39,10 @@ type SQLStateStore struct {
|
||||
typingLock sync.RWMutex
|
||||
}
|
||||
|
||||
type mxRegistered struct {
|
||||
UserID string `gorm:"primaryKey"`
|
||||
}
|
||||
|
||||
var _ appservice.StateStore = (*SQLStateStore)(nil)
|
||||
|
||||
func NewSQLStateStore(db *Database) *SQLStateStore {
|
||||
@ -50,55 +54,72 @@ func NewSQLStateStore(db *Database) *SQLStateStore {
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) IsRegistered(userID id.UserID) bool {
|
||||
row := store.db.QueryRow("SELECT EXISTS(SELECT 1 FROM mx_registrations WHERE user_id=$1)", userID)
|
||||
var isRegistered bool
|
||||
err := row.Scan(&isRegistered)
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to scan registration existence for %s: %v", userID, err)
|
||||
v := mxRegistered{UserID: userID.String()}
|
||||
ans := store.db.First(&v)
|
||||
|
||||
if errors.Is(ans.Error, gorm.ErrRecordNotFound) {
|
||||
return false
|
||||
}
|
||||
return isRegistered
|
||||
if ans.Error != nil {
|
||||
store.log.Warnfln("Failed to scan registration existence for %s: %v", userID, ans.Error)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) MarkRegistered(userID id.UserID) {
|
||||
var err error
|
||||
if store.db.dialect == "postgres" {
|
||||
_, err = store.db.Exec("INSERT INTO mx_registrations (user_id) VALUES ($1) ON CONFLICT (user_id) DO NOTHING", userID)
|
||||
} else if store.db.dialect == "sqlite3" {
|
||||
_, err = store.db.Exec("INSERT OR REPLACE INTO mx_registrations (user_id) VALUES ($1)", userID)
|
||||
} else {
|
||||
err = fmt.Errorf("unsupported dialect %s", store.db.dialect)
|
||||
}
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to mark %s as registered: %v", userID, err)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) GetRoomMembers(roomID id.RoomID) map[id.UserID]*event.MemberEventContent {
|
||||
members := make(map[id.UserID]*event.MemberEventContent)
|
||||
rows, err := store.db.Query("SELECT user_id, membership, displayname, avatar_url FROM mx_user_profile WHERE room_id=$1", roomID)
|
||||
if err != nil {
|
||||
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 rows.Next() {
|
||||
err := rows.Scan(&userID, &member.Membership, &member.Displayname, &member.AvatarURL)
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to scan member in %s: %v", roomID, err)
|
||||
} else {
|
||||
members[userID] = &member
|
||||
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 {
|
||||
row := store.db.QueryRow("SELECT membership FROM mx_user_profile WHERE room_id=$1 AND user_id=$2", roomID, userID)
|
||||
var user mxUserProfile
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Take(&user)
|
||||
membership := event.MembershipLeave
|
||||
err := row.Scan(&membership)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
store.log.Warnfln("Failed to scan membership of %s in %s: %v", userID, roomID, err)
|
||||
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
|
||||
}
|
||||
|
||||
@ -111,25 +132,31 @@ func (store *SQLStateStore) GetMember(roomID id.RoomID, userID id.UserID) *event
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) TryGetMember(roomID id.RoomID, userID id.UserID) (*event.MemberEventContent, bool) {
|
||||
row := store.db.QueryRow("SELECT membership, displayname, avatar_url FROM mx_user_profile WHERE room_id=$1 AND user_id=$2", roomID, userID)
|
||||
var member event.MemberEventContent
|
||||
err := row.Scan(&member.Membership, &member.Displayname, &member.AvatarURL)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
store.log.Warnfln("Failed to scan member info of %s in %s: %v", userID, roomID, err)
|
||||
var user mxUserProfile
|
||||
ans := store.db.Where("room_id = ? AND user_id = ?", roomID, userID).Take(&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)
|
||||
}
|
||||
return &member, err == nil
|
||||
eventMember := event.MemberEventContent{
|
||||
Membership: event.Membership(user.Membership),
|
||||
Displayname: user.DisplayName,
|
||||
AvatarURL: id.ContentURIString(user.AvatarURL),
|
||||
}
|
||||
|
||||
return &eventMember, ans.Error != nil
|
||||
}
|
||||
|
||||
func (store *SQLStateStore) FindSharedRooms(userID id.UserID) (rooms []id.RoomID) {
|
||||
rows, err := store.db.Query(`
|
||||
SELECT room_id FROM mx_user_profile
|
||||
LEFT JOIN portal ON portal.mxid=mx_user_profile.room_id
|
||||
WHERE user_id=$1 AND portal.encrypted=true
|
||||
`, userID)
|
||||
|
||||
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()
|
||||
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)
|
||||
@ -162,141 +189,150 @@ func (store *SQLStateStore) IsMembership(roomID id.RoomID, userID id.UserID, all
|
||||
|
||||
func (store *SQLStateStore) SetMembership(roomID id.RoomID, userID id.UserID, membership event.Membership) {
|
||||
var err error
|
||||
if store.db.dialect == "postgres" {
|
||||
_, err = store.db.Exec(`INSERT INTO mx_user_profile (room_id, user_id, membership) VALUES ($1, $2, $3)
|
||||
ON CONFLICT (room_id, user_id) DO UPDATE SET membership=$3`, roomID, userID, membership)
|
||||
} else if store.db.dialect == "sqlite3" {
|
||||
_, err = store.db.Exec("INSERT OR REPLACE INTO mx_user_profile (room_id, user_id, membership) VALUES ($1, $2, $3)", roomID, userID, membership)
|
||||
} else {
|
||||
err = fmt.Errorf("unsupported dialect %s", store.db.dialect)
|
||||
user := mxUserProfile{
|
||||
RoomID: roomID.String(),
|
||||
UserID: userID.String(),
|
||||
Membership: string(membership),
|
||||
}
|
||||
if err != nil {
|
||||
print("weird thing 2 502650285")
|
||||
print(user.Membership)
|
||||
|
||||
ans := store.db.Select("roomID", "userID", "membership").Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "roomID"}, {Name: "userID"}},
|
||||
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) {
|
||||
var err error
|
||||
if store.db.dialect == "postgres" {
|
||||
_, err = store.db.Exec(`INSERT INTO mx_user_profile (room_id, user_id, membership, displayname, avatar_url) VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (room_id, user_id) DO UPDATE SET membership=$3`, roomID, userID, member.Membership, member.Displayname, member.AvatarURL)
|
||||
} else if store.db.dialect == "sqlite3" {
|
||||
_, err = store.db.Exec("INSERT OR REPLACE INTO mx_user_profile (room_id, user_id, membership, displayname, avatar_url) VALUES ($1, $2, $3, $4, $5)",
|
||||
roomID, userID, member.Membership, member.Displayname, member.AvatarURL)
|
||||
} else {
|
||||
err = fmt.Errorf("unsupported dialect %s", store.db.dialect)
|
||||
|
||||
user := mxUserProfile{
|
||||
RoomID: roomID.String(),
|
||||
UserID: userID.String(),
|
||||
Membership: string(member.Membership),
|
||||
DisplayName: member.Displayname,
|
||||
AvatarURL: string(member.AvatarURL),
|
||||
}
|
||||
if err != nil {
|
||||
store.log.Warnfln("Failed to set membership of %s in %s to %s: %v", userID, roomID, member, err)
|
||||
ans := store.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "roomID"}, {Name: "userID"}},
|
||||
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, 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)
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// 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)
|
||||
// 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
|
||||
}
|
||||
|
@ -1,66 +1,198 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[0] = upgrade{"Initial schema", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`CREATE TABLE IF NOT EXISTS portal (
|
||||
jid VARCHAR(255),
|
||||
receiver VARCHAR(255),
|
||||
mxid VARCHAR(255) UNIQUE,
|
||||
upgrades[0] = upgrade{"Initial schema", func(tx *gorm.DB, ctx context) error {
|
||||
// _, err := 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(255) NOT NULL,
|
||||
avatar VARCHAR(255) NOT NULL,
|
||||
// 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)
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// PRIMARY KEY (jid, receiver)
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
_, err = tx.Exec(`CREATE TABLE IF NOT EXISTS puppet (
|
||||
jid VARCHAR(255) PRIMARY KEY,
|
||||
avatar VARCHAR(255),
|
||||
displayname VARCHAR(255),
|
||||
name_quality SMALLINT
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// _, err = 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
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
_, err = tx.Exec(`CREATE TABLE IF NOT EXISTS "user" (
|
||||
mxid VARCHAR(255) PRIMARY KEY,
|
||||
jid VARCHAR(255) UNIQUE,
|
||||
// _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS "user" (
|
||||
// mxid VARCHAR(255) PRIMARY KEY,
|
||||
// jid VARCHAR(255) UNIQUE,
|
||||
|
||||
management_room VARCHAR(255),
|
||||
// management_room VARCHAR(255),
|
||||
|
||||
client_id VARCHAR(255),
|
||||
client_token VARCHAR(255),
|
||||
server_token VARCHAR(255),
|
||||
enc_key bytea,
|
||||
mac_key bytea
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 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
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
_, err = 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,
|
||||
// _, err = 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 (chat_jid, chat_receiver, jid),
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 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
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = 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
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS mx_registrations (
|
||||
// user_id VARCHAR(255) PRIMARY KEY
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS mx_room_state (
|
||||
// room_id VARCHAR(255) PRIMARY KEY,
|
||||
// power_levels TEXT
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = 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)
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE IF NOT EXISTS crypto_olm_session (
|
||||
// session_id CHAR(43) PRIMARY KEY,
|
||||
// sender_key CHAR(43) NOT NULL,
|
||||
// session bytea NOT NULL,
|
||||
// created_at timestamp NOT NULL,
|
||||
// last_used timestamp NOT NULL
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE crypto_megolm_inbound_session (
|
||||
// session_id CHAR(43) PRIMARY KEY,
|
||||
// sender_key CHAR(43) NOT NULL,
|
||||
// signing_key CHAR(43) NOT NULL,
|
||||
// room_id VARCHAR(255) NOT NULL,
|
||||
// session bytea NOT NULL,
|
||||
// forwarding_chains bytea NOT NULL
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE 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)
|
||||
// )`)
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE crypto_tracked_user (
|
||||
// user_id VARCHAR(255) PRIMARY KEY
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE 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")
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE crypto_account (
|
||||
// device_id VARCHAR(255) PRIMARY KEY,
|
||||
// shared BOOLEAN NOT NULL,
|
||||
// sync_token TEXT NOT NULL,
|
||||
// account bytea NOT NULL
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// _, err = tx.Exec(`CREATE TABLE crypto_megolm_outbound_session (
|
||||
// room_id VARCHAR(255) PRIMARY KEY,
|
||||
// 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
|
||||
// )`)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
return nil
|
||||
}}
|
||||
|
@ -1,31 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[1] = upgrade{"Add ON DELETE CASCADE to message table", func(tx *sql.Tx, ctx context) error {
|
||||
if ctx.dialect == SQLite {
|
||||
// SQLite doesn't support constraint updates, but it isn't that careful with constraints anyway.
|
||||
return nil
|
||||
}
|
||||
res, _ := ctx.db.Query(`SELECT EXISTS(SELECT constraint_name FROM information_schema.table_constraints
|
||||
WHERE table_name='message' AND constraint_name='message_chat_jid_fkey')`)
|
||||
var exists bool
|
||||
_ = res.Scan(&exists)
|
||||
if exists {
|
||||
_, err := tx.Exec("ALTER TABLE message DROP CONSTRAINT IF EXISTS message_chat_jid_fkey")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE message ADD CONSTRAINT message_chat_jid_fkey
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||
ON DELETE CASCADE`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[2] = upgrade{"Add timestamp column to messages", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec("ALTER TABLE message ADD COLUMN timestamp BIGINT NOT NULL DEFAULT 0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[3] = upgrade{"Add last_connection column to users", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE "user" ADD COLUMN last_connection BIGINT NOT NULL DEFAULT 0`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var keys = []string{"imageMessage", "contactMessage", "locationMessage", "extendedTextMessage", "documentMessage", "audioMessage", "videoMessage"}
|
||||
upgrades[4] = upgrade{"Update message content to new protocol version. This may take a while.", func(tx *sql.Tx, ctx context) error {
|
||||
rows, err := ctx.db.Query("SELECT mxid, content FROM message")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for rows.Next() {
|
||||
var mxid string
|
||||
var rawContent []byte
|
||||
err = rows.Scan(&mxid, &rawContent)
|
||||
if err != nil {
|
||||
fmt.Println("Error scanning:", err)
|
||||
continue
|
||||
}
|
||||
var content map[string]interface{}
|
||||
err = json.Unmarshal(rawContent, &content)
|
||||
if err != nil {
|
||||
fmt.Printf("Error unmarshaling content of %s: %v\n", mxid, err)
|
||||
continue
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
val, ok := content[key].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
ci, ok := val["contextInfo"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
qm, ok := ci["quotedMessage"].([]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
ci["quotedMessage"] = qm[0]
|
||||
goto save
|
||||
}
|
||||
continue
|
||||
|
||||
save:
|
||||
rawContent, err = json.Marshal(&content)
|
||||
if err != nil {
|
||||
fmt.Printf("Error marshaling updated content of %s: %v\n", mxid, err)
|
||||
}
|
||||
_, err = tx.Exec("UPDATE message SET content=$1 WHERE mxid=$2", rawContent, mxid)
|
||||
if err != nil {
|
||||
fmt.Printf("Error updating row of %s: %v\n", mxid, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[5] = upgrade{"Add columns to store custom puppet info", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE puppet ADD COLUMN custom_mxid VARCHAR(255)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE puppet ADD COLUMN access_token VARCHAR(1023)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE puppet ADD COLUMN next_batch VARCHAR(255)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[6] = upgrade{"Add user-portal mapping table", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`CREATE TABLE user_portal (
|
||||
user_jid VARCHAR(255),
|
||||
portal_jid VARCHAR(255),
|
||||
portal_receiver VARCHAR(255),
|
||||
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
|
||||
)`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[7] = upgrade{"Add columns to store avatar MXC URIs", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE puppet ADD COLUMN avatar_url VARCHAR(255)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE portal ADD COLUMN avatar_url VARCHAR(255)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[8] = upgrade{"Add columns to store portal in filtering community meta", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE user_portal ADD COLUMN in_community BOOLEAN NOT NULL DEFAULT FALSE`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"maunium.net/go/mautrix/event"
|
||||
)
|
||||
|
||||
func init() {
|
||||
migrateRegistrations := func(tx *sql.Tx, registrations map[string]bool) error {
|
||||
if len(registrations) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
executeBatch := func(tx *sql.Tx, valueStrings []string, values ...interface{}) error {
|
||||
valueString := strings.Join(valueStrings, ",")
|
||||
_, err := tx.Exec("INSERT INTO mx_registrations (user_id) VALUES "+valueString, values...)
|
||||
return err
|
||||
}
|
||||
|
||||
batchSize := 100
|
||||
values := make([]interface{}, 0, batchSize)
|
||||
valueStrings := make([]string, 0, batchSize)
|
||||
i := 1
|
||||
for userID, registered := range registrations {
|
||||
if i == batchSize {
|
||||
err := executeBatch(tx, valueStrings, values...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i = 1
|
||||
values = make([]interface{}, 0, batchSize)
|
||||
valueStrings = make([]string, 0, batchSize)
|
||||
}
|
||||
if registered {
|
||||
values = append(values, userID)
|
||||
valueStrings = append(valueStrings, fmt.Sprintf("($%d)", i))
|
||||
i++
|
||||
}
|
||||
}
|
||||
return executeBatch(tx, valueStrings, values...)
|
||||
}
|
||||
|
||||
migrateMemberships := func(tx *sql.Tx, rooms map[string]map[string]event.Membership) error {
|
||||
for roomID, members := range rooms {
|
||||
if len(members) == 0 {
|
||||
continue
|
||||
}
|
||||
var values []interface{}
|
||||
var valueStrings []string
|
||||
i := 1
|
||||
for userID, membership := range members {
|
||||
values = append(values, roomID, userID, membership)
|
||||
valueStrings = append(valueStrings, fmt.Sprintf("($%d, $%d, $%d)", i, i+1, i+2))
|
||||
i += 3
|
||||
}
|
||||
valueString := strings.Join(valueStrings, ",")
|
||||
_, err := tx.Exec("INSERT INTO mx_user_profile (room_id, user_id, membership) VALUES "+valueString, values...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
migratePowerLevels := func(tx *sql.Tx, rooms map[string]*event.PowerLevelsEventContent) error {
|
||||
if len(rooms) == 0 {
|
||||
return nil
|
||||
}
|
||||
var values []interface{}
|
||||
var valueStrings []string
|
||||
i := 1
|
||||
for roomID, powerLevels := range rooms {
|
||||
powerLevelBytes, err := json.Marshal(powerLevels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
values = append(values, roomID, powerLevelBytes)
|
||||
valueStrings = append(valueStrings, fmt.Sprintf("($%d, $%d)", i, i+1))
|
||||
i += 2
|
||||
}
|
||||
valueString := strings.Join(valueStrings, ",")
|
||||
_, err := tx.Exec("INSERT INTO mx_room_state (room_id, power_levels) VALUES "+valueString, values...)
|
||||
return err
|
||||
}
|
||||
|
||||
userProfileTable := `CREATE TABLE mx_user_profile (
|
||||
room_id VARCHAR(255),
|
||||
user_id VARCHAR(255),
|
||||
membership VARCHAR(15) NOT NULL,
|
||||
PRIMARY KEY (room_id, user_id)
|
||||
)`
|
||||
|
||||
roomStateTable := `CREATE TABLE mx_room_state (
|
||||
room_id VARCHAR(255) PRIMARY KEY,
|
||||
power_levels TEXT
|
||||
)`
|
||||
|
||||
registrationsTable := `CREATE TABLE mx_registrations (
|
||||
user_id VARCHAR(255) PRIMARY KEY
|
||||
)`
|
||||
|
||||
type TempStateStore struct {
|
||||
Registrations map[string]bool `json:"registrations"`
|
||||
Members map[string]map[string]event.Membership `json:"memberships"`
|
||||
PowerLevels map[string]*event.PowerLevelsEventContent `json:"power_levels"`
|
||||
}
|
||||
|
||||
upgrades[9] = upgrade{"Move state store to main DB", func(tx *sql.Tx, ctx context) error {
|
||||
if ctx.dialect == Postgres {
|
||||
roomStateTable = strings.Replace(roomStateTable, "TEXT", "JSONB", 1)
|
||||
}
|
||||
|
||||
var store TempStateStore
|
||||
if _, err := tx.Exec(userProfileTable); err != nil {
|
||||
return err
|
||||
} else if _, err = tx.Exec(roomStateTable); err != nil {
|
||||
return err
|
||||
} else if _, err = tx.Exec(registrationsTable); err != nil {
|
||||
return err
|
||||
} else if data, err := ioutil.ReadFile("mx-state.json"); err != nil {
|
||||
ctx.log.Debugln("mx-state.json not found, not migrating state store")
|
||||
} else if err = json.Unmarshal(data, &store); err != nil {
|
||||
return err
|
||||
} else if err = migrateRegistrations(tx, store.Registrations); err != nil {
|
||||
return err
|
||||
} else if err = migrateMemberships(tx, store.Members); err != nil {
|
||||
return err
|
||||
} else if err = migratePowerLevels(tx, store.PowerLevels); err != nil {
|
||||
return err
|
||||
} else if err = os.Rename("mx-state.json", "mx-state.json.bak"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[10] = upgrade{"Add columns to store full member info in state store", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE mx_user_profile ADD COLUMN displayname TEXT`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE mx_user_profile ADD COLUMN avatar_url VARCHAR(255)`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[11] = upgrade{"Adjust the length of column topic in portal", func(tx *sql.Tx, ctx context) error {
|
||||
if ctx.dialect == SQLite {
|
||||
// SQLite doesn't support constraint updates, but it isn't that careful with constraints anyway.
|
||||
return nil
|
||||
}
|
||||
_, err := tx.Exec(`ALTER TABLE portal ALTER COLUMN topic TYPE VARCHAR(512)`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[12] = upgrade{"Add encryption status to portal table", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE portal ADD COLUMN encrypted BOOLEAN NOT NULL DEFAULT false`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[13] = upgrade{"Add crypto store to database", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`CREATE TABLE crypto_account (
|
||||
device_id VARCHAR(255) PRIMARY KEY,
|
||||
shared BOOLEAN NOT NULL,
|
||||
sync_token TEXT NOT NULL,
|
||||
account bytea NOT NULL
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`CREATE TABLE 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")
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`CREATE TABLE crypto_tracked_user (
|
||||
user_id VARCHAR(255) PRIMARY KEY
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`CREATE TABLE 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)
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`CREATE TABLE crypto_olm_session (
|
||||
session_id CHAR(43) PRIMARY KEY,
|
||||
sender_key CHAR(43) NOT NULL,
|
||||
session bytea NOT NULL,
|
||||
created_at timestamp NOT NULL,
|
||||
last_used timestamp NOT NULL
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`CREATE TABLE crypto_megolm_inbound_session (
|
||||
session_id CHAR(43) PRIMARY KEY,
|
||||
sender_key CHAR(43) NOT NULL,
|
||||
signing_key CHAR(43) NOT NULL,
|
||||
room_id VARCHAR(255) NOT NULL,
|
||||
session bytea NOT NULL,
|
||||
forwarding_chains bytea NOT NULL
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[14] = upgrade{"Add outbound group sessions to database", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`CREATE TABLE crypto_megolm_outbound_session (
|
||||
room_id VARCHAR(255) PRIMARY KEY,
|
||||
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
|
||||
)`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[15] = upgrade{"Add enable_presence column for puppets", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE puppet ADD COLUMN enable_presence BOOLEAN NOT NULL DEFAULT true`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"maunium.net/go/mautrix/crypto/sql_store_upgrade"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[16] = upgrade{"Add account_id to crypto store", func(tx *sql.Tx, c context) error {
|
||||
return sql_store_upgrade.Upgrades[1](tx, c.dialect.String())
|
||||
}}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[17] = upgrade{"Add enable_receipts column for puppets", func(tx *sql.Tx, ctx context) error {
|
||||
_, err := tx.Exec(`ALTER TABLE puppet ADD COLUMN enable_receipts BOOLEAN NOT NULL DEFAULT true`)
|
||||
return err
|
||||
}}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"maunium.net/go/mautrix/crypto/sql_store_upgrade"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[18] = upgrade{"Add megolm withheld data to crypto store", func(tx *sql.Tx, c context) error {
|
||||
return sql_store_upgrade.Upgrades[2](tx, c.dialect.String())
|
||||
}}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"maunium.net/go/mautrix/crypto/sql_store_upgrade"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[19] = upgrade{"Add cross-signing keys to crypto store", func(tx *sql.Tx, c context) error {
|
||||
return sql_store_upgrade.Upgrades[3](tx, c.dialect.String())
|
||||
}}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
)
|
||||
|
||||
@ -26,11 +27,11 @@ func (dialect Dialect) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
type upgradeFunc func(*sql.Tx, context) error
|
||||
type upgradeFunc func(*gorm.DB, context) error
|
||||
|
||||
type context struct {
|
||||
dialect Dialect
|
||||
db *sql.DB
|
||||
db *gorm.DB
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
@ -39,36 +40,45 @@ type upgrade struct {
|
||||
fn upgradeFunc
|
||||
}
|
||||
|
||||
const NumberOfUpgrades = 20
|
||||
type version struct {
|
||||
gorm.Model
|
||||
V int
|
||||
}
|
||||
|
||||
const NumberOfUpgrades = 1
|
||||
|
||||
var upgrades [NumberOfUpgrades]upgrade
|
||||
|
||||
var UnsupportedDatabaseVersion = fmt.Errorf("unsupported database version")
|
||||
|
||||
func GetVersion(db *sql.DB) (int, error) {
|
||||
_, err := db.Exec("CREATE TABLE IF NOT EXISTS version (version INTEGER)")
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
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")
|
||||
|
||||
version := 0
|
||||
row := db.QueryRow("SELECT version FROM version LIMIT 1")
|
||||
if row != nil {
|
||||
_ = row.Scan(&version)
|
||||
} else {
|
||||
return 0, result.Error
|
||||
}
|
||||
}
|
||||
return version, nil
|
||||
return int(ver.V), nil
|
||||
}
|
||||
|
||||
func SetVersion(tx *sql.Tx, version int) error {
|
||||
_, err := tx.Exec("DELETE FROM version")
|
||||
if err != nil {
|
||||
return err
|
||||
func SetVersion(tx *gorm.DB, newVersion int) error {
|
||||
err := tx.Where("v IS NOT NULL").Delete(&version{})
|
||||
if err.Error != nil {
|
||||
return err.Error
|
||||
}
|
||||
_, err = tx.Exec("INSERT INTO version (version) VALUES ($1)", version)
|
||||
return err
|
||||
|
||||
val := version{V: newVersion}
|
||||
tx = tx.Create(&val)
|
||||
return tx.Error
|
||||
}
|
||||
|
||||
func Run(log log.Logger, dialectName string, db *sql.DB) error {
|
||||
func Run(log log.Logger, dialectName string, db *gorm.DB) error {
|
||||
var dialect Dialect
|
||||
switch strings.ToLower(dialectName) {
|
||||
case "postgres":
|
||||
@ -79,7 +89,9 @@ func Run(log log.Logger, dialectName string, db *sql.DB) error {
|
||||
return fmt.Errorf("unknown dialect %s", dialectName)
|
||||
}
|
||||
|
||||
db.AutoMigrate(&version{})
|
||||
version, err := GetVersion(db)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -91,22 +103,21 @@ func Run(log log.Logger, dialectName string, db *sql.DB) error {
|
||||
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)
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = upgrade.fn(tx, context{dialect, db, log})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = SetVersion(tx, version+i+1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Commit()
|
||||
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
|
||||
}
|
||||
|
257
database/user.go
257
database/user.go
@ -18,16 +18,14 @@ package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
@ -44,31 +42,33 @@ func (uq *UserQuery) New() *User {
|
||||
}
|
||||
|
||||
func (uq *UserQuery) GetAll() (users []*User) {
|
||||
rows, err := uq.db.Query(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user"`)
|
||||
if err != nil || rows == nil {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
users = append(users, uq.New().Scan(rows))
|
||||
}
|
||||
// rows, err := uq.db.Query(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user"`)
|
||||
// if err != nil || rows == nil {
|
||||
// return nil
|
||||
// }
|
||||
// defer rows.Close()
|
||||
// for rows.Next() {
|
||||
// users = append(users, uq.New().Scan(rows))
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (uq *UserQuery) GetByMXID(userID id.UserID) *User {
|
||||
row := uq.db.QueryRow(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user" WHERE mxid=$1`, userID)
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return uq.New().Scan(row)
|
||||
// row := uq.db.QueryRow(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user" WHERE mxid=$1`, userID)
|
||||
// if row == nil {
|
||||
// return nil
|
||||
// }
|
||||
// return uq.New().Scan(row)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) GetByJID(userID types.WhatsAppID) *User {
|
||||
row := uq.db.QueryRow(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user" WHERE jid=$1`, stripSuffix(userID))
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
return uq.New().Scan(row)
|
||||
func (uq *UserQuery) GetByJID(userID types.GroupMeID) *User {
|
||||
// row := uq.db.QueryRow(`SELECT mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key FROM "user" WHERE jid=$1`, stripSuffix(userID))
|
||||
// if row == nil {
|
||||
// return nil
|
||||
// }
|
||||
// return uq.New().Scan(row)
|
||||
return nil
|
||||
}
|
||||
|
||||
type User struct {
|
||||
@ -76,9 +76,10 @@ type User struct {
|
||||
log log.Logger
|
||||
|
||||
MXID id.UserID
|
||||
JID types.WhatsAppID
|
||||
JID types.GroupMeID
|
||||
Token types.AuthToken
|
||||
|
||||
ManagementRoom id.RoomID
|
||||
Session *whatsapp.Session
|
||||
LastConnection uint64
|
||||
}
|
||||
|
||||
@ -94,21 +95,21 @@ func (user *User) Scan(row Scannable) *User {
|
||||
}
|
||||
if len(jid.String) > 0 && len(clientID.String) > 0 {
|
||||
user.JID = jid.String + whatsappExt.NewUserSuffix
|
||||
user.Session = &whatsapp.Session{
|
||||
ClientId: clientID.String,
|
||||
ClientToken: clientToken.String,
|
||||
ServerToken: serverToken.String,
|
||||
EncKey: encKey,
|
||||
MacKey: macKey,
|
||||
Wid: jid.String + whatsappExt.OldUserSuffix,
|
||||
}
|
||||
} else {
|
||||
user.Session = nil
|
||||
}
|
||||
// user.Session = &whatsapp.Session{
|
||||
// ClientId: clientID.String,
|
||||
// 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.WhatsAppID) string {
|
||||
func stripSuffix(jid types.GroupMeID) string {
|
||||
if len(jid) == 0 {
|
||||
return jid
|
||||
}
|
||||
@ -130,41 +131,41 @@ func (user *User) jidPtr() *string {
|
||||
}
|
||||
|
||||
func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
||||
if user.Session != nil {
|
||||
sess = *user.Session
|
||||
}
|
||||
return
|
||||
// if user.Session != nil {
|
||||
// sess = *user.Session
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (user *User) Insert() {
|
||||
sess := user.sessionUnptr()
|
||||
_, err := user.db.Exec(`INSERT INTO "user" (mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
|
||||
user.MXID, user.jidPtr(),
|
||||
user.ManagementRoom, user.LastConnection,
|
||||
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||
}
|
||||
// sess := user.sessionUnptr()
|
||||
// _, err := user.db.Exec(`INSERT INTO "user" (mxid, jid, management_room, last_connection, client_id, client_token, server_token, enc_key, mac_key) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
|
||||
// user.MXID, user.jidPtr(),
|
||||
// user.ManagementRoom, user.LastConnection,
|
||||
// sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey)
|
||||
// if err != nil {
|
||||
// user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||
// }
|
||||
}
|
||||
|
||||
func (user *User) UpdateLastConnection() {
|
||||
user.LastConnection = uint64(time.Now().Unix())
|
||||
_, err := user.db.Exec(`UPDATE "user" SET last_connection=$1 WHERE mxid=$2`,
|
||||
user.LastConnection, user.MXID)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to update last connection ts: %v", err)
|
||||
}
|
||||
// user.LastConnection = uint64(time.Now().Unix())
|
||||
// _, err := user.db.Exec(`UPDATE "user" SET last_connection=$1 WHERE mxid=$2`,
|
||||
// user.LastConnection, user.MXID)
|
||||
// if err != nil {
|
||||
// user.log.Warnfln("Failed to update last connection ts: %v", err)
|
||||
// }
|
||||
}
|
||||
|
||||
func (user *User) Update() {
|
||||
sess := user.sessionUnptr()
|
||||
_, err := user.db.Exec(`UPDATE "user" SET jid=$1, management_room=$2, last_connection=$3, client_id=$4, client_token=$5, server_token=$6, enc_key=$7, mac_key=$8 WHERE mxid=$9`,
|
||||
user.jidPtr(), user.ManagementRoom, user.LastConnection,
|
||||
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey,
|
||||
user.MXID)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to update %s: %v", user.MXID, err)
|
||||
}
|
||||
// sess := user.sessionUnptr()
|
||||
// _, err := user.db.Exec(`UPDATE "user" SET jid=$1, management_room=$2, last_connection=$3, client_id=$4, client_token=$5, server_token=$6, enc_key=$7, mac_key=$8 WHERE mxid=$9`,
|
||||
// user.jidPtr(), user.ManagementRoom, user.LastConnection,
|
||||
// sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey,
|
||||
// user.MXID)
|
||||
// if err != nil {
|
||||
// user.log.Warnfln("Failed to update %s: %v", user.MXID, err)
|
||||
// }
|
||||
}
|
||||
|
||||
type PortalKeyWithMeta struct {
|
||||
@ -173,77 +174,81 @@ type PortalKeyWithMeta struct {
|
||||
}
|
||||
|
||||
func (user *User) SetPortalKeys(newKeys []PortalKeyWithMeta) error {
|
||||
tx, err := user.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec("DELETE FROM user_portal WHERE user_jid=$1", user.jidPtr())
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
valueStrings := make([]string, len(newKeys))
|
||||
values := make([]interface{}, len(newKeys)*4)
|
||||
for i, key := range newKeys {
|
||||
pos := i * 4
|
||||
valueStrings[i] = fmt.Sprintf("($%d, $%d, $%d, $%d)", pos+1, pos+2, pos+3, pos+4)
|
||||
values[pos] = user.jidPtr()
|
||||
values[pos+1] = key.JID
|
||||
values[pos+2] = key.Receiver
|
||||
values[pos+3] = key.InCommunity
|
||||
}
|
||||
query := fmt.Sprintf("INSERT INTO user_portal (user_jid, portal_jid, portal_receiver, in_community) VALUES %s",
|
||||
strings.Join(valueStrings, ", "))
|
||||
_, err = tx.Exec(query, values...)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
return tx.Commit()
|
||||
// tx, err := user.db.Begin()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// _, err = tx.Exec("DELETE FROM user_portal WHERE user_jid=$1", user.jidPtr())
|
||||
// if err != nil {
|
||||
// _ = tx.Rollback()
|
||||
// return err
|
||||
// }
|
||||
// valueStrings := make([]string, len(newKeys))
|
||||
// values := make([]interface{}, len(newKeys)*4)
|
||||
// for i, key := range newKeys {
|
||||
// pos := i * 4
|
||||
// valueStrings[i] = fmt.Sprintf("($%d, $%d, $%d, $%d)", pos+1, pos+2, pos+3, pos+4)
|
||||
// values[pos] = user.jidPtr()
|
||||
// values[pos+1] = key.JID
|
||||
// values[pos+2] = key.Receiver
|
||||
// values[pos+3] = key.InCommunity
|
||||
// }
|
||||
// query := fmt.Sprintf("INSERT INTO user_portal (user_jid, portal_jid, portal_receiver, in_community) VALUES %s",
|
||||
// strings.Join(valueStrings, ", "))
|
||||
// _, err = tx.Exec(query, values...)
|
||||
// if err != nil {
|
||||
// _ = tx.Rollback()
|
||||
// return err
|
||||
// }
|
||||
// return tx.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user *User) IsInPortal(key PortalKey) bool {
|
||||
row := user.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM user_portal WHERE user_jid=$1 AND portal_jid=$2 AND portal_receiver=$3)`, user.jidPtr(), &key.JID, &key.Receiver)
|
||||
var exists bool
|
||||
_ = row.Scan(&exists)
|
||||
return exists
|
||||
// row := user.db.QueryRow(`SELECT EXISTS(SELECT 1 FROM user_portal WHERE user_jid=$1 AND portal_jid=$2 AND portal_receiver=$3)`, user.jidPtr(), &key.JID, &key.Receiver)
|
||||
// var exists bool
|
||||
// _ = row.Scan(&exists)
|
||||
// return exists
|
||||
return false
|
||||
}
|
||||
|
||||
func (user *User) GetPortalKeys() []PortalKey {
|
||||
rows, err := user.db.Query(`SELECT portal_jid, portal_receiver FROM user_portal WHERE user_jid=$1`, user.jidPtr())
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to get user portal keys:", err)
|
||||
return nil
|
||||
}
|
||||
var keys []PortalKey
|
||||
for rows.Next() {
|
||||
var key PortalKey
|
||||
err = rows.Scan(&key.JID, &key.Receiver)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to scan row:", err)
|
||||
continue
|
||||
}
|
||||
keys = append(keys, key)
|
||||
}
|
||||
return keys
|
||||
// rows, err := user.db.Query(`SELECT portal_jid, portal_receiver FROM user_portal WHERE user_jid=$1`, user.jidPtr())
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Failed to get user portal keys:", err)
|
||||
// return nil
|
||||
// }
|
||||
// var keys []PortalKey
|
||||
// for rows.Next() {
|
||||
// var key PortalKey
|
||||
// err = rows.Scan(&key.JID, &key.Receiver)
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Failed to scan row:", err)
|
||||
// continue
|
||||
// }
|
||||
// keys = append(keys, key)
|
||||
// }
|
||||
// return keys
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user *User) GetInCommunityMap() map[PortalKey]bool {
|
||||
rows, err := user.db.Query(`SELECT portal_jid, portal_receiver, in_community FROM user_portal WHERE user_jid=$1`, user.jidPtr())
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to get user portal keys:", err)
|
||||
return nil
|
||||
}
|
||||
keys := make(map[PortalKey]bool)
|
||||
for rows.Next() {
|
||||
var key PortalKey
|
||||
var inCommunity bool
|
||||
err = rows.Scan(&key.JID, &key.Receiver, &inCommunity)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to scan row:", err)
|
||||
continue
|
||||
}
|
||||
keys[key] = inCommunity
|
||||
}
|
||||
return keys
|
||||
// rows, err := user.db.Query(`SELECT portal_jid, portal_receiver, in_community FROM user_portal WHERE user_jid=$1`, user.jidPtr())
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Failed to get user portal keys:", err)
|
||||
// return nil
|
||||
// }
|
||||
// keys := make(map[PortalKey]bool)
|
||||
// for rows.Next() {
|
||||
// var key PortalKey
|
||||
// var inCommunity bool
|
||||
// err = rows.Scan(&key.JID, &key.Receiver, &inCommunity)
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Failed to scan row:", err)
|
||||
// continue
|
||||
// }
|
||||
// keys[key] = inCommunity
|
||||
// }
|
||||
// return keys
|
||||
return nil
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
)
|
||||
|
||||
var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)")
|
||||
@ -58,9 +58,9 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
||||
if mxid[0] == '@' {
|
||||
puppet := bridge.GetPuppetByMXID(id.UserID(mxid))
|
||||
if puppet != nil {
|
||||
jids, ok := ctx[mentionedJIDsContextKey].([]types.WhatsAppID)
|
||||
jids, ok := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
||||
if !ok {
|
||||
ctx[mentionedJIDsContextKey] = []types.WhatsAppID{puppet.JID}
|
||||
ctx[mentionedJIDsContextKey] = []types.GroupMeID{puppet.JID}
|
||||
} else {
|
||||
ctx[mentionedJIDsContextKey] = append(jids, puppet.JID)
|
||||
}
|
||||
@ -100,12 +100,11 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
||||
return fmt.Sprintf("<code>%s</code>", str)
|
||||
},
|
||||
}
|
||||
formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{
|
||||
}
|
||||
formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{}
|
||||
return formatter
|
||||
}
|
||||
|
||||
func (formatter *Formatter) getMatrixInfoByJID(jid types.WhatsAppID) (mxid id.UserID, displayname string) {
|
||||
func (formatter *Formatter) getMatrixInfoByJID(jid types.GroupMeID) (mxid id.UserID, displayname string) {
|
||||
if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||
mxid = user.MXID
|
||||
displayname = string(user.MXID)
|
||||
@ -116,7 +115,7 @@ func (formatter *Formatter) getMatrixInfoByJID(jid types.WhatsAppID) (mxid id.Us
|
||||
return
|
||||
}
|
||||
|
||||
func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []types.WhatsAppID) {
|
||||
func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, mentionedJIDs []types.GroupMeID) {
|
||||
output := html.EscapeString(content.Body)
|
||||
for regex, replacement := range formatter.waReplString {
|
||||
output = regex.ReplaceAllString(output, replacement)
|
||||
@ -140,9 +139,9 @@ func (formatter *Formatter) ParseWhatsApp(content *event.MessageEventContent, me
|
||||
}
|
||||
}
|
||||
|
||||
func (formatter *Formatter) ParseMatrix(html string) (string, []types.WhatsAppID) {
|
||||
func (formatter *Formatter) ParseMatrix(html string) (string, []types.GroupMeID) {
|
||||
ctx := make(format.Context)
|
||||
result := formatter.matrixHTMLParser.Parse(html, ctx)
|
||||
mentionedJIDs, _ := ctx[mentionedJIDsContextKey].([]types.WhatsAppID)
|
||||
mentionedJIDs, _ := ctx[mentionedJIDsContextKey].([]types.GroupMeID)
|
||||
return result, mentionedJIDs
|
||||
}
|
||||
|
35
go.mod
35
go.mod
@ -1,19 +1,38 @@
|
||||
module maunium.net/go/mautrix-whatsapp
|
||||
|
||||
go 1.14
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/Rhymen/go-whatsapp v0.1.0
|
||||
github.com/Rhymen/go-whatsapp v0.1.1
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/lib/pq v1.7.0
|
||||
github.com/mattn/go-sqlite3 v1.14.0
|
||||
github.com/prometheus/client_golang v1.7.0
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
|
||||
github.com/karmanyaahm/groupme v0.2.0
|
||||
github.com/karmanyaahm/wray v0.0.0-20210129044305-8ca7d2cc2388 // indirect
|
||||
github.com/lib/pq v1.9.0
|
||||
github.com/mattn/go-sqlite3 v1.14.6
|
||||
github.com/prometheus/client_golang v1.9.0
|
||||
github.com/prometheus/procfs v0.6.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
github.com/tidwall/sjson v1.1.5 // indirect
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // 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
|
||||
maunium.net/go/mauflag v1.0.0
|
||||
maunium.net/go/maulogger/v2 v2.1.1
|
||||
maunium.net/go/mautrix v0.8.0
|
||||
maunium.net/go/mautrix v0.8.2
|
||||
)
|
||||
|
||||
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.16
|
||||
|
||||
replace github.com/karmanyaahm/groupme => ../groupme
|
||||
|
||||
replace maunium.net/go/mautrix => ../mautrix
|
||||
|
||||
replace maunium.net/go/mautrix/i => ../mautrix_go/id
|
||||
|
445
go.sum
445
go.sum
@ -1,16 +1,34 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
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/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/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/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/autogrowsystems/wray v0.0.0-20160519030252-f36984f6648c/go.mod h1:druJ8QMeBCUmwJ7ZSFowx77dWxEWF3SYlQlsqZaLZQg=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
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/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=
|
||||
@ -21,23 +39,59 @@ github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVa
|
||||
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/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/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
|
||||
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/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/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-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 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/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/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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
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-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/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/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.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@ -50,149 +104,487 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/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-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/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
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/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 h1:b1105ZGEMFe7aCvrT1Cca3VoVb4ZFMaFJLJcg/3zD+8=
|
||||
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/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/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
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/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.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.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/karmanyaahm/wray v0.0.0-20160519030252-f36984f6648c h1:K6LcMJIgTvSTgi77TUeD7qx7Vq5lEYRKTYSTp5WPMH4=
|
||||
github.com/karmanyaahm/wray v0.0.0-20160519030252-f36984f6648c/go.mod h1:LqTl7/Bd5gKDCT0UI3kbfgjCcr1caZHsNk0PZ7bZid8=
|
||||
github.com/karmanyaahm/wray v0.0.0-20210129044305-8ca7d2cc2388 h1:CzxW/fioYusHCV+N+sHsPOAn8rgH0nq3tq8/T7ZCCAE=
|
||||
github.com/karmanyaahm/wray v0.0.0-20210129044305-8ca7d2cc2388/go.mod h1:ysD86MIEevmAkdfdg5s6Qt3I07RN6fvMAyna7jCGG2o=
|
||||
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/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.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/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/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
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/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.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
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.7.0 h1:h93mCPfUSkaul3Ka/VG8uZdmW1uMHDGxzu0NWHuJmHY=
|
||||
github.com/lib/pq v1.7.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
|
||||
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-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/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.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
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.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.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
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-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
|
||||
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
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/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U=
|
||||
github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
|
||||
github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||
github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
|
||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
|
||||
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
|
||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
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/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/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
|
||||
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
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/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/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 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
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.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
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/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
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.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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
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/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
|
||||
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
|
||||
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
|
||||
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=
|
||||
github.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/sjson v1.1.1 h1:7h1vk049Jnd5EH9NyzNiEuwYW4b5qgreBbqRC19AS3U=
|
||||
github.com/tidwall/sjson v1.1.1/go.mod h1:yvVuSnpEQv5cYIrO+AT6kw4QVfd5SDZoGIS7/5+fZFs=
|
||||
github.com/tulir/go-whatsapp v0.3.13 h1:RPc/GdZ7KlhlGiZp2Zk7B/OP9v0l7ywOt5I2kKAZ+xU=
|
||||
github.com/tulir/go-whatsapp v0.3.13/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
|
||||
github.com/tulir/go-whatsapp v0.3.14 h1:VKXBMw6GvGKRQTceEQ9Dcg6wR+jRy5/G8SDPbisWZqs=
|
||||
github.com/tulir/go-whatsapp v0.3.14/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
|
||||
github.com/tulir/go-whatsapp v0.3.15 h1:Ogu+f5hvB6Fbdjl6BG7nUb5wuJGCzUa9Z1FraS23M50=
|
||||
github.com/tulir/go-whatsapp v0.3.15/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
|
||||
github.com/tidwall/sjson v1.1.5 h1:wsUceI/XDyZk3J1FUvuuYlK62zJv2HO2Pzb8A5EWdUE=
|
||||
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/tulir/go-whatsapp v0.3.16 h1:NfcXC2DQXwls3qkAjbFqSeoMX+rUbbpBBGGvCXI3RUw=
|
||||
github.com/tulir/go-whatsapp v0.3.16/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
|
||||
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/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
|
||||
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.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.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.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.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
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.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/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.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-20181029021203-45a5f77698d3/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-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-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-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-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
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-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/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-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201026091529-146b70c837a4 h1:awiuzyrRjJDb+OXi9ceHO3SDxVoN3JER57mhtqkdQBs=
|
||||
golang.org/x/net v0.0.0-20201026091529-146b70c837a4/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
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/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-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-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-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-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-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-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-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/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-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||
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/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
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.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
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-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-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
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-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-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-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/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-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
@ -204,27 +596,48 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEGA=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
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/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/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/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
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=
|
||||
gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=
|
||||
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
|
||||
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/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-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
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/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/maulogger/v2 v2.1.1 h1:NAZNc6XUFJzgzfewCzVoGkxNAsblLCSSEdtDuIjP0XA=
|
||||
maunium.net/go/maulogger/v2 v2.1.1/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
||||
maunium.net/go/mautrix v0.8.0-rc.3 h1:bb18oNxHUmeiJ0V63YTRVGMjgoeLwu+G40l4n42Z5GI=
|
||||
maunium.net/go/mautrix v0.8.0-rc.3/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
maunium.net/go/mautrix v0.8.0-rc.4 h1:3JXoL2JJPE5nh/YSw9sv9dQA9ulma9yHTMOBMBY1xdo=
|
||||
maunium.net/go/mautrix v0.8.0-rc.4/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
maunium.net/go/mautrix v0.8.0 h1:G1jlVslNUTWEqaxuatHAMmzTWnGyoCIc4tAF5GpQJd8=
|
||||
maunium.net/go/mautrix v0.8.0/go.mod h1:TtVePxoEaw6+RZDKVajw66Yaj1lqLjH8l4FF3krsqWY=
|
||||
maunium.net/go/mautrix v0.8.2 h1:E3NudQ/QolmE/yhHau8iCkbmcq6gCLvoEvukdqPFJu4=
|
||||
maunium.net/go/mautrix v0.8.2/go.mod h1:KiViCshKBUZwrVRvTOXsJBFfstvR/btxckHUbOPdu54=
|
||||
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=
|
||||
|
3
groupme-ext/client.go
Normal file
3
groupme-ext/client.go
Normal file
@ -0,0 +1,3 @@
|
||||
package groupmeExt
|
||||
|
||||
type Session struct{}
|
33
groupme-ext/message.go
Normal file
33
groupme-ext/message.go
Normal file
@ -0,0 +1,33 @@
|
||||
package groupmeExt
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
)
|
||||
|
||||
type Message struct{ groupme.Message }
|
||||
|
||||
func (m *Message) Scan(value interface{}) error {
|
||||
bytes, ok := value.([]byte)
|
||||
if !ok {
|
||||
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
|
||||
}
|
||||
|
||||
message := Message{}
|
||||
err := json.Unmarshal(bytes, &message)
|
||||
|
||||
*m = Message(message)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Message) Value() (driver.Value, error) {
|
||||
e, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e, nil
|
||||
}
|
31
main.go
31
main.go
@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
@ -137,14 +138,14 @@ type Bridge struct {
|
||||
Metrics *MetricsHandler
|
||||
|
||||
usersByMXID map[id.UserID]*User
|
||||
usersByJID map[types.WhatsAppID]*User
|
||||
usersByJID map[types.GroupMeID]*User
|
||||
usersLock sync.Mutex
|
||||
managementRooms map[id.RoomID]*User
|
||||
managementRoomsLock sync.Mutex
|
||||
portalsByMXID map[id.RoomID]*Portal
|
||||
portalsByJID map[database.PortalKey]*Portal
|
||||
portalsLock sync.Mutex
|
||||
puppets map[types.WhatsAppID]*Puppet
|
||||
puppets map[types.GroupMeID]*Puppet
|
||||
puppetsByCustomMXID map[id.UserID]*Puppet
|
||||
puppetsLock sync.Mutex
|
||||
}
|
||||
@ -163,11 +164,11 @@ type Crypto interface {
|
||||
func NewBridge() *Bridge {
|
||||
bridge := &Bridge{
|
||||
usersByMXID: make(map[id.UserID]*User),
|
||||
usersByJID: make(map[types.WhatsAppID]*User),
|
||||
usersByJID: make(map[types.GroupMeID]*User),
|
||||
managementRooms: make(map[id.RoomID]*User),
|
||||
portalsByMXID: make(map[id.RoomID]*Portal),
|
||||
portalsByJID: make(map[database.PortalKey]*Portal),
|
||||
puppets: make(map[types.WhatsAppID]*Puppet),
|
||||
puppets: make(map[types.GroupMeID]*Puppet),
|
||||
puppetsByCustomMXID: make(map[id.UserID]*Puppet),
|
||||
}
|
||||
|
||||
@ -223,7 +224,10 @@ func (bridge *Bridge) Init() {
|
||||
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)
|
||||
@ -242,8 +246,8 @@ func (bridge *Bridge) Init() {
|
||||
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)
|
||||
// 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" {
|
||||
@ -383,16 +387,18 @@ func (bridge *Bridge) Stop() {
|
||||
continue
|
||||
}
|
||||
bridge.Log.Debugln("Disconnecting", user.MXID)
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err != nil {
|
||||
bridge.Log.Errorfln("Error while disconnecting %s: %v", user.MXID, err)
|
||||
} else if len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
//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)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
func (bridge *Bridge) Main() {
|
||||
|
||||
if *generateRegistration {
|
||||
bridge.GenerateRegistration()
|
||||
return
|
||||
@ -400,7 +406,6 @@ func (bridge *Bridge) Main() {
|
||||
bridge.MigrateDatabase()
|
||||
return
|
||||
}
|
||||
|
||||
bridge.Init()
|
||||
bridge.Log.Infoln("Bridge initialization complete, starting...")
|
||||
bridge.Start()
|
||||
|
51
matrix.go
51
matrix.go
@ -168,6 +168,7 @@ func (mx *MatrixHandler) createPrivatePortalFromInvite(roomID id.RoomID, inviter
|
||||
if portal.bridge.Config.Bridge.PrivateChatPortalMeta {
|
||||
portal.Name = puppet.Displayname
|
||||
portal.AvatarURL = puppet.AvatarURL
|
||||
print("possible bug with pointer above")
|
||||
portal.Avatar = puppet.Avatar
|
||||
_, _ = portal.MainIntent().SetRoomName(portal.MXID, portal.Name)
|
||||
_, _ = portal.MainIntent().SetRoomAvatar(portal.MXID, portal.AvatarURL)
|
||||
@ -288,33 +289,33 @@ func (mx *MatrixHandler) HandleMembership(evt *event.Event) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
// 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
|
||||
}
|
||||
// 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)
|
||||
}
|
||||
// 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 {
|
||||
|
98
metrics.go
98
metrics.go
@ -56,11 +56,11 @@ type MetricsHandler struct {
|
||||
unencryptedPrivateCount prometheus.Gauge
|
||||
|
||||
connected prometheus.Gauge
|
||||
connectedState map[types.WhatsAppID]bool
|
||||
connectedState map[types.GroupMeID]bool
|
||||
loggedIn prometheus.Gauge
|
||||
loggedInState map[types.WhatsAppID]bool
|
||||
loggedInState map[types.GroupMeID]bool
|
||||
syncLocked prometheus.Gauge
|
||||
syncLockedState map[types.WhatsAppID]bool
|
||||
syncLockedState map[types.GroupMeID]bool
|
||||
bufferLength *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
@ -109,17 +109,17 @@ func NewMetricsHandler(address string, log log.Logger, db *database.Database) *M
|
||||
Name: "bridge_logged_in",
|
||||
Help: "Users logged into the bridge",
|
||||
}),
|
||||
loggedInState: make(map[types.WhatsAppID]bool),
|
||||
loggedInState: make(map[types.GroupMeID]bool),
|
||||
connected: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_connected",
|
||||
Help: "Bridge users connected to WhatsApp",
|
||||
}),
|
||||
connectedState: make(map[types.WhatsAppID]bool),
|
||||
connectedState: make(map[types.GroupMeID]bool),
|
||||
syncLocked: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "bridge_sync_locked",
|
||||
Help: "Bridge users locked in post-login sync",
|
||||
}),
|
||||
syncLockedState: make(map[types.WhatsAppID]bool),
|
||||
syncLockedState: make(map[types.GroupMeID]bool),
|
||||
bufferLength: promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "bridge_buffer_size",
|
||||
Help: "Number of messages in buffer",
|
||||
@ -149,7 +149,7 @@ func (mh *MetricsHandler) TrackDisconnection(userID id.UserID) {
|
||||
mh.disconnections.With(prometheus.Labels{"user_id": string(userID)}).Inc()
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackLoginState(jid types.WhatsAppID, loggedIn bool) {
|
||||
func (mh *MetricsHandler) TrackLoginState(jid types.GroupMeID, loggedIn bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
@ -164,7 +164,7 @@ func (mh *MetricsHandler) TrackLoginState(jid types.WhatsAppID, loggedIn bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackConnectionState(jid types.WhatsAppID, connected bool) {
|
||||
func (mh *MetricsHandler) TrackConnectionState(jid types.GroupMeID, connected bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
@ -179,7 +179,7 @@ func (mh *MetricsHandler) TrackConnectionState(jid types.WhatsAppID, connected b
|
||||
}
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) TrackSyncLock(jid types.WhatsAppID, locked bool) {
|
||||
func (mh *MetricsHandler) TrackSyncLock(jid types.GroupMeID, locked bool) {
|
||||
if !mh.running {
|
||||
return
|
||||
}
|
||||
@ -202,49 +202,49 @@ func (mh *MetricsHandler) TrackBufferLength(id id.UserID, length int) {
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) updateStats() {
|
||||
start := time.Now()
|
||||
var puppetCount int
|
||||
err := mh.db.QueryRowContext(mh.ctx, "SELECT COUNT(*) FROM puppet").Scan(&puppetCount)
|
||||
if err != nil {
|
||||
mh.log.Warnln("Failed to scan number of puppets:", err)
|
||||
} else {
|
||||
mh.puppetCount.Set(float64(puppetCount))
|
||||
}
|
||||
// start := time.Now()
|
||||
// var puppetCount int
|
||||
// err := mh.db.QueryRowContext(mh.ctx, "SELECT COUNT(*) FROM puppet").Scan(&puppetCount)
|
||||
// if err != nil {
|
||||
// mh.log.Warnln("Failed to scan number of puppets:", err)
|
||||
// } else {
|
||||
// mh.puppetCount.Set(float64(puppetCount))
|
||||
// }
|
||||
|
||||
var userCount int
|
||||
err = mh.db.QueryRowContext(mh.ctx, `SELECT COUNT(*) FROM "user"`).Scan(&userCount)
|
||||
if err != nil {
|
||||
mh.log.Warnln("Failed to scan number of users:", err)
|
||||
} else {
|
||||
mh.userCount.Set(float64(userCount))
|
||||
}
|
||||
// var userCount int
|
||||
// err = mh.db.QueryRowContext(mh.ctx, `SELECT COUNT(*) FROM "user"`).Scan(&userCount)
|
||||
// if err != nil {
|
||||
// mh.log.Warnln("Failed to scan number of users:", err)
|
||||
// } else {
|
||||
// mh.userCount.Set(float64(userCount))
|
||||
// }
|
||||
|
||||
var messageCount int
|
||||
err = mh.db.QueryRowContext(mh.ctx, "SELECT COUNT(*) FROM message").Scan(&messageCount)
|
||||
if err != nil {
|
||||
mh.log.Warnln("Failed to scan number of messages:", err)
|
||||
} else {
|
||||
mh.messageCount.Set(float64(messageCount))
|
||||
}
|
||||
// var messageCount int
|
||||
// err = mh.db.QueryRowContext(mh.ctx, "SELECT COUNT(*) FROM message").Scan(&messageCount)
|
||||
// if err != nil {
|
||||
// mh.log.Warnln("Failed to scan number of messages:", err)
|
||||
// } else {
|
||||
// mh.messageCount.Set(float64(messageCount))
|
||||
// }
|
||||
|
||||
var encryptedGroupCount, encryptedPrivateCount, unencryptedGroupCount, unencryptedPrivateCount int
|
||||
err = mh.db.QueryRowContext(mh.ctx, `
|
||||
SELECT
|
||||
COUNT(CASE WHEN jid 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 jid 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
|
||||
FROM portal WHERE mxid<>''
|
||||
`).Scan(&encryptedGroupCount, &encryptedPrivateCount, &unencryptedGroupCount, &unencryptedPrivateCount)
|
||||
if err != nil {
|
||||
mh.log.Warnln("Failed to scan number of portals:", err)
|
||||
} else {
|
||||
mh.encryptedGroupCount.Set(float64(encryptedGroupCount))
|
||||
mh.encryptedPrivateCount.Set(float64(encryptedPrivateCount))
|
||||
mh.unencryptedGroupCount.Set(float64(unencryptedGroupCount))
|
||||
mh.unencryptedPrivateCount.Set(float64(encryptedPrivateCount))
|
||||
}
|
||||
mh.countCollection.Observe(time.Now().Sub(start).Seconds())
|
||||
// var encryptedGroupCount, encryptedPrivateCount, unencryptedGroupCount, unencryptedPrivateCount int
|
||||
// err = mh.db.QueryRowContext(mh.ctx, `
|
||||
// SELECT
|
||||
// COUNT(CASE WHEN jid 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 jid 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
|
||||
// FROM portal WHERE mxid<>''
|
||||
// `).Scan(&encryptedGroupCount, &encryptedPrivateCount, &unencryptedGroupCount, &unencryptedPrivateCount)
|
||||
// if err != nil {
|
||||
// mh.log.Warnln("Failed to scan number of portals:", err)
|
||||
// } else {
|
||||
// mh.encryptedGroupCount.Set(float64(encryptedGroupCount))
|
||||
// mh.encryptedPrivateCount.Set(float64(encryptedPrivateCount))
|
||||
// mh.unencryptedGroupCount.Set(float64(unencryptedGroupCount))
|
||||
// mh.unencryptedPrivateCount.Set(float64(encryptedPrivateCount))
|
||||
// }
|
||||
// mh.countCollection.Observe(time.Now().Sub(start).Seconds())
|
||||
}
|
||||
|
||||
func (mh *MetricsHandler) startUpdatingStats() {
|
||||
|
516
provisioning.go
516
provisioning.go
@ -18,17 +18,14 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/Rhymen/go-whatsapp"
|
||||
"github.com/gorilla/websocket"
|
||||
log "maunium.net/go/maulogger/v2"
|
||||
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
)
|
||||
|
||||
type ProvisioningAPI struct {
|
||||
@ -90,41 +87,41 @@ type Response struct {
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) DeleteSession(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
if user.Session == nil && user.Conn == nil {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "Nothing to purge: no session information stored and no active connection.",
|
||||
ErrCode: "no session",
|
||||
})
|
||||
return
|
||||
}
|
||||
user.SetSession(nil)
|
||||
if user.Conn != nil {
|
||||
_, _ = user.Conn.Disconnect()
|
||||
user.Conn.RemoveHandlers()
|
||||
user.Conn = nil
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
}
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Session information purged"})
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Session == nil && user.Conn == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "Nothing to purge: no session information stored and no active connection.",
|
||||
// ErrCode: "no session",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// user.SetSession(nil)
|
||||
// if user.Conn != nil {
|
||||
// _, _ = user.Conn.Disconnect()
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// }
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Session information purged"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) DeleteConnection(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
if user.Conn == nil {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "You don't have a WhatsApp connection.",
|
||||
ErrCode: "not connected",
|
||||
})
|
||||
return
|
||||
}
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err == nil && len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
user.Conn.RemoveHandlers()
|
||||
user.Conn = nil
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp and connection deleted"})
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Conn == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You don't have a WhatsApp connection.",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err == nil && len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp and connection deleted"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request) {
|
||||
@ -136,145 +133,146 @@ func (prov *ProvisioningAPI) Disconnect(w http.ResponseWriter, r *http.Request)
|
||||
})
|
||||
return
|
||||
}
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err == whatsapp.ErrNotConnected {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "You were not connected",
|
||||
ErrCode: "not connected",
|
||||
})
|
||||
return
|
||||
} else if err != nil {
|
||||
user.log.Warnln("Error while disconnecting:", err)
|
||||
jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
Error: fmt.Sprintf("Unknown error while disconnecting: %v", err),
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
return
|
||||
} else if len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
//sess, err :=
|
||||
user.Conn.Stop(context.TODO())
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You were not connected",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// return
|
||||
// } else if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting:", err)
|
||||
// jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while disconnecting: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Disconnected from WhatsApp"})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Reconnect(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
if user.Conn == nil {
|
||||
if user.Session == nil {
|
||||
jsonResponse(w, http.StatusForbidden, Error{
|
||||
Error: "No existing connection and no session. Please log in first.",
|
||||
ErrCode: "no session",
|
||||
})
|
||||
} else {
|
||||
user.Connect(false)
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Created connection to WhatsApp."})
|
||||
}
|
||||
return
|
||||
}
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Conn == nil {
|
||||
// if user.Session == nil {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "No existing connection and no session. Please log in first.",
|
||||
// ErrCode: "no session",
|
||||
// })
|
||||
// } else {
|
||||
// user.Connect(false)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Created connection to WhatsApp."})
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
wasConnected := true
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err == whatsapp.ErrNotConnected {
|
||||
wasConnected = false
|
||||
} else if err != nil {
|
||||
user.log.Warnln("Error while disconnecting:", err)
|
||||
} else if len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
// wasConnected := true
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err == whatsapp.ErrNotConnected {
|
||||
// wasConnected = false
|
||||
// } else if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
|
||||
err = user.Conn.Restore()
|
||||
if err == whatsapp.ErrInvalidSession {
|
||||
if user.Session != nil {
|
||||
user.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
|
||||
var sess whatsapp.Session
|
||||
sess, err = user.Conn.RestoreWithSession(*user.Session)
|
||||
if err == nil {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
} else {
|
||||
jsonResponse(w, http.StatusForbidden, Error{
|
||||
Error: "You're not logged in",
|
||||
ErrCode: "not logged in",
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if err == whatsapp.ErrLoginInProgress {
|
||||
jsonResponse(w, http.StatusConflict, Error{
|
||||
Error: "A login or reconnection is already in progress.",
|
||||
ErrCode: "login in progress",
|
||||
})
|
||||
return
|
||||
} else if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
jsonResponse(w, http.StatusConflict, Error{
|
||||
Error: "You were already connected.",
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
user.log.Warnln("Error while reconnecting:", err)
|
||||
if err.Error() == "restore session connection timed out" {
|
||||
jsonResponse(w, http.StatusForbidden, Error{
|
||||
Error: "Reconnection timed out. Is WhatsApp on your phone reachable?",
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
} else {
|
||||
jsonResponse(w, http.StatusForbidden, Error{
|
||||
Error: fmt.Sprintf("Unknown error while reconnecting: %v", err),
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
}
|
||||
user.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err != nil {
|
||||
user.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
|
||||
} else if len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
return
|
||||
}
|
||||
user.ConnectionErrors = 0
|
||||
user.PostLogin()
|
||||
// err = user.Conn.Restore()
|
||||
// if err == whatsapp.ErrInvalidSession {
|
||||
// if user.Session != nil {
|
||||
// user.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
|
||||
// var sess whatsapp.Session
|
||||
// sess, err = user.Conn.RestoreWithSession(*user.Session)
|
||||
// if err == nil {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// } else {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "You're not logged in",
|
||||
// ErrCode: "not logged in",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// } else if err == whatsapp.ErrLoginInProgress {
|
||||
// jsonResponse(w, http.StatusConflict, Error{
|
||||
// Error: "A login or reconnection is already in progress.",
|
||||
// ErrCode: "login in progress",
|
||||
// })
|
||||
// return
|
||||
// } else if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// jsonResponse(w, http.StatusConflict, Error{
|
||||
// Error: "You were already connected.",
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while reconnecting:", err)
|
||||
// if err.Error() == "restore session connection timed out" {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: "Reconnection timed out. Is WhatsApp on your phone reachable?",
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// } else {
|
||||
// jsonResponse(w, http.StatusForbidden, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while reconnecting: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// }
|
||||
// user.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// user.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
|
||||
// } else if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
// user.ConnectionErrors = 0
|
||||
// user.PostLogin()
|
||||
|
||||
var msg string
|
||||
if wasConnected {
|
||||
msg = "Reconnected successfully."
|
||||
} else {
|
||||
msg = "Connected successfully."
|
||||
}
|
||||
// var msg string
|
||||
// if wasConnected {
|
||||
// msg = "Reconnected successfully."
|
||||
// } else {
|
||||
// msg = "Connected successfully."
|
||||
// }
|
||||
|
||||
jsonResponse(w, http.StatusOK, Response{true, msg})
|
||||
// jsonResponse(w, http.StatusOK, Response{true, msg})
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Ping(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
wa := map[string]interface{}{
|
||||
"has_session": user.Session != nil,
|
||||
"management_room": user.ManagementRoom,
|
||||
"jid": user.JID,
|
||||
"conn": nil,
|
||||
"ping": nil,
|
||||
}
|
||||
if user.Conn != nil {
|
||||
wa["conn"] = map[string]interface{}{
|
||||
"is_connected": user.Conn.IsConnected(),
|
||||
"is_logged_in": user.Conn.IsLoggedIn(),
|
||||
"is_login_in_progress": user.Conn.IsLoginInProgress(),
|
||||
}
|
||||
err := user.Conn.AdminTest()
|
||||
wa["ping"] = map[string]interface{}{
|
||||
"ok": err == nil,
|
||||
"err": err,
|
||||
}
|
||||
}
|
||||
resp := map[string]interface{}{
|
||||
"mxid": user.MXID,
|
||||
"admin": user.Admin,
|
||||
"whitelisted": user.Whitelisted,
|
||||
"relaybot_whitelisted": user.RelaybotWhitelisted,
|
||||
"whatsapp": wa,
|
||||
}
|
||||
jsonResponse(w, http.StatusOK, resp)
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// wa := map[string]interface{}{
|
||||
// "has_session": user.Client != nil,
|
||||
// "management_room": user.ManagementRoom,
|
||||
// "jid": user.JID,
|
||||
// "conn": nil,
|
||||
// "ping": nil,
|
||||
// }
|
||||
// if user.Conn != nil {
|
||||
// wa["conn"] = map[string]interface{}{
|
||||
// "is_connected": user.IsConnected(),
|
||||
// "is_logged_in": user.IsLoggedIn(),
|
||||
// "is_login_in_progress": user.IsLoginInProgress(),
|
||||
// }
|
||||
// err := user.Conn.AdminTest()
|
||||
// wa["ping"] = map[string]interface{}{
|
||||
// "ok": err == nil,
|
||||
// "err": err,
|
||||
// }
|
||||
// }
|
||||
// resp := map[string]interface{}{
|
||||
// "mxid": user.MXID,
|
||||
// "admin": user.Admin,
|
||||
// "whitelisted": user.Whitelisted,
|
||||
// "relaybot_whitelisted": user.RelaybotWhitelisted,
|
||||
// "whatsapp": wa,
|
||||
// }
|
||||
// jsonResponse(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func jsonResponse(w http.ResponseWriter, status int, response interface{}) {
|
||||
@ -284,51 +282,51 @@ func jsonResponse(w http.ResponseWriter, status int, response interface{}) {
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Logout(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value("user").(*User)
|
||||
if user.Session == nil {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "You're not logged in",
|
||||
ErrCode: "not logged in",
|
||||
})
|
||||
return
|
||||
}
|
||||
// user := r.Context().Value("user").(*User)
|
||||
// if user.Session == nil {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You're not logged in",
|
||||
// ErrCode: "not logged in",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
force := strings.ToLower(r.URL.Query().Get("force")) != "false"
|
||||
// force := strings.ToLower(r.URL.Query().Get("force")) != "false"
|
||||
|
||||
if user.Conn == nil {
|
||||
if !force {
|
||||
jsonResponse(w, http.StatusNotFound, Error{
|
||||
Error: "You're not connected",
|
||||
ErrCode: "not connected",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
err := user.Conn.Logout()
|
||||
if err != nil {
|
||||
user.log.Warnln("Error while logging out:", err)
|
||||
if !force {
|
||||
jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
Error: fmt.Sprintf("Unknown error while logging out: %v", err),
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
_, err = user.Conn.Disconnect()
|
||||
if err != nil {
|
||||
user.log.Warnln("Error while disconnecting after logout:", err)
|
||||
}
|
||||
user.Conn.RemoveHandlers()
|
||||
user.Conn = nil
|
||||
}
|
||||
// if user.Conn == nil {
|
||||
// if !force {
|
||||
// jsonResponse(w, http.StatusNotFound, Error{
|
||||
// Error: "You're not connected",
|
||||
// ErrCode: "not connected",
|
||||
// })
|
||||
// }
|
||||
// } else {
|
||||
// err := user.Conn.Logout()
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while logging out:", err)
|
||||
// if !force {
|
||||
// jsonResponse(w, http.StatusInternalServerError, Error{
|
||||
// Error: fmt.Sprintf("Unknown error while logging out: %v", err),
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// _, err = user.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Error while disconnecting after logout:", err)
|
||||
// }
|
||||
// user.Conn.RemoveHandlers()
|
||||
// user.Conn = nil
|
||||
// }
|
||||
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
user.removeFromJIDMap()
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// user.removeFromJIDMap()
|
||||
|
||||
// TODO this causes a foreign key violation, which should be fixed
|
||||
//ce.User.JID = ""
|
||||
user.SetSession(nil)
|
||||
jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."})
|
||||
// // TODO this causes a foreign key violation, which should be fixed
|
||||
// //ce.User.JID = ""
|
||||
// user.SetSession(nil)
|
||||
// jsonResponse(w, http.StatusOK, Response{true, "Logged out successfully."})
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
@ -339,63 +337,63 @@ var upgrader = websocket.Upgrader{
|
||||
}
|
||||
|
||||
func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) {
|
||||
userID := r.URL.Query().Get("user_id")
|
||||
user := prov.bridge.GetUserByMXID(id.UserID(userID))
|
||||
// userID := r.URL.Query().Get("user_id")
|
||||
// user := prov.bridge.GetUserByMXID(id.UserID(userID))
|
||||
|
||||
c, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
prov.log.Errorfln("Failed to upgrade connection to websocket:", err)
|
||||
return
|
||||
}
|
||||
defer c.Close()
|
||||
// c, err := upgrader.Upgrade(w, r, nil)
|
||||
// if err != nil {
|
||||
// prov.log.Errorfln("Failed to upgrade connection to websocket:", err)
|
||||
// return
|
||||
// }
|
||||
// defer c.Close()
|
||||
|
||||
if !user.Connect(true) {
|
||||
user.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
|
||||
_ = c.WriteJSON(Error{
|
||||
Error: "Failed to connect to WhatsApp",
|
||||
ErrCode: "connection error",
|
||||
})
|
||||
return
|
||||
}
|
||||
// if !user.Connect(true) {
|
||||
// user.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
|
||||
// _ = c.WriteJSON(Error{
|
||||
// Error: "Failed to connect to WhatsApp",
|
||||
// ErrCode: "connection error",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
|
||||
qrChan := make(chan string, 3)
|
||||
go func() {
|
||||
for code := range qrChan {
|
||||
if code == "stop" {
|
||||
return
|
||||
}
|
||||
_ = c.WriteJSON(map[string]interface{}{
|
||||
"code": code,
|
||||
})
|
||||
}
|
||||
}()
|
||||
session, err := user.Conn.LoginWithRetry(qrChan, user.bridge.Config.Bridge.LoginQRRegenCount)
|
||||
qrChan <- "stop"
|
||||
if err != nil {
|
||||
var msg string
|
||||
if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
msg = "You're already logged in"
|
||||
} else if err == whatsapp.ErrLoginInProgress {
|
||||
msg = "You have a login in progress already."
|
||||
} else if err == whatsapp.ErrLoginTimedOut {
|
||||
msg = "QR code scan timed out. Please try again."
|
||||
} else {
|
||||
user.log.Warnln("Failed to log in:", err)
|
||||
msg = fmt.Sprintf("Unknown error while logging in: %v", err)
|
||||
}
|
||||
_ = c.WriteJSON(Error{
|
||||
Error: msg,
|
||||
ErrCode: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
user.ConnectionErrors = 0
|
||||
user.JID = strings.Replace(user.Conn.Info.Wid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, 1)
|
||||
user.addToJIDMap()
|
||||
user.SetSession(&session)
|
||||
_ = c.WriteJSON(map[string]interface{}{
|
||||
"success": true,
|
||||
"jid": user.JID,
|
||||
})
|
||||
user.PostLogin()
|
||||
// qrChan := make(chan string, 3)
|
||||
// go func() {
|
||||
// for code := range qrChan {
|
||||
// if code == "stop" {
|
||||
// return
|
||||
// }
|
||||
// _ = c.WriteJSON(map[string]interface{}{
|
||||
// "code": code,
|
||||
// })
|
||||
// }
|
||||
// }()
|
||||
// session, err := user.Conn.LoginWithRetry(qrChan, user.bridge.Config.Bridge.LoginQRRegenCount)
|
||||
// qrChan <- "stop"
|
||||
// if err != nil {
|
||||
// var msg string
|
||||
// if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// msg = "You're already logged in"
|
||||
// } else if err == whatsapp.ErrLoginInProgress {
|
||||
// msg = "You have a login in progress already."
|
||||
// } else if err == whatsapp.ErrLoginTimedOut {
|
||||
// msg = "QR code scan timed out. Please try again."
|
||||
// } else {
|
||||
// user.log.Warnln("Failed to log in:", err)
|
||||
// msg = fmt.Sprintf("Unknown error while logging in: %v", err)
|
||||
// }
|
||||
// _ = c.WriteJSON(Error{
|
||||
// Error: msg,
|
||||
// ErrCode: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// user.ConnectionErrors = 0
|
||||
// user.JID = strings.Replace(user.Conn.Info.Wid, whatsappExt.OldUserSuffix, whatsappExt.NewUserSuffix, 1)
|
||||
// user.addToJIDMap()
|
||||
// user.SetSession(&session)
|
||||
// _ = c.WriteJSON(map[string]interface{}{
|
||||
// "success": true,
|
||||
// "jid": user.JID,
|
||||
// })
|
||||
// user.PostLogin()
|
||||
}
|
||||
|
121
puppet.go
121
puppet.go
@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@ -30,12 +29,12 @@ import (
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/database"
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
)
|
||||
|
||||
var userIDRegex *regexp.Regexp
|
||||
|
||||
func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.WhatsAppID, bool) {
|
||||
func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.GroupMeID, bool) {
|
||||
if userIDRegex == nil {
|
||||
userIDRegex = regexp.MustCompile(fmt.Sprintf("^@%s:%s$",
|
||||
bridge.Config.Bridge.FormatUsername("([0-9]+)"),
|
||||
@ -46,7 +45,7 @@ func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.WhatsAppID, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
jid := types.WhatsAppID(match[1] + whatsappExt.NewUserSuffix)
|
||||
jid := types.GroupMeID(match[1] + whatsappExt.NewUserSuffix)
|
||||
return jid, true
|
||||
}
|
||||
|
||||
@ -59,7 +58,7 @@ func (bridge *Bridge) GetPuppetByMXID(mxid id.UserID) *Puppet {
|
||||
return bridge.GetPuppetByJID(jid)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetPuppetByJID(jid types.WhatsAppID) *Puppet {
|
||||
func (bridge *Bridge) GetPuppetByJID(jid types.GroupMeID) *Puppet {
|
||||
bridge.puppetsLock.Lock()
|
||||
defer bridge.puppetsLock.Unlock()
|
||||
puppet, ok := bridge.puppets[jid]
|
||||
@ -124,7 +123,7 @@ func (bridge *Bridge) dbPuppetsToPuppets(dbPuppets []*database.Puppet) []*Puppet
|
||||
return output
|
||||
}
|
||||
|
||||
func (bridge *Bridge) FormatPuppetMXID(jid types.WhatsAppID) id.UserID {
|
||||
func (bridge *Bridge) FormatPuppetMXID(jid types.GroupMeID) id.UserID {
|
||||
return id.NewUserID(
|
||||
bridge.Config.Bridge.FormatUsername(
|
||||
strings.Replace(
|
||||
@ -181,54 +180,54 @@ func (puppet *Puppet) DefaultIntent() *appservice.IntentAPI {
|
||||
}
|
||||
|
||||
func (puppet *Puppet) UpdateAvatar(source *User, avatar *whatsappExt.ProfilePicInfo) bool {
|
||||
if avatar == nil {
|
||||
var err error
|
||||
avatar, err = source.Conn.GetProfilePicThumb(puppet.JID)
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to get avatar:", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
// if avatar == nil {
|
||||
// var err error
|
||||
// avatar, err = source.Conn.GetProfilePicThumb(puppet.JID)
|
||||
// if err != nil {
|
||||
// puppet.log.Warnln("Failed to get avatar:", err)
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
if avatar.Status != 0 {
|
||||
return false
|
||||
}
|
||||
// if avatar.Status != 0 {
|
||||
// return false
|
||||
// }
|
||||
|
||||
if avatar.Tag == puppet.Avatar {
|
||||
return false
|
||||
}
|
||||
// if avatar.Tag == puppet.Avatar {
|
||||
// return false
|
||||
// }
|
||||
|
||||
if len(avatar.URL) == 0 {
|
||||
err := puppet.DefaultIntent().SetAvatarURL(id.ContentURI{})
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to remove avatar:", err)
|
||||
}
|
||||
puppet.AvatarURL = id.ContentURI{}
|
||||
puppet.Avatar = avatar.Tag
|
||||
go puppet.updatePortalAvatar()
|
||||
return true
|
||||
}
|
||||
// if len(avatar.URL) == 0 {
|
||||
// err := puppet.DefaultIntent().SetAvatarURL(id.ContentURI{})
|
||||
// if err != nil {
|
||||
// puppet.log.Warnln("Failed to remove avatar:", err)
|
||||
// }
|
||||
// puppet.AvatarURL = id.ContentURI{}
|
||||
// puppet.Avatar = avatar.Tag
|
||||
// go puppet.updatePortalAvatar()
|
||||
// return true
|
||||
// }
|
||||
|
||||
data, err := avatar.DownloadBytes()
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to download avatar:", err)
|
||||
return false
|
||||
}
|
||||
// data, err := avatar.DownloadBytes()
|
||||
// if err != nil {
|
||||
// puppet.log.Warnln("Failed to download avatar:", err)
|
||||
// return false
|
||||
// }
|
||||
|
||||
mime := http.DetectContentType(data)
|
||||
resp, err := puppet.DefaultIntent().UploadBytes(data, mime)
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to upload avatar:", err)
|
||||
return false
|
||||
}
|
||||
// mime := http.DetectContentType(data)
|
||||
// resp, err := puppet.DefaultIntent().UploadBytes(data, mime)
|
||||
// if err != nil {
|
||||
// puppet.log.Warnln("Failed to upload avatar:", err)
|
||||
// return false
|
||||
// }
|
||||
|
||||
puppet.AvatarURL = resp.ContentURI
|
||||
err = puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
|
||||
if err != nil {
|
||||
puppet.log.Warnln("Failed to set avatar:", err)
|
||||
}
|
||||
puppet.Avatar = avatar.Tag
|
||||
go puppet.updatePortalAvatar()
|
||||
// puppet.AvatarURL = resp.ContentURI
|
||||
// err = puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
|
||||
// if err != nil {
|
||||
// puppet.log.Warnln("Failed to set avatar:", err)
|
||||
// }
|
||||
// puppet.Avatar = avatar.Tag
|
||||
// go puppet.updatePortalAvatar()
|
||||
return true
|
||||
}
|
||||
|
||||
@ -285,19 +284,19 @@ func (puppet *Puppet) updatePortalName() {
|
||||
}
|
||||
|
||||
func (puppet *Puppet) Sync(source *User, contact whatsapp.Contact) {
|
||||
err := puppet.DefaultIntent().EnsureRegistered()
|
||||
if err != nil {
|
||||
puppet.log.Errorln("Failed to ensure registered:", err)
|
||||
}
|
||||
// err := puppet.DefaultIntent().EnsureRegistered()
|
||||
// if err != nil {
|
||||
// puppet.log.Errorln("Failed to ensure registered:", err)
|
||||
// }
|
||||
|
||||
if contact.Jid == source.JID {
|
||||
contact.Notify = source.Conn.Info.Pushname
|
||||
}
|
||||
// if contact.Jid == source.JID {
|
||||
// contact.Notify = source.Conn.Info.Pushname
|
||||
// }
|
||||
|
||||
update := false
|
||||
update = puppet.UpdateName(source, contact) || update
|
||||
update = puppet.UpdateAvatar(source, nil) || update
|
||||
if update {
|
||||
puppet.Update()
|
||||
}
|
||||
// update := false
|
||||
// update = puppet.UpdateName(source, contact) || update
|
||||
// update = puppet.UpdateAvatar(source, nil) || update
|
||||
// if update {
|
||||
// puppet.Update()
|
||||
// }
|
||||
}
|
||||
|
@ -16,8 +16,11 @@
|
||||
|
||||
package types
|
||||
|
||||
// WhatsAppID is a WhatsApp JID.
|
||||
type WhatsAppID = string
|
||||
// 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
|
||||
|
527
user.go
527
user.go
@ -17,12 +17,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -39,14 +38,15 @@ import (
|
||||
"maunium.net/go/mautrix/format"
|
||||
"maunium.net/go/mautrix/id"
|
||||
|
||||
"github.com/karmanyaahm/groupme"
|
||||
"maunium.net/go/mautrix-whatsapp/database"
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
whatsappExt "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
*database.User
|
||||
Conn *whatsappExt.ExtendedConn
|
||||
Conn *groupme.PushSubscription
|
||||
|
||||
bridge *Bridge
|
||||
log log.Logger
|
||||
@ -57,6 +57,7 @@ type User struct {
|
||||
|
||||
IsRelaybot bool
|
||||
|
||||
Client *groupme.Client
|
||||
ConnectionErrors int
|
||||
CommunityID string
|
||||
|
||||
@ -90,7 +91,7 @@ func (bridge *Bridge) GetUserByMXID(userID id.UserID) *User {
|
||||
return user
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetUserByJID(userID types.WhatsAppID) *User {
|
||||
func (bridge *Bridge) GetUserByJID(userID types.GroupMeID) *User {
|
||||
bridge.usersLock.Lock()
|
||||
defer bridge.usersLock.Unlock()
|
||||
user, ok := bridge.usersByJID[userID]
|
||||
@ -222,17 +223,17 @@ func (user *User) SetManagementRoom(roomID id.RoomID) {
|
||||
}
|
||||
|
||||
func (user *User) SetSession(session *whatsapp.Session) {
|
||||
user.Session = session
|
||||
if session == nil {
|
||||
user.LastConnection = 0
|
||||
}
|
||||
user.Update()
|
||||
// user.Session = session
|
||||
// if session == nil {
|
||||
// user.LastConnection = 0
|
||||
// }
|
||||
// user.Update()
|
||||
}
|
||||
|
||||
func (user *User) Connect(evenIfNoSession bool) bool {
|
||||
func (user *User) Connect(evenIfNoLogin bool) bool {
|
||||
if user.Conn != nil {
|
||||
return true
|
||||
} else if !evenIfNoSession && user.Session == nil {
|
||||
} else if !evenIfNoLogin && len(user.Token) < 0 {
|
||||
return false
|
||||
}
|
||||
user.log.Debugln("Connecting to WhatsApp")
|
||||
@ -240,43 +241,51 @@ func (user *User) Connect(evenIfNoSession bool) bool {
|
||||
if timeout == 0 {
|
||||
timeout = 20
|
||||
}
|
||||
conn, err := whatsapp.NewConn(timeout * time.Second)
|
||||
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.AddHandler(user)
|
||||
conn := groupme.NewPushSubscription(context.TODO())
|
||||
user.Conn = &conn
|
||||
// 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.AddHandler(user)
|
||||
|
||||
//TODO: typing notification?
|
||||
return user.RestoreSession()
|
||||
}
|
||||
|
||||
func (user *User) RestoreSession() bool {
|
||||
if user.Session != nil {
|
||||
sess, err := user.Conn.RestoreWithSession(*user.Session)
|
||||
if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
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 := user.Conn.Disconnect()
|
||||
if err != nil {
|
||||
user.log.Errorln("Failed to disconnect after failed session restore:", err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
if len(user.Token) > 0 {
|
||||
//sess, err :=
|
||||
user.Conn.SubscribeToUser(context.TODO(), groupme.ID(user.GetJID()), user.Token)
|
||||
// if err == whatsapp.ErrAlreadyLoggedIn {
|
||||
// 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 :=
|
||||
user.Conn.Stop(context.TODO())
|
||||
// if err != nil {
|
||||
// user.log.Errorln("Failed to disconnect after failed session restore:", err)
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
user.Conn.SubscribeToUser(context.TODO(), groupme.ID(user.JID), user.Token)
|
||||
|
||||
user.ConnectionErrors = 0
|
||||
user.SetSession(&sess)
|
||||
//user.SetSession(&sess)
|
||||
user.log.Debugln("Session restored successfully")
|
||||
user.PostLogin()
|
||||
}
|
||||
@ -284,15 +293,30 @@ func (user *User) RestoreSession() bool {
|
||||
}
|
||||
|
||||
func (user *User) HasSession() bool {
|
||||
return user.Session != nil
|
||||
return user.Conn != nil && len(user.Token) > 0
|
||||
}
|
||||
|
||||
func (user *User) IsConnected() bool {
|
||||
return user.Conn != nil && user.Conn.IsConnected() && user.Conn.IsLoggedIn()
|
||||
// return user.Conn != nil && user.Conn.IsConnected() && user.Conn.IsLoggedIn()
|
||||
return true
|
||||
}
|
||||
|
||||
func (user *User) IsLoggedIn() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
func (user *User) IsLoginInProgress() bool {
|
||||
return user.Conn != nil && user.Conn.IsLoginInProgress()
|
||||
// return user.Conn != nil && user.Conn.IsLoginInProgress()
|
||||
return false
|
||||
}
|
||||
|
||||
func (user *User) GetJID() types.GroupMeID {
|
||||
if len(user.JID) == 0 {
|
||||
u, _ := user.Client.MyUser(context.TODO())
|
||||
user.JID = u.ID.String()
|
||||
}
|
||||
return user.JID
|
||||
}
|
||||
|
||||
func (user *User) loginQrChannel(ce *CommandEvent, qrChan <-chan string, eventIDChan chan<- id.EventID) {
|
||||
@ -348,49 +372,51 @@ func (user *User) loginQrChannel(ce *CommandEvent, qrChan <-chan string, eventID
|
||||
}
|
||||
|
||||
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)
|
||||
// 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)
|
||||
user.Token = ce.Args[0]
|
||||
|
||||
user.addToJIDMap()
|
||||
user.SetSession(&session)
|
||||
//user.SetSession(&session)
|
||||
ce.Reply("Successfully logged in, synchronizing chats...")
|
||||
user.PostLogin()
|
||||
// user.PostLogin()
|
||||
}
|
||||
|
||||
type Chat struct {
|
||||
@ -469,26 +495,27 @@ func (user *User) sendMarkdownBridgeAlert(formatString string, args ...interface
|
||||
}
|
||||
|
||||
func (user *User) postConnPing() bool {
|
||||
user.log.Debugln("Making post-connection ping")
|
||||
err := user.Conn.AdminTest()
|
||||
if err != nil {
|
||||
user.log.Errorfln("Post-connection ping failed: %v. Disconnecting and then reconnecting after a second", err)
|
||||
sess, disconnectErr := user.Conn.Disconnect()
|
||||
if disconnectErr != nil {
|
||||
user.log.Warnln("Error while disconnecting after failed post-connection ping:", disconnectErr)
|
||||
} else {
|
||||
user.Session = &sess
|
||||
}
|
||||
user.bridge.Metrics.TrackDisconnection(user.MXID)
|
||||
go func() {
|
||||
time.Sleep(1 * time.Second)
|
||||
user.tryReconnect(fmt.Sprintf("Post-connection ping failed: %v", err))
|
||||
}()
|
||||
return false
|
||||
} else {
|
||||
user.log.Debugln("Post-connection ping OK")
|
||||
return true
|
||||
}
|
||||
// user.log.Debugln("Making post-connection ping")
|
||||
// err := user.Conn.AdminTest()
|
||||
// if err != nil {
|
||||
// user.log.Errorfln("Post-connection ping failed: %v. Disconnecting and then reconnecting after a second", err)
|
||||
// sess, disconnectErr := user.Conn.Disconnect()
|
||||
// if disconnectErr != nil {
|
||||
// user.log.Warnln("Error while disconnecting after failed post-connection ping:", disconnectErr)
|
||||
// } else {
|
||||
// user.Session = &sess
|
||||
// }
|
||||
// user.bridge.Metrics.TrackDisconnection(user.MXID)
|
||||
// go func() {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// user.tryReconnect(fmt.Sprintf("Post-connection ping failed: %v", err))
|
||||
// }()
|
||||
// return false
|
||||
// } else {
|
||||
// user.log.Debugln("Post-connection ping OK")
|
||||
// return true
|
||||
// }
|
||||
return true
|
||||
}
|
||||
|
||||
func (user *User) intPostLogin() {
|
||||
@ -539,83 +566,83 @@ func (user *User) HandleStreamEvent(evt whatsappExt.StreamEvent) {
|
||||
}
|
||||
|
||||
func (user *User) HandleChatList(chats []whatsapp.Chat) {
|
||||
user.log.Infoln("Chat list received")
|
||||
chatMap := make(map[string]whatsapp.Chat)
|
||||
for _, chat := range user.Conn.Store.Chats {
|
||||
chatMap[chat.Jid] = chat
|
||||
}
|
||||
for _, chat := range chats {
|
||||
chatMap[chat.Jid] = chat
|
||||
}
|
||||
select {
|
||||
case user.chatListReceived <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
go user.syncPortals(chatMap, false)
|
||||
// user.log.Infoln("Chat list received")
|
||||
// chatMap := make(map[string]whatsapp.Chat)
|
||||
// for _, chat := range user.Conn.Store.Chats {
|
||||
// chatMap[chat.Jid] = chat
|
||||
// }
|
||||
// for _, chat := range chats {
|
||||
// chatMap[chat.Jid] = chat
|
||||
// }
|
||||
// select {
|
||||
// case user.chatListReceived <- struct{}{}:
|
||||
// default:
|
||||
// }
|
||||
// go user.syncPortals(chatMap, false)
|
||||
}
|
||||
|
||||
func (user *User) syncPortals(chatMap map[string]whatsapp.Chat, createAll bool) {
|
||||
if chatMap == nil {
|
||||
chatMap = user.Conn.Store.Chats
|
||||
}
|
||||
user.log.Infoln("Reading chat list")
|
||||
chats := make(ChatList, 0, len(chatMap))
|
||||
existingKeys := user.GetInCommunityMap()
|
||||
portalKeys := make([]database.PortalKeyWithMeta, 0, len(chatMap))
|
||||
for _, chat := range chatMap {
|
||||
ts, err := strconv.ParseUint(chat.LastMessageTime, 10, 64)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Non-integer last message time in %s: %s", chat.Jid, chat.LastMessageTime)
|
||||
continue
|
||||
}
|
||||
portal := user.GetPortalByJID(chat.Jid)
|
||||
// if chatMap == nil {
|
||||
// chatMap = user.Conn.Store.Chats
|
||||
// }
|
||||
// user.log.Infoln("Reading chat list")
|
||||
// chats := make(ChatList, 0, len(chatMap))
|
||||
// existingKeys := user.GetInCommunityMap()
|
||||
// portalKeys := make([]database.PortalKeyWithMeta, 0, len(chatMap))
|
||||
// for _, chat := range chatMap {
|
||||
// ts, err := strconv.ParseUint(chat.LastMessageTime, 10, 64)
|
||||
// if err != nil {
|
||||
// user.log.Warnfln("Non-integer last message time in %s: %s", chat.Jid, chat.LastMessageTime)
|
||||
// continue
|
||||
// }
|
||||
// portal := user.GetPortalByJID(chat.Jid)
|
||||
|
||||
chats = append(chats, Chat{
|
||||
Portal: portal,
|
||||
Contact: user.Conn.Store.Contacts[chat.Jid],
|
||||
LastMessageTime: ts,
|
||||
})
|
||||
var inCommunity, ok bool
|
||||
if inCommunity, ok = existingKeys[portal.Key]; !ok || !inCommunity {
|
||||
inCommunity = user.addPortalToCommunity(portal)
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
user.addPuppetToCommunity(puppet)
|
||||
}
|
||||
}
|
||||
portalKeys = append(portalKeys, database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
}
|
||||
user.log.Infoln("Read chat list, updating user-portal mapping")
|
||||
err := user.SetPortalKeys(portalKeys)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to update user-portal mapping:", err)
|
||||
}
|
||||
sort.Sort(chats)
|
||||
limit := user.bridge.Config.Bridge.InitialChatSync
|
||||
if limit < 0 {
|
||||
limit = len(chats)
|
||||
}
|
||||
now := uint64(time.Now().Unix())
|
||||
user.log.Infoln("Syncing portals")
|
||||
for i, chat := range chats {
|
||||
if chat.LastMessageTime+user.bridge.Config.Bridge.SyncChatMaxAge < now {
|
||||
break
|
||||
}
|
||||
create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
|
||||
if len(chat.Portal.MXID) > 0 || create || createAll {
|
||||
chat.Portal.Sync(user, chat.Contact)
|
||||
err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
|
||||
if err != nil {
|
||||
chat.Portal.log.Errorln("Error backfilling history:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
user.UpdateDirectChats(nil)
|
||||
user.log.Infoln("Finished syncing portals")
|
||||
select {
|
||||
case user.syncPortalsDone <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
// chats = append(chats, Chat{
|
||||
// Portal: portal,
|
||||
// Contact: user.Conn.Store.Contacts[chat.Jid],
|
||||
// LastMessageTime: ts,
|
||||
// })
|
||||
// var inCommunity, ok bool
|
||||
// if inCommunity, ok = existingKeys[portal.Key]; !ok || !inCommunity {
|
||||
// inCommunity = user.addPortalToCommunity(portal)
|
||||
// if portal.IsPrivateChat() {
|
||||
// puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
// user.addPuppetToCommunity(puppet)
|
||||
// }
|
||||
// }
|
||||
// portalKeys = append(portalKeys, database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
// }
|
||||
// user.log.Infoln("Read chat list, updating user-portal mapping")
|
||||
// err := user.SetPortalKeys(portalKeys)
|
||||
// if err != nil {
|
||||
// user.log.Warnln("Failed to update user-portal mapping:", err)
|
||||
// }
|
||||
// sort.Sort(chats)
|
||||
// limit := user.bridge.Config.Bridge.InitialChatSync
|
||||
// if limit < 0 {
|
||||
// limit = len(chats)
|
||||
// }
|
||||
// now := uint64(time.Now().Unix())
|
||||
// user.log.Infoln("Syncing portals")
|
||||
// for i, chat := range chats {
|
||||
// if chat.LastMessageTime+user.bridge.Config.Bridge.SyncChatMaxAge < now {
|
||||
// break
|
||||
// }
|
||||
// create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
|
||||
// if len(chat.Portal.MXID) > 0 || create || createAll {
|
||||
// chat.Portal.Sync(user, chat.Contact)
|
||||
// err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
|
||||
// if err != nil {
|
||||
// chat.Portal.log.Errorln("Error backfilling history:", err)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// user.UpdateDirectChats(nil)
|
||||
// user.log.Infoln("Finished syncing portals")
|
||||
// select {
|
||||
// case user.syncPortalsDone <- struct{}{}:
|
||||
// default:
|
||||
// }
|
||||
}
|
||||
|
||||
func (user *User) getDirectChats() map[id.UserID][]id.RoomID {
|
||||
@ -682,17 +709,17 @@ func (user *User) HandleContactList(contacts []whatsapp.Contact) {
|
||||
}
|
||||
|
||||
func (user *User) syncPuppets(contacts map[string]whatsapp.Contact) {
|
||||
if contacts == nil {
|
||||
contacts = user.Conn.Store.Contacts
|
||||
}
|
||||
user.log.Infoln("Syncing puppet info from contacts")
|
||||
for jid, contact := range contacts {
|
||||
if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
|
||||
puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
||||
puppet.Sync(user, contact)
|
||||
}
|
||||
}
|
||||
user.log.Infoln("Finished syncing puppet info from contacts")
|
||||
// if contacts == nil {
|
||||
// contacts = user.Conn.Store.Contacts
|
||||
// }
|
||||
// user.log.Infoln("Syncing puppet info from contacts")
|
||||
// for jid, contact := range contacts {
|
||||
// if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
|
||||
// puppet := user.bridge.GetPuppetByJID(contact.Jid)
|
||||
// puppet.Sync(user, contact)
|
||||
// }
|
||||
// }
|
||||
// user.log.Infoln("Finished syncing puppet info from contacts")
|
||||
}
|
||||
|
||||
func (user *User) updateLastConnectionIfNecessary() {
|
||||
@ -723,62 +750,62 @@ func (user *User) HandleError(err error) {
|
||||
}
|
||||
|
||||
func (user *User) tryReconnect(msg string) {
|
||||
user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
if user.ConnectionErrors > user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
user.sendMarkdownBridgeAlert("%s. Use the `reconnect` command to reconnect.", msg)
|
||||
return
|
||||
}
|
||||
if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
user.sendBridgeNotice("%s. Reconnecting...", msg)
|
||||
// Don't want the same error to be repeated
|
||||
msg = ""
|
||||
}
|
||||
var tries uint
|
||||
var exponentialBackoff bool
|
||||
baseDelay := time.Duration(user.bridge.Config.Bridge.ConnectionRetryDelay)
|
||||
if baseDelay < 0 {
|
||||
exponentialBackoff = true
|
||||
baseDelay = -baseDelay + 1
|
||||
}
|
||||
delay := baseDelay
|
||||
for user.ConnectionErrors <= user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
err := user.Conn.Restore()
|
||||
if err == nil {
|
||||
user.ConnectionErrors = 0
|
||||
if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
user.sendBridgeNotice("Reconnected successfully")
|
||||
}
|
||||
user.PostLogin()
|
||||
return
|
||||
} else if err.Error() == "init responded with 400" {
|
||||
user.log.Infoln("Got init 400 error when trying to reconnect, resetting connection...")
|
||||
sess, err := user.Conn.Disconnect()
|
||||
if err != nil {
|
||||
user.log.Debugln("Error while disconnecting for connection reset:", err)
|
||||
}
|
||||
if len(sess.Wid) > 0 {
|
||||
user.SetSession(&sess)
|
||||
}
|
||||
}
|
||||
user.log.Errorln("Error while trying to reconnect after disconnection:", err)
|
||||
tries++
|
||||
user.ConnectionErrors++
|
||||
if user.ConnectionErrors <= user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
if exponentialBackoff {
|
||||
delay = (1 << tries) + baseDelay
|
||||
}
|
||||
if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
user.sendBridgeNotice("Reconnection attempt failed: %v. Retrying in %d seconds...", err, delay)
|
||||
}
|
||||
time.Sleep(delay * time.Second)
|
||||
}
|
||||
}
|
||||
// user.bridge.Metrics.TrackConnectionState(user.JID, false)
|
||||
// if user.ConnectionErrors > user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
// user.sendMarkdownBridgeAlert("%s. Use the `reconnect` command to reconnect.", msg)
|
||||
// return
|
||||
// }
|
||||
// if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
// user.sendBridgeNotice("%s. Reconnecting...", msg)
|
||||
// // Don't want the same error to be repeated
|
||||
// msg = ""
|
||||
// }
|
||||
// var tries uint
|
||||
// var exponentialBackoff bool
|
||||
// baseDelay := time.Duration(user.bridge.Config.Bridge.ConnectionRetryDelay)
|
||||
// if baseDelay < 0 {
|
||||
// exponentialBackoff = true
|
||||
// baseDelay = -baseDelay + 1
|
||||
// }
|
||||
// delay := baseDelay
|
||||
// for user.ConnectionErrors <= user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
// err := user.Conn.Restore()
|
||||
// if err == nil {
|
||||
// user.ConnectionErrors = 0
|
||||
// if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
// user.sendBridgeNotice("Reconnected successfully")
|
||||
// }
|
||||
// user.PostLogin()
|
||||
// return
|
||||
// } else if err.Error() == "init responded with 400" {
|
||||
// user.log.Infoln("Got init 400 error when trying to reconnect, resetting connection...")
|
||||
// sess, err := user.Conn.Disconnect()
|
||||
// if err != nil {
|
||||
// user.log.Debugln("Error while disconnecting for connection reset:", err)
|
||||
// }
|
||||
// if len(sess.Wid) > 0 {
|
||||
// user.SetSession(&sess)
|
||||
// }
|
||||
// }
|
||||
// user.log.Errorln("Error while trying to reconnect after disconnection:", err)
|
||||
// tries++
|
||||
// user.ConnectionErrors++
|
||||
// if user.ConnectionErrors <= user.bridge.Config.Bridge.MaxConnectionAttempts {
|
||||
// if exponentialBackoff {
|
||||
// delay = (1 << tries) + baseDelay
|
||||
// }
|
||||
// if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
// user.sendBridgeNotice("Reconnection attempt failed: %v. Retrying in %d seconds...", err, delay)
|
||||
// }
|
||||
// time.Sleep(delay * time.Second)
|
||||
// }
|
||||
// }
|
||||
|
||||
if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
user.sendMarkdownBridgeAlert("%d reconnection attempts failed. Use the `reconnect` command to try to reconnect manually.", tries)
|
||||
} else {
|
||||
user.sendMarkdownBridgeAlert("\u26a0 %s. Additionally, %d reconnection attempts failed. Use the `reconnect` command to try to reconnect.", msg, tries)
|
||||
}
|
||||
// if user.bridge.Config.Bridge.ReportConnectionRetry {
|
||||
// user.sendMarkdownBridgeAlert("%d reconnection attempts failed. Use the `reconnect` command to try to reconnect manually.", tries)
|
||||
// } else {
|
||||
// user.sendMarkdownBridgeAlert("\u26a0 %s. Additionally, %d reconnection attempts failed. Use the `reconnect` command to try to reconnect.", msg, tries)
|
||||
// }
|
||||
}
|
||||
|
||||
func (user *User) ShouldCallSynchronously() bool {
|
||||
@ -789,11 +816,11 @@ func (user *User) HandleJSONParseError(err error) {
|
||||
user.log.Errorln("WhatsApp JSON parse error:", err)
|
||||
}
|
||||
|
||||
func (user *User) PortalKey(jid types.WhatsAppID) database.PortalKey {
|
||||
func (user *User) PortalKey(jid types.GroupMeID) database.PortalKey {
|
||||
return database.NewPortalKey(jid, user.JID)
|
||||
}
|
||||
|
||||
func (user *User) GetPortalByJID(jid types.WhatsAppID) *Portal {
|
||||
func (user *User) GetPortalByJID(jid types.GroupMeID) *Portal {
|
||||
return user.bridge.GetPortalByJID(user.PortalKey(jid))
|
||||
}
|
||||
|
||||
@ -805,7 +832,7 @@ func (user *User) runMessageRingBuffer() {
|
||||
default:
|
||||
dropped := <-user.messageOutput
|
||||
user.log.Warnln("Buffer is full, dropping message in", dropped.chat)
|
||||
user.messageOutput<-msg
|
||||
user.messageOutput <- msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,16 +17,13 @@
|
||||
package whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
)
|
||||
|
||||
type CreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.WhatsAppID `json:"gid"`
|
||||
Participants map[types.WhatsAppID]struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.GroupMeID `json:"gid"`
|
||||
Participants map[types.GroupMeID]struct {
|
||||
Code string `json:"code"`
|
||||
} `json:"participants"`
|
||||
|
||||
@ -34,35 +31,36 @@ type CreateGroupResponse struct {
|
||||
}
|
||||
|
||||
type actualCreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.WhatsAppID `json:"gid"`
|
||||
Participants []map[types.WhatsAppID]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.WhatsAppID) (*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.WhatsAppID]struct {
|
||||
Code string `json:"code"`
|
||||
})
|
||||
for _, participantMap := range actualResp.Participants {
|
||||
for jid, status := range participantMap {
|
||||
resp.Participants[jid] = status
|
||||
}
|
||||
}
|
||||
return &resp, nil
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user