Need help to sort the chat

I can’t sort the discussion by date. someone to help me i’m confused and lost

What is last msg ms? You know you can just sort by created date or modified date right? Unless there is a very particular reason you don’t even need to have that last msg ms attribute.

“last message creation data” … I tried that too but it didn’t work

So yeah, first of all you don’t need that, because creation date is programmed into each data type by default. What happens when you try to sort it by creation date?

the “chat” is between two people the “message” is the one containing the discussion the photos… as I want to sort the “chat” by the last message this is why I created the “last msg ms” to store the date of the last “message” send… I sorted by the creation date but it didn’t work maybe I arranged things wrong

Ok, couple of things. last-mesg is unnecessary because each message will have a creation date by default (so just sort by creation date, descneding = yes). Also what is msg user? Creator of the message? Unless you have messages created by the system itself, you don’t need a msg user because yoou have the creator of the message by default. Also in the chat itself you don’t need a last msg ms for the same reason mentioned above.

Actually I recently built a chat app myself, so I will just share the data structure that I used to create the chat (I have tested it and it works properly).

As you can see my Conversation (Chat in your case) has only Participants. Message itself has parent Conversation, Participants (which it inherits from parent Conversation; this is done in order to include those 2 participants in the messages within a specific Conversation), Status (in your case this would be yes/no value of read), and Text, which is self explanatory. You can just use the same data structure and add another field of image to the Message data type. Try it, it works :slight_smile:

ok thank you for your information, I will try the new method to see how it will work… I will get back to you

This topic was automatically closed after 70 days. New replies are no longer allowed.