diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go index d646a0e41..d202183a9 100644 --- a/syncapi/storage/postgres/current_room_state_table.go +++ b/syncapi/storage/postgres/current_room_state_table.go @@ -75,7 +75,7 @@ const DeleteRoomStateForRoomSQL = "" + "DELETE FROM syncapi_current_room_state WHERE event_id = $1" const selectRoomIDsWithMembershipSQL = "" + - "SELECT DISTINCT room_id FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = $1 AND membership = $2" + "SELECT DISTINCT room_id FROM syncapi_current_room_state WHERE (type = 'm.room.member' AND state_key = $1 AND membership = $2) OR sender = $1" const selectRoomIDsWithAnyMembershipSQL = "" + "SELECT DISTINCT room_id, membership FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = $1" diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go index 587f9d240..81c0d694e 100644 --- a/syncapi/storage/sqlite3/current_room_state_table.go +++ b/syncapi/storage/sqlite3/current_room_state_table.go @@ -64,7 +64,7 @@ const DeleteRoomStateForRoomSQL = "" + "DELETE FROM syncapi_current_room_state WHERE event_id = $1" const selectRoomIDsWithMembershipSQL = "" + - "SELECT DISTINCT room_id FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = $1 AND membership = $2" + "SELECT DISTINCT room_id FROM syncapi_current_room_state WHERE (type = 'm.room.member' AND state_key = $1 AND membership = $2) OR sender = $3" const selectRoomIDsWithAnyMembershipSQL = "" + "SELECT DISTINCT room_id, membership FROM syncapi_current_room_state WHERE type = 'm.room.member' AND state_key = $1" @@ -165,7 +165,7 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership( membership string, // nolint: unparam ) ([]string, error) { stmt := sqlutil.TxStmt(txn, s.selectRoomIDsWithMembershipStmt) - rows, err := stmt.QueryContext(ctx, userID, membership) + rows, err := stmt.QueryContext(ctx, userID, membership, userID) if err != nil { return nil, err }