Help for Simple Meteor Algorithm

Implement a simple Meteor Application for messaging between users who are logged in. Messages should disappear from the system after a definite timeout. Timeout value should be initialized by the sender ?

I have one prototype but I can’t added log in system all logged in users see other logged in users. and see messages also but messages don’t arrive end of time that sender’s initialized before

We need more information to know how to help you.

1 Like

I write this but I just started web programming with Meteor framework. I don’t know it’s true.

/** BOTH **/
Messages = new Mongo.Collection(‘chat’);

/** SERVER **/
//publish a users message
Meteor.publish(‘chat’, function() {
return Messages.find({
toUser: this.userId

//add a new message
‘createMessage’: function(message, timeout) {
//check if message is valid
message.expiresAt = + timeout;
message.sentBy = Meteor.userId();

//clear old messages
Meteor.setInterval(function() {
expiresAt: {$lt:}
}, 1000*60); //every min

/** CLIENT **/
window.createMessage = function(message, toUser, timeout = 30000) {‘createMessage’, {
text: message,
}, timeout, function(err) {
if(!err) {

//creates a subscription which will get all messages

//this creates an observer so you can see how messages are added and deleted
added: function(message) {
console.log(‘new message’, message);
removed: function(messageId) {
console.log(‘message expired’, messageId);

I want login system but all users must see other logged in users and messages until end of the time ( sender’s create time)

But it may not work. I want a simple algorithm. If logic is true enough for me .

You could use socialize:messaging and add a TTL index on the messages collection.