Class: Chat
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Chat
- Defined in:
- lib/generators/kablam/templates/chat.rb
Instance Method Summary collapse
- #broadcast_self ⇒ Object
- #latest_message ⇒ Object
- #messages_array ⇒ Object
- #not_answered(user_id) ⇒ Object
- #unread_messages(user_id) ⇒ Object
- #users ⇒ Object
Instance Method Details
#broadcast_self ⇒ Object
29 30 31 |
# File 'lib/generators/kablam/templates/chat.rb', line 29 def broadcast_self ActionCable.server.broadcast "ChatChannel_#{self.id}", {chat: .last } end |
#latest_message ⇒ Object
21 22 23 |
# File 'lib/generators/kablam/templates/chat.rb', line 21 def .last end |
#messages_array ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/kablam/templates/chat.rb', line 7 def y = .map do |x| u = User.find(x.sender_id) h = x.serializable_hash # h["status"] = x.status(user_id) h["chat_id"] = id.to_s h["image"] = u.name? ? u.avatar_url(50) : "/assets/default.png" h['username'] = u.name || "An Amazing Person~" h["user_time"] = x.user_time h end y.sort_by{|x|x["created_at"]} end |
#not_answered(user_id) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/generators/kablam/templates/chat.rb', line 37 def not_answered(user_id) if !.blank? return .last.sender_id != user_id else return false end end |
#unread_messages(user_id) ⇒ Object
25 26 27 |
# File 'lib/generators/kablam/templates/chat.rb', line 25 def (user_id) .where(user_id: user_id.to_i, read: false).count end |
#users ⇒ Object
33 34 35 |
# File 'lib/generators/kablam/templates/chat.rb', line 33 def users .map{ |m| m.sender_id}.uniq end |