[Room] Request history with users

This commit is contained in:
Christian Pauly 2019-08-29 12:28:50 +02:00
parent 95b20ea41c
commit 2802901eec
3 changed files with 34 additions and 7 deletions

View File

@ -52,9 +52,9 @@ class Connection {
}));
}
String get _syncFilters => '{"room":{"state":{"lazy_load_members":true}}}';
static String syncFilters = '{"room":{"state":{"lazy_load_members":true}}}';
String get _firstSyncFilters =>
static String firstSyncFilters =
'{"room":{"include_leave":true,"state":{"lazy_load_members":true}}}';
/// Handles the connection to the Matrix Homeserver. You can change this to a
@ -284,10 +284,10 @@ class Connection {
Future<void> _sync() async {
if (client.isLogged() == false) return;
String action = "/client/r0/sync?filter=$_firstSyncFilters";
String action = "/client/r0/sync?filter=$firstSyncFilters";
if (client.prevBatch != null) {
action = "/client/r0/sync?filter=$_syncFilters";
action = "/client/r0/sync?filter=$syncFilters";
action += "&timeout=30000";
action += "&since=${client.prevBatch}";
}

View File

@ -353,7 +353,7 @@ class Room {
final dynamic resp = await client.connection.jsonRequest(
type: HTTPType.GET,
action:
"/client/r0/rooms/$id/messages?from=${prev_batch}&dir=b&limit=$historyCount");
"/client/r0/rooms/$id/messages?from=${prev_batch}&dir=b&limit=$historyCount&filter=${Connection.syncFilters}");
if (resp is ErrorResponse) return;
@ -364,6 +364,33 @@ class Room {
resp["chunk"].length > 0 &&
resp["end"] is String)) return;
if (resp["state"] is List<dynamic>) {
client.store?.transaction(() {
for (int i = 0; i < resp["state"].length; i++) {
EventUpdate eventUpdate = EventUpdate(
type: "state",
roomID: id,
eventType: resp["state"][i]["type"],
content: resp["state"][i],
);
client.connection.onEvent.add(eventUpdate);
client.store.storeEventUpdate(eventUpdate);
}
return;
});
if (client.store == null) {
for (int i = 0; i < resp["state"].length; i++) {
EventUpdate eventUpdate = EventUpdate(
type: "state",
roomID: id,
eventType: resp["state"][i]["type"],
content: resp["state"][i],
);
client.connection.onEvent.add(eventUpdate);
}
}
}
List<dynamic> history = resp["chunk"];
client.store?.transaction(() {
for (int i = 0; i < history.length; i++) {

View File

@ -39,7 +39,7 @@ class FakeMatrixApi extends MockClient {
method == "GET" ? request.url.queryParameters : request.body;
var res = {};
print("$method request to $action with Data: $data");
//print("$method request to $action with Data: $data");
// Sync requests with timeout
if (data is Map<String, dynamic> && data["timeout"] is String) {
@ -92,7 +92,7 @@ class FakeMatrixApi extends MockClient {
"origin_server_ts": 1432735824653,
"unsigned": {"age": 1234}
},
"/client/r0/rooms/!1234:example.com/messages?from=1234&dir=b&limit=100":
"/client/r0/rooms/!1234:example.com/messages?from=1234&dir=b&limit=100&filter=%7B%22room%22:%7B%22state%22:%7B%22lazy_load_members%22:true%7D%7D%7D":
(var req) => {
"start": "t47429-4392820_219380_26003_2265",
"end": "t47409-4357353_219380_26003_2265",