0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-12-14 13:03:51 +01:00

Add invites to /sync responses (#103)

This commit is contained in:
Kegsay 2017-05-15 17:41:54 +01:00 committed by GitHub
parent 94e1c62745
commit 675759c192
3 changed files with 50 additions and 6 deletions

View file

@ -508,6 +508,35 @@ func main() {
// $ curl -XPUT -d '{"name":"A Different Custom Room Name"}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/state/m.room.name?access_token=@alice:localhost"
// $ curl -XPUT -d '{"msgtype":"m.text","body":"hello bob"}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/send/m.room.message/2?access_token=@alice:localhost"
// $ curl -XPUT -d '{"membership":"invite"}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/state/m.room.member/@charlie:localhost?access_token=@bob:localhost"
if err := exe.WriteToTopic(inputTopic, canonicalJSONInput(outputRoomEventTestData[11:14])); err != nil {
panic(err)
}
// Make sure charlie sees the invite both with and without a ?since= token
// TODO: Invite state should include the invite event and the room name.
charlieInviteData := `{
"account_data": {
"events": []
},
"next_batch": "14",
"presence": {
"events": []
},
"rooms": {
"invite": {
"!PjrbIMW2cIiaYF4t:localhost": {
"invite_state": {
"events": []
}
}
},
"join": {},
"leave": {}
}
}`
testSyncServer(syncServerCmdChan, "@charlie:localhost", "7", charlieInviteData)
testSyncServer(syncServerCmdChan, "@charlie:localhost", "", charlieInviteData)
// $ curl -XPUT -d '{"membership":"join"}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/state/m.room.member/@charlie:localhost?access_token=@charlie:localhost"
// $ curl -XPUT -d '{"msgtype":"m.text","body":"not charlie..."}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/send/m.room.message/3?access_token=@alice:localhost"
// $ curl -XPUT -d '{"membership":"leave"}' "http://localhost:8009/_matrix/client/r0/rooms/%21PjrbIMW2cIiaYF4t:localhost/state/m.room.member/@charlie:localhost?access_token=@alice:localhost"

View file

@ -132,7 +132,7 @@ func (d *SyncServerDatabase) IncrementalSync(userID string, fromPos, toPos types
// - For each room which has membership list changes:
// * Check if the room is 'newly joined' (insufficient to just check for a join event because we allow dupe joins TODO).
// If it is, then we need to send the full room state down (and 'limited' is always true).
// * TODO Check if user is still CURRENTLY invited to the room. If so, add room to 'invited' block.
// * Check if user is still CURRENTLY invited to the room. If so, add room to 'invited' block.
// * TODO Check if the user is CURRENTLY left/banned. If so, add room to 'archived' block.
// work out which rooms transitioned to 'joined' between the 2 stream positions and add full state where needed.
@ -175,7 +175,8 @@ func (d *SyncServerDatabase) IncrementalSync(userID string, fromPos, toPos types
jr.State.Events = gomatrixserverlib.ToClientEvents(state[roomID], gomatrixserverlib.FormatSync)
res.Rooms.Join[roomID] = *jr
}
return nil
return d.addInvitesToResponse(txn, userID, res)
})
return
}
@ -200,7 +201,7 @@ func (d *SyncServerDatabase) CompleteSync(userID string, numRecentEventsPerRoom
return err
}
// Build up a /sync response
// Build up a /sync response. Add joined rooms.
res = types.NewResponse(pos)
for _, roomID := range roomIDs {
stateEvents, err := d.roomstate.CurrentState(txn, roomID)
@ -221,12 +222,26 @@ func (d *SyncServerDatabase) CompleteSync(userID string, numRecentEventsPerRoom
jr.State.Events = gomatrixserverlib.ToClientEvents(stateEvents, gomatrixserverlib.FormatSync)
res.Rooms.Join[roomID] = *jr
}
// TODO: Add invites!
return nil
return d.addInvitesToResponse(txn, userID, res)
})
return
}
func (d *SyncServerDatabase) addInvitesToResponse(txn *sql.Tx, userID string, res *types.Response) error {
// Add invites - TODO: This will break over federation as they won't be in the current state table according to Mark.
roomIDs, err := d.roomstate.SelectRoomIDsWithMembership(txn, userID, "invite")
if err != nil {
return err
}
for _, roomID := range roomIDs {
ir := types.NewInviteResponse()
// TODO: invite_state. The state won't be in the current state table in cases where you get invited over federation
res.Rooms.Invite[roomID] = *ir
}
return nil
}
// There may be some overlap where events in stateEvents are already in recentEvents, so filter
// them out so we don't include them twice in the /sync response. They should be in recentEvents
// only, so clients get to the correct state once they have rolled forward.

View file

@ -97,7 +97,7 @@ func NewJoinResponse() *JoinResponse {
// InviteResponse represents a /sync response for a room which is under the 'invite' key.
type InviteResponse struct {
InviteState struct {
Events []gomatrixserverlib.ClientEvent
Events []gomatrixserverlib.ClientEvent `json:"events"`
} `json:"invite_state"`
}