Class: Collavre::Channel
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Collavre::Channel
- Defined in:
- app/models/collavre/channel.rb,
app/models/collavre/channel/injected_message.rb
Direct Known Subclasses
Defined Under Namespace
Classes: InjectedMessage
Constant Summary collapse
- BOT_EMAIL =
"channel@collavre.local"- BOT_NAME =
"Channel"
Instance Method Summary collapse
-
#badge_state ⇒ Object
Badge interface for the typing-indicator chip.
- #badge_title ⇒ Object
-
#default_label ⇒ Object
Chip fallbacks rendered before any webhook event populates latest_label / latest_link.
- #default_link ⇒ Object
- #detach! ⇒ Object
-
#dismiss! ⇒ Object
Hide the chip from the typing-indicator row.
- #dismissed? ⇒ Boolean
- #handle(event:, payload:) ⇒ Object
- #inject_into_topic!(injected_message) ⇒ Object
- #record_event!(label:, link:) ⇒ Object
Instance Method Details
#badge_state ⇒ Object
Badge interface for the typing-indicator chip. Subclasses override ‘badge_state` to drive the chip badge color (the value becomes a CSS modifier: channel-chip-badge–<state>), and `badge_title` to provide a localized title / aria-label string. Returning nil from `badge_state` hides the badge entirely.
34 35 36 |
# File 'app/models/collavre/channel.rb', line 34 def badge_state nil end |
#badge_title ⇒ Object
38 39 40 |
# File 'app/models/collavre/channel.rb', line 38 def badge_title nil end |
#default_label ⇒ Object
Chip fallbacks rendered before any webhook event populates latest_label / latest_link. Base class returns nil; subclasses override when they can derive a stable label/link from their own config (e.g. PR #N + URL).
21 22 23 |
# File 'app/models/collavre/channel.rb', line 21 def default_label nil end |
#default_link ⇒ Object
25 26 27 |
# File 'app/models/collavre/channel.rb', line 25 def default_link nil end |
#detach! ⇒ Object
42 43 44 |
# File 'app/models/collavre/channel.rb', line 42 def detach! update!(state: :detached) end |
#dismiss! ⇒ Object
Hide the chip from the typing-indicator row. Performs detach! as a side-effect when the channel is still active so dismissal is a single user-facing action — clicking the X always removes the chip regardless of prior state.
54 55 56 57 58 59 |
# File 'app/models/collavre/channel.rb', line 54 def dismiss! transaction do detach! if active? update!(dismissed_at: Time.current) if dismissed_at.nil? end end |
#dismissed? ⇒ Boolean
46 47 48 |
# File 'app/models/collavre/channel.rb', line 46 def dismissed? dismissed_at.present? end |
#handle(event:, payload:) ⇒ Object
14 15 16 |
# File 'app/models/collavre/channel.rb', line 14 def handle(event:, payload:) raise NotImplementedError, "#{self.class} must implement #handle" end |
#inject_into_topic!(injected_message) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/collavre/channel.rb', line 65 def inject_into_topic!() transaction do comment = topic.creative.comments.create!( user: .speaker, topic_id: topic.id, content: ., private: false ) record_event!(label: .label, link: .link) comment end end |
#record_event!(label:, link:) ⇒ Object
61 62 63 |
# File 'app/models/collavre/channel.rb', line 61 def record_event!(label:, link:) update!(latest_label: label, latest_link: link, last_event_at: Time.current) end |