mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 00:03:09 -06:00
Persist the parent room_id/servers in edge metadata
Other events cannot assert the true room_id/servers for the parent event, only make claims to them, hence why this is edge metadata.
This commit is contained in:
parent
f33e2258f6
commit
b52a383250
|
|
@ -188,7 +188,7 @@ func eventRelationshipHandler(db Database, rsAPI roomserver.RoomserverInternalAP
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can the user see (according to history visibility) event_id? If no, reject the request, else continue.
|
// Can the user see (according to history visibility) event_id? If no, reject the request, else continue.
|
||||||
event := rc.getEventIfVisible(relation.EventID)
|
event := rc.getEventIfVisible(relation.EventID, nil)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 403,
|
Code: 403,
|
||||||
|
|
@ -249,7 +249,7 @@ func (rc *reqCtx) includeParent(event *gomatrixserverlib.HeaderedEvent) (parent
|
||||||
if parentID == "" {
|
if parentID == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return rc.getEventIfVisible(parentID)
|
return rc.getEventIfVisible(parentID, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If include_children: true, lookup all events which have event_id as an m.relationship
|
// If include_children: true, lookup all events which have event_id as an m.relationship
|
||||||
|
|
@ -264,7 +264,7 @@ func (rc *reqCtx) includeChildren(db Database, parentID string, limit int, recen
|
||||||
}
|
}
|
||||||
var childEvents []*gomatrixserverlib.HeaderedEvent
|
var childEvents []*gomatrixserverlib.HeaderedEvent
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
childEvent := rc.getEventIfVisible(child.EventID)
|
childEvent := rc.getEventIfVisible(child.EventID, nil)
|
||||||
if childEvent != nil {
|
if childEvent != nil {
|
||||||
childEvents = append(childEvents, childEvent)
|
childEvents = append(childEvents, childEvent)
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +302,7 @@ func walkThread(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the event.
|
// Process the event.
|
||||||
event := rc.getEventIfVisible(wi.EventID)
|
event := rc.getEventIfVisible(wi.EventID, nil)
|
||||||
if event != nil {
|
if event != nil {
|
||||||
result = append(result, event)
|
result = append(result, event)
|
||||||
}
|
}
|
||||||
|
|
@ -317,7 +317,7 @@ func walkThread(
|
||||||
return result, limited
|
return result, limited
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reqCtx) getEventIfVisible(eventID string) *gomatrixserverlib.HeaderedEvent {
|
func (rc *reqCtx) getEventIfVisible(eventID string, child *gomatrixserverlib.HeaderedEvent) *gomatrixserverlib.HeaderedEvent {
|
||||||
event, joinedToRoom := getEventIfVisible(rc.ctx, rc.rsAPI, eventID, rc.userID)
|
event, joinedToRoom := getEventIfVisible(rc.ctx, rc.rsAPI, eventID, rc.userID)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ type eventInfo struct {
|
||||||
EventID string
|
EventID string
|
||||||
OriginServerTS gomatrixserverlib.Timestamp
|
OriginServerTS gomatrixserverlib.Timestamp
|
||||||
RoomID string
|
RoomID string
|
||||||
|
Servers []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Database interface {
|
type Database interface {
|
||||||
|
|
@ -56,6 +57,8 @@ func newPostgresDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
||||||
parent_event_id TEXT NOT NULL,
|
parent_event_id TEXT NOT NULL,
|
||||||
child_event_id TEXT NOT NULL,
|
child_event_id TEXT NOT NULL,
|
||||||
rel_type TEXT NOT NULL,
|
rel_type TEXT NOT NULL,
|
||||||
|
parent_room_id TEXT NOT NULL,
|
||||||
|
parent_servers TEXT NOT NULL,
|
||||||
CONSTRAINT msc2836_edges_uniq UNIQUE (parent_event_id, child_event_id, rel_type)
|
CONSTRAINT msc2836_edges_uniq UNIQUE (parent_event_id, child_event_id, rel_type)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -69,7 +72,7 @@ func newPostgresDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if d.insertEdgeStmt, err = d.db.Prepare(`
|
if d.insertEdgeStmt, err = d.db.Prepare(`
|
||||||
INSERT INTO msc2836_edges(parent_event_id, child_event_id, rel_type) VALUES($1, $2, $3) ON CONFLICT DO NOTHING
|
INSERT INTO msc2836_edges(parent_event_id, child_event_id, rel_type, parent_room_id, parent_servers) VALUES($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +109,8 @@ func newSQLiteDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
||||||
parent_event_id TEXT NOT NULL,
|
parent_event_id TEXT NOT NULL,
|
||||||
child_event_id TEXT NOT NULL,
|
child_event_id TEXT NOT NULL,
|
||||||
rel_type TEXT NOT NULL,
|
rel_type TEXT NOT NULL,
|
||||||
|
parent_room_id TEXT NOT NULL,
|
||||||
|
parent_servers TEXT NOT NULL,
|
||||||
UNIQUE (parent_event_id, child_event_id, rel_type)
|
UNIQUE (parent_event_id, child_event_id, rel_type)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -119,7 +124,7 @@ func newSQLiteDatabase(dbOpts *config.DatabaseOptions) (Database, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if d.insertEdgeStmt, err = d.db.Prepare(`
|
if d.insertEdgeStmt, err = d.db.Prepare(`
|
||||||
INSERT INTO msc2836_edges(parent_event_id, child_event_id, rel_type) VALUES($1, $2, $3) ON CONFLICT (parent_event_id, child_event_id, rel_type) DO NOTHING
|
INSERT INTO msc2836_edges(parent_event_id, child_event_id, rel_type, parent_room_id, parent_servers) VALUES($1, $2, $3, $4, $5) ON CONFLICT (parent_event_id, child_event_id, rel_type) DO NOTHING
|
||||||
`); err != nil {
|
`); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -148,8 +153,13 @@ func (p *DB) StoreRelation(ctx context.Context, ev *gomatrixserverlib.HeaderedEv
|
||||||
if parent == "" || child == "" {
|
if parent == "" || child == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
relationRoomID, relationServers := roomIDAndServers(ev)
|
||||||
|
relationServersJSON, err := json.Marshal(relationServers)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return p.writer.Do(p.db, nil, func(txn *sql.Tx) error {
|
return p.writer.Do(p.db, nil, func(txn *sql.Tx) error {
|
||||||
_, err := txn.Stmt(p.insertEdgeStmt).ExecContext(ctx, parent, child, relType)
|
_, err := txn.Stmt(p.insertEdgeStmt).ExecContext(ctx, parent, child, relType, relationRoomID, string(relationServersJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -199,3 +209,18 @@ func parentChildEventIDs(ev *gomatrixserverlib.HeaderedEvent) (parent, child, re
|
||||||
}
|
}
|
||||||
return body.Relationship.EventID, ev.EventID(), body.Relationship.RelType
|
return body.Relationship.EventID, ev.EventID(), body.Relationship.RelType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func roomIDAndServers(ev *gomatrixserverlib.HeaderedEvent) (roomID string, servers []string) {
|
||||||
|
servers = []string{}
|
||||||
|
if ev == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
body := struct {
|
||||||
|
RoomID string `json:"relationship_room_id"`
|
||||||
|
Servers []string `json:"relationship_servers"`
|
||||||
|
}{}
|
||||||
|
if err := json.Unmarshal(ev.Unsigned(), &body); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return body.RoomID, body.Servers
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue