mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 21:12:45 +00:00
Implement history visibility on /messages
, /context
, /sync
(#2511)
* Add possibility to set history_visibility and user AccountType * Add new DB queries * Add actual history_visibility changes for /messages * Add passing tests * Extract check function * Cleanup * Cleanup * Fix build on 386 * Move ApplyHistoryVisibilityFilter to internal * Move queries to topology table * Add filtering to /sync and /context Some cleanup * Add passing tests; Remove failing tests :( * Re-add passing tests * Move filtering to own function to avoid duplication * Re-add passing test * Use newly added GMSL HistoryVisibility * Update gomatrixserverlib * Set the visibility when creating events * Default to shared history visibility * Remove unused query * Update history visibility checks to use gmsl Update tests * Remove unused statement * Update migrations to set "correct" history visibility * Add method to fetch the membership at a given event * Tweaks and logging * Use actual internal rsAPI, default to shared visibility in tests * Revert "Move queries to topology table" This reverts commit 4f0d41be9c194a46379796435ce73e79203edbd6. * Remove noise/unneeded code * More cleanup * Try to optimize database requests * Fix imports * PR peview fixes/changes * Move setting history visibility to own migration, be more restrictive * Fix unit tests * Lint * Fix missing entries * Tweaks for incremental syncs * Adapt generic changes Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com> Co-authored-by: kegsay <kegan@matrix.org>
This commit is contained in:
parent
371336c6b5
commit
05cafbd197
31 changed files with 1043 additions and 224 deletions
28
test/room.go
28
test/room.go
|
@ -37,10 +37,11 @@ var (
|
|||
)
|
||||
|
||||
type Room struct {
|
||||
ID string
|
||||
Version gomatrixserverlib.RoomVersion
|
||||
preset Preset
|
||||
creator *User
|
||||
ID string
|
||||
Version gomatrixserverlib.RoomVersion
|
||||
preset Preset
|
||||
visibility gomatrixserverlib.HistoryVisibility
|
||||
creator *User
|
||||
|
||||
authEvents gomatrixserverlib.AuthEvents
|
||||
currentState map[string]*gomatrixserverlib.HeaderedEvent
|
||||
|
@ -61,6 +62,7 @@ func NewRoom(t *testing.T, creator *User, modifiers ...roomModifier) *Room {
|
|||
preset: PresetPublicChat,
|
||||
Version: gomatrixserverlib.RoomVersionV9,
|
||||
currentState: make(map[string]*gomatrixserverlib.HeaderedEvent),
|
||||
visibility: gomatrixserverlib.HistoryVisibilityShared,
|
||||
}
|
||||
for _, m := range modifiers {
|
||||
m(t, r)
|
||||
|
@ -97,10 +99,14 @@ func (r *Room) insertCreateEvents(t *testing.T) {
|
|||
fallthrough
|
||||
case PresetPrivateChat:
|
||||
joinRule.JoinRule = "invite"
|
||||
hisVis.HistoryVisibility = "shared"
|
||||
hisVis.HistoryVisibility = gomatrixserverlib.HistoryVisibilityShared
|
||||
case PresetPublicChat:
|
||||
joinRule.JoinRule = "public"
|
||||
hisVis.HistoryVisibility = "shared"
|
||||
hisVis.HistoryVisibility = gomatrixserverlib.HistoryVisibilityShared
|
||||
}
|
||||
|
||||
if r.visibility != "" {
|
||||
hisVis.HistoryVisibility = r.visibility
|
||||
}
|
||||
|
||||
r.CreateAndInsert(t, r.creator, gomatrixserverlib.MRoomCreate, map[string]interface{}{
|
||||
|
@ -183,7 +189,9 @@ func (r *Room) CreateEvent(t *testing.T, creator *User, eventType string, conten
|
|||
if err = gomatrixserverlib.Allowed(ev, &r.authEvents); err != nil {
|
||||
t.Fatalf("CreateEvent[%s]: failed to verify event was allowed: %s", eventType, err)
|
||||
}
|
||||
return ev.Headered(r.Version)
|
||||
headeredEvent := ev.Headered(r.Version)
|
||||
headeredEvent.Visibility = r.visibility
|
||||
return headeredEvent
|
||||
}
|
||||
|
||||
// Add a new event to this room DAG. Not thread-safe.
|
||||
|
@ -242,6 +250,12 @@ func RoomPreset(p Preset) roomModifier {
|
|||
}
|
||||
}
|
||||
|
||||
func RoomHistoryVisibility(vis gomatrixserverlib.HistoryVisibility) roomModifier {
|
||||
return func(t *testing.T, r *Room) {
|
||||
r.visibility = vis
|
||||
}
|
||||
}
|
||||
|
||||
func RoomVersion(ver gomatrixserverlib.RoomVersion) roomModifier {
|
||||
return func(t *testing.T, r *Room) {
|
||||
r.Version = ver
|
||||
|
|
10
test/user.go
10
test/user.go
|
@ -20,6 +20,7 @@ import (
|
|||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
|
@ -45,7 +46,8 @@ var (
|
|||
)
|
||||
|
||||
type User struct {
|
||||
ID string
|
||||
ID string
|
||||
accountType api.AccountType
|
||||
// key ID and private key of the server who has this user, if known.
|
||||
keyID gomatrixserverlib.KeyID
|
||||
privKey ed25519.PrivateKey
|
||||
|
@ -62,6 +64,12 @@ func WithSigningServer(srvName gomatrixserverlib.ServerName, keyID gomatrixserve
|
|||
}
|
||||
}
|
||||
|
||||
func WithAccountType(accountType api.AccountType) UserOpt {
|
||||
return func(u *User) {
|
||||
u.accountType = accountType
|
||||
}
|
||||
}
|
||||
|
||||
func NewUser(t *testing.T, opts ...UserOpt) *User {
|
||||
counter := atomic.AddInt64(&userIDCounter, 1)
|
||||
var u User
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue