mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FEATURE: rush posting read times for newly read posts
FEATURE: "read" indicator on posts CHANGE: anon is now assumed to have read everything
This commit is contained in:
parent
d7f62f7148
commit
3405253405
|
@ -550,20 +550,22 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
}
|
||||
}.observes('currentPost'),
|
||||
|
||||
sawObjects: function(posts) {
|
||||
if (posts) {
|
||||
var self = this,
|
||||
lastReadPostNumber = this.get('last_read_post_number');
|
||||
readPosts: function(topicId, postNumbers) {
|
||||
var postStream = this.get('postStream');
|
||||
|
||||
posts.forEach(function(post) {
|
||||
var postNumber = post.get('post_number');
|
||||
if (postNumber > lastReadPostNumber) {
|
||||
lastReadPostNumber = postNumber;
|
||||
if(this.get('postStream.topic.id') === topicId){
|
||||
_.each(postStream.get('posts'), function(post){
|
||||
// optimise heavy loop
|
||||
// TODO identity map for postNumber
|
||||
if(_.include(postNumbers,post.post_number) && !post.read){
|
||||
post.set("read", true);
|
||||
}
|
||||
post.set('read', true);
|
||||
});
|
||||
self.set('last_read_post_number', lastReadPostNumber);
|
||||
|
||||
var max = _.max(postNumbers);
|
||||
if(max > this.get('last_read_post_number')){
|
||||
this.set('last_read_post_number', max);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
this.reset();
|
||||
},
|
||||
|
||||
start: function(topicId) {
|
||||
start: function(topicId, topicController) {
|
||||
var currentTopicId = this.get('topicId');
|
||||
if (currentTopicId && (currentTopicId !== topicId)) {
|
||||
this.tick();
|
||||
|
@ -34,6 +34,7 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
}
|
||||
|
||||
this.set('topicId', topicId);
|
||||
this.set('topicController', topicController);
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
|
@ -46,6 +47,7 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
this.flush();
|
||||
this.reset();
|
||||
this.set('topicId', null);
|
||||
this.set('topicController', null);
|
||||
if (this.get('interval')) {
|
||||
clearInterval(this.get('interval'));
|
||||
this.set('interval', null);
|
||||
|
@ -87,7 +89,8 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
if (!Discourse.User.current()) return;
|
||||
|
||||
var newTimings = {},
|
||||
totalTimings = this.get('totalTimings');
|
||||
totalTimings = this.get('totalTimings'),
|
||||
self = this;
|
||||
|
||||
_.each(this.get('timings'), function(timing) {
|
||||
if (!totalTimings[timing.postNumber])
|
||||
|
@ -126,6 +129,14 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
headers: {
|
||||
'X-SILENCE-LOGGER': 'true'
|
||||
}
|
||||
}).then(function(){
|
||||
var controller = self.get('topicController');
|
||||
if(controller){
|
||||
var postNumbers = Object.keys(newTimings).map(function(v){
|
||||
return parseInt(v,10);
|
||||
});
|
||||
controller.readPosts(topicId, postNumbers);
|
||||
}
|
||||
});
|
||||
|
||||
this.set('topicTime', 0);
|
||||
|
@ -145,7 +156,16 @@ Discourse.ScreenTrack = Ember.Object.extend({
|
|||
var diff = new Date().getTime() - this.get('lastTick');
|
||||
this.set('lastFlush', this.get('lastFlush') + diff);
|
||||
this.set('lastTick', new Date().getTime());
|
||||
if (this.get('lastFlush') > (Discourse.SiteSettings.flush_timings_secs * 1000)) {
|
||||
|
||||
var totalTimings = this.get('totalTimings'), timings = this.get('timings');
|
||||
var nextFlush = Discourse.SiteSettings.flush_timings_secs * 1000;
|
||||
|
||||
// rush new post numbers
|
||||
var rush = _.any(_.filter(timings, function(t){return t.time>0;}), function(t){
|
||||
return !totalTimings[t.postNumber];
|
||||
});
|
||||
|
||||
if (this.get('lastFlush') > nextFlush || rush) {
|
||||
this.flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ Discourse.TopicRoute = Discourse.Route.extend({
|
|||
controller.subscribe();
|
||||
|
||||
// We reset screen tracking every time a topic is entered
|
||||
Discourse.ScreenTrack.current().start(model.get('id'));
|
||||
Discourse.ScreenTrack.current().start(model.get('id'), controller);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div {{bind-attr class=":read-state read"}} title="{{i18n post.unread}}"><i class='fa fa-circle'></i></div>
|
||||
</div>
|
||||
|
||||
<div {{bind-attr class=":select-posts controller.multiSelect::hidden"}}>
|
||||
|
|
|
@ -51,7 +51,7 @@ h1 .topic-statuses .topic-status i {
|
|||
|
||||
.reply-to-tab {
|
||||
position: absolute;
|
||||
right: 350px;
|
||||
right: 375px;
|
||||
z-index: 400;
|
||||
padding: 13px 6px 5px;
|
||||
border-top: 1px solid scale-color-diff();
|
||||
|
@ -1080,3 +1080,17 @@ span.highlighted {
|
|||
.username.new-user a {
|
||||
color: scale-color($primary, $lightness: 70%);
|
||||
}
|
||||
|
||||
.read-state {
|
||||
color: scale-color($tertiary, $lightness: 50%);
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
margin-top: 1px;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.read-state.read {
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 1s ease-out;
|
||||
transition: opacity 1s ease-out;
|
||||
}
|
||||
|
|
|
@ -940,6 +940,7 @@ en:
|
|||
other: "{{count}} posts hidden"
|
||||
more_links: "{{count}} more..."
|
||||
|
||||
unread: "Post is unread"
|
||||
has_replies:
|
||||
one: "Reply"
|
||||
other: "Replies"
|
||||
|
|
|
@ -183,6 +183,7 @@ class TopicView
|
|||
end
|
||||
|
||||
def read?(post_number)
|
||||
return true unless @user
|
||||
read_posts_set.include?(post_number)
|
||||
end
|
||||
|
||||
|
|
|
@ -169,8 +169,8 @@ describe TopicView do
|
|||
|
||||
context '.read?' do
|
||||
it 'tracks correctly' do
|
||||
# anon has nothing
|
||||
TopicView.new(topic.id).read?(1).should be_false
|
||||
# anon is assumed to have read everything
|
||||
TopicView.new(topic.id).read?(1).should be_true
|
||||
|
||||
# random user has nothing
|
||||
topic_view.read?(1).should be_false
|
||||
|
|
|
@ -88,7 +88,7 @@ describe SiteSetting do
|
|||
end
|
||||
|
||||
describe "top_menu" do
|
||||
before(:each) { SiteSetting.stubs(:top_menu).returns('one,-nope|two|three,-not|four,ignored|category/xyz') }
|
||||
before(:each) { SiteSetting.top_menu = 'one,-nope|two|three,-not|four,ignored|category/xyz' }
|
||||
|
||||
describe "items" do
|
||||
let(:items) { SiteSetting.top_menu_items }
|
||||
|
|
Loading…
Reference in New Issue
Block a user