Merge pull request #483 from mautrix/sumner/bri-3038

backfill: skip chats if the user is not a participant
This commit is contained in:
Sumner Evans 2022-04-27 08:32:35 -06:00 committed by GitHub
commit 2259b5007f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -106,6 +106,16 @@ func (bq *BackfillQuery) DeleteAll(userID id.UserID) error {
return err return err
} }
func (bq *BackfillQuery) DeleteAllForPortal(userID id.UserID, portalKey PortalKey) error {
_, err := bq.db.Exec(`
DELETE FROM backfill_queue
WHERE user_mxid=$1
AND portal_jid=$2
AND portal_receiver=$3
`, userID, portalKey.JID, portalKey.Receiver)
return err
}
type Backfill struct { type Backfill struct {
db *Database db *Database
log log.Logger log log.Logger

View file

@ -314,3 +314,13 @@ func (hsq *HistorySyncQuery) DeleteAllMessages(userID id.UserID) error {
_, err := hsq.db.Exec("DELETE FROM history_sync_message WHERE user_mxid=$1", userID) _, err := hsq.db.Exec("DELETE FROM history_sync_message WHERE user_mxid=$1", userID)
return err return err
} }
func (hsq *HistorySyncQuery) DeleteAllMessagesForPortal(userID id.UserID, portalKey PortalKey) error {
_, err := hsq.db.Exec(`
DELETE FROM history_sync_message
WHERE user_mxid=$1
AND portal_jid=$2
AND portal_receiver=$3
`, userID, portalKey.JID, portalKey.Receiver)
return err
}

View file

@ -1221,7 +1221,15 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i
} else { } else {
if groupInfo == nil || !isFullInfo { if groupInfo == nil || !isFullInfo {
foundInfo, err := user.Client.GetGroupInfo(portal.Key.JID) foundInfo, err := user.Client.GetGroupInfo(portal.Key.JID)
if err != nil {
// Ensure that the user is actually a participant in the conversation
// before creating the matrix room
if errors.Is(err, whatsmeow.ErrNotInGroup) {
user.log.Debugfln("Skipping creating matrix room for %s because the user is not a participant", portal.Key.JID)
user.bridge.DB.BackfillQuery.DeleteAllForPortal(user.MXID, portal.Key)
user.bridge.DB.HistorySyncQuery.DeleteAllMessagesForPortal(user.MXID, portal.Key)
return err
} else if err != nil {
portal.log.Warnfln("Failed to get group info through %s: %v", user.JID, err) portal.log.Warnfln("Failed to get group info through %s: %v", user.JID, err)
} else { } else {
groupInfo = foundInfo groupInfo = foundInfo