correct watcher, live updates for unread

This commit is contained in:
Sam 2013-05-30 16:49:11 +10:00
parent 6ad86aa305
commit d20056ad0e
4 changed files with 14 additions and 8 deletions

View File

@ -47,7 +47,7 @@ Discourse.ListController = Discourse.Controller.extend({
draft_key: items.draft_key,
draft_sequence: items.draft_sequence
});
if(trackingState) {
if(trackingState) {
trackingState.sync(items, filterMode);
trackingState.trackIncoming(filterMode);
}

View File

@ -17,9 +17,9 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
tracker.removeTopic(data.topic_id);
}
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type == "read") {
tracker.states["t" + data.topic_id] = data.payload;
if (data.message_type === "new_topic" || data.message_type === "unread" || data.message_type === "read") {
tracker.notify(data);
tracker.states["t" + data.topic_id] = data.payload;
}
tracker.incrementMessageCount();
@ -38,6 +38,12 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
if ((this.filter === "latest" || this.filter === "new") && data.message_type === "new_topic" ) {
this.newIncoming.push(data.topic_id);
}
if (this.filter === "unread" && data.message_type === "unread") {
var old = this.states["t" + data.topic_id];
if(!old) {
this.newIncoming.push(data.topic_id);
}
}
this.set("incomingCount", this.newIncoming.length);
},

View File

@ -49,7 +49,7 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
if(topics) {
return this.get('list.topics').length > 0 || this.get('topicTrackingState.hasIncoming');
}
}.property('list.topics','topicTrackingState.hasIncoming'),
}.property('list.topics.@each','topicTrackingState.hasIncoming'),
loadMore: function() {
var listTopicsView = this;

View File

@ -48,13 +48,13 @@ puts "Simulating activity for user id #{user.id}: #{user.name}"
while true
# puts "Creating a random topi"
puts "Creating a random topic"
# category = Category.where(secure: false).order('random()').first
# PostCreator.create(user, raw: sentence, title: sentence[0..50].strip, category: category.name)
category = Category.where(secure: false).order('random()').first
PostCreator.create(user, raw: sentence, title: sentence[0..50].strip, category: category.name)
puts "creating random reply"
PostCreator.create(user, raw: sentence, topic_id: last_topics.sample)
sleep 3
sleep 10
end