mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
fix topic counts not updating automatically in various spots (top menu / categories page / drop down)
This commit is contained in:
@@ -114,13 +114,17 @@ Discourse.Category = Discourse.Model.extend({
|
|||||||
return this.get("topics")[0];
|
return this.get("topics")[0];
|
||||||
}.property("topics"),
|
}.property("topics"),
|
||||||
|
|
||||||
|
topicTrackingState: function(){
|
||||||
|
return Discourse.TopicTrackingState.current();
|
||||||
|
}.property(),
|
||||||
|
|
||||||
unreadTopics: function(){
|
unreadTopics: function(){
|
||||||
return Discourse.TopicTrackingState.current().countUnread(this.get('name'));
|
return this.get('topicTrackingState').countUnread(this.get('name'));
|
||||||
}.property('Discourse.TopicTrackingState.current.messageCount'),
|
}.property('topicTrackingState.messageCount'),
|
||||||
|
|
||||||
newTopics: function(){
|
newTopics: function(){
|
||||||
return Discourse.TopicTrackingState.current().countNew(this.get('name'));
|
return this.get('topicTrackingState').countNew(this.get('name'));
|
||||||
}.property('Discourse.TopicTrackingState.current.messageCount')
|
}.property('topicTrackingState.messageCount')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -13,16 +13,22 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
|||||||
var tracker = this;
|
var tracker = this;
|
||||||
|
|
||||||
var process = function(data){
|
var process = function(data){
|
||||||
|
|
||||||
if (data.message_type === "delete") {
|
if (data.message_type === "delete") {
|
||||||
tracker.removeTopic(data.topic_id);
|
tracker.removeTopic(data.topic_id);
|
||||||
|
tracker.incrementMessageCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type === "read") {
|
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type === "read") {
|
||||||
tracker.notify(data);
|
tracker.notify(data);
|
||||||
tracker.states["t" + data.topic_id] = data.payload;
|
var old = tracker.states["t" + data.topic_id];
|
||||||
|
|
||||||
|
if(!_.isEqual(old, data.payload)){
|
||||||
|
tracker.states["t" + data.topic_id] = data.payload;
|
||||||
|
tracker.incrementMessageCount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tracker.incrementMessageCount();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Discourse.MessageBus.subscribe("/new", process);
|
Discourse.MessageBus.subscribe("/new", process);
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
{{#if currentUser}}
|
{{#if currentUser}}
|
||||||
{{#with view.category}}
|
{{#with view.category}}
|
||||||
{{#if unreadTopics}}
|
{{#if unreadTopics}}
|
||||||
<a href={{unbound unreadUrl}} class='badge unread-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a>
|
<a href={{unbound unreadUrl}} class='badge unread-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unreadTopics}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if newTopics}}
|
{{#if newTopics}}
|
||||||
<a href={{unbound newUrl}} class='badge new-posts badge-notification' title='{{i18n topic.new_topics count="newTopics"}}'>{{unbound newTopics}} <i class='icon icon-asterisk'></i></a>
|
<a href={{unbound newUrl}} class='badge new-posts badge-notification' title='{{i18n topic.new_topics count="newTopics"}}'>{{newTopics}} <i class='icon icon-asterisk'></i></a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|||||||
@@ -54,10 +54,10 @@
|
|||||||
{{topicStatus topic=this}}
|
{{topicStatus topic=this}}
|
||||||
<a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
|
<a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
|
||||||
{{#if unread}}
|
{{#if unread}}
|
||||||
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unbound unread}}</a>
|
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unread}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if new_posts}}
|
{{#if new_posts}}
|
||||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{unbound new_posts}}</a>
|
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{new_posts}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if unseen}}
|
{{#if unseen}}
|
||||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
|
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ Discourse.NavItemView = Discourse.View.extend({
|
|||||||
attributeBindings: ['title'],
|
attributeBindings: ['title'],
|
||||||
|
|
||||||
hidden: Em.computed.not('content.visible'),
|
hidden: Em.computed.not('content.visible'),
|
||||||
count: Ember.computed.alias('content.count'),
|
shouldRerender: Discourse.View.renderIfChanged('content.count'),
|
||||||
shouldRerender: Discourse.View.renderIfChanged('count'),
|
|
||||||
active: Discourse.computed.propertyEqual('content.filterMode', 'controller.filterMode'),
|
active: Discourse.computed.propertyEqual('content.filterMode', 'controller.filterMode'),
|
||||||
|
|
||||||
title: function() {
|
title: function() {
|
||||||
@@ -41,7 +40,7 @@ Discourse.NavItemView = Discourse.View.extend({
|
|||||||
extra.categoryName = Discourse.Formatter.toTitleCase(categoryName);
|
extra.categoryName = Discourse.Formatter.toTitleCase(categoryName);
|
||||||
}
|
}
|
||||||
return I18n.t("filters." + name + ".title", extra);
|
return I18n.t("filters." + name + ".title", extra);
|
||||||
}.property('count'),
|
}.property('content.count'),
|
||||||
|
|
||||||
render: function(buffer) {
|
render: function(buffer) {
|
||||||
var content = this.get('content');
|
var content = this.get('content');
|
||||||
|
|||||||
@@ -53,25 +53,26 @@ class TopicTrackingState
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageBus.publish("/unread/#{tu.user_id}", message.as_json, group_ids: group_ids)
|
MessageBus.publish("/unread/#{tu.user_id}", message.as_json, group_ids: group_ids)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.publish_read(topic_id, last_read_post_number, user_id)
|
def self.publish_read(topic_id, last_read_post_number, user_id)
|
||||||
|
|
||||||
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
|
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
|
||||||
|
|
||||||
message = {
|
message = {
|
||||||
topic_id: topic_id,
|
topic_id: topic_id,
|
||||||
message_type: "read",
|
message_type: "read",
|
||||||
payload: {
|
payload: {
|
||||||
last_read_post_number: last_read_post_number,
|
last_read_post_number: last_read_post_number,
|
||||||
highest_post_number: highest_post_number,
|
highest_post_number: highest_post_number,
|
||||||
topic_id: topic_id
|
topic_id: topic_id
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id])
|
||||||
|
|
||||||
MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.treat_as_new_topic_clause
|
def self.treat_as_new_topic_clause
|
||||||
|
|||||||
Reference in New Issue
Block a user