[Room] Request history with users
This commit is contained in:
parent
95b20ea41c
commit
2802901eec
|
|
@ -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}}}';
|
'{"room":{"include_leave":true,"state":{"lazy_load_members":true}}}';
|
||||||
|
|
||||||
/// Handles the connection to the Matrix Homeserver. You can change this to a
|
/// Handles the connection to the Matrix Homeserver. You can change this to a
|
||||||
|
|
@ -284,10 +284,10 @@ class Connection {
|
||||||
Future<void> _sync() async {
|
Future<void> _sync() async {
|
||||||
if (client.isLogged() == false) return;
|
if (client.isLogged() == false) return;
|
||||||
|
|
||||||
String action = "/client/r0/sync?filter=$_firstSyncFilters";
|
String action = "/client/r0/sync?filter=$firstSyncFilters";
|
||||||
|
|
||||||
if (client.prevBatch != null) {
|
if (client.prevBatch != null) {
|
||||||
action = "/client/r0/sync?filter=$_syncFilters";
|
action = "/client/r0/sync?filter=$syncFilters";
|
||||||
action += "&timeout=30000";
|
action += "&timeout=30000";
|
||||||
action += "&since=${client.prevBatch}";
|
action += "&since=${client.prevBatch}";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -353,7 +353,7 @@ class Room {
|
||||||
final dynamic resp = await client.connection.jsonRequest(
|
final dynamic resp = await client.connection.jsonRequest(
|
||||||
type: HTTPType.GET,
|
type: HTTPType.GET,
|
||||||
action:
|
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;
|
if (resp is ErrorResponse) return;
|
||||||
|
|
||||||
|
|
@ -364,6 +364,33 @@ class Room {
|
||||||
resp["chunk"].length > 0 &&
|
resp["chunk"].length > 0 &&
|
||||||
resp["end"] is String)) return;
|
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"];
|
List<dynamic> history = resp["chunk"];
|
||||||
client.store?.transaction(() {
|
client.store?.transaction(() {
|
||||||
for (int i = 0; i < history.length; i++) {
|
for (int i = 0; i < history.length; i++) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class FakeMatrixApi extends MockClient {
|
||||||
method == "GET" ? request.url.queryParameters : request.body;
|
method == "GET" ? request.url.queryParameters : request.body;
|
||||||
var res = {};
|
var res = {};
|
||||||
|
|
||||||
print("$method request to $action with Data: $data");
|
//print("$method request to $action with Data: $data");
|
||||||
|
|
||||||
// Sync requests with timeout
|
// Sync requests with timeout
|
||||||
if (data is Map<String, dynamic> && data["timeout"] is String) {
|
if (data is Map<String, dynamic> && data["timeout"] is String) {
|
||||||
|
|
@ -92,7 +92,7 @@ class FakeMatrixApi extends MockClient {
|
||||||
"origin_server_ts": 1432735824653,
|
"origin_server_ts": 1432735824653,
|
||||||
"unsigned": {"age": 1234}
|
"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) => {
|
(var req) => {
|
||||||
"start": "t47429-4392820_219380_26003_2265",
|
"start": "t47429-4392820_219380_26003_2265",
|
||||||
"end": "t47409-4357353_219380_26003_2265",
|
"end": "t47409-4357353_219380_26003_2265",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue