Search code examples
javascriptangularjsmeteormaterializeangular-meteor

Server-side triggered toast in Meteor


I have a case where few users are on a page (ui-router state) in a Meteor app using angular-meteor. I want to make a toast appear for all the users each time a user performs an action, which is an update for a collection.

I guess that for this I should trigger the toast from the server the moment the collection get updated, but since it's a CSS and client thing I can't figure out how to do it.

Is there a way to implement some listener on a collection and tell whenever it gets updated by a toast to all the users that are currently on a specific state (page)?


Solution

  • You'd have to create a notifications collection that inserts a notification for each user for each action. You'll also need a notifications pub/sub that subscribes to only the current user's notifications. Then, in your template helpers:

    notifications() {
        var notification = Notifications.findOne();
        if( notification ) {
          // Execute a modal popup or something - make sure to pass the current value.
          // Call a meteor method to remove the notification.
        }
    }