ish_models 0.0.33.274 → 0.0.33.275

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: 90de218899ddf4fc0764c1f548417c53fcd398e1c3a1a31560ca796e411832bc
4
- data.tar.gz: d0b1ec1ada583d9ac93b924a2a1701c2df0ba62c57c1243c80fcdaddeb00f3dc
3
+ metadata.gz: cb3b606c0341b93021417a856e8fc0a063702b35322f251f9c90a3ea0fda0f64
4
+ data.tar.gz: 5b71e854c048e75107fed2a849b1d743dde82e66fc627e0d9cbd098b8c2a7574
5
5
  SHA512:
6
- metadata.gz: eb4f60187c093f0661b90d0c064eb6ba4e294455f2b5287cc22f876041144a48fa9052162980dd8599986015fa89ed45b6a1ab809c0f8943b3bcc188ce14cd59
7
- data.tar.gz: cd94a83ea12c95bd829385f26277c6fe730982d88c9078153a58065fdb8ec171c1b5436d286da506a34605c8aea2070b5108c99952a4c8e251b84476c7aea3d9
6
+ metadata.gz: ac6d3b421013aa46142df4b361056b739a980f6d1f9786b1d76256b9840475899fe237f6a845ff73434760d35b7090e8a55537c7a7fe447edbb54b235437c451
7
+ data.tar.gz: 0fa6529999ecfc23d6fa92119114f87945bef3689588af0c872ad547087b45011c33ec08adeb90a8af9b4128fa7b26371bd87859e38d14664b78cedc3fe617f7
data/lib/ish_models.rb CHANGED
@@ -69,6 +69,8 @@ require 'office/admin_message'
69
69
  require 'office/email_action'
70
70
  require 'office/email_action_tie'
71
71
  require 'office/email_conversation'
72
+ require 'office/email_conversation_lead'
73
+ require 'office/email_conversation_tag'
72
74
  require 'office/email_filter'
73
75
  require 'office/email_message'
74
76
  require 'office/email_message_stub'
@@ -5,13 +5,18 @@ class Office::EmailConversation
5
5
  include Mongoid::Paranoia
6
6
 
7
7
  STATE_UNREAD = 'state_unread'
8
- STATE_READ = 'state_read'
9
- STATES = [ STATE_UNREAD, STATE_READ ]
8
+ STATE_READ = 'state_read'
9
+ STATES = [ STATE_UNREAD, STATE_READ ]
10
10
  field :state
11
11
 
12
12
  field :subject
13
13
  field :latest_at
14
+ index({ latest_at: -1 })
14
15
 
16
+ has_many :email_conversation_leads, class_name: 'Office::EmailConversationLead'
17
+ # def lead_ids
18
+ # email_conversation_leads.map( &:lead_id )
19
+ # end
15
20
  field :lead_ids, type: :array, default: []
16
21
  def leads
17
22
  Lead.find( lead_ids.compact )
@@ -22,69 +27,100 @@ class Office::EmailConversation
22
27
  Office::EmailMessage.where( email_conversation_id: self.id )
23
28
  end
24
29
 
25
- def tags
26
- WpTag.find( wp_term_ids )
30
+ ##
31
+ ## A `tags` concern
32
+ ##
33
+
34
+ has_many :email_conversation_tags, class_name: 'Office::EmailConversationTag'
35
+
36
+ def wp_term_ids ## @TODO: remove _vp_ 2023-09-23
37
+ email_conversation_tags.map( &:wp_term_id )
27
38
  end
28
39
 
29
- ## Copied from email_message
30
- field :wp_term_ids, type: Array, default: []
40
+ def tags
41
+ WpTag.find( email_conversation_tags.map( &:wp_term_id ) )
42
+ end
31
43
 
32
44
  ## Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? _vp_ 2023-03-07
33
- def add_tag tag
34
- case tag.class.name
35
- when 'Integer'
36
- tag = WpTag.find( tag )
37
- when 'WpTag'
38
- ; # tag is WpTag
39
- when 'String'
40
- tag = WpTag.emailtag(tag)
41
- else
42
- throw "#add_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter."
43
- end
44
- self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq
45
- self.save!
45
+ def add_tag which
46
+ tag = WpTag.iso_get which
47
+ # puts!( tag.slug, "Adding tag" ) if DEBUG
48
+ Office::EmailConversationTag.find_or_create_by!({
49
+ email_conversation_id: id,
50
+ wp_term_id: tag.id,
51
+ })
46
52
  end
47
53
 
