Module: Livechat::InboxHelper
- Defined in:
- app/helpers/livechat/inbox_helper.rb
Constant Summary collapse
- AVATAR_COLORS =
Agents have no avatar images (no FK to host users) — initials in a deterministically colored circle do the job: same label, same color, every page load. Full label rides the title tooltip.
6
Instance Method Summary collapse
- #livechat_agent_avatar(label) ⇒ Object
- #livechat_attachment_link(attachment) ⇒ Object
-
#livechat_cable_data(stream_name) ⇒ Object
data-* attributes that hand dashboard.js a signed cable stream to watch, or {} when push is off.
-
#livechat_message_attachments(message) ⇒ Object
A message's attachments, rendered like the widget: images inline as thumbnails, everything else as a download link.
Instance Method Details
#livechat_agent_avatar(label) ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/helpers/livechat/inbox_helper.rb', line 10 def livechat_agent_avatar(label) initials = label.to_s.split.first(2).map { |word| word[0] }.join.upcase initials = label.to_s.first(2).upcase if initials.blank? color = label.to_s.each_byte.sum % AVATAR_COLORS tag.span(initials, class: "avatar color-#{color}", title: label) end |
#livechat_attachment_link(attachment) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/livechat/inbox_helper.rb', line 40 def () if [:image] link_to image_tag([:url], alt: [:name], loading: 'lazy'), [:url], target: '_blank', rel: 'noopener', class: 'att-img' else link_to [:name], [:url], target: '_blank', rel: 'noopener', class: 'att-file' end end |
#livechat_cable_data(stream_name) ⇒ Object
data-* attributes that hand dashboard.js a signed cable stream to watch, or {} when push is off. Merge into the element that already polls, so a nudge just fires its existing refresh sooner.
33 34 35 36 37 38 |
# File 'app/helpers/livechat/inbox_helper.rb', line 33 def livechat_cable_data(stream_name) return {} unless Livechat.action_cable_enabled? { 'cable-url' => Livechat.config.action_cable_url, 'cable-stream' => Livechat.sign_stream(stream_name) } end |
#livechat_message_attachments(message) ⇒ Object
A message's attachments, rendered like the widget: images inline as thumbnails, everything else as a download link. Both point at the gated engine route, never a public blob URL.
21 22 23 24 25 26 27 28 |
# File 'app/helpers/livechat/inbox_helper.rb', line 21 def () = . return if .empty? tag.div(class: 'atts') do safe_join(.map { || () }) end end |