Create user_portal row when creating portal for new chat
Closes #273 Co-authored-by: dbedoya <dbedoya@ikono.com.co>
This commit is contained in:
parent
82ae61685c
commit
3d778a5a44
3 changed files with 17 additions and 2 deletions
|
@ -334,7 +334,8 @@ func (handler *CommandHandler) CommandCreate(ce *CommandEvent) {
|
|||
portal.UpdateBridgeInfo()
|
||||
|
||||
ce.Reply("Successfully created WhatsApp group %s", portal.Key.JID)
|
||||
ce.User.addPortalToCommunity(portal)
|
||||
inCommunity := ce.User.addPortalToCommunity(portal)
|
||||
ce.User.CreateUserPortal(database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
}
|
||||
|
||||
const cmdSetPowerLevelHelp = `set-pl [user ID] <power level> - Change the power level in a portal room. Only for bridge admins.`
|
||||
|
|
|
@ -245,3 +245,14 @@ func (user *User) GetInCommunityMap() map[PortalKey]bool {
|
|||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func (user *User) CreateUserPortal(newKey PortalKeyWithMeta) {
|
||||
user.log.Debugfln("Creating new portal %s for %s", newKey.PortalKey.JID, newKey.PortalKey.Receiver)
|
||||
_, err := user.db.Exec(`INSERT INTO user_portal (user_jid, portal_jid, portal_receiver, in_community) VALUES ($1, $2, $3, $4)`,
|
||||
user.jidPtr(),
|
||||
newKey.PortalKey.JID, newKey.PortalKey.Receiver,
|
||||
newKey.InCommunity)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to insert %s: %v", user.MXID, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1131,7 +1131,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
if broadcastMetadata != nil {
|
||||
portal.SyncBroadcastRecipients(broadcastMetadata)
|
||||
}
|
||||
user.addPortalToCommunity(portal)
|
||||
inCommunity := user.addPortalToCommunity(portal)
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
user.addPuppetToCommunity(puppet)
|
||||
|
@ -1145,6 +1145,9 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
|
||||
user.UpdateDirectChats(map[id.UserID][]id.RoomID{puppet.MXID: {portal.MXID}})
|
||||
}
|
||||
|
||||
user.CreateUserPortal(database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
|
||||
err = portal.FillInitialHistory(user)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to fill history:", err)
|
||||
|
|
Loading…
Reference in a new issue