Class: Office::EmailConversation
- Inherits:
-
Object
- Object
- Office::EmailConversation
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- lib/office/email_conversation.rb
Constant Summary collapse
- STATE_UNREAD =
'state_unread'- STATE_READ =
'state_read'- STATES =
[ STATE_UNREAD, STATE_READ ]
Class Method Summary collapse
Instance Method Summary collapse
-
#add_tag(tag) ⇒ Object
Tested manually ok, does not pass the spec.
- #email_messages ⇒ Object
- #leads ⇒ Object
- #remove_tag(tag) ⇒ Object
- #tags ⇒ Object
-
#wp_term_ids ⇒ Object
Copied from email_message.
Class Method Details
.in_emailtag(which) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/office/email_conversation.rb', line 67 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 |
.in_inbox ⇒ Object
58 59 60 |
# File 'lib/office/email_conversation.rb', line 58 def self.in_inbox ::Office::EmailConversation.where( :wp_term_ids => WpTag.email_inbox_tag.id ).order_by( latest_at: :desc ) end |
.in_no_trash ⇒ Object
62 63 64 65 |
# File 'lib/office/email_conversation.rb', line 62 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 |
Instance Method Details
#add_tag(tag) ⇒ Object
Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? vp 2023-03-07
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/office/email_conversation.rb', line 35 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 |
#email_messages ⇒ Object
23 24 25 |
# File 'lib/office/email_conversation.rb', line 23 def Office::EmailMessage.where( email_conversation_id: self.id ) end |
#leads ⇒ Object
16 17 18 |
# File 'lib/office/email_conversation.rb', line 16 def leads Lead.find( lead_ids ) end |
#remove_tag(tag) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/office/email_conversation.rb', line 49 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 |
#tags ⇒ Object
27 28 29 |
# File 'lib/office/email_conversation.rb', line 27 def WpTag.find( wp_term_ids ) end |
#wp_term_ids ⇒ Object
Copied from email_message
32 |
# File 'lib/office/email_conversation.rb', line 32 field :wp_term_ids, type: Array, default: [] |