@@ -18,6 +18,7 @@ class PostService {
18
18
retweetsCount: doc.data ()['retweetsCount' ] ?? 0 ,
19
19
retweet: doc.data ()['retweet' ] ?? false ,
20
20
originalId: doc.data ()['originalId' ] ?? null ,
21
+ ref: doc.reference,
21
22
);
22
23
}).toList ();
23
24
}
@@ -33,6 +34,7 @@ class PostService {
33
34
retweetsCount: snapshot.data ()['retweetsCount' ] ?? 0 ,
34
35
retweet: snapshot.data ()['retweet' ] ?? false ,
35
36
originalId: snapshot.data ()['originalId' ] ?? null ,
37
+ ref: snapshot.reference,
36
38
)
37
39
: null ;
38
40
}
@@ -41,7 +43,20 @@ class PostService {
41
43
await FirebaseFirestore .instance.collection ("posts" ).add ({
42
44
'text' : text,
43
45
'creator' : FirebaseAuth .instance.currentUser.uid,
44
- 'timestamp' : FieldValue .serverTimestamp ()
46
+ 'timestamp' : FieldValue .serverTimestamp (),
47
+ 'retweet' : false
48
+ });
49
+ }
50
+
51
+ Future reply (PostModel post, String text) async {
52
+ if (text == '' ) {
53
+ return ;
54
+ }
55
+ await post.ref.collection ("replies" ).add ({
56
+ 'text' : text,
57
+ 'creator' : FirebaseAuth .instance.currentUser.uid,
58
+ 'timestamp' : FieldValue .serverTimestamp (),
59
+ 'retweet' : false
45
60
});
46
61
}
47
62
@@ -149,6 +164,15 @@ class PostService {
149
164
.map (_postListFromSnapshot);
150
165
}
151
166
167
+ Future <List <PostModel >> getReplies (PostModel post) async {
168
+ QuerySnapshot querySnapshot = await post.ref
169
+ .collection ("replies" )
170
+ .orderBy ('timestamp' , descending: true )
171
+ .get ();
172
+
173
+ return _postListFromSnapshot (querySnapshot);
174
+ }
175
+
152
176
Future <List <PostModel >> getFeed () async {
153
177
List <String > usersFollowing = await UserService () //['uid1', 'uid2']
154
178
.getUserFollowing (FirebaseAuth .instance.currentUser.uid);
0 commit comments