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
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/office/email_conversation.rb', line 77 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/office/email_conversation.rb', line 65 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/office/email_conversation.rb', line 33 def add_tag tag case tag.class.name when 'Integer' tag = WpTag.find( tag ) when 'WpTag' ; # tag is WpTag when 'String' tag = WpTag.emailtag(tag) else throw "#add_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter." end self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq self.save! end |
#email_messages ⇒ Object
21 22 23 |
# File 'lib/office/email_conversation.rb', line 21 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 61 62 |
# File 'lib/office/email_conversation.rb', line 48 def remove_tag tag case tag.class.name when 'Integer' tag = WpTag.find( tag ) when 'String' tag = WpTag.emailtag( tag ) when 'WpTag' ; # tag is WpTag else throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter." end self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ] out = self.save! out end |
#rmtag(tag) ⇒ Object
63 |
# File 'lib/office/email_conversation.rb', line 63 def rmtag tag; remove_tag tag; end |
#tags ⇒ Object
25 26 27 |
# File 'lib/office/email_conversation.rb', line 25 def WpTag.find( wp_term_ids ) end |
#wp_term_ids ⇒ Object
Copied from email_message
30 |
# File 'lib/office/email_conversation.rb', line 30 field :wp_term_ids, type: Array, default: [] |