-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.dart
55 lines (48 loc) · 1.44 KB
/
database.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'package:cloud_firestore/cloud_firestore.dart';
class DatabaseMethods {
getUserByUsername(String username) async {
return await FirebaseFirestore.instance
.collection("Users")
.where("username", isEqualTo: username)
.get();
}
getUserByUserEmail(String email) async {
return await FirebaseFirestore.instance
.collection("Users")
.where("email", isEqualTo: email)
.get();
}
uploadUserInfo(Map usermap) {
FirebaseFirestore.instance.collection("Users").add(usermap);
}
createChatRoom(String chatRoomId, Map chatRoomMap) {
FirebaseFirestore.instance
.collection("chatroom")
.doc(chatRoomId)
.set(chatRoomMap);
}
addChatMessages(String chatRoomId, Map chatMap) {
FirebaseFirestore.instance
.collection("chatroom")
.doc(chatRoomId)
.collection("chats")
.add(chatMap)
.catchError((e) {
print(e.toString());
});
}
getChatMessages(String chatRoomId) async {
return await FirebaseFirestore.instance
.collection("chatroom")
.doc(chatRoomId)
.collection("chats")
.orderBy("time", descending: false)
.snapshots();
}
getChatRooms(String userName) async {
return await FirebaseFirestore.instance
.collection("chatroom")
.where("Users", arrayContains: userName)
.snapshots();
}
}