Class: Collavre::Channel

Inherits:
ApplicationRecord show all
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–<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_titleObject



38
39
40
# File 'app/models/collavre/channel.rb', line 38

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).



21
22
23
# File 'app/models/collavre/channel.rb', line 21

def default_label
  nil
end


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

Returns:

  • (Boolean)


46
47
48
# File 'app/models/collavre/channel.rb', line 46

def dismissed?
  dismissed_at.present?
end

#handle(event:, payload:) ⇒ Object

Raises:

  • (NotImplementedError)


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!(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



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