isolate notifications in channel per user

This commit is contained in:
Sam Saffron 2013-02-24 10:23:52 +11:00
parent f83494d012
commit 82e2fae1b8
5 changed files with 11 additions and 2050 deletions

View File

@ -46,8 +46,8 @@
var bus, user;
bus = Discourse.MessageBus;
// We don't want to receive any previous user notidications
bus.unsubscribe("/notification");
// We don't want to receive any previous user notifications
bus.unsubscribe("/notification/*");
bus.callbackInterval = Discourse.SiteSettings.anon_polling_interval;
bus.enableLongPolling = false;
user = this.get('currentUser');
@ -59,7 +59,7 @@
return user.set('site_flagged_posts_count', data.total);
});
}
return bus.subscribe("/notification", (function(data) {
return bus.subscribe("/notification/" + user.id, (function(data) {
user.set('unread_notifications', data.unread_notifications);
return user.set('unread_private_messages', data.unread_private_messages);
}), user.notification_channel_position);
@ -98,7 +98,8 @@
// If we're in the same topic, don't push the state
topicRegexp = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/;
newMatches = topicRegexp.exec(path);
if (newTopicId = newMatches ? newMatches[2] : void 0) {
newTopicId = newMatches ? newMatches[2] : null;
if (newTopicId) {
oldMatches = topicRegexp.exec(window.location.pathname);
if ((oldTopicId = oldMatches ? oldMatches[2] : void 0) && (oldTopicId === newTopicId)) {
Discourse.replaceState(path);
@ -255,8 +256,8 @@
return 0;
}
}).each(function(item) {
var output;
if (output = f("" + item.k, item.v)) {
var output = f("" + item.k, item.v);
if (output) {
return console.log(output);
}
});
@ -288,7 +289,7 @@
oldBuilder.call(this);
}
return builder.call(this);
}
};
},
start: function() {
this.bindDOMEvents();

View File

@ -49,10 +49,10 @@ class MessageBusObserver < DiscourseObserver
def refresh_notification_count(notification)
user_id = notification.user.id
MessageBus.publish("/notification",
MessageBus.publish("/notification/#{user_id}",
{unread_notifications: notification.user.unread_notifications,
unread_private_messages: notification.user.unread_private_messages},
user_ids: [notification.user.id] # only publish the notification to this user
user_ids: [user_id] # only publish the notification to this user
)
end
end

View File

@ -85,7 +85,6 @@ class PostAlertObserver < ActiveRecord::Observer
# Don't notify the same user about the same notification on the same post
return if user.notifications.exists?(notification_type: type, topic_id: post.topic_id, post_number: post.post_number)
user.notifications.create(notification_type: type,
topic_id: post.topic_id,
post_number: post.post_number,

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,6 @@ class MessageBus::Client
r = []
@subscriptions.each do |k,v|
next if v.to_i < 0
messages = MessageBus.backlog(k,v)
messages.each do |msg|
allowed = !msg.user_ids || msg.user_ids.include?(self.user_id)