Fix filtering issue

Signed-off-by: Till Faelligen <2353100+S7evinK@users.noreply.github.com>
This commit is contained in:
Till Faelligen 2025-06-05 20:35:30 +02:00
parent ee42cb48a4
commit 7e5e7dc34b
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
2 changed files with 78 additions and 68 deletions

View file

@ -46,7 +46,7 @@ func prepareWithFilters(
params, offset = append(params, v), offset+1 params, offset = append(params, v), offset+1
} }
} else { } else {
query += ` AND sender NOT = ""` query += ` AND sender != ""`
} }
} }
if types != nil { if types != nil {
@ -66,7 +66,7 @@ func prepareWithFilters(
params, offset = append(params, v), offset+1 params, offset = append(params, v), offset+1
} }
} else { } else {
query += ` AND type NOT = ""` query += ` AND type != ""`
} }
} }
if containsURL != nil { if containsURL != nil {

View file

@ -548,6 +548,13 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
DisplayName: "BOB", DisplayName: "BOB",
} }
filters := []string{
// check that lazy loading doesn't break history visibility
`{"lazy_load_members":true}`,
// Test that using "not" filters does not break in SQLite
`{"lazy_load_members":true,"types":null,"not_types":[],"rooms":null,"not_rooms":[],"senders":null,"not_senders":[],"contains_url":null,"io.element.relation_senders":[],"io.element.relation_types":["io.element.thread"]}`,
}
ctx := context.Background() ctx := context.Background()
// check guest and normal user accounts // check guest and normal user accounts
for _, accType := range []userapi.AccountType{userapi.AccountTypeGuest, userapi.AccountTypeUser} { for _, accType := range []userapi.AccountType{userapi.AccountTypeGuest, userapi.AccountTypeUser} {
@ -614,6 +621,8 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
for _, tc := range testCases { for _, tc := range testCases {
testname := fmt.Sprintf("%s - %s", tc.historyVisibility, userType) testname := fmt.Sprintf("%s - %s", tc.historyVisibility, userType)
t.Run(testname, func(t *testing.T) { t.Run(testname, func(t *testing.T) {
for _, filter := range filters {
t.Logf("Using filter: %s", filter)
// create a room with the given visibility // create a room with the given visibility
room := test.NewRoom(t, alice, test.RoomHistoryVisibility(tc.historyVisibility)) room := test.NewRoom(t, alice, test.RoomHistoryVisibility(tc.historyVisibility))
@ -636,7 +645,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
routers.Client.ServeHTTP(w, test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/messages", room.ID), test.WithQueryParams(map[string]string{ routers.Client.ServeHTTP(w, test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/messages", room.ID), test.WithQueryParams(map[string]string{
"access_token": bobDev.AccessToken, "access_token": bobDev.AccessToken,
"dir": "b", "dir": "b",
"filter": `{"lazy_load_members":true}`, // check that lazy loading doesn't break history visibility "filter": filter,
}))) })))
if w.Code != 200 { if w.Code != 200 {
t.Logf("%s", w.Body.String()) t.Logf("%s", w.Body.String())
@ -687,6 +696,7 @@ func testHistoryVisibility(t *testing.T, dbType test.DBType) {
// verify results // verify results
verifyEventVisible(t, tc.wantResult.seeBeforeJoin, beforeJoinEv, res.Chunk) verifyEventVisible(t, tc.wantResult.seeBeforeJoin, beforeJoinEv, res.Chunk)
verifyEventVisible(t, tc.wantResult.seeAfterInvite, afterInviteEv, res.Chunk) verifyEventVisible(t, tc.wantResult.seeAfterInvite, afterInviteEv, res.Chunk)
}
}) })
} }
} }