I need assistance with comparing timestamps and userIds of messages in a collection. Specifically, I want to access the data of the previous message in relation to the current one when rendering each message in the collection. Any tips on how to achieve this would be greatly appreciated.
Below are my templates:
<template name="messageList">
<ul>
{{#each messages}}
{{>messageItem}}
{{/each}}
</ul>
</template>
<template name="messageItem">
<li>
<p class="{{nameVisibility}}">{{userName}}</p>
<p>{{body}}</p>
</li>
</template>
This is from my helpers file:
Template.messageItem.helpers({
nameVisibility: function() {
//I am unsure how to query the previous message.
previousMessage = Messages.findOne(...);
if (this.userId != previousMessage.userId) {
return false;
else {
return "hideName";
}
}
});