mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 00:03:09 -06:00
guts to pass through room_id/servers
This commit is contained in:
parent
b52a383250
commit
37790d6c68
|
|
@ -188,7 +188,8 @@ 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, nil)
|
// We should have the event being referenced so don't give any claimed room ID / servers
|
||||||
|
event := rc.getEventIfVisible(relation.EventID, "", nil)
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 403,
|
Code: 403,
|
||||||
|
|
@ -249,7 +250,8 @@ func (rc *reqCtx) includeParent(event *gomatrixserverlib.HeaderedEvent) (parent
|
||||||
if parentID == "" {
|
if parentID == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return rc.getEventIfVisible(parentID, event)
|
claimedRoomID, claimedServers := roomIDAndServers(event)
|
||||||
|
return rc.getEventIfVisible(parentID, claimedRoomID, claimedServers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 +266,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, nil)
|
childEvent := rc.getEventIfVisible(child.EventID, child.RoomID, child.Servers)
|
||||||
if childEvent != nil {
|
if childEvent != nil {
|
||||||
childEvents = append(childEvents, childEvent)
|
childEvents = append(childEvents, childEvent)
|
||||||
}
|
}
|
||||||
|
|
@ -302,7 +304,7 @@ func walkThread(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the event.
|
// Process the event.
|
||||||
event := rc.getEventIfVisible(wi.EventID, nil)
|
event := rc.getEventIfVisible(wi.EventID, "", nil)
|
||||||
if event != nil {
|
if event != nil {
|
||||||
result = append(result, event)
|
result = append(result, event)
|
||||||
}
|
}
|
||||||
|
|
@ -317,29 +319,39 @@ func walkThread(
|
||||||
return result, limited
|
return result, limited
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reqCtx) getEventIfVisible(eventID string, child *gomatrixserverlib.HeaderedEvent) *gomatrixserverlib.HeaderedEvent {
|
func (rc *reqCtx) getEventIfVisible(eventID string, claimedRoomID string, claimedServers []string) *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 && joinedToRoom {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if joinedToRoom {
|
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
if rc.req.AutoJoin {
|
// either we don't have the event or we aren't joined to the room, regardless we should try joining if auto join is enabled
|
||||||
|
if !rc.req.AutoJoin {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
roomID := claimedRoomID
|
||||||
|
var servers []gomatrixserverlib.ServerName
|
||||||
|
if event != nil {
|
||||||
|
roomID = event.RoomID()
|
||||||
|
}
|
||||||
|
for _, s := range claimedServers {
|
||||||
|
servers = append(servers, gomatrixserverlib.ServerName(s))
|
||||||
|
}
|
||||||
var joinRes roomserver.PerformJoinResponse
|
var joinRes roomserver.PerformJoinResponse
|
||||||
rc.rsAPI.PerformJoin(rc.ctx, &roomserver.PerformJoinRequest{
|
rc.rsAPI.PerformJoin(rc.ctx, &roomserver.PerformJoinRequest{
|
||||||
UserID: rc.userID,
|
UserID: rc.userID,
|
||||||
Content: map[string]interface{}{},
|
Content: map[string]interface{}{},
|
||||||
RoomIDOrAlias: event.RoomID(),
|
RoomIDOrAlias: roomID,
|
||||||
// TODO: Add server_names from linked room, currently this join will only work if the HS is already in the room
|
ServerNames: servers,
|
||||||
}, &joinRes)
|
}, &joinRes)
|
||||||
if joinRes.Error != nil {
|
if joinRes.Error != nil {
|
||||||
util.GetLogger(rc.ctx).WithError(joinRes.Error).WithField("room_id", event.RoomID()).Error("Failed to auto-join room")
|
util.GetLogger(rc.ctx).WithError(joinRes.Error).WithField("room_id", roomID).Error("Failed to auto-join room")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if event != nil {
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
util.GetLogger(rc.ctx).Infof("user not in room and auto_join disabled")
|
// TODO: fetch the event in question
|
||||||
|
util.GetLogger(rc.ctx).Infof("joined room but need to fetch event TODO")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue