Class: Collavre::Channel
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Collavre::Channel
- Includes:
- IndexedJsonColumns
- 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--badge_title to provide a
localized title / aria-label string. Returning nil from badge_state
hides the badge entirely.
50 51 52 |
# File 'app/models/collavre/channel.rb', line 50 def badge_state nil end |
#badge_title ⇒ Object
54 55 56 |
# File 'app/models/collavre/channel.rb', line 54 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).
37 38 39 |
# File 'app/models/collavre/channel.rb', line 37 def default_label nil end |
#default_link ⇒ Object
41 42 43 |
# File 'app/models/collavre/channel.rb', line 41 def default_link nil end |
#detach! ⇒ Object
58 59 60 |
# File 'app/models/collavre/channel.rb', line 58 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.
70 71 72 73 74 75 |
# File 'app/models/collavre/channel.rb', line 70 def dismiss! transaction do detach! if active? update!(dismissed_at: Time.current) if dismissed_at.nil? end end |
#dismissed? ⇒ Boolean
62 63 64 |
# File 'app/models/collavre/channel.rb', line 62 def dismissed? dismissed_at.present? end |
#handle(event:, payload:) ⇒ Object
30 31 32 |
# File 'app/models/collavre/channel.rb', line 30 def handle(event:, payload:) raise NotImplementedError, "#{self.class} must implement #handle" end |
#inject_into_topic!(injected_message) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/collavre/channel.rb', line 81 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
77 78 79 |
# File 'app/models/collavre/channel.rb', line 77 def record_event!(label:, link:) update!(latest_label: label, latest_link: link, last_event_at: Time.current) end |