From 631efe6f9ebf12e6adcdc940e9bb4c7c153a5b5e Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Fri, 11 Jul 2025 14:22:11 +0300 Subject: [PATCH] fix: chats --- lib/features/chat/models/chat_room_pagination_model.dart | 2 ++ .../chat/presentation/bloc/chats_cubit/chats_cubit.dart | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/features/chat/models/chat_room_pagination_model.dart b/lib/features/chat/models/chat_room_pagination_model.dart index 699df5e8..19de28c3 100644 --- a/lib/features/chat/models/chat_room_pagination_model.dart +++ b/lib/features/chat/models/chat_room_pagination_model.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/models/pagination_model.dart'; import 'package:eatvio_app/features/chat/models/chat_message_model.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -10,6 +11,7 @@ abstract class ChatRoomPaginationModel with _$ChatRoomPaginationModel { const factory ChatRoomPaginationModel({ @JsonKey(name: "data") required List data, @JsonKey(name: "number_of_unread_chat_rooms") required int unreadChatsCount, + required Meta meta, }) = _ChatRoomPreviewModel; factory ChatRoomPaginationModel.fromJson(Map json) => _$ChatRoomPaginationModelFromJson(json); diff --git a/lib/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart b/lib/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart index 24028797..174108b3 100644 --- a/lib/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart +++ b/lib/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart @@ -21,7 +21,7 @@ class ChatsCubit extends Cubit { required this.chatRepository, required this.wsManager, required this.profileRepository, - }) : super(ChatsState()) { + }) : super(ChatsState()) { newLastMessageSubscription = chatRepository.newUserMessagesStream.listen((message) { _setNewLastMessage(message); }); @@ -29,6 +29,7 @@ class ChatsCubit extends Cubit { String? _query; int page = 1; late int lastPage; + Future connectToWebSocket() async { await newIncomingMessagesSubscription?.cancel(); newIncomingMessagesSubscription = wsManager.newMessagesStream?.listen((event) { @@ -43,7 +44,7 @@ class ChatsCubit extends Cubit { try { final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query); final unreadChats = chatRoomsPaginationModel.unreadChatsCount; - // lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1; + lastPage = chatRoomsPaginationModel.meta.lastPage + 1; emit( state.copyWith( chatRooms: chatRoomsPaginationModel.data, @@ -65,7 +66,7 @@ class ChatsCubit extends Cubit { try { final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query); final unreadChats = chatRoomsPaginationModel.unreadChatsCount; - // lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1; + lastPage = chatRoomsPaginationModel.meta.lastPage + 1; emit( state.copyWith( chatRooms: chatRoomsPaginationModel.data,