Class: Unread

Inherits:
Object
  • Object
show all
Defined in:
lib/unread.rb

Instance Method Summary collapse

Constructor Details

#initialize(topic, topic_user, guardian) ⇒ Unread

This module helps us calculate unread post counts



6
7
8
9
10
# File 'lib/unread.rb', line 6

def initialize(topic, topic_user, guardian)
  @guardian = guardian
  @topic = topic
  @topic_user = topic_user
end

Instance Method Details

#unread_postsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/unread.rb', line 12

def unread_posts
  return 0 if @topic_user.last_read_post_number.blank?
  return 0 if do_not_notify?(@topic_user.notification_level)

  highest_post_number =
    @guardian.is_whisperer? ? @topic.highest_staff_post_number : @topic.highest_post_number

  return 0 if @topic_user.last_read_post_number > highest_post_number

  unread = (highest_post_number - @topic_user.last_read_post_number)
  unread = 0 if unread < 0
  unread
end