Module: TurboChat::ApplicationHelper::ConfigSupport
- Included in:
- TurboChat::ApplicationHelper
- Defined in:
- app/helpers/turbo_chat/application_helper/config_support.rb
Constant Summary collapse
- BOOLEAN_CHAT_SETTINGS =
{ enable_mentions: true, mention_filter_exclude_self: true, mention_filter_hide_roles: true, emit_typing_events: false, emit_message_events: false, emit_mention_events: false, emit_invitation_events: false, emit_chat_lifecycle_events: false, show_members: true, show_members_list: true, show_members_invite_controls: true, show_invite_fallback_when_members_hidden: true, show_self_signals: false, disable_input: false, show_header_title: true, show_header_status: true, show_header_close_action: true, show_header_leave_action: true, show_header_back_action: true, composer_add_files_display: false, composer_add_files_active: false, composer_microphone_display: false, composer_microphone_active: false, signal_text_sheen: true, show_timestamp: true, show_role: false, render_message_html: false }.freeze
Instance Method Summary collapse
- #chat_assistant_mode?(chat) ⇒ Boolean
- #chat_composer_placeholder_text(chat: nil) ⇒ Object
- #chat_message_append_start?(chat: nil) ⇒ Boolean
- #chat_message_insert_position(chat: nil) ⇒ Object
- #chat_message_source_badge_label(chat_message) ⇒ Object
- #chat_message_source_label(source, chat: nil) ⇒ Object
- #chat_message_source_labels(chat: nil) ⇒ Object
- #chat_mode_key(chat) ⇒ Object
- #chat_shell_style_class(chat: nil) ⇒ Object
- #chat_signal_ttl_seconds(chat: nil) ⇒ Object
- #chat_style_key(chat: nil) ⇒ Object
- #chat_unbounded_style?(chat: nil) ⇒ Boolean
Instance Method Details
#chat_assistant_mode?(chat) ⇒ Boolean
126 127 128 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 126 def chat_assistant_mode?(chat) chat_mode_key(chat) == :assistant end |
#chat_composer_placeholder_text(chat: nil) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 40 def chat_composer_placeholder_text(chat: nil) value = chat_config_value(:composer_placeholder_text, default: "start chatting", chat: chat) normalized = value.to_s.strip normalized.present? ? normalized : "start chatting" end |
#chat_message_append_start?(chat: nil) ⇒ Boolean
112 113 114 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 112 def (chat: nil) (chat: chat) == "append_start" end |
#chat_message_insert_position(chat: nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 100 def (chat: nil) raw_position = chat_config_value(:message_insert_position, default: "append_end", chat: chat) normalized = raw_position.to_s.strip.downcase case normalized when "append_start", "start", "prepend" "append_start" else "append_end" end end |
#chat_message_source_badge_label(chat_message) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 70 def () return nil unless .respond_to?(:source) source_key = TurboChat::ChatMessage.normalize_source_key(.source) return nil if source_key == TurboChat::ChatMessage::DEFAULT_SOURCE = .respond_to?(:chat) ? .chat : nil (source_key, chat: ) end |
#chat_message_source_label(source, chat: nil) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 61 def (source, chat: nil) source_key = TurboChat::ChatMessage.normalize_source_key(source) labels = (chat: chat) label = labels[source_key] return label if label.present? source_key.tr("_-", " ").split.map(&:capitalize).join(" ") end |
#chat_message_source_labels(chat: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 46 def (chat: nil) configured = chat_config_value(:message_source_labels, default: {}, chat: chat) return {} unless configured.respond_to?(:each_pair) configured.each_with_object({}) do |(source_key, label), normalized| source = normalize_config_source_key(source_key) next if source.blank? rendered_label = label.to_s.strip next if rendered_label.blank? normalized[source] = rendered_label end end |
#chat_mode_key(chat) ⇒ Object
122 123 124 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 122 def chat_mode_key(chat) TurboChat::Configuration.extract_chat_mode(chat) || :standard end |
#chat_shell_style_class(chat: nil) ⇒ Object
96 97 98 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 96 def chat_shell_style_class(chat: nil) chat_unbounded_style?(chat: chat) ? "chat-shell--style-unbounded" : "chat-shell--style-bounded" end |
#chat_signal_ttl_seconds(chat: nil) ⇒ Object
116 117 118 119 120 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 116 def chat_signal_ttl_seconds(chat: nil) value = chat_config_value(:signal_ttl_seconds, default: 60, chat: chat) ttl = value.to_i ttl.positive? ? ttl : 60 end |
#chat_style_key(chat: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 80 def chat_style_key(chat: nil) raw_style = chat_config_value(:chat_style, default: "chat_style_bounded", chat: chat) normalized = raw_style.to_s.strip.downcase case normalized when "chat_style_unbounded", "unbounded" "chat_style_unbounded" else "chat_style_bounded" end end |
#chat_unbounded_style?(chat: nil) ⇒ Boolean
92 93 94 |
# File 'app/helpers/turbo_chat/application_helper/config_support.rb', line 92 def chat_unbounded_style?(chat: nil) chat_style_key(chat: chat) == "chat_style_unbounded" end |