Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/com/safaorhan/reunion/FirestoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
Expand Down Expand Up @@ -102,7 +103,7 @@ public static void sendMessage(final String messageText, final DocumentReference
@Override
public void onSuccess(DocumentReference documentReference) {
conversationRef
.update("lastMessage", documentReference)
.update("lastMessage", documentReference, "conversationTime", Timestamp.now())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need to send conversationTime since it's annotated as @ServerTimestamp.

It should get updated everytime you do an update.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it but it didn't update. It creates time stamp when conversation created. Because of that, I added this line. I added it to order last updated conversation. If you prefer I can add a new timestamp and we have created time and last updated time.

.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setConversationClickListener(ConversationClickListener conversationC
public static ConversationAdapter get() {
Query query = FirebaseFirestore.getInstance()
.collection("conversations")
//.orderBy("timestamp")
.orderBy("conversationTime", Query.Direction.DESCENDING)
.whereEqualTo(FirestoreHelper.getMe().getId(), true)
.limit(50);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.safaorhan.reunion.model;

import com.google.firebase.Timestamp;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.DocumentReference;

Expand All @@ -9,6 +10,8 @@ public class Conversation {
String id;
DocumentReference lastMessage;
List<DocumentReference> participants;
@ServerTimestamp
Timestamp conversationTime;

public String getId() {
return id;
Expand Down