backfill: delete messages for rooms the user is not in

If the chat turns out to be not bridgable due to the user not being in
the room, delete the messages, and stop trying to backfill it.
This commit is contained in:
Sumner Evans 2022-04-27 08:29:15 -06:00
parent 2afdf80937
commit caf0a363c9
No known key found for this signature in database
GPG key ID: 8904527AB50022FD
3 changed files with 22 additions and 0 deletions

View file

@ -106,6 +106,16 @@ func (bq *BackfillQuery) DeleteAll(userID id.UserID) error {
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 {
db *Database
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)
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

@ -1226,6 +1226,8 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, i
// 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)