48
- def remove_tag tag
49
- case tag.class.name
50
- when 'Integer'
51
- tag = WpTag.find( tag )
52
- when 'String'
53
- tag = WpTag.emailtag( tag )
54
- when 'WpTag'
55
- ; # tag is WpTag
56
- else
57
- throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) or id as the only parameter."
58
- end
59
- self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ]
60
- out = self.save!
61
- out
54
+ def remove_tag which
55
+ tag = WpTag.iso_get which
56
+ # puts!( tag.slug, "Removing tag" ) if DEBUG
57
+ Office::EmailConversationTag.where({
58
+ email_conversation_id: id,
59
+ wp_term_id: tag.id,
60
+ }).first&.delete
62
61
  end
63
- def rmtag tag; remove_tag tag; end
64
62
 
65
- def self.not_in_emailtag which
66
- case which.class.name
67
- when 'String'
68
- tag_id = WpTag.emailtag(which).id
69
- when 'WpTag'
70
- tag_id = which.id
71
- else
72
- throw "unsupported in #not_in_emailtag: #{which}"
73
- end
74
- return ::Office::EmailConversation.where( :wp_term_ids.ne => tag_id ).order_by( latest_at: :desc )
63
+ def in_emailtag? which
64
+ tag = WpTag.iso_get( which )
65
+ email_conversation_tags.where({ wp_term_id: tag.id }).present?
75
66
  end
76
67
 
77
68
  def self.in_emailtag which
78
- case which.class.name
79
- when 'String'
80
- tag_id = WpTag.emailtag(which).id
81
- when 'WpTag'
82
- tag_id = which.id
69
+ tag = WpTag.iso_get( which )
70
+ email_conversation_tags = Office::EmailConversationTag.where({ wp_term_id: tag.id })
71
+ where({ :id.in => email_conversation_tags.map(&:email_conversation_id) })
72
+ end
73
+
74
+ def self.not_in_emailtag which
75
+ tag = WpTag.iso_get( which )
76
+ email_conversation_tags = Office::EmailConversationTag.where({ wp_term_id: tag.id })
77
+ where({ :id.nin => email_conversation_tags.map(&:email_conversation_id) })
78
+ end
79
+
80
+
81
+ def apply_filter filter
82
+ case filter.kind
83
+
84
+ when ::Office::EmailFilter::KIND_DESTROY_SCHS
85
+ add_tag ::WpTag::TRASH
86
+ remove_tag ::WpTag::INBOX
87
+ tmp_lead = ::Lead.where( email: self.part_txt.split("\n")[1] ).first
88
+ if tmp_lead
89
+ tmp_lead.schs.each do |sch|
90
+ sch.update_attributes({ state: ::Sch::STATE_TRASH })
91
+ end
92
+ end
93
+
94
+ when ::Office::EmailFilter::KIND_ADD_TAG
95
+ add_tag filter.wp_term_id
96
+ if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug
97
+ remove_tag ::WpTag::INBOX
98
+ end
99
+
100
+ when ::Office::EmailFilter::KIND_REMOVE_TAG
101
+ remove_tag filter.wp_term_id
102
+
103
+ when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL
104
+ Ish::EmailContext.create({
105
+ email_template: filter.email_template,
106
+ lead_id: lead.id,
107
+ send_at: Time.now + 22.minutes,
108
+ })
109
+
110
+ when ::Office::EmailFilter::KIND_AUTORESPOND_EACT
111
+ ::Sch.create({
112
+ email_action: filter.email_action,
113
+ state: ::Sch::STATE_ACTIVE,
114
+ lead_id: lead.id,
115
+ perform_at: Time.now + 22.minutes,
116
+ })
117
+
83
118
  else
84
- throw "unsupported in #in_emailtag: #{which}"
119
+ raise "unknown filter kind: #{filter.kind}"
85
120
  end
86
- return ::Office::EmailConversation.where( :wp_term_ids => tag_id ).order_by( latest_at: :desc )
87
121
  end
88
122
 
123
+
124
+
89
125
  end
90
126
  Conv = Office::EmailConversation
@@ -0,0 +1,11 @@
1
+
2
+ class Office::EmailConversationLead
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ belongs_to :email_conversation, class_name: 'Office::EmailConversation'
7
+
8
+ field :lead_id, type: :integer
9
+ validates :lead_id, uniqueness: { scope: :email_conversation_id }, presence: true
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+
2
+ class Office::EmailConversationTag
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ belongs_to :email_conversation, class_name: 'Office::EmailConversation'
7
+
8
+ field :wp_term_id, type: :integer
9
+ validates :wp_term_id, uniqueness: { scope: :email_conversation_id }, presence: true
10
+
11
+ end
@@ -44,93 +44,11 @@ class Office::EmailMessage
44
44
  date
45
45
  end
46
46
 
