mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 13:39:36 -06:00
FIX: Bug with cached topics not being marked as read in your topics
list.
This commit is contained in:
parent
ec4e268703
commit
c2c256cdd9
@ -196,10 +196,16 @@ Discourse.TopicList.reopenClass({
|
||||
**/
|
||||
list: function(filter, params) {
|
||||
var session = Discourse.Session.current(),
|
||||
list = session.get('topicList');
|
||||
list = session.get('topicList'),
|
||||
tracking = Discourse.TopicTrackingState.current();
|
||||
|
||||
if (list && (list.get('filter') === filter)) {
|
||||
list.set('loaded', true);
|
||||
|
||||
if (tracking) {
|
||||
tracking.updateTopics(list.get('topics'));
|
||||
}
|
||||
|
||||
return Ember.RSVP.resolve(list);
|
||||
}
|
||||
session.setProperties({topicList: null, topicListScrollPosition: null});
|
||||
@ -223,7 +229,13 @@ Discourse.TopicList.reopenClass({
|
||||
}
|
||||
});
|
||||
|
||||
return Discourse.TopicList.find(filter, _.extend(findParams, params || {}));
|
||||
return Discourse.TopicList.find(filter, _.extend(findParams, params || {})).then(function (list) {
|
||||
if (tracking) {
|
||||
tracking.sync(list, list.filter);
|
||||
tracking.trackIncoming(list.filter);
|
||||
}
|
||||
return list;
|
||||
});
|
||||
},
|
||||
|
||||
find: function(filter, params) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
Discourse.TopicTrackingState = Discourse.Model.extend({
|
||||
messageCount: 0,
|
||||
|
||||
init: function(){
|
||||
this._super();
|
||||
_setup: function() {
|
||||
this.unreadSequence = [];
|
||||
this.newSequence = [];
|
||||
this.states = {};
|
||||
},
|
||||
}.on('init'),
|
||||
|
||||
establishChannels: function() {
|
||||
var tracker = this;
|
||||
@ -104,18 +103,48 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
||||
delete this.states["t" + topic_id];
|
||||
},
|
||||
|
||||
sync: function(list, filter){
|
||||
var tracker = this;
|
||||
var states = this.states;
|
||||
// If we have a cached topic list, we can update it from our tracking
|
||||
// information.
|
||||
updateTopics: function(topics) {
|
||||
if (Em.isEmpty(topics)) { return; }
|
||||
|
||||
if(!list || !list.topics) { return; }
|
||||
var states = this.states;
|
||||
topics.forEach(function(t) {
|
||||
var state = states['t' + t.get('id')];
|
||||
|
||||
if (state) {
|
||||
var lastRead = t.get('last_read_post_number');
|
||||
if (lastRead !== state.last_read_post_number) {
|
||||
var postsCount = t.get('posts_count'),
|
||||
newPosts = postsCount - state.highest_post_number,
|
||||
unread = postsCount - state.last_read_post_number;
|
||||
|
||||
if (newPosts < 0) { newPosts = 0; }
|
||||
if (unread < 0) { unread = 0; }
|
||||
|
||||
t.setProperties({
|
||||
highest_post_number: state.highest_post_number,
|
||||
last_read_post_number: state.last_read_post_number,
|
||||
new_posts: newPosts,
|
||||
unread: unread
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
sync: function(list, filter) {
|
||||
var tracker = this,
|
||||
states = tracker.states;
|
||||
|
||||
if (!list || !list.topics) { return; }
|
||||
|
||||
// compensate for delayed "new" topics
|
||||
// client side we know they are not new, server side we think they are
|
||||
for(var i=list.topics.length-1; i>=0; i--){
|
||||
for (var i=list.topics.length-1; i>=0; i--) {
|
||||
var state = states["t"+ list.topics[i].id];
|
||||
if(state && state.last_read_post_number > 0){
|
||||
if(filter === "new"){
|
||||
if (state && state.last_read_post_number > 0) {
|
||||
if (filter === "new") {
|
||||
list.topics.splice(i, 1);
|
||||
} else {
|
||||
list.topics[i].unseen = false;
|
||||
@ -124,16 +153,16 @@ Discourse.TopicTrackingState = Discourse.Model.extend({
|
||||
}
|
||||
}
|
||||
|
||||
_.each(list.topics, function(topic){
|
||||
list.topics.forEach(function(topic){
|
||||
var row = tracker.states["t" + topic.id] || {};
|
||||
|
||||
row.topic_id = topic.id;
|
||||
if(topic.unseen) {
|
||||
|
||||
if (topic.unseen) {
|
||||
row.last_read_post_number = null;
|
||||
} else if (topic.unread || topic.new_posts){
|
||||
} else if (topic.unread || topic.new_posts) {
|
||||
row.last_read_post_number = topic.highest_post_number - ((topic.unread||0) + (topic.new_posts||0));
|
||||
} else {
|
||||
if(!topic.dont_sync) {
|
||||
if (!topic.dont_sync) {
|
||||
delete tracker.states["t" + topic.id];
|
||||
}
|
||||
return;
|
||||
|
@ -53,12 +53,6 @@ export default function(filter, params) {
|
||||
var findOpts = filterQueryParams(transaction.queryParams, params);
|
||||
|
||||
return Discourse.TopicList.list(listFilter, findOpts).then(function(list) {
|
||||
var tracking = Discourse.TopicTrackingState.current();
|
||||
if (tracking) {
|
||||
tracking.sync(list, listFilter);
|
||||
tracking.trackIncoming(listFilter);
|
||||
}
|
||||
|
||||
// If all the categories are the same, we can hide them
|
||||
var hideCategory = !list.get('topics').find(function (t) { return t.get('category') !== model; });
|
||||
list.set('hideCategory', hideCategory);
|
||||
|
@ -26,14 +26,7 @@ export default function(filter) {
|
||||
Discourse.ScreenTrack.current().stop();
|
||||
|
||||
var findOpts = filterQueryParams(transaction.queryParams);
|
||||
return Discourse.TopicList.list(filter, findOpts).then(function(list) {
|
||||
var tracking = Discourse.TopicTrackingState.current();
|
||||
if (tracking) {
|
||||
tracking.sync(list, filter);
|
||||
tracking.trackIncoming(filter);
|
||||
}
|
||||
return list;
|
||||
});
|
||||
return Discourse.TopicList.list(filter, findOpts);
|
||||
},
|
||||
|
||||
setupController: function(controller, model, trans) {
|
||||
|
@ -1,14 +1,13 @@
|
||||
|
||||
{{#if showDismissAtTop}}
|
||||
<div class="row">
|
||||
{{#if showDismissRead}}
|
||||
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" class='btn dismiss-read' {{action dismissRead "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>
|
||||
<button title="{{i18n topics.bulk.dismiss_posts_tooltip}}" class='btn dismiss-read' {{action dismissRead "posts"}}>{{i18n topics.bulk.dismiss_posts}}</button>
|
||||
{{/if}}
|
||||
{{#if showResetNew}}
|
||||
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.dismiss_new}}</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{#if showDismissRead}}
|
||||
<button title="{{i18n topics.bulk.dismiss_topics_tooltip}}" class='btn dismiss-read' {{action dismissRead "topics"}}>{{i18n topics.bulk.dismiss_topics}}</button>
|
||||
<button title="{{i18n topics.bulk.dismiss_posts_tooltip}}" class='btn dismiss-read' {{action dismissRead "posts"}}>{{i18n topics.bulk.dismiss_posts}}</button>
|
||||
{{/if}}
|
||||
{{#if showResetNew}}
|
||||
<button class='btn dismiss-read' {{action resetNew}}>{{i18n topics.bulk.dismiss_new}}</button>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if selected}}
|
||||
@ -37,8 +36,6 @@
|
||||
{{/if}}
|
||||
{{#sortable-heading sortBy="default" action="changeSort" order=order ascending=ascending}}
|
||||
{{i18n topic.title}}
|
||||
|
||||
|
||||
{{/sortable-heading}}
|
||||
{{#unless controller.hideCategory}}
|
||||
{{#sortable-heading sortBy="category" action="changeSort" order=order ascending=ascending}}
|
||||
|
Loading…
Reference in New Issue
Block a user