mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-15 12:13:43 +01:00
MSC2946: Use new MSC1772 format for space parents (#1713)
This commit is contained in:
parent
2626525c65
commit
5366c33885
3 changed files with 14 additions and 23 deletions
|
@ -36,7 +36,7 @@ import (
|
||||||
const (
|
const (
|
||||||
ConstCreateEventContentKey = "org.matrix.msc1772.type"
|
ConstCreateEventContentKey = "org.matrix.msc1772.type"
|
||||||
ConstSpaceChildEventType = "org.matrix.msc1772.space.child"
|
ConstSpaceChildEventType = "org.matrix.msc1772.space.child"
|
||||||
ConstSpaceParentEventType = "org.matrix.msc1772.room.parent"
|
ConstSpaceParentEventType = "org.matrix.msc1772.space.parent"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SpacesRequest is the request body to POST /_matrix/client/r0/rooms/{roomID}/spaces
|
// SpacesRequest is the request body to POST /_matrix/client/r0/rooms/{roomID}/spaces
|
||||||
|
@ -57,7 +57,7 @@ type SpacesResponse struct {
|
||||||
NextBatch string `json:"next_batch"`
|
NextBatch string `json:"next_batch"`
|
||||||
// Rooms are nodes on the space graph.
|
// Rooms are nodes on the space graph.
|
||||||
Rooms []Room `json:"rooms"`
|
Rooms []Room `json:"rooms"`
|
||||||
// Events are edges on the space graph, exclusively m.space.child or m.room.parent events
|
// Events are edges on the space graph, exclusively m.space.child or m.space.parent events
|
||||||
Events []gomatrixserverlib.ClientEvent `json:"events"`
|
Events []gomatrixserverlib.ClientEvent `json:"events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,8 +182,8 @@ func (w *walker) walk() *SpacesResponse {
|
||||||
if !w.authorised(roomID) {
|
if !w.authorised(roomID) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Get all `m.space.child` and `m.room.parent` state events for the room. *In addition*, get
|
// Get all `m.space.child` and `m.space.parent` state events for the room. *In addition*, get
|
||||||
// all `m.space.child` and `m.room.parent` state events which *point to* (via `state_key` or `content.room_id`)
|
// all `m.space.child` and `m.space.parent` state events which *point to* (via `state_key` or `content.room_id`)
|
||||||
// this room. This requires servers to store reverse lookups.
|
// this room. This requires servers to store reverse lookups.
|
||||||
refs, err := w.references(roomID)
|
refs, err := w.references(roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -196,7 +196,7 @@ func (w *walker) walk() *SpacesResponse {
|
||||||
if !w.alreadySent(roomID) {
|
if !w.alreadySent(roomID) {
|
||||||
pubRoom := w.publicRoomsChunk(roomID)
|
pubRoom := w.publicRoomsChunk(roomID)
|
||||||
roomType := ""
|
roomType := ""
|
||||||
create := w.stateEvent(roomID, "m.room.create", "")
|
create := w.stateEvent(roomID, gomatrixserverlib.MRoomCreate, "")
|
||||||
if create != nil {
|
if create != nil {
|
||||||
roomType = gjson.GetBytes(create.Content(), ConstCreateEventContentKey).Str
|
roomType = gjson.GetBytes(create.Content(), ConstCreateEventContentKey).Str
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &room1,
|
StateKey: &room1,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
rootToR2 := mustCreateEvent(t, fledglingEvent{
|
rootToR2 := mustCreateEvent(t, fledglingEvent{
|
||||||
|
@ -96,8 +95,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &room2,
|
StateKey: &room2,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
rootToS1 := mustCreateEvent(t, fledglingEvent{
|
rootToS1 := mustCreateEvent(t, fledglingEvent{
|
||||||
|
@ -106,8 +104,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &subSpaceS1,
|
StateKey: &subSpaceS1,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
s1ToR3 := mustCreateEvent(t, fledglingEvent{
|
s1ToR3 := mustCreateEvent(t, fledglingEvent{
|
||||||
|
@ -116,8 +113,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &room3,
|
StateKey: &room3,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
s1ToR4 := mustCreateEvent(t, fledglingEvent{
|
s1ToR4 := mustCreateEvent(t, fledglingEvent{
|
||||||
|
@ -126,8 +122,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &room4,
|
StateKey: &room4,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
s1ToS2 := mustCreateEvent(t, fledglingEvent{
|
s1ToS2 := mustCreateEvent(t, fledglingEvent{
|
||||||
|
@ -136,8 +131,7 @@ func TestMSC2946(t *testing.T) {
|
||||||
Type: msc2946.ConstSpaceChildEventType,
|
Type: msc2946.ConstSpaceChildEventType,
|
||||||
StateKey: &subSpaceS2,
|
StateKey: &subSpaceS2,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"via": []string{"localhost"},
|
"via": []string{"localhost"},
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// This is a parent link only
|
// This is a parent link only
|
||||||
|
@ -145,11 +139,9 @@ func TestMSC2946(t *testing.T) {
|
||||||
RoomID: room5,
|
RoomID: room5,
|
||||||
Sender: alice,
|
Sender: alice,
|
||||||
Type: msc2946.ConstSpaceParentEventType,
|
Type: msc2946.ConstSpaceParentEventType,
|
||||||
StateKey: &empty,
|
StateKey: &subSpaceS2,
|
||||||
Content: map[string]interface{}{
|
Content: map[string]interface{}{
|
||||||
"room_id": subSpaceS2,
|
"via": []string{"localhost"},
|
||||||
"via": []string{"localhost"},
|
|
||||||
"present": true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// history visibility for R4
|
// history visibility for R4
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -175,7 +174,7 @@ func SpaceTarget(he *gomatrixserverlib.HeaderedEvent) string {
|
||||||
}
|
}
|
||||||
switch he.Type() {
|
switch he.Type() {
|
||||||
case ConstSpaceParentEventType:
|
case ConstSpaceParentEventType:
|
||||||
return gjson.GetBytes(he.Content(), "room_id").Str
|
return *he.StateKey()
|
||||||
case ConstSpaceChildEventType:
|
case ConstSpaceChildEventType:
|
||||||
return *he.StateKey()
|
return *he.StateKey()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue