Show all Messages of One Conversation

Hello i am trying to build a chat live in a meteor App
well All it’s fine but i am having a little problem in showing the messages of one conversation in two seperated div “sent” and repley
this is a screenshot of my app

well in my helper i am getting the messages of a clicked conversation, i have a field called TypeMessage; if TypeMessage==“1” then i want to show that message in the sent div
and if TypeMessage==“2” then i want to show that message in the repley div
this is my helper code

 allMessagesOfConversation: function() {

        return Messages.find({idConversation: Session.get('conversationId')},{sort: {createdAt: -1}}).map(function(message, messageSender) {
            if (message.typeMessage ==="1") {
                return messageSender;
            }else {
                return message;



and this is my template code

 <div class="messages">
                    {{#each allMessagesOfConversation}}
                            {{#if isFirst}}

                                <li class="sent">
                                    <img src="" alt="" />
                                    <p>{{message}} </p>

                                <li class="replies">
                                    <img src="" alt="" />

correct me please

if (message.typeMessage === "1") {
  message.isFirst = true;
  return messageSender;
} else {
  return message;

Looks like you’re returning messageSender when you should be returning message:

if (message.typeMessage === "1") {
  message.isFirst = true;
return message;

And you should to do your subscriptions in the template’s onCreated hook, not in the helper

Also the map function on a cursor won’t pass (message, messageSender) to the callback. passes three arguments to the callback function: the document, a 0-based index, and cursor itself.

1 Like

thanks for replying , i changed my code and it worked

Thanks coagmano , i worked with your advice