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(which) ⇒ Object
Tested manually ok, does not pass the spec.
- #apply_filter(filter) ⇒ Object
- #in_emailtag?(which) ⇒ Boolean
-
#leads ⇒ Object
def lead_ids email_conversation_leads.map( &:lead_id ) end field :lead_ids, type: :array, default: [].
- #remove_tag(which) ⇒ Object
- #rmtag(which) ⇒ Object
- #tags ⇒ Object
-
#wp_term_ids ⇒ Object
@TODO: remove vp 2023-09-23.
Class Method Details
.in_emailtag(which) ⇒ Object
63 64 65 66 67 |
# File 'lib/office/email_conversation.rb', line 63 def self.in_emailtag which tag = WpTag.iso_get( which ) = Office::EmailConversationTag.where({ wp_term_id: tag.id }) where({ :id.in => .map(&:email_conversation_id) }) end |
.not_in_emailtag(which) ⇒ Object
69 70 71 72 73 |
# File 'lib/office/email_conversation.rb', line 69 def self.not_in_emailtag which tag = WpTag.iso_get( which ) = Office::EmailConversationTag.where({ wp_term_id: tag.id }) where({ :id.nin => .map(&:email_conversation_id) }) end |
Instance Method Details
#add_tag(which) ⇒ Object
Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? vp 2023-03-07
39 40 41 42 43 44 45 46 |
# File 'lib/office/email_conversation.rb', line 39 def add_tag which tag = WpTag.iso_get which # puts!( tag.slug, "Adding tag" ) if DEBUG Office::EmailConversationTag.find_or_create_by!({ email_conversation_id: id, wp_term_id: tag.id, }) end |
#apply_filter(filter) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/office/email_conversation.rb', line 76 def apply_filter filter case filter.kind when ::Office::EmailFilter::KIND_DESTROY_SCHS add_tag ::WpTag::TRASH remove_tag ::WpTag::INBOX tmp_lead = ::Lead.where( email: self.part_txt.split("\n")[1] ).first if tmp_lead tmp_lead.schs.each do |sch| sch.update_attributes({ state: ::Sch::STATE_TRASH }) end end when ::Office::EmailFilter::KIND_ADD_TAG add_tag filter.wp_term_id if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug remove_tag ::WpTag::INBOX end when ::Office::EmailFilter::KIND_REMOVE_TAG remove_tag filter.wp_term_id when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL Ish::EmailContext.create({ email_template: filter.email_template, lead_id: lead.id, send_at: Time.now + 22.minutes, }) when ::Office::EmailFilter::KIND_AUTORESPOND_EACT ::Sch.create({ email_action: filter.email_action, state: ::Sch::STATE_ACTIVE, lead_id: lead.id, perform_at: Time.now + 22.minutes, }) else raise "unknown filter kind: #{filter.kind}" end end |
#in_emailtag?(which) ⇒ Boolean
58 59 60 61 |
# File 'lib/office/email_conversation.rb', line 58 def in_emailtag? which tag = WpTag.iso_get( which ) .where({ wp_term_id: tag.id }).present? end |
#leads ⇒ Object
def lead_ids
email_conversation_leads.map( &:lead_id )
end field :lead_ids, type: :array, default: []
23 24 25 |
# File 'lib/office/email_conversation.rb', line 23 def leads Lead.find( lead_ties.map( &:lead_id ) ) end |
#remove_tag(which) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/office/email_conversation.rb', line 48 def remove_tag which tag = WpTag.iso_get which # puts!( tag.slug, "Removing tag" ) if DEBUG Office::EmailConversationTag.where({ email_conversation_id: id, wp_term_id: tag.id, }).first&.delete end |
#rmtag(which) ⇒ Object
56 |
# File 'lib/office/email_conversation.rb', line 56 def rmtag which; remove_tag which; end |
#tags ⇒ Object
34 35 36 |
# File 'lib/office/email_conversation.rb', line 34 def WpTag.find( .map( &:wp_term_id ) ) end |
#wp_term_ids ⇒ Object
@TODO: remove vp 2023-09-23
30 31 32 |
# File 'lib/office/email_conversation.rb', line 30 def wp_term_ids ## @TODO: remove _vp_ 2023-09-23 .map( &:wp_term_id ) end |