load more threads when requesting history
This commit is contained in:
parent
98031bbb3d
commit
6b5ecb21d4
|
|
@ -137,10 +137,14 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Thread> threads = <String, Thread>{};
|
Map<String, Thread> threads = <String, Thread>{};
|
||||||
|
String? getThreadRootsBatch;
|
||||||
|
bool loadedAllThreads = false;
|
||||||
|
|
||||||
Future<void> _loadThreadsFromServer() async {
|
Future<void> _loadThreadsFromServer() async {
|
||||||
try {
|
try {
|
||||||
final response = await client.getThreadRoots(id);
|
if (loadedAllThreads) return;
|
||||||
|
final response =
|
||||||
|
await client.getThreadRoots(id, from: getThreadRootsBatch);
|
||||||
|
|
||||||
for (final threadEvent in response.chunk) {
|
for (final threadEvent in response.chunk) {
|
||||||
final event = Event.fromMatrixEvent(threadEvent, this);
|
final event = Event.fromMatrixEvent(threadEvent, this);
|
||||||
|
|
@ -153,7 +157,14 @@ class Room {
|
||||||
1, // count
|
1, // count
|
||||||
client,
|
client,
|
||||||
);
|
);
|
||||||
threads[event.eventId] = (await client.database.getThread(id, event.eventId, client))!;
|
threads[event.eventId] =
|
||||||
|
(await client.database.getThread(id, event.eventId, client))!;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.nextBatch == null) {
|
||||||
|
loadedAllThreads = true;
|
||||||
|
} else {
|
||||||
|
getThreadRootsBatch = response.nextBatch;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logs().w('Failed to load threads from server', e);
|
Logs().w('Failed to load threads from server', e);
|
||||||
|
|
@ -232,7 +243,8 @@ class Room {
|
||||||
|
|
||||||
Future<Thread> getThread(Event rootEvent) async {
|
Future<Thread> getThread(Event rootEvent) async {
|
||||||
final threads = await getThreads();
|
final threads = await getThreads();
|
||||||
if (threads.containsKey(rootEvent.eventId)) return threads[rootEvent.eventId]!;
|
if (threads.containsKey(rootEvent.eventId))
|
||||||
|
return threads[rootEvent.eventId]!;
|
||||||
return Thread(
|
return Thread(
|
||||||
room: this,
|
room: this,
|
||||||
rootEvent: rootEvent,
|
rootEvent: rootEvent,
|
||||||
|
|
@ -1511,6 +1523,9 @@ class Room {
|
||||||
direction = Direction.b,
|
direction = Direction.b,
|
||||||
StateFilter? filter,
|
StateFilter? filter,
|
||||||
}) async {
|
}) async {
|
||||||
|
|
||||||
|
unawaited(_loadThreadsFromServer());
|
||||||
|
|
||||||
final prev_batch = this.prev_batch;
|
final prev_batch = this.prev_batch;
|
||||||
|
|
||||||
final storeInDatabase = !isArchived;
|
final storeInDatabase = !isArchived;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue