Class: Collavre::Channel

Inherits:
ApplicationRecord show all
Includes:
IndexedJsonColumns
Defined in:
app/models/collavre/channel.rb,
app/models/collavre/channel/injected_message.rb

Direct Known Subclasses

PreviewChannel

Defined Under Namespace

Classes: InjectedMessage

Constant Summary collapse

BOT_EMAIL =
"channel@collavre.local"
BOT_NAME =
"Channel"

Instance Method Summary collapse

Instance Method Details

#badge_stateObject

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--), and 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_titleObject



54
55
56
# File 'app/models/collavre/channel.rb', line 54

def badge_title
  nil
end

#default_labelObject

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


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

Returns:

  • (Boolean)


62
63
64
# File 'app/models/collavre/channel.rb', line 62

def dismissed?
  dismissed_at.present?
end

#handle(event:, payload:) ⇒ Object

Raises:

  • (NotImplementedError)


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!(injected_message)
  transaction do
    comment = topic.creative.comments.create!(
      user: injected_message.speaker,
      topic_id: topic.id,
      content: injected_message.message,
      private: false
    )
    record_event!(label: injected_message.label, link: injected_message.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