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
- #rmtag(tag) ⇒ Object
- #tags ⇒ Object
-
#wp_term_ids ⇒ Object
Copied from email_message.
Class Method Details
.in_emailtag(which) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/office/email_conversation.rb', line 75 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 |
.not_in_emailtag(which) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/office/email_conversation.rb', line 63 def self.not_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 #not_in_emailtag: #{which}" end return ::Office::EmailConversation.where( :wp_term_ids.ne => tag_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 |
# 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::INBOX) as the only parameter." end 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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/office/email_conversation.rb', line 48 def remove_tag tag case tag.class.name when 'WpTag' ; when 'String' tag = WpTag.emailtag(tag) else throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) as the only parameter." end self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ] out = self.save! out end |
#rmtag(tag) ⇒ Object
61 |
# File 'lib/office/email_conversation.rb', line 61 def rmtag tag; remove_tag tag; 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: [] |