Class: Pageflow::EntryCommentSummary Private

Inherits:
Object
  • Object
show all
Defined in:
app/models/pageflow/entry_comment_summary.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Counts of comment topics and of activity the user has not seen, for displaying an indicator next to an entry in lists of entries.

Built for a whole page of entries at once: rendering a list must not query per row.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_count:, unread_topic_count:, unread_reply_count:, unread_resolution_count: 0) ⇒ EntryCommentSummary

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of EntryCommentSummary.



26
27
28
29
30
31
32
# File 'app/models/pageflow/entry_comment_summary.rb', line 26

def initialize(topic_count:, unread_topic_count:, unread_reply_count:,
               unread_resolution_count: 0)
  @topic_count = topic_count
  @unread_topic_count = unread_topic_count
  @unread_reply_count = unread_reply_count
  @unread_resolution_count = unread_resolution_count
end

Instance Attribute Details

#topic_countObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'app/models/pageflow/entry_comment_summary.rb', line 10

def topic_count
  @topic_count
end

#unread_reply_countObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'app/models/pageflow/entry_comment_summary.rb', line 10

def unread_reply_count
  @unread_reply_count
end

#unread_resolution_countObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'app/models/pageflow/entry_comment_summary.rb', line 10

def unread_resolution_count
  @unread_resolution_count
end

#unread_topic_countObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'app/models/pageflow/entry_comment_summary.rb', line 10

def unread_topic_count
  @unread_topic_count
end

Class Method Details

.for_entries(entries, user:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/pageflow/entry_comment_summary.rb', line 12

def self.for_entries(entries, user:)
  entries = entries.to_a
  return {} if entries.empty?

  threads = threads_by_entry_id(entries)
  read_at = read_at_by_entry_id(entries, user)

  entries.to_h do |entry|
    [entry.id, build(threads.fetch(entry.id, []),
                     read_at: read_at.fetch(entry.id, {}),
                     user:)]
  end
end

Instance Method Details

#any?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unread activity shows even where no topic is left open: the last one being resolved is exactly what the user should not miss.

Returns:

  • (Boolean)


36
37
38
# File 'app/models/pageflow/entry_comment_summary.rb', line 36

def any?
  topic_count.positive? || unread?
end

#unread?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


40
41
42
43
44
# File 'app/models/pageflow/entry_comment_summary.rb', line 40

def unread?
  unread_topic_count.positive? ||
    unread_reply_count.positive? ||
    unread_resolution_count.positive?
end