Fix desegregation changes to make the bridge work again
This commit is contained in:
parent
347854dc8c
commit
22cdf519f2
@ -56,7 +56,7 @@ func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, mes
|
|||||||
args := strings.Split(message, " ")
|
args := strings.Split(message, " ")
|
||||||
cmd := strings.ToLower(args[0])
|
cmd := strings.ToLower(args[0])
|
||||||
ce := &CommandEvent{
|
ce := &CommandEvent{
|
||||||
Bot: handler.bridge.AS.BotIntent(),
|
Bot: handler.bridge.Bot,
|
||||||
Bridge: handler.bridge,
|
Bridge: handler.bridge,
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
RoomID: roomID,
|
RoomID: roomID,
|
||||||
|
@ -30,12 +30,12 @@ type MessageQuery struct {
|
|||||||
|
|
||||||
func (mq *MessageQuery) CreateTable() error {
|
func (mq *MessageQuery) CreateTable() error {
|
||||||
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
_, err := mq.db.Exec(`CREATE TABLE IF NOT EXISTS message (
|
||||||
chat_jid VARCHAR(25) NOT NULL,
|
chat_jid VARCHAR(25),
|
||||||
chat_receiver VARCHAR(25) NOT NULL,
|
chat_receiver VARCHAR(25),
|
||||||
jid VARCHAR(255) NOT NULL,
|
jid VARCHAR(255),
|
||||||
mxid VARCHAR(255) NOT NULL UNIQUE,
|
mxid VARCHAR(255) NOT NULL UNIQUE,
|
||||||
|
|
||||||
PRIMARY KEY (chat_jid, jid),
|
PRIMARY KEY (chat_jid, chat_receiver, jid),
|
||||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||||
)`)
|
)`)
|
||||||
return err
|
return err
|
||||||
@ -97,9 +97,9 @@ func (msg *Message) Scan(row Scannable) *Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (msg *Message) Insert() error {
|
func (msg *Message) Insert() error {
|
||||||
_, err := msg.db.Exec("INSERT INTO message VALUES (?, ?, ?)", msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID)
|
_, err := msg.db.Exec("INSERT INTO message VALUES (?, ?, ?, ?)", msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg.log.Warnfln("Failed to update %s: %v", msg.Chat, msg.JID, err)
|
msg.log.Warnfln("Failed to insert %s: %v", msg.Chat, msg.JID, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -122,13 +122,15 @@ type Portal struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) Scan(row Scannable) *Portal {
|
func (portal *Portal) Scan(row Scannable) *Portal {
|
||||||
err := row.Scan(&portal.Key.JID, &portal.Key.Receiver, &portal.MXID, &portal.Name, &portal.Topic, &portal.Avatar)
|
var mxid sql.NullString
|
||||||
|
err := row.Scan(&portal.Key.JID, &portal.Key.Receiver, &mxid, &portal.Name, &portal.Topic, &portal.Avatar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
portal.log.Errorln("Database scan failed:", err)
|
portal.log.Errorln("Database scan failed:", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
portal.MXID = mxid.String
|
||||||
return portal
|
return portal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,13 +74,16 @@ type Puppet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
func (puppet *Puppet) Scan(row Scannable) *Puppet {
|
||||||
err := row.Scan(&puppet.JID, &puppet.Displayname, &puppet.Avatar)
|
var displayname, avatar sql.NullString
|
||||||
|
err := row.Scan(&puppet.JID, &displayname, &avatar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
puppet.log.Errorln("Database scan failed:", err)
|
puppet.log.Errorln("Database scan failed:", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
puppet.Displayname = displayname.String
|
||||||
|
puppet.Avatar = avatar.String
|
||||||
return puppet
|
return puppet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,10 +18,12 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Rhymen/go-whatsapp"
|
"github.com/Rhymen/go-whatsapp"
|
||||||
log "maunium.net/go/maulogger"
|
log "maunium.net/go/maulogger"
|
||||||
"maunium.net/go/mautrix-whatsapp/types"
|
"maunium.net/go/mautrix-whatsapp/types"
|
||||||
|
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserQuery struct {
|
type UserQuery struct {
|
||||||
@ -40,8 +42,7 @@ func (uq *UserQuery) CreateTable() error {
|
|||||||
client_token VARCHAR(255),
|
client_token VARCHAR(255),
|
||||||
server_token VARCHAR(255),
|
server_token VARCHAR(255),
|
||||||
enc_key BLOB,
|
enc_key BLOB,
|
||||||
mac_key BLOB,
|
mac_key BLOB
|
||||||
wid VARCHAR(255)
|
|
||||||
)`)
|
)`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ func (uq *UserQuery) GetByMXID(userID types.MatrixUserID) *User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (uq *UserQuery) GetByJID(userID types.WhatsAppID) *User {
|
func (uq *UserQuery) GetByJID(userID types.WhatsAppID) *User {
|
||||||
row := uq.db.QueryRow("SELECT * FROM user WHERE jid=?", userID)
|
row := uq.db.QueryRow("SELECT * FROM user WHERE jid=?", stripSuffix(userID))
|
||||||
if row == nil {
|
if row == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -92,28 +93,42 @@ type User struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) Scan(row Scannable) *User {
|
func (user *User) Scan(row Scannable) *User {
|
||||||
sess := whatsapp.Session{}
|
var managementRoom, clientID, clientToken, serverToken, jid sql.NullString
|
||||||
err := row.Scan(&user.MXID, &user.JID, &user.ManagementRoom, &sess.ClientId, &sess.ClientToken, &sess.ServerToken,
|
var encKey, macKey []byte
|
||||||
&sess.EncKey, &sess.MacKey, &sess.Wid)
|
err := row.Scan(&user.MXID, &jid, &managementRoom, &clientID, &clientToken, &serverToken, &encKey, &macKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
user.log.Errorln("Database scan failed:", err)
|
user.log.Errorln("Database scan failed:", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(sess.ClientId) > 0 {
|
if len(jid.String) > 0 && len(clientID.String) > 0 {
|
||||||
user.Session = &sess
|
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 {
|
} else {
|
||||||
user.Session = nil
|
user.Session = nil
|
||||||
}
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) jidPtr() *string {
|
func stripSuffix(jid types.WhatsAppID) string {
|
||||||
if len(user.JID) > 0 {
|
if len(jid) == 0 {
|
||||||
return &user.JID
|
return jid
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
index := strings.IndexRune(jid, '@')
|
||||||
|
if index < 0 {
|
||||||
|
return jid
|
||||||
|
}
|
||||||
|
|
||||||
|
return jid[:index]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
||||||
@ -125,16 +140,17 @@ func (user *User) sessionUnptr() (sess whatsapp.Session) {
|
|||||||
|
|
||||||
func (user *User) Insert() error {
|
func (user *User) Insert() error {
|
||||||
sess := user.sessionUnptr()
|
sess := user.sessionUnptr()
|
||||||
_, err := user.db.Exec("INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", user.MXID, user.jidPtr(), user.ManagementRoom,
|
_, err := user.db.Exec("INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?)", user.MXID, stripSuffix(user.JID),
|
||||||
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey, sess.Wid)
|
user.ManagementRoom,
|
||||||
|
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) Update() error {
|
func (user *User) Update() error {
|
||||||
sess := user.sessionUnptr()
|
sess := user.sessionUnptr()
|
||||||
_, err := user.db.Exec("UPDATE user SET jid=?, management_room=?, client_id=?, client_token=?, server_token=?, enc_key=?, mac_key=?, wid=? WHERE mxid=?",
|
_, err := user.db.Exec("UPDATE user SET jid=?, management_room=?, client_id=?, client_token=?, server_token=?, enc_key=?, mac_key=? WHERE mxid=?",
|
||||||
user.jidPtr(), user.ManagementRoom,
|
stripSuffix(user.JID), user.ManagementRoom,
|
||||||
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey, sess.Wid,
|
sess.ClientId, sess.ClientToken, sess.ServerToken, sess.EncKey, sess.MacKey,
|
||||||
user.MXID)
|
user.MXID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"maunium.net/go/gomatrix"
|
"maunium.net/go/gomatrix"
|
||||||
"maunium.net/go/gomatrix/format"
|
"maunium.net/go/gomatrix/format"
|
||||||
|
"maunium.net/go/mautrix-whatsapp/types"
|
||||||
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
"maunium.net/go/mautrix-whatsapp/whatsapp-ext"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -104,7 +105,7 @@ func NewFormatter(bridge *Bridge) *Formatter {
|
|||||||
return formatter
|
return formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *Formatter) getMatrixInfoByJID(jid string) (mxid, displayname string) {
|
func (formatter *Formatter) getMatrixInfoByJID(jid types.WhatsAppID) (mxid, displayname string) {
|
||||||
if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
if user := formatter.bridge.GetUserByJID(jid); user != nil {
|
||||||
mxid = user.MXID
|
mxid = user.MXID
|
||||||
displayname = user.MXID
|
displayname = user.MXID
|
||||||
|
8
main.go
8
main.go
@ -165,18 +165,18 @@ func (bridge *Bridge) UpdateBotProfile() {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
if botConfig.Avatar == "remove" {
|
if botConfig.Avatar == "remove" {
|
||||||
err = bridge.AS.BotIntent().SetAvatarURL("")
|
err = bridge.Bot.SetAvatarURL("")
|
||||||
} else if len(botConfig.Avatar) > 0 {
|
} else if len(botConfig.Avatar) > 0 {
|
||||||
err = bridge.AS.BotIntent().SetAvatarURL(botConfig.Avatar)
|
err = bridge.Bot.SetAvatarURL(botConfig.Avatar)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bridge.Log.Warnln("Failed to update bot avatar:", err)
|
bridge.Log.Warnln("Failed to update bot avatar:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if botConfig.Displayname == "remove" {
|
if botConfig.Displayname == "remove" {
|
||||||
err = bridge.AS.BotIntent().SetDisplayName("")
|
err = bridge.Bot.SetDisplayName("")
|
||||||
} else if len(botConfig.Avatar) > 0 {
|
} else if len(botConfig.Avatar) > 0 {
|
||||||
err = bridge.AS.BotIntent().SetDisplayName(botConfig.Displayname)
|
err = bridge.Bot.SetDisplayName(botConfig.Displayname)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bridge.Log.Warnln("Failed to update bot displayname:", err)
|
bridge.Log.Warnln("Failed to update bot displayname:", err)
|
||||||
|
40
portal.go
40
portal.go
@ -126,7 +126,7 @@ func (portal *Portal) SyncParticipants(metadata *whatsappExt.GroupInfo) {
|
|||||||
puppet.Intent().EnsureJoined(portal.MXID)
|
puppet.Intent().EnsureJoined(portal.MXID)
|
||||||
|
|
||||||
user := portal.bridge.GetUserByJID(participant.JID)
|
user := portal.bridge.GetUserByJID(participant.JID)
|
||||||
if !portal.bridge.AS.StateStore.IsInvited(portal.MXID, user.MXID) {
|
if user != nil && !portal.bridge.AS.StateStore.IsInvited(portal.MXID, user.MXID) {
|
||||||
portal.MainIntent().InviteUser(portal.MXID, &gomatrix.ReqInviteUser{
|
portal.MainIntent().InviteUser(portal.MXID, &gomatrix.ReqInviteUser{
|
||||||
UserID: user.MXID,
|
UserID: user.MXID,
|
||||||
})
|
})
|
||||||
@ -144,7 +144,10 @@ func (portal *Portal) SyncParticipants(metadata *whatsappExt.GroupInfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to change power levels:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,10 +261,10 @@ func (portal *Portal) GetBasePowerLevels() *gomatrix.PowerLevels {
|
|||||||
Users: map[string]int{
|
Users: map[string]int{
|
||||||
portal.MainIntent().UserID: 100,
|
portal.MainIntent().UserID: 100,
|
||||||
},
|
},
|
||||||
Events: map[gomatrix.EventType]int{
|
Events: map[string]int{
|
||||||
gomatrix.StateRoomName: anyone,
|
gomatrix.StateRoomName.Type: anyone,
|
||||||
gomatrix.StateRoomAvatar: anyone,
|
gomatrix.StateRoomAvatar.Type: anyone,
|
||||||
gomatrix.StateTopic: anyone,
|
gomatrix.StateTopic.Type: anyone,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,7 +289,10 @@ func (portal *Portal) ChangeAdminStatus(jids []string, setAdmin bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if changed {
|
if changed {
|
||||||
portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to change power levels:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +306,10 @@ func (portal *Portal) RestrictMessageSending(restrict bool) {
|
|||||||
} else {
|
} else {
|
||||||
levels.EventsDefault = 0
|
levels.EventsDefault = 0
|
||||||
}
|
}
|
||||||
portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to change power levels:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) RestrictMetadataChanges(restrict bool) {
|
func (portal *Portal) RestrictMetadataChanges(restrict bool) {
|
||||||
@ -317,7 +326,10 @@ func (portal *Portal) RestrictMetadataChanges(restrict bool) {
|
|||||||
changed = levels.EnsureEventLevel(gomatrix.StateRoomAvatar, newLevel) || changed
|
changed = levels.EnsureEventLevel(gomatrix.StateRoomAvatar, newLevel) || changed
|
||||||
changed = levels.EnsureEventLevel(gomatrix.StateTopic, newLevel) || changed
|
changed = levels.EnsureEventLevel(gomatrix.StateTopic, newLevel) || changed
|
||||||
if changed {
|
if changed {
|
||||||
portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
||||||
|
if err != nil {
|
||||||
|
portal.log.Errorln("Failed to change power levels:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +379,7 @@ func (portal *Portal) MainIntent() *appservice.IntentAPI {
|
|||||||
if portal.IsPrivateChat() {
|
if portal.IsPrivateChat() {
|
||||||
return portal.bridge.GetPuppetByJID(portal.Key.JID).Intent()
|
return portal.bridge.GetPuppetByJID(portal.Key.JID).Intent()
|
||||||
}
|
}
|
||||||
return portal.bridge.AS.BotIntent()
|
return portal.bridge.Bot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) IsDuplicate(id types.WhatsAppMessageID) bool {
|
func (portal *Portal) IsDuplicate(id types.WhatsAppMessageID) bool {
|
||||||
@ -386,13 +398,13 @@ func (portal *Portal) MarkHandled(jid types.WhatsAppMessageID, mxid types.Matrix
|
|||||||
msg.Insert()
|
msg.Insert()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (portal *Portal) GetMessageIntent(info whatsapp.MessageInfo) *appservice.IntentAPI {
|
func (portal *Portal) GetMessageIntent(user *User, info whatsapp.MessageInfo) *appservice.IntentAPI {
|
||||||
if info.FromMe {
|
if info.FromMe {
|
||||||
if portal.IsPrivateChat() {
|
if portal.IsPrivateChat() {
|
||||||
// TODO handle own messages in private chats properly
|
// TODO handle own messages in private chats properly
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return portal.bridge.GetPuppetByJID(portal.Key.Receiver).Intent()
|
return portal.bridge.GetPuppetByJID(user.JID).Intent()
|
||||||
} else if portal.IsPrivateChat() {
|
} else if portal.IsPrivateChat() {
|
||||||
return portal.MainIntent()
|
return portal.MainIntent()
|
||||||
} else if len(info.SenderJid) == 0 {
|
} else if len(info.SenderJid) == 0 {
|
||||||
@ -432,7 +444,7 @@ func (portal *Portal) HandleTextMessage(source *User, message whatsapp.TextMessa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
intent := portal.GetMessageIntent(message.Info)
|
intent := portal.GetMessageIntent(source, message.Info)
|
||||||
if intent == nil {
|
if intent == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -466,7 +478,7 @@ func (portal *Portal) HandleMediaMessage(source *User, download func() ([]byte,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
intent := portal.GetMessageIntent(info)
|
intent := portal.GetMessageIntent(source, info)
|
||||||
if intent == nil {
|
if intent == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
15
user.go
15
user.go
@ -37,7 +37,6 @@ type User struct {
|
|||||||
|
|
||||||
Admin bool
|
Admin bool
|
||||||
Whitelisted bool
|
Whitelisted bool
|
||||||
jid string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bridge *Bridge) GetUserByMXID(userID types.MatrixUserID) *User {
|
func (bridge *Bridge) GetUserByMXID(userID types.MatrixUserID) *User {
|
||||||
@ -53,6 +52,9 @@ func (bridge *Bridge) GetUserByMXID(userID types.MatrixUserID) *User {
|
|||||||
}
|
}
|
||||||
user = bridge.NewUser(dbUser)
|
user = bridge.NewUser(dbUser)
|
||||||
bridge.usersByMXID[user.MXID] = user
|
bridge.usersByMXID[user.MXID] = user
|
||||||
|
if len(user.JID) > 0 {
|
||||||
|
bridge.usersByJID[user.JID] = user
|
||||||
|
}
|
||||||
if len(user.ManagementRoom) > 0 {
|
if len(user.ManagementRoom) > 0 {
|
||||||
bridge.managementRooms[user.ManagementRoom] = user
|
bridge.managementRooms[user.ManagementRoom] = user
|
||||||
}
|
}
|
||||||
@ -66,13 +68,12 @@ func (bridge *Bridge) GetUserByJID(userID types.WhatsAppID) *User {
|
|||||||
defer bridge.usersLock.Unlock()
|
defer bridge.usersLock.Unlock()
|
||||||
user, ok := bridge.usersByJID[userID]
|
user, ok := bridge.usersByJID[userID]
|
||||||
if !ok {
|
if !ok {
|
||||||
dbUser := bridge.DB.User.GetByMXID(userID)
|
dbUser := bridge.DB.User.GetByJID(userID)
|
||||||
if dbUser == nil {
|
if dbUser == nil {
|
||||||
dbUser = bridge.DB.User.New()
|
return nil
|
||||||
dbUser.MXID = userID
|
|
||||||
dbUser.Insert()
|
|
||||||
}
|
}
|
||||||
user = bridge.NewUser(dbUser)
|
user = bridge.NewUser(dbUser)
|
||||||
|
bridge.usersByMXID[user.MXID] = user
|
||||||
bridge.usersByJID[user.JID] = user
|
bridge.usersByJID[user.JID] = user
|
||||||
if len(user.ManagementRoom) > 0 {
|
if len(user.ManagementRoom) > 0 {
|
||||||
bridge.managementRooms[user.ManagementRoom] = user
|
bridge.managementRooms[user.ManagementRoom] = user
|
||||||
@ -91,6 +92,9 @@ func (bridge *Bridge) GetAllUsers() []*User {
|
|||||||
if !ok {
|
if !ok {
|
||||||
user = bridge.NewUser(dbUser)
|
user = bridge.NewUser(dbUser)
|
||||||
bridge.usersByMXID[user.MXID] = user
|
bridge.usersByMXID[user.MXID] = user
|
||||||
|
if len(user.JID) > 0 {
|
||||||
|
bridge.usersByJID[user.JID] = user
|
||||||
|
}
|
||||||
if len(user.ManagementRoom) > 0 {
|
if len(user.ManagementRoom) > 0 {
|
||||||
bridge.managementRooms[user.ManagementRoom] = user
|
bridge.managementRooms[user.ManagementRoom] = user
|
||||||
}
|
}
|
||||||
@ -147,6 +151,7 @@ func (user *User) Connect(evenIfNoSession bool) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
user.Conn = whatsappExt.ExtendConn(conn)
|
user.Conn = whatsappExt.ExtendConn(conn)
|
||||||
|
user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa")
|
||||||
user.log.Debugln("WhatsApp connection successful")
|
user.log.Debugln("WhatsApp connection successful")
|
||||||
user.Conn.AddHandler(user)
|
user.Conn.AddHandler(user)
|
||||||
return user.RestoreSession()
|
return user.RestoreSession()
|
||||||
|
Loading…
Reference in New Issue
Block a user