forked from MirrorHub/mautrix-whatsapp
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:
parent
2afdf80937
commit
caf0a363c9
3 changed files with 22 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue