Module: HasMessages
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/has_messages.rb
Overview
Adds a generic implementation for sending messages between users
Instance Method Summary collapse
- #conversations ⇒ Object
- #find_conversation_by_id(id) ⇒ Object
-
#last_received_message_per_thread ⇒ Object
Returns the most recent message of each thread.
- #original_conversations ⇒ Object
-
#sent_messages ⇒ Object
Composed messages that have already been sent.
- #unread_messages ⇒ Object
-
#unsent_messages ⇒ Object
Composed messages that have not yet been sent.
Instance Method Details
#conversations ⇒ Object
38 39 40 |
# File 'lib/has_messages.rb', line 38 def conversations ( + .map(&:message)).compact.uniq end |
#find_conversation_by_id(id) ⇒ Object
46 47 48 |
# File 'lib/has_messages.rb', line 46 def find_conversation_by_id(id) conversations.select{ || .id == id.to_i }.first end |
#last_received_message_per_thread ⇒ Object
Returns the most recent message of each thread
34 35 36 |
# File 'lib/has_messages.rb', line 34 def MessageRecipient.find_all_by_receiver_id(id, :order => 'id desc', :joins => :message, :conditions => 'message_recipients.hidden_at is null', :group => 'COALESCE(original_message_id,messages.id)') end |
#original_conversations ⇒ Object
42 43 44 |
# File 'lib/has_messages.rb', line 42 def original_conversations conversations.select{ || . == nil } end |
#sent_messages ⇒ Object
Composed messages that have already been sent. These consists of all messages that are currently in the “queued” or “sent” states.
29 30 31 |
# File 'lib/has_messages.rb', line 29 def .with_states(:queued, :sent) end |
#unread_messages ⇒ Object
50 51 52 |
# File 'lib/has_messages.rb', line 50 def .select(&:unread?).map(&:message) end |
#unsent_messages ⇒ Object
Composed messages that have not yet been sent. These consists of all messages that are currently in the “unsent” state.
23 24 25 |
# File 'lib/has_messages.rb', line 23 def .with_state(:unsent) end |