I am currently working on a Meteor application that also has a chat functionality.
I want to have a list of all conversations that show the most recent message in each conversation. (Similar to Sample of a basic conversation overview)
Let's say I have a collection Messages with a variable conversationId. New messages get assigned a new conversationId and any replies will get assigned the conversationId of the first message.
To achieve this conversation overview, my question is, how do I return from my collection only the most recent entry for each conversationId?
This is where I am stuck:
Template.tabsTwo.helpers({
messages: function () {
//to retrieve all messages from the logged in user, then retrieve the conversationIDs and drop duplicates
var userMessages = Messages.find({senderId: Meteor.userId()}, {sort: {date_created: -1, subject: -1}});
var userConversationIds = userMessages.map((function(a) {
return a.conversationId;
}));
var uniqueConversationIDs = [];
$.each(userConversationIds, function(i, el){
if($.inArray(el, uniqueConversationIDs) === -1) uniqueConversationIDs.push(el);
});
return Messages.find({conversationId: {$in:uniqueConversationIDs}}, {sort: {date_created: -1}});
}
});
This still gives me back all messages. I am asking myself right now if I can modify this query to make it work or if I need to approach this differently (e.g. do a loop and a .findOne query)?
(I have tried many things and searched for answers in the docs and SO but have troubles getting this right. Any help would be greatly appreciated.)
Does anyone knows how to directly call a array key of a Map Object. As shown in below code, I can map.get(arr), but not map.get([0, 1, 2, 3]) const map = new Map() const arr = [0,1,2,3] map....
Does anyone knows how to directly call a array key of a Map Object. As shown in below code, I can map.get(arr), but not map.get([0, 1, 2, 3]) const map = new Map() const arr = [0,1,2,3] map....
In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?
In my console's browser, when I do : console.log(typeof(typeof)) it returns an error Uncaught SyntaxError: Unexpected token ')' Why is that? Why can't I get typeof's type ?
ul element that has dynamically loaded li a children, sometimes the li a populate empty innerHTML. How do I remove all of the li elements that have an empty a child? Current (errors Uncaught ...
ul element that has dynamically loaded li a children, sometimes the li a populate empty innerHTML. How do I remove all of the li elements that have an empty a child? Current (errors Uncaught ...
I'm building a Node.js app (Node v10.11.0) and want to do it in a OOP-way without using Typescript. So I've built some classes like this: class Component { constructor(param1, param2, param3) { ...
I'm building a Node.js app (Node v10.11.0) and want to do it in a OOP-way without using Typescript. So I've built some classes like this: class Component { constructor(param1, param2, param3) { ...