Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making use of Meteor Streams as Message Threads #13

Open
liveitchina opened this issue Oct 1, 2013 · 7 comments
Open

Making use of Meteor Streams as Message Threads #13

liveitchina opened this issue Oct 1, 2013 · 7 comments

Comments

@liveitchina
Copy link

Having an issue integrating Meteor-Streams to the application i am creating. The design i am doing is much more similar to Streaming Private Page communication pattern. What will happen is that i have 2 text area with TO and the Message. In the TO field it is the recipient of the message and the MESSAGE field is the main message.

Issue: Meteor-Streams should only send the message to the designated recipient on the TO FIELD, NOT ALL USERS THAT IS ACTIVE. Is there a way on how will i approach this?

@arunoda
Copy link
Owner

arunoda commented Oct 1, 2013

How about this solution.

stream = new Meteor.Stream('private');

if(Meteor.isClient) {
  stream.on(Meteor.userId(), function(message) {
    alert('new message:', message);
  });

  sendMessage = function(message, to) {
    //to is an array of userIds (in your to field)
    stream.emit('send', message, to);
  }
}

if(Meteor.isServer) {
  stream.permissions.write(function(eventName) {
    return eventName == 'send';
  });

  stream.permissions.read(function(eventName) {
    return this.userId == eventName;
  });

  stream.on('send', function(message, to) {
    to.forEach(function(userId) {
      stream.emit(to, message);
    });
  });
}

@liveitchina
Copy link
Author

Hi Arunoda,

Thanks for the reply. I will try this out..

@ggmacasaet
Copy link

Hi Arunoda,

Does the solution you provided has already a collection attached to it? or that is only reachable if the Receiving User is online?

@arunoda
Copy link
Owner

arunoda commented Oct 21, 2013

I simply use Meteor.userId() for the demonstration purpose. You can use a nickname, random string or anything depending on your app.

@ggmacasaet
Copy link

Hi Arunoda,

Sorry for the confusion. What i meant is that are the messages already STORED inside a collection so that whenever a user has logged in he/she can already see the message that is intended for them?

@arunoda
Copy link
Owner

arunoda commented Oct 21, 2013

Okay. Now I got it.

Meteor Streams does not handle the message persistence. You can use stream
filters http://arunoda.github.io/meteor-streams/filters.html to store
messages to the db.
So, in the very first you can get messages via a meteor method or using
streams itself.

Is this answer your question?

On Mon, Oct 21, 2013 at 4:39 PM, ggmacasaet [email protected]:

Hi Arunoda,

Sorry for the confusion. What i meant is that are the messages already
STORED inside a collection so that whenever a user has logged in he/she can
already see the message that is intended for them?


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-26708570
.

Arunoda Susiripala

@arunoda http://twitter.com/arunoda
http://gplus.to/arunodahttps://github.com/arunoda
http://www.linkedin.com/in/arunoda

@iwoork
Copy link

iwoork commented Apr 24, 2014

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants