ish_models 0.0.33.247 → 0.0.33.248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823be62d6f3e6bf6817ef43ebbcefda4c12049f01aedafb95b9fd01a624c6453
4
- data.tar.gz: 9b1db16ef558002d83c109426fb41757a4b4892acc3f81a38dbaf130759b23dd
3
+ metadata.gz: 2def700aeaad8af0e705ff8942ad3644d42e9bd1ac93360dda132e81eac94c3a
4
+ data.tar.gz: 0efc6da855db6c6087405a8a86a32c1c5ec331fa6605f5c73bf6ba50cd3ab788
5
5
  SHA512:
6
- metadata.gz: 2238d1a7cd112636cc58aba0eaaea3534a9cd8bb504b901ebe0b3b2298bb8aba90cba6abd4b5063234063c8d0348290a94e7d8979308c204996929797e991cb3
7
- data.tar.gz: b2788efc4ae0447ff65d56aa829164a44ae1e42fa12538a63bcd6802c957568da23763d254cc8b79033eb5d25f358b28c4abf2e485dfe1709f274cb721fdc106
6
+ metadata.gz: 980d5d0b40716c183f460e92dceb012e0999a04f6449b9b5a637d45c1109f504949d6fd45cb598ef3263fb96f90dfac4609c9bfe10e280a2f1af1dbcae526515
7
+ data.tar.gz: e2629dfb10d8554ac7da8f8c5541f38da1f02333e5259ac0f2bedd7fd2d68d3b5ad5e7ca1532b31ca769f918a253f97d8feeed1fcca66fe78766c77e0f5ad7f0
@@ -45,8 +45,9 @@ class ::Ish::EmailTemplate
45
45
  binding()
46
46
  end
47
47
 
48
- has_many :email_actions, class_name: '::Office::EmailAction'
48
+ has_many :email_actions, class_name: '::Office::EmailAction'
49
49
  has_many :email_contexts, class_name: '::Ish::EmailContext'
50
+ has_many :email_filters, class_name: '::Office::EmailFilter', inverse_of: :email_template
50
51
 
51
52
  SLUG_BLANK = 'blank'
52
53
  def self.blank_template
@@ -22,5 +22,7 @@ class Office::EmailAction
22
22
  has_many :prev_ties, class_name: '::Office::EmailActionTie', inverse_of: :next_email_action
23
23
  accepts_nested_attributes_for :ties
24
24
 
25
+ has_many :email_filters, class_name: 'Office::EmailFilter', inverse_of: :email_action
26
+
25
27
  end
26
28
  EAct = Office::EmailAction
@@ -32,12 +32,14 @@ class Office::EmailConversation
32
32
  ## Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? _vp_ 2023-03-07
33
33
  def add_tag tag
34
34
  case tag.class.name
35
+ when 'Integer'
36
+ tag = WpTag.find( tag )
35
37
  when 'WpTag'
36
- ;
38
+ ; # tag is WpTag
37
39
  when 'String'
38
40
  tag = WpTag.emailtag(tag)
39
41
  else
40
- throw "#add_tag expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
42
+ throw "#add_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter."
41
43
  end
42
44
  self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq
43
45
  self.save!
@@ -45,12 +47,14 @@ class Office::EmailConversation
45
47
 
46
48
  def remove_tag tag
47
49
  case tag.class.name
48
- when 'WpTag'
49
- ;
50
+ when 'Integer'
51
+ tag = WpTag.find( tag )
50
52
  when 'String'
51
- tag = WpTag.emailtag(tag)
53
+ tag = WpTag.emailtag( tag )
54
+ when 'WpTag'
55
+ ; # tag is WpTag
52
56
  else
53
- throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
57
+ throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter."
54
58
  end
55
59
  self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ]
56
60
  out = self.save!
@@ -7,19 +7,36 @@ class Office::EmailFilter
7
7
  include Mongoid::Timestamps
8
8
 
9
9
  field :from_regex
10
+ field :from_exact
10
11
  field :subject_regex
12
+ field :subject_exact
11
13
  field :body_regex
14
+ field :body_exact
12
15
 
13
- KIND_SKIP_INBOX = 'skip-inbox'
14
- KIND_AUTORESPOND = 'autorespond'
15
- KINDS = [ nil, KIND_SKIP_INBOX, KIND_AUTORESPOND ]
16
+ KIND_AUTORESPOND = 'autorespond' # @deprecated, DO NOT USE!
17
+ KIND_AUTORESPOND_TMPL = 'autorespond-template'
18
+ KIND_AUTORESPOND_EACT = 'autorespond-email-action'
19
+ KIND_REMOVE_TAG = 'remove-tag'
20
+ KIND_ADD_TAG = 'add-tag'
21
+ KIND_DELETE = 'delete' # @obsolete, use add-tag
22
+ KIND_SKIP_INBOX = 'skip-inbox' # @obsolete, use remove-tag
23
+
24
+ KINDS = [ nil, KIND_AUTORESPOND_TMPL, KIND_AUTORESPOND_EACT, KIND_SKIP_INBOX, KIND_ADD_TAG, KIND_REMOVE_TAG]
16
25
  field :kind
17
26
 
18
- STATE_ACTIVE = 'active'
27
+ STATE_ACTIVE = 'active'
19
28
  STATE_INACTIVE = 'inactive'
20
29
  STATES = [ STATE_ACTIVE, STATE_INACTIVE ]
21
30
  field :state, type: :string, default: STATE_ACTIVE
22
31
  scope :active, ->{ where( state: STATE_ACTIVE ) }
23
32
 
33
+ belongs_to :email_template, class_name: 'Ish::EmailTemplate', optional: true
34
+ belongs_to :email_action, class_name: 'Office::EmailAction', optional: true
35
+
36
+ field :wp_term_id, type: :integer
37
+ def category
38
+ self.wp_term_id && WpTag.find( self.wp_term_id )
39
+ end
40
+
24
41
  end
25
42
 
@@ -93,14 +93,33 @@ class Office::EmailMessage
93
93
  ## @TODO: move to email_conversation _vp_ 2023-03-24
94
94
  def apply_filter filter
95
95
  case filter.kind
96
+
97
+ ## @deprecated, use KIND_REMOVE_TAG
96
98
  when ::Office::EmailFilter::KIND_SKIP_INBOX
97
99
  # self.remove_tag( WpTag::INBOX )
98
100
  self.conv.remove_tag( WpTag::INBOX )
99
- when ::Office::EmailFilter::KIND_AUTORESPOND
101
+
102
+ when ::Office::EmailFilter::KIND_ADD_TAG
103
+ self.conv.add_tag( filter.wp_term_id )
104
+
105
+ when ::Office::EmailFilter::KIND_REMOVE_TAG
106
+ self.conv.remove_tag( filter.wp_term_id )
107
+
108
+ when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL
100
109
  Ish::EmailContext.create({
101
- email_template: ::Tmpl.find_by_slug( filter.email_template_slug ),
102
- lead: lead,
110
+ email_template: filter.email_template,
111
+ lead_id: lead.id,
112
+ send_at: Time.now + 22.minutes,
103
113
  })
114
+
115
+ when ::Office::EmailFilter::KIND_AUTORESPOND_EACT
116
+ ::Sch.create({
117
+ email_action: filter.email_action,
118
+ state: ::Sch::STATE_ACTIVE,
119
+ lead_id: lead.id,
120
+ perform_at: Time.now + 22.minutes,
121
+ })
122
+
104
123
  else
105
124
  raise "unknown filter kind: #{filter.kind}"
106
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.247
4
+ version: 0.0.33.248
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox