Add message threads #394
This new view sorts the messages by threads based on the reply_to. Now we store only the message which started a new thread in the reply_to field to avoid recursive queries.
This commit is contained in:
parent
d56828fa4d
commit
8ac1471a89
12 changed files with 180 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ class Message < ActiveRecord::Base
|
|||
scope :pending, -> { where(:email_state => 0) }
|
||||
scope :sent, -> { where(:email_state => 1) }
|
||||
scope :pub, -> { where(:private => false) }
|
||||
scope :threads, -> { where(:reply_to => nil) }
|
||||
scope :thread, -> (id) { where("id = ? OR reply_to = ?", id, id) }
|
||||
|
||||
# Values for the email_state attribute: :none, :pending, :sent, :failed
|
||||
EMAIL_STATE = {
|
||||
|
|
@ -71,6 +73,10 @@ class Message < ActiveRecord::Base
|
|||
User.where(id: recipients_ids)
|
||||
end
|
||||
|
||||
def last_reply
|
||||
Message.where(reply_to: self.id).order(:created_at).last
|
||||
end
|
||||
|
||||
def deliver
|
||||
for user in recipients
|
||||
if user.receive_email?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue