Merge branch 'archive-fix-requesting-archive' into 'master'
[Archive] Fix requesting archive See merge request famedly/famedlysdk!140
This commit is contained in:
		
						commit
						ccdb33ba69
					
				|  | @ -24,6 +24,7 @@ | |||
| import 'dart:async'; | ||||
| import 'dart:core'; | ||||
| 
 | ||||
| import 'package:famedlysdk/famedlysdk.dart'; | ||||
| import 'package:famedlysdk/src/AccountData.dart'; | ||||
| import 'package:famedlysdk/src/Presence.dart'; | ||||
| import 'package:famedlysdk/src/StoreAPI.dart'; | ||||
|  | @ -34,6 +35,7 @@ import 'Connection.dart'; | |||
| import 'Room.dart'; | ||||
| import 'RoomList.dart'; | ||||
| //import 'Store.dart'; | ||||
| import 'RoomState.dart'; | ||||
| import 'User.dart'; | ||||
| import 'requests/SetPushersRequest.dart'; | ||||
| import 'responses/ErrorResponse.dart'; | ||||
|  | @ -286,14 +288,48 @@ class Client { | |||
|         rooms: rooms); | ||||
|   } | ||||
| 
 | ||||
|   Future<RoomList> get archive async { | ||||
|     RoomList archiveList = RoomList(client: this, rooms: [], onlyLeft: true); | ||||
|   Future<List<Room>> get archive async { | ||||
|     List<Room> archiveList = []; | ||||
|     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"; | ||||
|     final syncResp = | ||||
|     final sync = | ||||
|         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; | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -27,7 +27,7 @@ import 'package:famedlysdk/src/AccountData.dart'; | |||
| import 'package:famedlysdk/src/Client.dart'; | ||||
| import 'package:famedlysdk/src/Connection.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/requests/SetPushersRequest.dart'; | ||||
| import 'package:famedlysdk/src/responses/ErrorResponse.dart'; | ||||
|  | @ -363,12 +363,18 @@ void main() { | |||
|     }); | ||||
| 
 | ||||
|     test('get archive', () async { | ||||
|       RoomList archive = await matrix.archive; | ||||
|       List<Room> archive = await matrix.archive; | ||||
| 
 | ||||
|       await new Future.delayed(new Duration(milliseconds: 50)); | ||||
|       expect(archive.rooms.length, 1); | ||||
|       expect(archive.rooms[0].id, "!5345234234:example.com"); | ||||
|       expect(archive.rooms[0].membership, Membership.leave); | ||||
|       expect(archive.length, 2); | ||||
|       expect(archive[0].id, "!5345234234:example.com"); | ||||
|       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 { | ||||
|  |  | |||
|  | @ -393,7 +393,63 @@ class FakeMatrixApi extends MockClient { | |||
|       "invite": {}, | ||||
|       "leave": { | ||||
|         "!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, | ||||
|       "/client/r0/sync?filter=%7B%22room%22:%7B%22state%22:%7B%22lazy_load_members%22:true%7D%7D%7D": | ||||
|           (var req) => syncResponse, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue