Sha256: f4268901520cdd65a9d76f3d291e8222e9ff6d4a69bf5c105d532cfdf6ef46bd
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
class Office::EmailConversation include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia STATE_UNREAD = 'state_unread' STATE_READ = 'state_read' STATES = [ STATE_UNREAD, STATE_READ ] field :state field :subject field :latest_at field :lead_ids, type: :array, default: [] def leads Lead.find( lead_ids ) end has_many :email_messages def email_messages Office::EmailMessage.where( email_conversation_id: self.id ) end def tags WpTag.find( wp_term_ids ) end ## Copied from email_message field :wp_term_ids, type: Array, default: [] ## Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? _vp_ 2023-03-07 def add_tag tag case tag.class.name when 'WpTag' ; when 'String' tag = WpTag.emailtag(tag) else throw "#add_tag expects a WpTag or string (eg WpTag::EMAILTAG_INBOX) as the only parameter." end puts! tag, 'tag' self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq self.save! end def remove_tag tag if WpTag == tag.class self[:wp_term_ids].delete( tag.id ) self.save! else throw "#remove_tag expects a WpTag as the only parameter." end end def self.in_inbox ::Office::EmailConversation.where( :wp_term_ids => WpTag.email_inbox_tag.id ).order_by( latest_at: :desc ) end def self.in_no_trash trash_id = WpTag.emailtag('trash').id return ::Office::EmailConversation.where( :wp_term_ids.ne => trash_id ).order_by( latest_at: :desc ) end def self.in_emailtag which case which.class.name when 'String' tag_id = WpTag.emailtag(which).id when 'WpTag' tag_id = which.id else throw "unsupported in #in_emailtag: #{which}" end return ::Office::EmailConversation.where( :wp_term_ids => tag_id ).order_by( latest_at: :desc ) end end # EmailConversation = Office::EmailConversation Conv = Office::EmailConversation
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ish_models-0.0.33.204 | lib/office/email_conversation.rb |
ish_models-0.0.33.203 | lib/office/email_conversation.rb |
ish_models-0.0.33.202 | lib/office/email_conversation.rb |