forked from eatvio/eatvio_app
added unread messages and unread chats counters
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart';
|
||||
@@ -10,10 +12,18 @@ import 'package:http_parser/http_parser.dart';
|
||||
class ChatRepository {
|
||||
final ChatService chatService;
|
||||
|
||||
final _newUserMessagesController = StreamController<ChatMessageModel>();
|
||||
|
||||
Stream<ChatMessageModel> get newUserMessagesStream => _newUserMessagesController.stream;
|
||||
|
||||
ChatRepository({
|
||||
required this.chatService,
|
||||
});
|
||||
|
||||
void emitNewMessageToChats(ChatMessageModel message) {
|
||||
_newUserMessagesController.add(message);
|
||||
}
|
||||
|
||||
Future<void> sendMessage({
|
||||
required String chatId,
|
||||
String? data,
|
||||
@@ -66,7 +76,7 @@ class ChatRepository {
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<ChatRoomModel> getChatRoomIdByUserSlug({required String slug}) async {
|
||||
try {
|
||||
@@ -75,4 +85,12 @@ class ChatRepository {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> markMessagesAsRead(String chatId, List<int> messageIds) async {
|
||||
try {
|
||||
await chatService.markMessagesAsRead(id: chatId, body: {'messages_ids': messageIds});
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user