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
-
#email_conversation_tags ⇒ Object
A ‘tags` concern.
- #email_messages ⇒ Object
- #in_emailtag?(which) ⇒ Boolean
- #leads ⇒ Object
- #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
69 70 71 72 73 |
# File 'lib/office/email_conversation.rb', line 69 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
75 76 77 78 79 |
# File 'lib/office/email_conversation.rb', line 75 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
45 46 47 48 49 50 51 52 |
# File 'lib/office/email_conversation.rb', line 45 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
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 117 118 119 120 121 122 |
# File 'lib/office/email_conversation.rb', line 82 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 |
#email_conversation_tags ⇒ Object
A ‘tags` concern
34 |
# File 'lib/office/email_conversation.rb', line 34 has_many :email_conversation_tags, class_name: 'Office::EmailConversationTag' |
#email_messages ⇒ Object
26 27 28 |
# File 'lib/office/email_conversation.rb', line 26 def Office::EmailMessage.where( email_conversation_id: self.id ) end |
#in_emailtag?(which) ⇒ Boolean
64 65 66 67 |
# File 'lib/office/email_conversation.rb', line 64 def in_emailtag? which tag = WpTag.iso_get( which ) .where({ wp_term_id: tag.id }).present? end |
#leads ⇒ Object
21 22 23 |
# File 'lib/office/email_conversation.rb', line 21 def leads Lead.find( lead_ids.compact ) end |
#remove_tag(which) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/office/email_conversation.rb', line 54 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
62 |
# File 'lib/office/email_conversation.rb', line 62 def rmtag which; remove_tag which; end |
#tags ⇒ Object
40 41 42 |
# File 'lib/office/email_conversation.rb', line 40 def WpTag.find( .map( &:wp_term_id ) ) end |
#wp_term_ids ⇒ Object
@TODO: remove vp 2023-09-23
36 37 38 |
# File 'lib/office/email_conversation.rb', line 36 def wp_term_ids ## @TODO: remove _vp_ 2023-09-23 .map( &:wp_term_id ) end |