[Archive] Fix requesting archive
This commit is contained in:
		
							parent
							
								
									9979885168
								
							
						
					
					
						commit
						496349078b
					
				|  | @ -24,6 +24,7 @@ | ||||||
| import 'dart:async'; | import 'dart:async'; | ||||||
| import 'dart:core'; | import 'dart:core'; | ||||||
| 
 | 
 | ||||||
|  | import 'package:famedlysdk/famedlysdk.dart'; | ||||||
| import 'package:famedlysdk/src/AccountData.dart'; | import 'package:famedlysdk/src/AccountData.dart'; | ||||||
| import 'package:famedlysdk/src/Presence.dart'; | import 'package:famedlysdk/src/Presence.dart'; | ||||||
| import 'package:famedlysdk/src/StoreAPI.dart'; | import 'package:famedlysdk/src/StoreAPI.dart'; | ||||||
|  | @ -34,6 +35,7 @@ import 'Connection.dart'; | ||||||
| import 'Room.dart'; | import 'Room.dart'; | ||||||
| import 'RoomList.dart'; | import 'RoomList.dart'; | ||||||
| //import 'Store.dart'; | //import 'Store.dart'; | ||||||
|  | import 'RoomState.dart'; | ||||||
| import 'User.dart'; | import 'User.dart'; | ||||||
| import 'requests/SetPushersRequest.dart'; | import 'requests/SetPushersRequest.dart'; | ||||||
| import 'responses/ErrorResponse.dart'; | import 'responses/ErrorResponse.dart'; | ||||||
|  | @ -286,14 +288,48 @@ class Client { | ||||||
|         rooms: rooms); |         rooms: rooms); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   Future<RoomList> get archive async { |   Future<List<Room>> get archive async { | ||||||
|     RoomList archiveList = RoomList(client: this, rooms: [], onlyLeft: true); |     List<Room> archiveList = []; | ||||||
|     String syncFilters = |     String syncFilters = | ||||||
|         '{"room":{"include_leave":true,"timeline":{"limit":1}}}'; |         '{"room":{"include_leave":true,"timeline":{"limit":10}}}'; | ||||||
|     String action = "/client/r0/sync?filter=$syncFilters&timeout=0"; |     String action = "/client/r0/sync?filter=$syncFilters&timeout=0"; | ||||||
|     final syncResp = |     final sync = | ||||||
|         await connection.jsonRequest(type: HTTPType.GET, action: action); |         await connection.jsonRequest(type: HTTPType.GET, action: action); | ||||||
|     if (!(syncResp is ErrorResponse)) await connection.handleSync(syncResp); |     if (!(sync is ErrorResponse) && | ||||||
|  |         sync["rooms"]["leave"] is Map<String, dynamic>) { | ||||||
|  |       for (var entry in sync["rooms"]["leave"].entries) { | ||||||
|  |         final String id = entry.key; | ||||||
|  |         final dynamic room = entry.value; | ||||||
|  |         print(id); | ||||||
|  |         print(room.toString()); | ||||||
|  |         Room leftRoom = Room( | ||||||
|  |             id: id, | ||||||
|  |             membership: Membership.leave, | ||||||
|  |             client: this, | ||||||
|  |             roomAccountData: {}, | ||||||
|  |             mHeroes: []); | ||||||
|  |         if (room["account_data"] is Map<String, dynamic> && | ||||||
|  |             room["account_data"]["events"] is List<dynamic>) { | ||||||
|  |           for (dynamic event in room["account_data"]["events"]) { | ||||||
|  |             leftRoom.roomAccountData[event["type"]] = | ||||||
|  |                 RoomAccountData.fromJson(event, leftRoom); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         if (room["timeline"] is Map<String, dynamic> && | ||||||
|  |             room["timeline"]["events"] is List<dynamic>) { | ||||||
|  |           for (dynamic event in room["timeline"]["events"]) { | ||||||
|  |             leftRoom.setState(RoomState.fromJson(event, leftRoom)); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         if (room["state"] is Map<String, dynamic> && | ||||||
|  |             room["state"]["events"] is List<dynamic>) { | ||||||
|  |           for (dynamic event in room["state"]["events"]) { | ||||||
|  |             leftRoom.setState(RoomState.fromJson(event, leftRoom)); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         archiveList.add(leftRoom); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     return archiveList; |     return archiveList; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,7 +27,7 @@ import 'package:famedlysdk/src/AccountData.dart'; | ||||||
| import 'package:famedlysdk/src/Client.dart'; | import 'package:famedlysdk/src/Client.dart'; | ||||||
| import 'package:famedlysdk/src/Connection.dart'; | import 'package:famedlysdk/src/Connection.dart'; | ||||||
| import 'package:famedlysdk/src/Presence.dart'; | import 'package:famedlysdk/src/Presence.dart'; | ||||||
| import 'package:famedlysdk/src/RoomList.dart'; | import 'package:famedlysdk/src/Room.dart'; | ||||||
| import 'package:famedlysdk/src/User.dart'; | import 'package:famedlysdk/src/User.dart'; | ||||||
| import 'package:famedlysdk/src/requests/SetPushersRequest.dart'; | import 'package:famedlysdk/src/requests/SetPushersRequest.dart'; | ||||||
| import 'package:famedlysdk/src/responses/ErrorResponse.dart'; | import 'package:famedlysdk/src/responses/ErrorResponse.dart'; | ||||||
|  | @ -363,12 +363,18 @@ void main() { | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     test('get archive', () async { |     test('get archive', () async { | ||||||
|       RoomList archive = await matrix.archive; |       List<Room> archive = await matrix.archive; | ||||||
| 
 | 
 | ||||||
|       await new Future.delayed(new Duration(milliseconds: 50)); |       await new Future.delayed(new Duration(milliseconds: 50)); | ||||||
|       expect(archive.rooms.length, 1); |       expect(archive.length, 2); | ||||||
|       expect(archive.rooms[0].id, "!5345234234:example.com"); |       expect(archive[0].id, "!5345234234:example.com"); | ||||||
|       expect(archive.rooms[0].membership, Membership.leave); |       expect(archive[0].membership, Membership.leave); | ||||||
|  |       expect(archive[0].name, "The room name"); | ||||||
|  |       expect(archive[0].lastMessage, "This is an example text message"); | ||||||
|  |       expect(archive[0].roomAccountData.length, 1); | ||||||
|  |       expect(archive[1].id, "!5345234235:example.com"); | ||||||
|  |       expect(archive[1].membership, Membership.leave); | ||||||
|  |       expect(archive[1].name, "The room name 2"); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     test('getProfileFromUserId', () async { |     test('getProfileFromUserId', () async { | ||||||
|  |  | ||||||
|  | @ -393,7 +393,63 @@ class FakeMatrixApi extends MockClient { | ||||||
|       "invite": {}, |       "invite": {}, | ||||||
|       "leave": { |       "leave": { | ||||||
|         "!5345234234:example.com": { |         "!5345234234:example.com": { | ||||||
|           "timeline": {"events": []} |           "timeline": { | ||||||
|  |             "events": [ | ||||||
|  |               { | ||||||
|  |                 "content": { | ||||||
|  |                   "body": "This is an example text message", | ||||||
|  |                   "msgtype": "m.text", | ||||||
|  |                   "format": "org.matrix.custom.html", | ||||||
|  |                   "formatted_body": "<b>This is an example text message</b>" | ||||||
|  |                 }, | ||||||
|  |                 "type": "m.room.message", | ||||||
|  |                 "event_id": "143273582443PhrSn:example.org", | ||||||
|  |                 "room_id": "!5345234234:example.com", | ||||||
|  |                 "sender": "@example:example.org", | ||||||
|  |                 "origin_server_ts": 1432735824653, | ||||||
|  |                 "unsigned": {"age": 1234} | ||||||
|  |               }, | ||||||
|  |             ] | ||||||
|  |           }, | ||||||
|  |           "state": { | ||||||
|  |             "events": [ | ||||||
|  |               { | ||||||
|  |                 "content": {"name": "The room name"}, | ||||||
|  |                 "type": "m.room.name", | ||||||
|  |                 "event_id": "2143273582443PhrSn:example.org", | ||||||
|  |                 "room_id": "!5345234234:example.com", | ||||||
|  |                 "sender": "@example:example.org", | ||||||
|  |                 "origin_server_ts": 1432735824653, | ||||||
|  |                 "unsigned": {"age": 1234}, | ||||||
|  |                 "state_key": "" | ||||||
|  |               }, | ||||||
|  |             ] | ||||||
|  |           }, | ||||||
|  |           "account_data": { | ||||||
|  |             "events": [ | ||||||
|  |               { | ||||||
|  |                 "type": "test.type.data", | ||||||
|  |                 "content": {"foo": "bar"}, | ||||||
|  |               }, | ||||||
|  |             ], | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|  |         "!5345234235:example.com": { | ||||||
|  |           "timeline": {"events": []}, | ||||||
|  |           "state": { | ||||||
|  |             "events": [ | ||||||
|  |               { | ||||||
|  |                 "content": {"name": "The room name 2"}, | ||||||
|  |                 "type": "m.room.name", | ||||||
|  |                 "event_id": "2143273582443PhrSn:example.org", | ||||||
|  |                 "room_id": "!5345234235:example.com", | ||||||
|  |                 "sender": "@example:example.org", | ||||||
|  |                 "origin_server_ts": 1432735824653, | ||||||
|  |                 "unsigned": {"age": 1234}, | ||||||
|  |                 "state_key": "" | ||||||
|  |               }, | ||||||
|  |             ] | ||||||
|  |           } | ||||||
|         }, |         }, | ||||||
|       }, |       }, | ||||||
|     } |     } | ||||||
|  | @ -680,7 +736,7 @@ class FakeMatrixApi extends MockClient { | ||||||
|               ] |               ] | ||||||
|             } |             } | ||||||
|           }, |           }, | ||||||
|       "/client/r0/sync?filter=%7B%22room%22:%7B%22include_leave%22:true,%22timeline%22:%7B%22limit%22:1%7D%7D%7D&timeout=0": |       "/client/r0/sync?filter=%7B%22room%22:%7B%22include_leave%22:true,%22timeline%22:%7B%22limit%22:10%7D%7D%7D&timeout=0": | ||||||
|           (var req) => archiveSyncResponse, |           (var req) => archiveSyncResponse, | ||||||
|       "/client/r0/sync?filter=%7B%22room%22:%7B%22state%22:%7B%22lazy_load_members%22:true%7D%7D%7D": |       "/client/r0/sync?filter=%7B%22room%22:%7B%22state%22:%7B%22lazy_load_members%22:true%7D%7D%7D": | ||||||
|           (var req) => syncResponse, |           (var req) => syncResponse, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue