2 Added example of preventing messages from displaying
source | link

You should be able to add an event listener onto the MessageCenter listening for the "newmessage" event. You'll probably have to filter off of the returned event object's data property. It's a multi step process, as the data object only contains a messageID property. You can use this identifier to retrieve the actual message object, and perform your predicate off of that.

$messages.addEventListener('newmessage', function (event) {
    var messageId = event.data.messageID;
    var message = $messages.getMessageByID(messageId);
    var className = message.getClassName();

    if (className === "goal") {
        // do something with goals... etc...
    }
});

Hope that helps!

Update

If trying to prevent a message of a certain type from displaying completely, I wasn't able to find an out of the box way (at least poking at the 2013 SP1 API, not sure if Web 8 introduced a way). Calling doArchive and dispose from the event handler causes the message to show for a brief moment before fading away.

We can of course do a little monkey patching by keeping a reference of the original MessageCenter's registerMessage method and overriding it to perform our check in there. If its a message we should hide, we can call the doArchive or dispose from there as well as not call the original method. If the message is fine to show, we then pass the message param to our original method. Here's a quick example of doing such a process to not display any goal messages:

var originalRegisterMessage = Tridion.MessageCenter.prototype.registerMessage; // we store the original register message here...

Tridion.MessageCenter.prototype.registerMessage = function (msg) {
    if (msg.getClassName() === 'goal') {
        // don't do anything if its a goal message
        msg.doArchive(); // marks as read, call this if you still want it to display in the Show All area
        msg.dispose(); // or call this so doesn't show up in notification center at all
        return;
    }
    originalRegisterMessage.call(this, msg); // call the original function if the notification should show
};

You should be able to add an event listener onto the MessageCenter listening for the "newmessage" event. You'll probably have to filter off of the returned event object's data property. It's a multi step process, as the data object only contains a messageID property. You can use this identifier to retrieve the actual message object, and perform your predicate off of that.

$messages.addEventListener('newmessage', function (event) {
    var messageId = event.data.messageID;
    var message = $messages.getMessageByID(messageId);
    var className = message.getClassName();

    if (className === "goal") {
        // do something with goals... etc...
    }
});

Hope that helps!

You should be able to add an event listener onto the MessageCenter listening for the "newmessage" event. You'll probably have to filter off of the returned event object's data property. It's a multi step process, as the data object only contains a messageID property. You can use this identifier to retrieve the actual message object, and perform your predicate off of that.

$messages.addEventListener('newmessage', function (event) {
    var messageId = event.data.messageID;
    var message = $messages.getMessageByID(messageId);
    var className = message.getClassName();

    if (className === "goal") {
        // do something with goals... etc...
    }
});

Hope that helps!

Update

If trying to prevent a message of a certain type from displaying completely, I wasn't able to find an out of the box way (at least poking at the 2013 SP1 API, not sure if Web 8 introduced a way). Calling doArchive and dispose from the event handler causes the message to show for a brief moment before fading away.

We can of course do a little monkey patching by keeping a reference of the original MessageCenter's registerMessage method and overriding it to perform our check in there. If its a message we should hide, we can call the doArchive or dispose from there as well as not call the original method. If the message is fine to show, we then pass the message param to our original method. Here's a quick example of doing such a process to not display any goal messages:

var originalRegisterMessage = Tridion.MessageCenter.prototype.registerMessage; // we store the original register message here...

Tridion.MessageCenter.prototype.registerMessage = function (msg) {
    if (msg.getClassName() === 'goal') {
        // don't do anything if its a goal message
        msg.doArchive(); // marks as read, call this if you still want it to display in the Show All area
        msg.dispose(); // or call this so doesn't show up in notification center at all
        return;
    }
    originalRegisterMessage.call(this, msg); // call the original function if the notification should show
};
1
source | link

You should be able to add an event listener onto the MessageCenter listening for the "newmessage" event. You'll probably have to filter off of the returned event object's data property. It's a multi step process, as the data object only contains a messageID property. You can use this identifier to retrieve the actual message object, and perform your predicate off of that.

$messages.addEventListener('newmessage', function (event) {
    var messageId = event.data.messageID;
    var message = $messages.getMessageByID(messageId);
    var className = message.getClassName();

    if (className === "goal") {
        // do something with goals... etc...
    }
});

Hope that helps!