init method
override
Initializes this repository.
Callback onMemberRemoved should be called once an User is removed from
a Chat.
Implementation
@override
Future<void> init({
Future<void> Function(ChatId, UserId)? onMemberRemoved,
bool? pagination,
}) async {
Log.debug('init(onMemberRemoved) for $me', '$runtimeType');
this.onMemberRemoved = onMemberRemoved ?? this.onMemberRemoved;
// Set the initial values to local ones, however those will be redefined
// during `_ensurePagination()` method, which invokes `_initSupport()` and
// `_initMonolog()`.
monolog = ChatId.local(me);
support = ChatId.local(_supportId);
_monologGuard.protect(() async {
if (isClosed) {
return;
}
final monologMixin = await _graphQlProvider.getMonolog();
if (isClosed) {
return;
}
Log.debug('getMonolog() -> $monologMixin', '$runtimeType');
monolog = monologMixin?.id ?? monolog;
final supportMixin = await _graphQlProvider.getDialog(
UserId(Config.supportId),
);
if (isClosed) {
return;
}
Log.debug('getDialog(supportId) -> $supportMixin', '$runtimeType');
support = supportMixin?.id ?? support;
});
// Popup shouldn't listen to recent chats remote updates, as it's happening
// inside single [Chat].
if (!WebUtils.isPopup && _remoteSubscription == null) {
_initRemoteSubscription();
_initFavoriteSubscription();
_initArchiveSubscription();
}
if ((pagination ?? !WebUtils.isPopup) && _paginatedSubscription == null) {
_initRemotePagination();
_paginatedSubscription = paginated.changes.listen((e) {
switch (e.op) {
case OperationKind.added:
_subscriptions[e.key!] ??= e.value!.updates.listen((_) {});
break;
case OperationKind.updated:
if (e.oldKey != e.key) {
final StreamSubscription? subscription = _subscriptions[e.oldKey];
if (subscription != null) {
_subscriptions[e.key!] = subscription;
_subscriptions.remove(e.oldKey);
}
}
break;
case OperationKind.removed:
_subscriptions.remove(e.key!)?.cancel();
break;
}
});
_initLocalPagination();
}
if ((pagination ?? !WebUtils.isPopup) && _archivedSubscription == null) {
_archivedSubscription = archived.items.changes.listen((e) {
switch (e.op) {
case OperationKind.added:
_archiveSubscriptions[e.key!] ??= e.value!.updates.listen((_) {});
break;
case OperationKind.updated:
if (e.oldKey != e.key) {
final StreamSubscription? subscription =
_archiveSubscriptions[e.oldKey];
if (subscription != null) {
_archiveSubscriptions[e.key!] = subscription;
_archiveSubscriptions.remove(e.oldKey);
}
}
break;
case OperationKind.removed:
_archiveSubscriptions.remove(e.key!)?.cancel();
break;
}
});
archived.around();
}
}