Merge branch 'fix_whisper'

This commit is contained in:
Sam
2016-12-05 10:01:03 +11:00
22 changed files with 328 additions and 103 deletions

View File

@@ -146,6 +146,9 @@ class PostCreator
end
if @post && errors.blank?
# update counters etc.
@post.topic.reload
publish
track_latest_on_category
@@ -199,7 +202,9 @@ class PostCreator
set_reply_info(post)
post.word_count = post.raw.scan(/[[:word:]]+/).size
post.post_number ||= Topic.next_post_number(post.topic_id, post.reply_to_post_number.present?)
whisper = post.post_type == Post.types[:whisper]
post.post_number ||= Topic.next_post_number(post.topic_id, post.reply_to_post_number.present?, whisper)
cooking_options = post.cooking_options || {}
cooking_options[:topic_id] = post.topic_id

View File

@@ -35,7 +35,7 @@ class PostJobsEnqueuer
def after_post_create
TopicTrackingState.publish_unread(@post) if @post.post_number > 1
TopicTrackingState.publish_latest(@topic)
TopicTrackingState.publish_latest(@topic, @post.post_type == Post.types[:whisper])
Jobs.enqueue_in(
SiteSetting.email_time_window_mins.minutes,

View File

@@ -242,9 +242,12 @@ class TopicQuery
.where("COALESCE(tu.notification_level, :tracking) >= :tracking", tracking: TopicUser.notification_levels[:tracking])
end
def self.unread_filter(list)
list.where("tu.last_read_post_number < topics.highest_post_number")
.where("COALESCE(tu.notification_level, :regular) >= :tracking", regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking])
def self.unread_filter(list, opts)
col_name = opts[:staff] ? "highest_staff_post_number" : "highest_post_number"
list.where("tu.last_read_post_number < topics.#{col_name}")
.where("COALESCE(tu.notification_level, :regular) >= :tracking",
regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking])
end
def prioritize_pinned_topics(topics, options)
@@ -320,7 +323,7 @@ class TopicQuery
end
def unread_results(options={})
result = TopicQuery.unread_filter(default_results(options.reverse_merge(:unordered => true)))
result = TopicQuery.unread_filter(default_results(options.reverse_merge(:unordered => true)), staff: @user.try(:staff?))
.order('CASE WHEN topics.user_id = tu.user_id THEN 1 ELSE 2 END')
self.class.results_filter_callbacks.each do |filter_callback|
@@ -656,7 +659,7 @@ class TopicQuery
end
def unread_messages(params)
TopicQuery.unread_filter(messages_for_groups_or_user(params[:my_group_ids]))
TopicQuery.unread_filter(messages_for_groups_or_user(params[:my_group_ids]), staff: @user.try(:staff?))
.limit(params[:count])
end

View File

@@ -2,7 +2,8 @@ class Unread
# This module helps us calculate unread and new post counts
def initialize(topic, topic_user)
def initialize(topic, topic_user, guardian)
@guardian = guardian
@topic = topic
@topic_user = topic_user
end
@@ -18,9 +19,12 @@ class Unread
def new_posts
return 0 if @topic_user.highest_seen_post_number.blank?
return 0 if do_not_notify?(@topic_user.notification_level)
return 0 if (@topic_user.last_read_post_number||0) > @topic.highest_post_number
new_posts = (@topic.highest_post_number - @topic_user.highest_seen_post_number)
highest_post_number = @guardian.is_staff? ? @topic.highest_staff_post_number : @topic.highest_post_number
return 0 if (@topic_user.last_read_post_number||0) > highest_post_number
new_posts = (highest_post_number - @topic_user.highest_seen_post_number)
new_posts = 0 if new_posts < 0
return new_posts
end