fix(chat): ws manager

This commit is contained in:
Anatoliy
2026-09-16 00:10:23 +03:00
parent 8ec6d5b799
commit 27e98bdb44
6 changed files with 201 additions and 5 deletions

View File

@@ -17,6 +17,7 @@ class ChatsCubit extends Cubit<ChatsState> {
final WsManager wsManager;
StreamSubscription? newIncomingMessagesSubscription;
StreamSubscription? newLastMessageSubscription;
StreamSubscription<void>? reconnectedSubscription;
ChatsCubit({
required this.chatRepository,
@@ -37,6 +38,11 @@ class ChatsCubit extends Cubit<ChatsState> {
newIncomingMessagesSubscription = wsManager.newMessagesStream?.listen((event) {
_handleNewMessageViaSocket(event.data);
});
await reconnectedSubscription?.cancel();
reconnectedSubscription = wsManager.reconnected.listen((_) {
unawaited(getChatRooms());
});
} catch (e, st) {
await reportFrom(e, st, this);
}
@@ -199,6 +205,7 @@ class ChatsCubit extends Cubit<ChatsState> {
@override
Future<void> close() {
newIncomingMessagesSubscription?.cancel();
reconnectedSubscription?.cancel();
return super.close();
}
}