fix: chats

This commit is contained in:
mso7nueh
2025-07-11 14:22:11 +03:00
parent 0749a53e24
commit 631efe6f9e
2 changed files with 6 additions and 3 deletions

View File

@@ -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/chat/models/chat_message_model.dart';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
@@ -10,6 +11,7 @@ abstract class ChatRoomPaginationModel with _$ChatRoomPaginationModel {
const factory ChatRoomPaginationModel({ const factory ChatRoomPaginationModel({
@JsonKey(name: "data") required List<ChatRoom> data, @JsonKey(name: "data") required List<ChatRoom> data,
@JsonKey(name: "number_of_unread_chat_rooms") required int unreadChatsCount, @JsonKey(name: "number_of_unread_chat_rooms") required int unreadChatsCount,
required Meta meta,
}) = _ChatRoomPreviewModel; }) = _ChatRoomPreviewModel;
factory ChatRoomPaginationModel.fromJson(Map<String, dynamic> json) => _$ChatRoomPaginationModelFromJson(json); factory ChatRoomPaginationModel.fromJson(Map<String, dynamic> json) => _$ChatRoomPaginationModelFromJson(json);

View File

@@ -21,7 +21,7 @@ class ChatsCubit extends Cubit<ChatsState> {
required this.chatRepository, required this.chatRepository,
required this.wsManager, required this.wsManager,
required this.profileRepository, required this.profileRepository,
}) : super(ChatsState()) { }) : super(ChatsState()) {
newLastMessageSubscription = chatRepository.newUserMessagesStream.listen((message) { newLastMessageSubscription = chatRepository.newUserMessagesStream.listen((message) {
_setNewLastMessage(message); _setNewLastMessage(message);
}); });
@@ -29,6 +29,7 @@ class ChatsCubit extends Cubit<ChatsState> {
String? _query; String? _query;
int page = 1; int page = 1;
late int lastPage; late int lastPage;
Future<void> connectToWebSocket() async { Future<void> connectToWebSocket() async {
await newIncomingMessagesSubscription?.cancel(); await newIncomingMessagesSubscription?.cancel();
newIncomingMessagesSubscription = wsManager.newMessagesStream?.listen((event) { newIncomingMessagesSubscription = wsManager.newMessagesStream?.listen((event) {
@@ -43,7 +44,7 @@ class ChatsCubit extends Cubit<ChatsState> {
try { try {
final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query); final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query);
final unreadChats = chatRoomsPaginationModel.unreadChatsCount; final unreadChats = chatRoomsPaginationModel.unreadChatsCount;
// lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1; lastPage = chatRoomsPaginationModel.meta.lastPage + 1;
emit( emit(
state.copyWith( state.copyWith(
chatRooms: chatRoomsPaginationModel.data, chatRooms: chatRoomsPaginationModel.data,
@@ -65,7 +66,7 @@ class ChatsCubit extends Cubit<ChatsState> {
try { try {
final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query); final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query);
final unreadChats = chatRoomsPaginationModel.unreadChatsCount; final unreadChats = chatRoomsPaginationModel.unreadChatsCount;
// lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1; lastPage = chatRoomsPaginationModel.meta.lastPage + 1;
emit( emit(
state.copyWith( state.copyWith(
chatRooms: chatRoomsPaginationModel.data, chatRooms: chatRoomsPaginationModel.data,