How to limit #each to show only one result if specific condition is met

Hey there,

I have a message collection that stores all messages as their own object, with a field that references the current conversation.

When I do and each loop it shows all messages in the side, even if they’re from the same conversation. This only happens on the person who sent the messages end.

How can I make it so that it only shows the first object with the conversation ID and not all of them?

Is each iterating over a cursor ( Collection.find() ) or an array? Why don’t you limit in your helper what each gets to iterate over?

2 Likes

Hey there, I eventually figured it out.

I was trying to build a private messaging system where the conversation preview was in the side (like facebook).

However each message is it’s own object and it was iterating through all of those objects in the side view filling it up every time the user replied.

How I fixed this was every time you send an original message to someone, it is marked as first and ever reply in that thread is not marked at all, and then the each statement shows all messages marked first.

A quick and easy way to get a private messaging system up!

Cheers for trying to help me though :slight_smile: