ish_models 0.0.33.274 → 0.0.33.276

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90de218899ddf4fc0764c1f548417c53fcd398e1c3a1a31560ca796e411832bc
4
- data.tar.gz: d0b1ec1ada583d9ac93b924a2a1701c2df0ba62c57c1243c80fcdaddeb00f3dc
3
+ metadata.gz: f8f21dc5065dc143e68133892d902db7b86c4dfe1645bbb91531c1cec0f03b8e
4
+ data.tar.gz: 6afb50d094d4c13a9fc2ed02c05fab69a222613403cc210118d011541579fb81
5
5
  SHA512:
6
- metadata.gz: eb4f60187c093f0661b90d0c064eb6ba4e294455f2b5287cc22f876041144a48fa9052162980dd8599986015fa89ed45b6a1ab809c0f8943b3bcc188ce14cd59
7
- data.tar.gz: cd94a83ea12c95bd829385f26277c6fe730982d88c9078153a58065fdb8ec171c1b5436d286da506a34605c8aea2070b5108c99952a4c8e251b84476c7aea3d9
6
+ metadata.gz: 67ee371dd91174041af92982d116dfb074cd5acd4ed13426553421b5858eaefe11487ecbc46d3b2f6d431429c6209a96b4edc834c86a3baaec7bb4db32dd5f76
7
+ data.tar.gz: d87df64042cb3f27ef9d87dd270988e713454c4389922ce5cdab2889676304ce2c9267eb4f687d57cc665151993be9c69dc0cd20a52cbb3e0d851b6946aa1b14
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,101 @@ 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
62
+ def rmtag which; remove_tag which; end
64
63
 
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 )
64
+ def in_emailtag? which
65
+ tag = WpTag.iso_get( which )
66
+ email_conversation_tags.where({ wp_term_id: tag.id }).present?
75
67
  end
76
68
 
77
69
  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
70
+ tag = WpTag.iso_get( which )
71
+ email_conversation_tags = Office::EmailConversationTag.where({ wp_term_id: tag.id })
72
+ where({ :id.in => email_conversation_tags.map(&:email_conversation_id) })
73
+ end
74
+
75
+ def self.not_in_emailtag which
76
+ tag = WpTag.iso_get( which )
77
+ email_conversation_tags = Office::EmailConversationTag.where({ wp_term_id: tag.id })
78
+ where({ :id.nin => email_conversation_tags.map(&:email_conversation_id) })
79
+ end
80
+
81
+
82
+ def apply_filter filter
83
+ case filter.kind
84
+
85
+ when ::Office::EmailFilter::KIND_DESTROY_SCHS
86
+ add_tag ::WpTag::TRASH
87
+ remove_tag ::WpTag::INBOX
88
+ tmp_lead = ::Lead.where( email: self.part_txt.split("\n")[1] ).first
89
+ if tmp_lead
90
+ tmp_lead.schs.each do |sch|
91
+ sch.update_attributes({ state: ::Sch::STATE_TRASH })
92
+ end
93
+ end
94
+
95
+ when ::Office::EmailFilter::KIND_ADD_TAG
96
+ add_tag filter.wp_term_id
97
+ if ::WpTag::TRASH == ::WpTag.find( filter.wp_term_id ).slug
98
+ remove_tag ::WpTag::INBOX
99
+ end
100
+
101
+ when ::Office::EmailFilter::KIND_REMOVE_TAG
102
+ remove_tag filter.wp_term_id
103
+
104
+ when ::Office::EmailFilter::KIND_AUTORESPOND_TMPL
105
+ Ish::EmailContext.create({
106
+ email_template: filter.email_template,
107
+ lead_id: lead.id,
108
+ send_at: Time.now + 22.minutes,
109
+ })
110
+
111
+ when ::Office::EmailFilter::KIND_AUTORESPOND_EACT
112
+ ::Sch.create({
113
+ email_action: filter.email_action,
114
+ state: ::Sch::STATE_ACTIVE,
115
+ lead_id: lead.id,
116
+ perform_at: Time.now + 22.minutes,
117
+ })
118
+
83
119
  else
84
- throw "unsupported in #in_emailtag: #{which}"
120
+ raise "unknown filter kind: #{filter.kind}"
85
121
  end
86
- return ::Office::EmailConversation.where( :wp_term_ids => tag_id ).order_by( latest_at: :desc )
87
122
  end
88
123
 
124
+
125
+
89
126
  end
90
127
  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.276
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