Add user-portal mapping to database
This commit is contained in:
@ -42,7 +42,7 @@ func NewPortalKey(jid, receiver types.WhatsAppID) PortalKey {
|
||||
receiver = jid
|
||||
}
|
||||
return PortalKey{
|
||||
JID: jid,
|
||||
JID: jid,
|
||||
Receiver: receiver,
|
||||
}
|
||||
}
|
||||
@ -152,3 +152,26 @@ func (portal *Portal) Delete() {
|
||||
portal.log.Warnfln("Failed to delete %s: %v", portal.Key, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) GetUserIDs() []types.MatrixUserID {
|
||||
rows, err := portal.db.Query(`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)
|
||||
if err != nil {
|
||||
portal.log.Debugln("Failed to get portal user ids:", err)
|
||||
return nil
|
||||
}
|
||||
var userIDs []types.MatrixUserID
|
||||
for rows.Next() {
|
||||
var userID types.MatrixUserID
|
||||
err = rows.Scan(&userID)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to scan row:", err)
|
||||
continue
|
||||
}
|
||||
userIDs = append(userIDs, userID)
|
||||
}
|
||||
return userIDs
|
||||
}
|
||||
|
Reference in New Issue
Block a user