Moved highestSeenByTopic to the Discourse.Session

This commit is contained in:
Robin Ward 2013-07-26 15:18:46 -04:00
parent 894dc2c6fd
commit e77ee1eaa8
5 changed files with 15 additions and 6 deletions

View File

@ -16,9 +16,6 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
// Are we currently scrolling?
scrolling: false,
// The highest seen post number by topic
highestSeenByTopic: {},
// Helps with integration tests
URL_FIXTURES: {},

View File

@ -98,7 +98,7 @@ Discourse.ScreenTrack = Ember.Object.extend({
highestSeen = Math.max(highestSeen, parseInt(postNumber, 10));
});
var highestSeenByTopic = Discourse.get('highestSeenByTopic');
var highestSeenByTopic = Discourse.Session.current('highestSeenByTopic');
if ((highestSeenByTopic[topicId] || 0) < highestSeen) {
highestSeenByTopic[topicId] = highestSeen;
Discourse.TopicTrackingState.current().updateSeen(topicId, highestSeen);

View File

@ -7,9 +7,14 @@
@namespace Discourse
@module Discourse
**/
Discourse.Session = Discourse.Model.extend({});
Discourse.Session = Discourse.Model.extend({
init: function() {
this.set('highestSeenByTopic', {});
}
});
Discourse.Session.reopenClass({
/**
Returns the current session.

View File

@ -87,7 +87,7 @@ Discourse.Topic = Discourse.Model.extend({
// So take what the browser has seen into consideration.
displayNewPosts: function() {
var delta, highestSeen, result;
if (highestSeen = Discourse.get('highestSeenByTopic')[this.get('id')]) {
if (highestSeen = Discourse.Session.current('highestSeenByTopic')[this.get('id')]) {
delta = highestSeen - this.get('last_read_post_number');
if (delta > 0) {
result = this.get('new_posts') - delta;

View File

@ -13,4 +13,11 @@ test('current', function(){
Discourse.Session.current('orange', 'juice');
equal(session.get('orange'), "juice", "it can be updated");
});
test('highestSeenByTopic', function() {
var session = Discourse.Session.current();
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
});