34 lines
1.0 KiB
Dart
34 lines
1.0 KiB
Dart
import 'fetch_chat_page.dart';
|
|
import 'get_chat_params.dart';
|
|
import 'get_chat_response.dart';
|
|
|
|
/// Long-poll variant of GetChat (`lookIntoFuture=1`); HTTP 304 is the normal
|
|
/// "no new messages" outcome (see [fetchChatPage]). `setReadMarker=on` lets
|
|
/// the server move the read cursor whenever the call returns messages.
|
|
class LongPollChat {
|
|
final String chatToken;
|
|
final int lastKnownMessageId;
|
|
final int timeoutSeconds;
|
|
|
|
LongPollChat({
|
|
required this.chatToken,
|
|
required this.lastKnownMessageId,
|
|
this.timeoutSeconds = 30,
|
|
});
|
|
|
|
/// Returns the response, or `null` on HTTP 304 (server timeout, nothing new).
|
|
Future<GetChatResponse?> run() => fetchChatPage(
|
|
label: 'LongPollChat',
|
|
chatToken: chatToken,
|
|
params: GetChatParams(
|
|
lookIntoFuture: GetChatParamsSwitch.on,
|
|
timeout: timeoutSeconds,
|
|
lastKnownMessageId: lastKnownMessageId,
|
|
includeLastKnown: GetChatParamsSwitch.off,
|
|
setReadMarker: GetChatParamsSwitch.on,
|
|
limit: 100,
|
|
),
|
|
timeout: Duration(seconds: timeoutSeconds + 15),
|
|
);
|
|
}
|