47
- ## Copied to email_conversation
48
- field :wp_term_ids, type: Array, default: []
49
-
50
- ## Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? _vp_ 2023-03-07
51
- def add_tag tag
52
- case tag.class.name
53
- when 'WpTag'
54
- ;
55
- when 'String'
56
- tag = WpTag.emailtag(tag)
57
- else
58
- throw "#add_tag2 expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
59
- end
60
- self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq
61
- self.save!
62
- end
63
- def remove_tag tag
64
- case tag.class.name
65
- when 'WpTag'
66
- ;
67
- when 'String'
68
- tag = WpTag.emailtag(tag)
69
- else
70
- throw "#remove_tag2 expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
71
- end
72
- self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ]
73
- out = self.save!
74
- out
75
- end
76
- def rmtag tag; remove_tag tag; end
77
-
78
47
  belongs_to :email_conversation
79
48
  def conv
80
49
  email_conversation
81
50
  end
82
51
 
83
- ## @TODO: reimplement
84
- def name
85
- return 'associate'
86
- # from[0].split('@')[0].upcase
87
- end
88
-
89
- def company_url
90
- from[0].split('@')[1]
91
- end
92
-
93
- ## @TODO: move to email_conversation _vp_ 2023-03-24
94
- def apply_filter filter
95
- case filter.kind
96
-
97
- when ::Office::EmailFilter::KIND_DESTROY_SCHS
98
- self.conv.add_tag( ::WpTag::TRASH )
99
- self.conv.remove_tag( ::WpTag::INBOX )
100
- tmp_lead = ::Lead.where( email: self.part_txt.split("\n")[1] ).first
101
- if tmp_lead
102
- tmp_lead.schs.each { |sch| sch.update_attributes({ state: ::Sch::STATE_TRASH }) }
103
- end
104
-
105
- when ::Office::EmailFilter::KIND_ADD_TAG
106
- self.conv.add_tag( filter.wp_term_id )
107
- if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug
108
- self.conv.remove_tag(::WpTag::INBOX )
109
- end
110
-
111
- when ::Office::EmailFilter::KIND_REMOVE_TAG
112
- self.conv.remove_tag( filter.wp_term_id )
113
-
114
- when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL
115
- Ish::EmailContext.create({
116
- email_template: filter.email_template,
117
- lead_id: lead.id,
118
- send_at: Time.now + 22.minutes,
119
- })
120
-
121
- when ::Office::EmailFilter::KIND_AUTORESPOND_EACT
122
- ::Sch.create({
123
- email_action: filter.email_action,
124
- state: ::Sch::STATE_ACTIVE,
125
- lead_id: lead.id,
126
- perform_at: Time.now + 22.minutes,
127
- })
128
-
129
- else
130
- raise "unknown filter kind: #{filter.kind}"
131
- end
132
- end
133
-
134
52
  def preview_str
135
53
  body = part_html || part_html || 'Neither part_html nor part_txt!'
136
54
  body = ::ActionView::Base.full_sanitizer.sanitize( body ).gsub(/\s+/, ' ')
@@ -140,3 +58,7 @@ class Office::EmailMessage
140
58
 
141
59
  end
142
60
  ::Msg = Office::EmailMessage
61
+
62
+
63
+
64
+
@@ -11,12 +11,12 @@ class Office::EmailMessageStub
11
11
  STATES = [ STATE_PENDING, STATE_PROCESSED ]
12
12
  field :state, type: :string, default: STATE_PENDING
13
13
 
14
- field :object_key, type: :string ## aka 'filename', use with bucket name + prefix
15
- validates_presence_of :object_key
14
+ field :object_key, type: :string ## aka 'filename', use with bucket name + prefix
15
+ validates :object_key, presence: true, uniqueness: true
16
16
 
17
- field :object_path, type: :string ## A routable s3 url ## @TODO: remove this field. _vp_ 2023-03-07
17
+ # field :object_path, type: :string ## A routable s3 url ## @TODO: remove this field. _vp_ 2023-03-07
18
18
 
19
- field :wp_term_ids, type: :array, default: []
19
+ # field :wp_term_ids, type: :array, default: []
20
20
 
21
21
  end
22
22
  MsgStub = EMS = Office::EmailMessageStub
data/lib/video.rb CHANGED
@@ -29,7 +29,8 @@ class Video
29
29
  end
30
30
 
31
31
  field :is_public, :type => Boolean, :default => false
32
- def public
32
+
33
+ def published
33
34
  where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc })
34
35
  end
35
36
 
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.274
4
+ version: 0.0.33.275
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -219,6 +219,8 @@ files:
219
219
  - lib/office/email_action.rb
220
220
  - lib/office/email_action_tie.rb
221
221
  - lib/office/email_conversation.rb
222
+ - lib/office/email_conversation_lead.rb
223
+ - lib/office/email_conversation_tag.rb
222
224
  - lib/office/email_filter.rb
223
225
  - lib/office/email_message.rb
224
226
  - lib/office/email_message_stub.rb