Class: Bible270::Comment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Bible270::Comment
- Defined in:
- app/models/bible270/comment.rb
Overview
A publicly visible reflection attached to a plan day (optionally a track).
Constant Summary collapse
- HEART =
One heart for both states. An unliked one is the same emoji shown grey by CSS, so it cannot drift in size from a real like, and hovering it previews exactly what clicking will produce.
The white heart this replaced was legible on white but nearly invisible on the paper background; an outline glyph like U+2661 is drawn by the font rather than the emoji set and needs hand-tuning to match.
'❤️'
Instance Method Summary collapse
-
#edited? ⇒ Boolean
A second's grace: created_at and updated_at differ by microseconds on insert, which would mark every reflection as edited.
- #hidden? ⇒ Boolean
-
#hide! ⇒ Object
Every reflection is visible when written; these are the moderation actions.
- #liked_by?(reader) ⇒ Boolean
- #moderated? ⇒ Boolean
- #reply? ⇒ Boolean
-
#toggle_like!(reader) ⇒ Object
Toggling returns the new state, so a caller can say what happened without asking again.
- #unhide! ⇒ Object
-
#visible_replies ⇒ Object
Visible replies, oldest first: a conversation reads forwards.
Instance Method Details
#edited? ⇒ Boolean
A second's grace: created_at and updated_at differ by microseconds on insert, which would mark every reflection as edited.
84 |
# File 'app/models/bible270/comment.rb', line 84 def edited? = updated_at - created_at > 1 |
#hidden? ⇒ Boolean
58 |
# File 'app/models/bible270/comment.rb', line 58 def hidden? = !approved |
#hide! ⇒ Object
Every reflection is visible when written; these are the moderation actions.
56 |
# File 'app/models/bible270/comment.rb', line 56 def hide! = update!(approved: false, moderated_at: Time.current) |
#liked_by?(reader) ⇒ Boolean
61 62 63 64 65 |
# File 'app/models/bible270/comment.rb', line 61 def liked_by?(reader) return false if reader.nil? likes.any? { |like| like.reader_id == reader.id } end |
#moderated? ⇒ Boolean
88 |
# File 'app/models/bible270/comment.rb', line 88 def moderated? = moderated_at.present? |
#reply? ⇒ Boolean
59 |
# File 'app/models/bible270/comment.rb', line 59 def reply? = parent_id.present? |
#toggle_like!(reader) ⇒ Object
Toggling returns the new state, so a caller can say what happened without asking again.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/bible270/comment.rb', line 69 def toggle_like!(reader) existing = likes.find { |like| like.reader_id == reader.id } if existing existing.destroy likes.reload false else likes.create(reader: reader) likes.reload true end end |
#unhide! ⇒ Object
57 |
# File 'app/models/bible270/comment.rb', line 57 def unhide! = update!(approved: true, moderated_at: Time.current) |
#visible_replies ⇒ Object
Visible replies, oldest first: a conversation reads forwards.
87 |
# File 'app/models/bible270/comment.rb', line 87 def visible_replies = replies.approved.order(created_at: :asc) |