Automatically unbridge guild when leaving if it has no other Matrix users

This commit is contained in:
Tulir Asokan
2023-01-27 21:06:29 +02:00
parent 587cf8a17e
commit 7d959c92dc
5 changed files with 23 additions and 3 deletions

View File

@@ -96,6 +96,16 @@ func (u *User) MarkNotInPortal(discordID string) {
}
}
func (u *User) PortalHasOtherUsers(discordID string) (hasOtherUsers bool) {
query := `SELECT COUNT(*) > 0 FROM user_portal WHERE user_mxid<>$1 AND discord_id=$2`
err := u.db.QueryRow(query, u.MXID, discordID).Scan(&hasOtherUsers)
if err != nil {
u.log.Errorfln("Failed to check if %s has users other than %s: %v", discordID, u.MXID, err)
panic(err)
}
return
}
func (u *User) PrunePortalList(beforeTS time.Time) []UserPortal {
query := `
DELETE FROM user_portal