[Timeline] Implement tests for request history function.
This commit is contained in:
parent
b5698b175f
commit
31bff2d00e
|
@ -293,7 +293,7 @@ class Room {
|
|||
|
||||
/// Request more previous events from the server.
|
||||
Future<void> requestHistory({int historyCount = 100}) async {
|
||||
final dynamic resp = client.connection.jsonRequest(
|
||||
final dynamic resp = await client.connection.jsonRequest(
|
||||
type: "GET",
|
||||
action: "/client/r0/rooms/$id/messages",
|
||||
data: {"from": prev_batch, "dir": "b", "limit": historyCount});
|
||||
|
@ -305,12 +305,12 @@ class Room {
|
|||
resp["end"] is String)) return;
|
||||
|
||||
List<dynamic> history = resp["chunk"];
|
||||
client.store.transaction(() {
|
||||
client.store?.transaction(() {
|
||||
for (int i = 0; i < history.length; i++) {
|
||||
EventUpdate eventUpdate = EventUpdate(
|
||||
eventType: "history",
|
||||
type: "history",
|
||||
roomID: id,
|
||||
type: history[i]["type"],
|
||||
eventType: history[i]["type"],
|
||||
content: history[i],
|
||||
);
|
||||
client.connection.onEvent.add(eventUpdate);
|
||||
|
@ -319,6 +319,17 @@ class Room {
|
|||
"UPDATE Rooms SET prev_batch=? WHERE id=?", [resp["end"], id]);
|
||||
}
|
||||
});
|
||||
if (client.store == null) {
|
||||
for (int i = 0; i < history.length; i++) {
|
||||
EventUpdate eventUpdate = EventUpdate(
|
||||
type: "history",
|
||||
roomID: id,
|
||||
eventType: history[i]["type"],
|
||||
content: history[i],
|
||||
);
|
||||
client.connection.onEvent.add(eventUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets this room as a direct chat for this user.
|
||||
|
|
|
@ -62,6 +62,64 @@ class FakeMatrixApi extends MockClient {
|
|||
|
||||
static final Map<String, Map<String, dynamic>> api = {
|
||||
"GET": {
|
||||
"/client/r0/rooms/!1234:example.com/messages": (var req) => {
|
||||
"start": "t47429-4392820_219380_26003_2265",
|
||||
"end": "t47409-4357353_219380_26003_2265",
|
||||
"chunk": [
|
||||
{
|
||||
"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": "3143273582443PhrSn:example.org",
|
||||
"room_id": "!1234:example.com",
|
||||
"sender": "@example:example.org",
|
||||
"origin_server_ts": 1432735824653,
|
||||
"unsigned": {"age": 1234}
|
||||
},
|
||||
{
|
||||
"content": {"name": "The room name"},
|
||||
"type": "m.room.name",
|
||||
"event_id": "2143273582443PhrSn:example.org",
|
||||
"room_id": "!1234:example.com",
|
||||
"sender": "@example:example.org",
|
||||
"origin_server_ts": 1432735824653,
|
||||
"unsigned": {"age": 1234},
|
||||
"state_key": ""
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"body": "Gangnam Style",
|
||||
"url": "mxc://example.org/a526eYUSFFxlgbQYZmo442",
|
||||
"info": {
|
||||
"thumbnail_url":
|
||||
"mxc://example.org/FHyPlCeYUSFFxlgbQYZmoEoe",
|
||||
"thumbnail_info": {
|
||||
"mimetype": "image/jpeg",
|
||||
"size": 46144,
|
||||
"w": 300,
|
||||
"h": 300
|
||||
},
|
||||
"w": 480,
|
||||
"h": 320,
|
||||
"duration": 2140786,
|
||||
"size": 1563685,
|
||||
"mimetype": "video/mp4"
|
||||
},
|
||||
"msgtype": "m.video"
|
||||
},
|
||||
"type": "m.room.message",
|
||||
"event_id": "1143273582443PhrSn:example.org",
|
||||
"room_id": "!1234:example.com",
|
||||
"sender": "@example:example.org",
|
||||
"origin_server_ts": 1432735824653,
|
||||
"unsigned": {"age": 1234}
|
||||
}
|
||||
]
|
||||
},
|
||||
"/client/versions": (var req) => {
|
||||
"versions": ["r0.0.1", "r0.1.0", "r0.2.0", "r0.3.0", "r0.4.0"],
|
||||
"unstable_features": {"m.lazy_load_members": true},
|
||||
|
|
|
@ -187,5 +187,17 @@ void main() {
|
|||
expect(timeline.events[0].content["txid"], "1234");
|
||||
expect(timeline.events[0].status, 1);
|
||||
});
|
||||
|
||||
test("Request history", () async {
|
||||
await room.requestHistory();
|
||||
|
||||
await new Future.delayed(new Duration(milliseconds: 50));
|
||||
|
||||
expect(updateCount, 19);
|
||||
expect(timeline.events.length, 9);
|
||||
expect(timeline.events[6].id, "1143273582443PhrSn:example.org");
|
||||
expect(timeline.events[7].id, "2143273582443PhrSn:example.org");
|
||||
expect(timeline.events[8].id, "3143273582443PhrSn:example.org");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue