dmails: clean up sender/recipient logic.
This commit is contained in:
@@ -202,7 +202,7 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def send_email
|
def send_email
|
||||||
if !is_spam? && to.receive_email_notifications? && to.email =~ /@/ && owner_id == to.id
|
if is_recipient? && !is_spam? && to.receive_email_notifications? && to.email =~ /@/
|
||||||
UserMailer.dmail_notice(self).deliver_now
|
UserMailer.dmail_notice(self).deliver_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -218,18 +218,26 @@ class Dmail < ApplicationRecord
|
|||||||
from == User.system
|
from == User.system
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_sender?
|
||||||
|
owner == from
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_recipient?
|
||||||
|
owner == to
|
||||||
|
end
|
||||||
|
|
||||||
def filtered?
|
def filtered?
|
||||||
CurrentUser.dmail_filter.try(:filtered?, self)
|
CurrentUser.dmail_filter.try(:filtered?, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_read_if_filtered
|
def auto_read_if_filtered
|
||||||
if owner_id != CurrentUser.id && to.dmail_filter.try(:filtered?, self)
|
if is_recipient? && to.dmail_filter.try(:filtered?, self)
|
||||||
self.is_read = true
|
self.is_read = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_recipient
|
def update_recipient
|
||||||
if owner_id != CurrentUser.user.id && !is_deleted? && !is_read?
|
if is_recipient? && !is_deleted? && !is_read?
|
||||||
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
|
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user