prosapp_web_app has chat, dashboard, calendar, support, 13 providers and Fluro URL routing. Keep Dockerfile + nginx.conf from previous prosappweb. Upgrade google_fonts 6.2.1 → 8.1.0 (Dart 3.12 compat fix). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'dart:developer';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:prosapp_web_app/models/chat_entity.dart';
|
|
import 'package:prosapp_web_app/models/message_entity.dart';
|
|
|
|
class FirebaseChatRepository {
|
|
final chatCollection = FirebaseFirestore.instance.collection('chats');
|
|
|
|
Stream<ChatEntity?> getChatById(String chatId) {
|
|
return chatCollection.doc(chatId).snapshots().map((snapshot) {
|
|
try {
|
|
if (snapshot.exists) {
|
|
return ChatEntity.fromDocument(snapshot.data()!);
|
|
} else {
|
|
return null;
|
|
}
|
|
} catch (e) {
|
|
log(e.toString());
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<ChatEntity> createNewChat(
|
|
String chatId, String userId, String professionalId) async {
|
|
ChatEntity chat = ChatEntity(
|
|
id: chatId,
|
|
userId: userId,
|
|
professionalId: professionalId,
|
|
messages: const [],
|
|
);
|
|
|
|
await chatCollection.doc(chatId).set(chat.toDocument());
|
|
|
|
return chat;
|
|
}
|
|
|
|
sendMessage(String chatId, MessageEntity message) {
|
|
chatCollection.doc(chatId).update({
|
|
'messages': FieldValue.arrayUnion([message.toDocument()])
|
|
});
|
|
}
|
|
}
|