mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 15:05:24 +08:00
BUGFIX: notifications were not updated correctly live
- missing notifications when multiple replies in topic (till refresh) - not cleared properly on click
This commit is contained in:
parent
1fcd72231a
commit
e06da1821d
|
@ -0,0 +1,11 @@
|
|||
Discourse.NotificationItemComponent = Ember.Component.extend({
|
||||
tagName: 'span',
|
||||
didInsertElement: function(){
|
||||
var self = this;
|
||||
this.$('a').click(function(){
|
||||
self.set('model.read', true);
|
||||
self.rerender();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
|
@ -16,6 +16,10 @@ export default Discourse.Controller.extend({
|
|||
return Discourse.User.current() && !this.get('topic.isPrivateMessage');
|
||||
}.property('topic.isPrivateMessage'),
|
||||
|
||||
resetCachedNotifications: function(){
|
||||
this.set("notifications", null);
|
||||
}.observes("currentUser.lastNotificationChange"),
|
||||
|
||||
actions: {
|
||||
toggleStar: function() {
|
||||
var topic = this.get('topic');
|
||||
|
@ -29,10 +33,11 @@ export default Discourse.Controller.extend({
|
|||
if (self.get('currentUser.unread_notifications') || self.get('currentUser.unread_private_messages') || !self.get('notifications')) {
|
||||
self.set("loading_notifications", true);
|
||||
Discourse.ajax("/notifications").then(function(result) {
|
||||
self.set('currentUser.unread_notifications', 0);
|
||||
|
||||
self.setProperties({
|
||||
notifications: result,
|
||||
loading_notifications: false,
|
||||
'currentUser.unread_notifications': 0
|
||||
loading_notifications: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,8 +18,15 @@ export default {
|
|||
});
|
||||
}
|
||||
bus.subscribe("/notification/" + user.get('id'), (function(data) {
|
||||
var oldUnread = user.get('unread_notifications');
|
||||
var oldPM = user.get('unread_private_messages');
|
||||
|
||||
user.set('unread_notifications', data.unread_notifications);
|
||||
user.set('unread_private_messages', data.unread_private_messages);
|
||||
|
||||
if(oldUnread !== data.unread_notifications || oldPM !== data.unread_private_messages) {
|
||||
user.set('lastNotificationChange', new Date());
|
||||
}
|
||||
}), user.notification_channel_position);
|
||||
|
||||
bus.subscribe("/categories", function(data){
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{unbound boundI18n scope linkBinding="model.link" usernameBinding="model.username"}}
|
|
@ -3,7 +3,7 @@
|
|||
{{#if content}}
|
||||
<ul>
|
||||
{{#each}}
|
||||
<li {{bind-attr class="read"}}>{{unbound boundI18n scope linkBinding="link" usernameBinding="username"}}</li>
|
||||
<li {{bind-attr class="read"}}>{{notification-item model=this scope=scope}}</li>
|
||||
{{/each}}
|
||||
<li class="read last">
|
||||
<a {{bind-attr href="currentUser.path"}}>{{i18n notifications.more}} …</a>
|
||||
|
|
|
@ -123,12 +123,7 @@ class Notification < ActiveRecord::Base
|
|||
protected
|
||||
|
||||
def refresh_notification_count
|
||||
user_id = user.id
|
||||
MessageBus.publish("/notification/#{user_id}",
|
||||
{unread_notifications: user.unread_notifications,
|
||||
unread_private_messages: user.unread_private_messages},
|
||||
user_ids: [user_id] # only publish the notification to this user
|
||||
)
|
||||
user.publish_notifications_state
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -76,6 +76,8 @@ class PostAlerter
|
|||
|
||||
user.notifications.where(notification_type: type,
|
||||
topic_id: topic.id).destroy_all
|
||||
# HACK so notification counts sync up correctly
|
||||
user.reload
|
||||
end
|
||||
|
||||
def create_notification(user, type, post, opts={})
|
||||
|
|
Loading…
Reference in New Issue
Block a user