mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 09:23: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
|
|
@ -71,8 +71,8 @@ const selectCurrentStateSQL = "" +
|
|||
"SELECT event_json FROM syncapi_current_room_state WHERE room_id = $1" +
|
||||
" AND ( $2::text[] IS NULL OR sender = ANY($2) )" +
|
||||
" AND ( $3::text[] IS NULL OR NOT(sender = ANY($3)) )" +
|
||||
" AND ( $4::text[] IS NULL OR type = ANY($4) )" +
|
||||
" AND ( $5::text[] IS NULL OR NOT(type = ANY($5)) )"
|
||||
" AND ( $4::text[] IS NULL OR type LIKE ANY($4) )" +
|
||||
" AND ( $5::text[] IS NULL OR NOT(type LIKE ANY($5)) )"
|
||||
|
||||
const selectJoinedUsersSQL = "" +
|
||||
"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,
|
||||
pq.StringArray(filter.Senders),
|
||||
pq.StringArray(filter.NotSenders),
|
||||
pq.StringArray(filter.Types),
|
||||
pq.StringArray(filter.NotTypes))
|
||||
pq.StringArray(filterConvertWildcardToSQL(filter.Types)),
|
||||
pq.StringArray(filterConvertWildcardToSQL(filter.NotTypes)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/matrix-org/gomatrix"
|
||||
)
|
||||
|
||||
|
|
@ -46,3 +48,11 @@ func hasValue(value string, list []string) bool {
|
|||
}
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ const selectRoomRecentEventsSQL = "" +
|
|||
" AND id > $2 AND id <= $3" +
|
||||
" AND ( $4::text[] IS NULL OR sender = ANY($4) )" +
|
||||
" AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" +
|
||||
" AND ( $6::text[] IS NULL OR type = ANY($6) )" +
|
||||
" AND ( $7::text[] IS NULL OR NOT(type = ANY($7)) )" +
|
||||
" AND ( $6::text[] IS NULL OR type LIKE ANY($6) )" +
|
||||
" AND ( $7::text[] IS NULL OR NOT(type LIKE ANY($7)) )" +
|
||||
" ORDER BY id DESC LIMIT $8"
|
||||
|
||||
const selectMaxEventIDSQL = "" +
|
||||
|
|
@ -244,8 +244,8 @@ func (s *outputRoomEventsStatements) selectRoomRecentEvents(
|
|||
rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos,
|
||||
pq.StringArray(timelineFilter.Senders),
|
||||
pq.StringArray(timelineFilter.NotSenders),
|
||||
pq.StringArray(timelineFilter.Types),
|
||||
pq.StringArray(timelineFilter.NotTypes),
|
||||
pq.StringArray(filterConvertWildcardToSQL(timelineFilter.Types)),
|
||||
pq.StringArray(filterConvertWildcardToSQL(timelineFilter.NotTypes)),
|
||||
timelineFilter.Limit+1, // TODO: limit abusive values? This can also be done in gomatrix.Filter.Validate
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue