mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 17:33:09 -06:00
Handling "m.room.*" type filters
Signed-off-by: Thibaut CHARLES cromfr@gmail.com
This commit is contained in:
parent
65e36484d6
commit
4ef80a4e48
|
|
@ -69,10 +69,10 @@ const selectRoomIDsWithMembershipSQL = "" +
|
||||||
|
|
||||||
const selectCurrentStateSQL = "" +
|
const selectCurrentStateSQL = "" +
|
||||||
"SELECT event_json FROM syncapi_current_room_state WHERE room_id = $1" +
|
"SELECT event_json FROM syncapi_current_room_state WHERE room_id = $1" +
|
||||||
" AND ( $2::text[] IS NULL OR sender = ANY($2) )" +
|
" AND ( $2::text[] IS NULL OR sender = ANY($2) )" +
|
||||||
" AND ( $3::text[] IS NULL OR NOT(sender = ANY($3)) )" +
|
" AND ( $3::text[] IS NULL OR NOT(sender = ANY($3)) )" +
|
||||||
" AND ( $4::text[] IS NULL OR type = ANY($4) )" +
|
" AND ( $4::text[] IS NULL OR type LIKE ANY($4) )" +
|
||||||
" AND ( $5::text[] IS NULL OR NOT(type = ANY($5)) )"
|
" AND ( $5::text[] IS NULL OR NOT(type LIKE ANY($5)) )"
|
||||||
|
|
||||||
const selectJoinedUsersSQL = "" +
|
const selectJoinedUsersSQL = "" +
|
||||||
"SELECT room_id, state_key FROM syncapi_current_room_state WHERE type = 'm.room.member' AND membership = 'join'"
|
"SELECT room_id, state_key FROM syncapi_current_room_state WHERE type = 'm.room.member' AND membership = 'join'"
|
||||||
|
|
@ -187,8 +187,8 @@ func (s *currentRoomStateStatements) selectCurrentState(
|
||||||
rows, err := stmt.QueryContext(ctx, roomID,
|
rows, err := stmt.QueryContext(ctx, roomID,
|
||||||
pq.StringArray(filter.Senders),
|
pq.StringArray(filter.Senders),
|
||||||
pq.StringArray(filter.NotSenders),
|
pq.StringArray(filter.NotSenders),
|
||||||
pq.StringArray(filter.Types),
|
pq.StringArray(filterConvertWildcardToSQL(filter.Types)),
|
||||||
pq.StringArray(filter.NotTypes))
|
pq.StringArray(filterConvertWildcardToSQL(filter.NotTypes)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -46,3 +48,11 @@ func hasValue(value string, list []string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterConvertWildcardToSQL(values []string) []string {
|
||||||
|
ret := make([]string, len(values))
|
||||||
|
for i := range values {
|
||||||
|
ret[i] = strings.Replace(values[i], "*", "%", -1)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,10 +75,10 @@ const selectRoomRecentEventsSQL = "" +
|
||||||
"SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" +
|
"SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" +
|
||||||
" WHERE room_id=$1 " +
|
" WHERE room_id=$1 " +
|
||||||
" AND id > $2 AND id <= $3" +
|
" AND id > $2 AND id <= $3" +
|
||||||
" AND ( $4::text[] IS NULL OR sender = ANY($4) )" +
|
" AND ( $4::text[] IS NULL OR sender = ANY($4) )" +
|
||||||
" AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" +
|
" AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" +
|
||||||
" AND ( $6::text[] IS NULL OR type = ANY($6) )" +
|
" AND ( $6::text[] IS NULL OR type LIKE ANY($6) )" +
|
||||||
" AND ( $7::text[] IS NULL OR NOT(type = ANY($7)) )" +
|
" AND ( $7::text[] IS NULL OR NOT(type LIKE ANY($7)) )" +
|
||||||
" ORDER BY id DESC LIMIT $8"
|
" ORDER BY id DESC LIMIT $8"
|
||||||
|
|
||||||
const selectMaxEventIDSQL = "" +
|
const selectMaxEventIDSQL = "" +
|
||||||
|
|
@ -244,8 +244,8 @@ func (s *outputRoomEventsStatements) selectRoomRecentEvents(
|
||||||
rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos,
|
rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos,
|
||||||
pq.StringArray(timelineFilter.Senders),
|
pq.StringArray(timelineFilter.Senders),
|
||||||
pq.StringArray(timelineFilter.NotSenders),
|
pq.StringArray(timelineFilter.NotSenders),
|
||||||
pq.StringArray(timelineFilter.Types),
|
pq.StringArray(filterConvertWildcardToSQL(timelineFilter.Types)),
|
||||||
pq.StringArray(timelineFilter.NotTypes),
|
pq.StringArray(filterConvertWildcardToSQL(timelineFilter.NotTypes)),
|
||||||
timelineFilter.Limit+1, // TODO: limit abusive values? This can also be done in gomatrix.Filter.Validate
|
timelineFilter.Limit+1, // TODO: limit abusive values? This can also be done in gomatrix.Filter.Validate
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue