fixed a pile of notification craziness

addes some tests around post timings
This commit is contained in:
Sam Saffron
2013-02-25 18:42:42 +11:00
parent cb3d839104
commit 77a2d8ccc4
7 changed files with 116 additions and 49 deletions
+28
View File
@@ -39,4 +39,32 @@ class PostTiming < ActiveRecord::Base
end
end
def self.process_timings(current_user, topic_id, highest_seen, topic_time, timings)
current_user.update_time_read!
original_unread = current_user.unread_notifications_by_type
timings.each do |post_number, time|
if post_number >= 0
PostTiming.record_timing(topic_id: topic_id,
post_number: post_number,
user_id: current_user.id,
msecs: time)
end
end
total_changed = 0
if timings.length > 0
total_changed = Notification.mark_posts_read(current_user, topic_id, timings.map{|t| t[0]})
end
TopicUser.update_last_read(current_user, topic_id, highest_seen, topic_time)
if total_changed > 0
current_user.reload
current_user.publish_notifications_state
end
end
end