order posts by publishing date
This commit is contained in:
parent
affdd3e4fb
commit
d59c475b6b
@ -19,9 +19,11 @@ import com.google.firebase.firestore.DocumentReference;
|
|||||||
import com.google.firebase.firestore.DocumentSnapshot;
|
import com.google.firebase.firestore.DocumentSnapshot;
|
||||||
import com.google.firebase.firestore.Filter;
|
import com.google.firebase.firestore.Filter;
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.firestore.FirebaseFirestore;
|
||||||
|
import com.google.firebase.firestore.Query;
|
||||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -42,7 +44,7 @@ public class PostService {
|
|||||||
|
|
||||||
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||||
try {
|
try {
|
||||||
for (QueryDocumentSnapshot post : Tasks.await(db.collection("/post").get())) {
|
for (QueryDocumentSnapshot post : Tasks.await(db.collection("post").orderBy("date", Query.Direction.DESCENDING).get())) {
|
||||||
DocumentSnapshot user = Tasks.await(post.getDocumentReference("user").get());
|
DocumentSnapshot user = Tasks.await(post.getDocumentReference("user").get());
|
||||||
String username = user.get("username", String.class);
|
String username = user.get("username", String.class);
|
||||||
String email = user.get("email", String.class);
|
String email = user.get("email", String.class);
|
||||||
@ -96,8 +98,10 @@ public class PostService {
|
|||||||
|
|
||||||
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||||
try {
|
try {
|
||||||
for (QueryDocumentSnapshot post : Tasks.await(db.collection("/post")
|
for (QueryDocumentSnapshot post : Tasks.await(db.collection("post")
|
||||||
.where(Filter.equalTo("user", db.document("/user/"+username))).get())) {
|
.where(Filter.equalTo("user", db.document("/user/"+username)))
|
||||||
|
.orderBy("date", Query.Direction.DESCENDING)
|
||||||
|
.get())) {
|
||||||
DocumentSnapshot user = Tasks.await(post.getDocumentReference("user").get());
|
DocumentSnapshot user = Tasks.await(post.getDocumentReference("user").get());
|
||||||
String username = user.get("username", String.class);
|
String username = user.get("username", String.class);
|
||||||
String email = user.get("email", String.class);
|
String email = user.get("email", String.class);
|
||||||
@ -157,6 +161,7 @@ public class PostService {
|
|||||||
post.put("content", strings[0]);
|
post.put("content", strings[0]);
|
||||||
post.put("image", "");
|
post.put("image", "");
|
||||||
post.put("user", user.getReference());
|
post.put("user", user.getReference());
|
||||||
|
post.put("date", new Date().getTime());
|
||||||
Tasks.await(db.collection("post").add(post));
|
Tasks.await(db.collection("post").add(post));
|
||||||
|
|
||||||
Log.d(this.getClass().getName(), "after adding post");
|
Log.d(this.getClass().getName(), "after adding post");
|
||||||
|
Loading…
Reference in New Issue
Block a user