Skip to content

Commit 6544f39

Browse files
committed
fix topic counts not updating automatically in various spots (top menu / categories page / drop down)
1 parent 92528d7 commit 6544f39

6 files changed

Lines changed: 34 additions & 24 deletions

File tree

app/assets/javascripts/discourse/models/category.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ Discourse.Category = Discourse.Model.extend({
114114
return this.get("topics")[0];
115115
}.property("topics"),
116116

117+
topicTrackingState: function(){
118+
return Discourse.TopicTrackingState.current();
119+
}.property(),
120+
117121
unreadTopics: function(){
118-
return Discourse.TopicTrackingState.current().countUnread(this.get('name'));
119-
}.property('Discourse.TopicTrackingState.current.messageCount'),
122+
return this.get('topicTrackingState').countUnread(this.get('name'));
123+
}.property('topicTrackingState.messageCount'),
120124

121125
newTopics: function(){
122-
return Discourse.TopicTrackingState.current().countNew(this.get('name'));
123-
}.property('Discourse.TopicTrackingState.current.messageCount')
126+
return this.get('topicTrackingState').countNew(this.get('name'));
127+
}.property('topicTrackingState.messageCount')
124128

125129
});
126130

app/assets/javascripts/discourse/models/topic_tracking_state.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
1313
var tracker = this;
1414

1515
var process = function(data){
16+
1617
if (data.message_type === "delete") {
1718
tracker.removeTopic(data.topic_id);
19+
tracker.incrementMessageCount();
1820
}
1921

2022
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type === "read") {
2123
tracker.notify(data);
22-
tracker.states["t" + data.topic_id] = data.payload;
24+
var old = tracker.states["t" + data.topic_id];
25+
26+
if(!_.isEqual(old, data.payload)){
27+
tracker.states["t" + data.topic_id] = data.payload;
28+
tracker.incrementMessageCount();
29+
}
2330
}
2431

25-
tracker.incrementMessageCount();
2632
};
2733

2834
Discourse.MessageBus.subscribe("/new", process);

app/assets/javascripts/discourse/templates/components/header-category-info.js.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
{{#if currentUser}}
33
{{#with view.category}}
44
{{#if unreadTopics}}
5-
<a href={{unbound unreadUrl}} class='badge unread-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unbound unreadTopics}}</a>
5+
<a href={{unbound unreadUrl}} class='badge unread-posts badge-notification' title='{{i18n topic.unread_topics count="unreadTopics"}}'>{{unreadTopics}}</a>
66
{{/if}}
77
{{#if newTopics}}
8-
<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>
8+
<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>
99
{{/if}}
1010
{{/with}}
1111
{{else}}

app/assets/javascripts/discourse/templates/list/wide_categories.js.handlebars

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
{{topicStatus topic=this}}
5555
<a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
5656
{{#if unread}}
57-
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unbound unread}}</a>
57+
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unread}}</a>
5858
{{/if}}
5959
{{#if new_posts}}
60-
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{unbound new_posts}}</a>
60+
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{new_posts}}</a>
6161
{{/if}}
6262
{{#if unseen}}
6363
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>

app/assets/javascripts/discourse/views/nav_item_view.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Discourse.NavItemView = Discourse.View.extend({
1212
attributeBindings: ['title'],
1313

1414
hidden: Em.computed.not('content.visible'),
15-
count: Ember.computed.alias('content.count'),
16-
shouldRerender: Discourse.View.renderIfChanged('count'),
15+
shouldRerender: Discourse.View.renderIfChanged('content.count'),
1716
active: Discourse.computed.propertyEqual('content.filterMode', 'controller.filterMode'),
1817

1918
title: function() {
@@ -41,7 +40,7 @@ Discourse.NavItemView = Discourse.View.extend({
4140
extra.categoryName = Discourse.Formatter.toTitleCase(categoryName);
4241
}
4342
return I18n.t("filters." + name + ".title", extra);
44-
}.property('count'),
43+
}.property('content.count'),
4544

4645
render: function(buffer) {
4746
var content = this.get('content');

app/models/topic_tracking_state.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,26 @@ def self.publish_unread(post)
5353
}
5454

5555
MessageBus.publish("/unread/#{tu.user_id}", message.as_json, group_ids: group_ids)
56-
5756
end
57+
5858
end
5959

6060
def self.publish_read(topic_id, last_read_post_number, user_id)
6161

62-
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
62+
highest_post_number = Topic.where(id: topic_id).pluck(:highest_post_number).first
6363

64-
message = {
65-
topic_id: topic_id,
66-
message_type: "read",
67-
payload: {
68-
last_read_post_number: last_read_post_number,
69-
highest_post_number: highest_post_number,
70-
topic_id: topic_id
71-
}
64+
message = {
65+
topic_id: topic_id,
66+
message_type: "read",
67+
payload: {
68+
last_read_post_number: last_read_post_number,
69+
highest_post_number: highest_post_number,
70+
topic_id: topic_id
7271
}
72+
}
73+
74+
MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id])
7375

74-
MessageBus.publish("/unread/#{user_id}", message.as_json, user_ids: [user_id])
7576
end
7677

7778
def self.treat_as_new_topic_clause

0 commit comments

Comments
 (0)