Class: CustomerServiceIm::Conversation
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CustomerServiceIm::Conversation
- Defined in:
- app/models/customer_service_im/conversation.rb
Instance Method Summary collapse
- #all_messages_read! ⇒ Object
- #broadcast_to_channel ⇒ Object
- #increment_unread_message_count(message) ⇒ Object
-
#last_message ⇒ Object
validates_presence_of :title.
- #message_created!(message) ⇒ Object
- #update_last_messaged_on(message) ⇒ Object
Instance Method Details
#all_messages_read! ⇒ Object
25 26 27 28 29 |
# File 'app/models/customer_service_im/conversation.rb', line 25 def .unread.includes(:user).update(state: :read) update(staff_unread_message_count: 0) broadcast_to_channel end |
#broadcast_to_channel ⇒ Object
31 32 33 34 |
# File 'app/models/customer_service_im/conversation.rb', line 31 def broadcast_to_channel conversation_data = JSON.parse(ApplicationController.render partial: "customer_service_im/conversations/conversation", locals: { conversation: self }) ActionCable.server.broadcast "customer_service_im/conversations_channel", conversation_data end |
#increment_unread_message_count(message) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/models/customer_service_im/conversation.rb', line 37 def () if .from_user? increment(:staff_unread_message_count) elsif .from_staff? increment(:user_unread_message_count) else # never arrived end end |
#last_message ⇒ Object
validates_presence_of :title
11 12 13 |
# File 'app/models/customer_service_im/conversation.rb', line 11 def .last end |
#message_created!(message) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/models/customer_service_im/conversation.rb', line 15 def () with_lock do () () broadcast_to_channel save! end end |
#update_last_messaged_on(message) ⇒ Object
47 48 49 |
# File 'app/models/customer_service_im/conversation.rb', line 47 def () self. = .created_at end |