mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:05:15 +08:00
Moved highestSeenByTopic to the Discourse.Session
This commit is contained in:
parent
894dc2c6fd
commit
e77ee1eaa8
|
@ -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: {},
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user