FIX: "Go Back" wasn't displaying properly most of the time

This commit is contained in:
Robin Ward
2016-05-24 16:21:23 -04:00
parent 3cebba5b1f
commit 3c30fa628b
5 changed files with 33 additions and 16 deletions

View File

@@ -849,14 +849,25 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
if (topic.get('id') === topicId) {
let highestReadPostId = 0;
// TODO identity map for postNumber
postStream.get('posts').forEach(post => {
if (!post.read && postNumbers.indexOf(post.post_number) !== -1) {
const id = post.get('id');
if (id > highestReadPostId) {
highestReadPostId = id;
}
post.set('read', true);
this.appEvents.trigger('post-stream:refresh', { id: post.id });
this.appEvents.trigger('post-stream:refresh', { id });
}
});
if (highestReadPostId > 0) {
topic.set('last_read_post_id', highestReadPostId);
}
const max = _.max(postNumbers);
if (max > topic.get("last_read_post_number")) {
topic.set("last_read_post_number", max);

View File

@@ -320,11 +320,6 @@ const TopicTrackingState = Discourse.Model.extend({
.length;
},
lastReadPostNumber(topicId) {
const state = this.states[`t${topicId}`];
return state ? state.last_read_post_number : null;
},
countCategory(category_id) {
let sum = 0;
_.each(this.states, function(topic){

View File

@@ -20,7 +20,7 @@ createWidget('timeline-last-read', {
this.attach('button', {
className: 'btn btn-primary btn-small',
icon: 'arrow-left',
label: 'go_back',
label: 'topic.timeline.back',
action: 'goBack'
})
];
@@ -92,7 +92,8 @@ createWidget('timeline-scrollarea', {
position() {
const { attrs } = this;
const percentage = this.state.percentage;
const postStream = attrs.topic.get('postStream');
const topic = attrs.topic;
const postStream = topic.get('postStream');
const total = postStream.get('filteredPostsCount');
let current = Math.round(total * percentage);
@@ -111,12 +112,13 @@ createWidget('timeline-scrollarea', {
lastReadPercentage: null
};
if (attrs.topicTrackingState) {
const lastRead = attrs.topicTrackingState.lastReadPostNumber(attrs.topic.id);
if (lastRead) {
result.lastRead = lastRead;
result.lastReadPercentage = lastRead === 1 ? 0.0 : parseFloat(lastRead) / total;
}
const lastReadId = topic.last_read_post_id;
const lastReadNumber = topic.last_read_post_number;
if (lastReadId && lastReadNumber) {
const idx = postStream.get('stream').indexOf(lastReadId) + 1;
result.lastRead = lastReadNumber;
result.lastReadPercentage = this._percentFor(topic, idx);
}
return result;
@@ -173,7 +175,6 @@ createWidget('timeline-scrollarea', {
_percentFor(topic, postNumber) {
const total = topic.get('postStream.filteredPostsCount');
console.log(postNumber, total);
let result = (postNumber === 1) ? 0.0 : parseFloat(postNumber) / total;
if (result < 0) { return 0.0; }