Module: Chat::ApplicationHelper
- Defined in:
- app/helpers/chat/application_helper.rb
Instance Method Summary collapse
- #chat_avatar(user) ⇒ Object
- #chat_avatar_count(conversation) ⇒ Object
- #chat_avatars(conversation) ⇒ Object
- #chat_list ⇒ Object
- #chatable_user_check_boxes(f) ⇒ Object
- #chatable_users ⇒ Object
- #conversation_user_count(conversation) ⇒ Object
- #launch_chat_fab ⇒ Object
- #message_classes(message) ⇒ Object
- #render_chat ⇒ Object
Instance Method Details
#chat_avatar(user) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/helpers/chat/application_helper.rb', line 35 def chat_avatar(user) if user.chat_avatar? image_tag(user.chat_avatar, class: "chat__user-avatar") else MaterialIcon.new.css_class("chat__user-avatar").person.to_s end end |
#chat_avatar_count(conversation) ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/helpers/chat/application_helper.rb', line 55 def chat_avatar_count(conversation) if (count = conversation_user_count(conversation)) <= 2 "count_#{count}" else "count_default" end end |
#chat_avatars(conversation) ⇒ Object
49 50 51 52 53 |
# File 'app/helpers/chat/application_helper.rb', line 49 def chat_avatars(conversation) (conversation.users - [current_user]).first(2).map do |u| chat_avatar(u) end end |
#chat_list ⇒ Object
43 44 45 46 47 |
# File 'app/helpers/chat/application_helper.rb', line 43 def chat_list @chat_list ||= current_user.conversations.includes(:users).order( "chat_conversations.created_at desc" ) end |
#chatable_user_check_boxes(f) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'app/helpers/chat/application_helper.rb', line 24 def chatable_user_check_boxes(f) f.collection_check_boxes(:user_ids, chatable_users, :id, :name) do |b| b.check_box + b.label(class: b.object.chat_status) do content_tag( :div, b.text, class: "chat__status #{b.object.chat_status}" ) end end end |
#chatable_users ⇒ Object
20 21 22 |
# File 'app/helpers/chat/application_helper.rb', line 20 def chatable_users @chatable_users ||= ::User.where.not(id: current_user.id) end |
#conversation_user_count(conversation) ⇒ Object
63 64 65 |
# File 'app/helpers/chat/application_helper.rb', line 63 def conversation_user_count(conversation) conversation.users.to_a.size - 1 end |
#launch_chat_fab ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/helpers/chat/application_helper.rb', line 11 def launch_chat_fab attrs = { class: "chat__launch", data: { "current-user" => current_user.id } } (attrs) do material_icon.forum.css_class("md-dark").to_s.html_safe end end |
#message_classes(message) ⇒ Object
67 68 69 70 71 |
# File 'app/helpers/chat/application_helper.rb', line 67 def () css_class = .user == current_user ? "right" : "left" css_class += .image? ? " image" : "" css_class end |
#render_chat ⇒ Object
5 6 7 8 9 |
# File 'app/helpers/chat/application_helper.rb', line 5 def render_chat return unless send Chat.signed_in render "chat/chat" end |