mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:11:09 +08:00
FIX: navigation item counters weren't updating properly
This commit is contained in:
@ -80,8 +80,9 @@ const NavItem = Discourse.Model.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@computed("topicTrackingState", "name", "category")
|
@computed("name", "category", "topicTrackingState.messageCount")
|
||||||
count(state, name, category) {
|
count(name, category) {
|
||||||
|
const state = this.get("topicTrackingState");
|
||||||
if (state) {
|
if (state) {
|
||||||
return state.lookupCount(name, category);
|
return state.lookupCount(name, category);
|
||||||
}
|
}
|
||||||
|
@ -179,8 +179,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||||||
delete this.states["t" + topic_id];
|
delete this.states["t" + topic_id];
|
||||||
},
|
},
|
||||||
|
|
||||||
// If we have a cached topic list, we can update it from our tracking
|
// If we have a cached topic list, we can update it from our tracking information.
|
||||||
// information.
|
|
||||||
updateTopics(topics) {
|
updateTopics(topics) {
|
||||||
if (Em.isEmpty(topics)) { return; }
|
if (Em.isEmpty(topics)) { return; }
|
||||||
|
|
||||||
@ -283,7 +282,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
incrementMessageCount() {
|
incrementMessageCount() {
|
||||||
this.set("messageCount", this.get("messageCount") + 1);
|
this.incrementProperty("messageCount");
|
||||||
},
|
},
|
||||||
|
|
||||||
countNew(category_id) {
|
countNew(category_id) {
|
||||||
@ -358,8 +357,7 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||||||
const states = this.states;
|
const states = this.states;
|
||||||
const idMap = Discourse.Category.idMap();
|
const idMap = Discourse.Category.idMap();
|
||||||
|
|
||||||
// I am taking some shortcuts here to avoid 500 gets for
|
// I am taking some shortcuts here to avoid 500 gets for a large list
|
||||||
// a large list
|
|
||||||
if (data) {
|
if (data) {
|
||||||
_.each(data,topic => {
|
_.each(data,topic => {
|
||||||
var category = idMap[topic.category_id];
|
var category = idMap[topic.category_id];
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import createStore from 'helpers/create-store';
|
||||||
|
|
||||||
QUnit.module("Discourse.NavItem", {
|
QUnit.module("Discourse.NavItem", {
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
Ember.run(function() {
|
Ember.run(function() {
|
||||||
@ -19,3 +21,15 @@ QUnit.test('href', assert =>{
|
|||||||
href('category/bug', '/c/bug', 'English category name');
|
href('category/bug', '/c/bug', 'English category name');
|
||||||
href('category/确实是这样', '/c/343434-category', 'Chinese category name');
|
href('category/确实是这样', '/c/343434-category', 'Chinese category name');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("count", assert => {
|
||||||
|
const navItem = createStore().createRecord("nav-item", { name: "new" });
|
||||||
|
|
||||||
|
assert.equal(navItem.get("count"), 0, "it has no count by default");
|
||||||
|
|
||||||
|
const tracker = navItem.get("topicTrackingState");
|
||||||
|
tracker.states["t1"] = { topic_id: 1, last_read_post_number: null };
|
||||||
|
tracker.incrementMessageCount();
|
||||||
|
|
||||||
|
assert.equal(navItem.get("count"), 1, "it updates when a new message arrives");
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user