@@ -761,7 +761,6 @@ class SlidingSyncRestServlet(RestServlet):
761
761
"lists": {
762
762
"foo-list": {
763
763
"ranges": [ [0, 99] ],
764
- "sort": [ "by_notification_level", "by_recency", "by_name" ],
765
764
"required_state": [
766
765
["m.room.join_rules", ""],
767
766
["m.room.history_visibility", ""],
@@ -771,18 +770,13 @@ class SlidingSyncRestServlet(RestServlet):
771
770
"filters": {
772
771
"is_dm": true
773
772
},
774
- "bump_event_types": [ "m.room.message", "m.room.encrypted" ],
775
773
}
776
774
},
777
775
// Room Subscriptions API
778
776
"room_subscriptions": {
779
777
"!sub1:bar": {
780
778
"required_state": [ ["*","*"] ],
781
779
"timeline_limit": 10,
782
- "include_old_rooms": {
783
- "timeline_limit": 1,
784
- "required_state": [ ["m.room.tombstone", ""], ["m.room.create", ""] ],
785
- }
786
780
}
787
781
},
788
782
// Extensions API
@@ -791,7 +785,7 @@ class SlidingSyncRestServlet(RestServlet):
791
785
792
786
Response JSON::
793
787
{
794
- "next_pos ": "s58_224_0_13_10_1_1_16_0_1",
788
+ "pos ": "s58_224_0_13_10_1_1_16_0_1",
795
789
"lists": {
796
790
"foo-list": {
797
791
"count": 1337,
@@ -830,7 +824,8 @@ class SlidingSyncRestServlet(RestServlet):
830
824
"joined_count": 41,
831
825
"invited_count": 1,
832
826
"notification_count": 1,
833
- "highlight_count": 0
827
+ "highlight_count": 0,
828
+ "num_live": 2"
834
829
},
835
830
// rooms from list
836
831
"!foo:bar": {
@@ -855,7 +850,8 @@ class SlidingSyncRestServlet(RestServlet):
855
850
"joined_count": 4,
856
851
"invited_count": 0,
857
852
"notification_count": 54,
858
- "highlight_count": 3
853
+ "highlight_count": 3,
854
+ "num_live": 1,
859
855
},
860
856
// ... 99 more items
861
857
},
@@ -871,10 +867,11 @@ def __init__(self, hs: "HomeServer"):
871
867
super ().__init__ ()
872
868
self .auth = hs .get_auth ()
873
869
self .store = hs .get_datastores ().main
870
+ self .clock = hs .get_clock ()
874
871
self .filtering = hs .get_filtering ()
875
872
self .sliding_sync_handler = hs .get_sliding_sync_handler ()
873
+ self .event_serializer = hs .get_event_client_serializer ()
876
874
877
- # TODO: Update this to `on_GET` once we figure out how we want to handle params
878
875
async def on_POST (self , request : SynapseRequest ) -> Tuple [int , JsonDict ]:
879
876
requester = await self .auth .get_user_by_req (request , allow_guest = True )
880
877
user = requester .user
@@ -920,22 +917,25 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
920
917
logger .info ("Client has disconnected; not serializing response." )
921
918
return 200 , {}
922
919
923
- response_content = await self .encode_response (sliding_sync_results )
920
+ response_content = await self .encode_response (requester , sliding_sync_results )
924
921
925
922
return 200 , response_content
926
923
927
924
# TODO: Is there a better way to encode things?
928
925
async def encode_response (
929
926
self ,
927
+ requester : Requester ,
930
928
sliding_sync_result : SlidingSyncResult ,
931
929
) -> JsonDict :
932
930
response : JsonDict = defaultdict (dict )
933
931
934
- response ["next_pos " ] = await sliding_sync_result .next_pos .to_string (self .store )
932
+ response ["pos " ] = await sliding_sync_result .next_pos .to_string (self .store )
935
933
serialized_lists = self .encode_lists (sliding_sync_result .lists )
936
934
if serialized_lists :
937
935
response ["lists" ] = serialized_lists
938
- response ["rooms" ] = {} # TODO: sliding_sync_result.rooms
936
+ response ["rooms" ] = await self .encode_rooms (
937
+ requester , sliding_sync_result .rooms
938
+ )
939
939
response ["extensions" ] = {} # TODO: sliding_sync_result.extensions
940
940
941
941
return response
@@ -961,6 +961,92 @@ def encode_operation(
961
961
962
962
return serialized_lists
963
963
964
+ async def encode_rooms (
965
+ self ,
966
+ requester : Requester ,
967
+ rooms : Dict [str , SlidingSyncResult .RoomResult ],
968
+ ) -> JsonDict :
969
+ time_now = self .clock .time_msec ()
970
+
971
+ serialize_options = SerializeEventConfig (
972
+ event_format = format_event_for_client_v2_without_room_id ,
973
+ requester = requester ,
974
+ )
975
+
976
+ serialized_rooms : Dict [str , JsonDict ] = {}
977
+ for room_id , room_result in rooms .items ():
978
+ serialized_rooms [room_id ] = {
979
+ "joined_count" : room_result .joined_count ,
980
+ "invited_count" : room_result .invited_count ,
981
+ "notification_count" : room_result .notification_count ,
982
+ "highlight_count" : room_result .highlight_count ,
983
+ }
984
+
985
+ if room_result .name :
986
+ serialized_rooms [room_id ]["name" ] = room_result .name
987
+
988
+ if room_result .avatar :
989
+ serialized_rooms [room_id ]["avatar" ] = room_result .avatar
990
+
991
+ if room_result .heroes :
992
+ serialized_rooms [room_id ]["heroes" ] = room_result .heroes
993
+
994
+ # We should only include the `initial` key if it's `True` to save bandwidth.
995
+ # The absense of this flag means `False`.
996
+ if room_result .initial :
997
+ serialized_rooms [room_id ]["initial" ] = room_result .initial
998
+
999
+ # This will omitted for invite/knock rooms with `stripped_state`
1000
+ if room_result .required_state is not None :
1001
+ serialized_required_state = (
1002
+ await self .event_serializer .serialize_events (
1003
+ room_result .required_state ,
1004
+ time_now ,
1005
+ config = serialize_options ,
1006
+ )
1007
+ )
1008
+ serialized_rooms [room_id ]["required_state" ] = serialized_required_state
1009
+
1010
+ # This will omitted for invite/knock rooms with `stripped_state`
1011
+ if room_result .timeline_events is not None :
1012
+ serialized_timeline = await self .event_serializer .serialize_events (
1013
+ room_result .timeline_events ,
1014
+ time_now ,
1015
+ config = serialize_options ,
1016
+ bundle_aggregations = room_result .bundled_aggregations ,
1017
+ )
1018
+ serialized_rooms [room_id ]["timeline" ] = serialized_timeline
1019
+
1020
+ # This will omitted for invite/knock rooms with `stripped_state`
1021
+ if room_result .limited is not None :
1022
+ serialized_rooms [room_id ]["limited" ] = room_result .limited
1023
+
1024
+ # This will omitted for invite/knock rooms with `stripped_state`
1025
+ if room_result .prev_batch is not None :
1026
+ serialized_rooms [room_id ]["prev_batch" ] = (
1027
+ await room_result .prev_batch .to_string (self .store )
1028
+ )
1029
+
1030
+ # This will omitted for invite/knock rooms with `stripped_state`
1031
+ if room_result .num_live is not None :
1032
+ serialized_rooms [room_id ]["num_live" ] = room_result .num_live
1033
+
1034
+ # Field should be absent on non-DM rooms
1035
+ if room_result .is_dm :
1036
+ serialized_rooms [room_id ]["is_dm" ] = room_result .is_dm
1037
+
1038
+ # Stripped state only applies to invite/knock rooms
1039
+ if room_result .stripped_state is not None :
1040
+ # TODO: `knocked_state` but that isn't specced yet.
1041
+ #
1042
+ # TODO: Instead of adding `knocked_state`, it would be good to rename
1043
+ # this to `stripped_state` so it can be shared between invite and knock
1044
+ # rooms, see
1045
+ # https://github.com/matrix-org/matrix-spec-proposals/pull/3575#discussion_r1117629919
1046
+ serialized_rooms [room_id ]["invite_state" ] = room_result .stripped_state
1047
+
1048
+ return serialized_rooms
1049
+
964
1050
965
1051
def register_servlets (hs : "HomeServer" , http_server : HttpServer ) -> None :
966
1052
SyncRestServlet (hs ).register (http_server )
0 commit comments