[Timeline] Better HistoryRequest in Timeline
This commit is contained in:
parent
97034743fe
commit
6a81fbc0aa
|
@ -174,6 +174,10 @@ class Room {
|
||||||
this.roomAccountData = const {},
|
this.roomAccountData = const {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The default count of how much events should be requested when requesting the
|
||||||
|
/// history of this room.
|
||||||
|
static const int DefaultHistoryCount = 100;
|
||||||
|
|
||||||
/// Calculates the displayname. First checks if there is a name, then checks for a canonical alias and
|
/// Calculates the displayname. First checks if there is a name, then checks for a canonical alias and
|
||||||
/// then generates a name from the heroes.
|
/// then generates a name from the heroes.
|
||||||
String get displayname {
|
String get displayname {
|
||||||
|
@ -445,8 +449,11 @@ class Room {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request more previous events from the server.
|
/// Request more previous events from the server. [historyCount] defines how much events should
|
||||||
Future<void> requestHistory({int historyCount = 100}) async {
|
/// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before**
|
||||||
|
/// the historical events will be published in the onEvent stream.
|
||||||
|
Future<void> requestHistory(
|
||||||
|
{int historyCount = DefaultHistoryCount, onHistoryReceived}) async {
|
||||||
final dynamic resp = await client.connection.jsonRequest(
|
final dynamic resp = await client.connection.jsonRequest(
|
||||||
type: HTTPType.GET,
|
type: HTTPType.GET,
|
||||||
action:
|
action:
|
||||||
|
@ -454,6 +461,7 @@ class Room {
|
||||||
|
|
||||||
if (resp is ErrorResponse) return;
|
if (resp is ErrorResponse) return;
|
||||||
|
|
||||||
|
if (onHistoryReceived != null) onHistoryReceived();
|
||||||
prev_batch = resp["end"];
|
prev_batch = resp["end"];
|
||||||
client.store?.storeRoomPrevBatch(this);
|
client.store?.storeRoomPrevBatch(this);
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,14 @@ class Timeline {
|
||||||
|
|
||||||
StreamSubscription<EventUpdate> sub;
|
StreamSubscription<EventUpdate> sub;
|
||||||
|
|
||||||
|
Future<void> requestHistory({int historyCount = Room.DefaultHistoryCount}) {
|
||||||
|
return room.requestHistory(
|
||||||
|
historyCount: historyCount,
|
||||||
|
onHistoryReceived: () {
|
||||||
|
if (room.prev_batch.isEmpty || room.prev_batch == null) events = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Timeline({this.room, this.events, this.onUpdate, this.onInsert}) {
|
Timeline({this.room, this.events, this.onUpdate, this.onInsert}) {
|
||||||
sub ??= room.client.connection.onEvent.stream.listen(_handleEventUpdate);
|
sub ??= room.client.connection.onEvent.stream.listen(_handleEventUpdate);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue