Class: Office::EmailConversation

Inherits:
Object
  • Object
show all
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

Class Method Details

.in_emailtag(which) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/office/email_conversation.rb', line 73

def self.in_emailtag which
  case which.class.name
  when 'String'
    tag_id = WpTag.emailtag(which).id
  when 'WpTag'
    tag_id = which.id
  else
    throw "unsupported in #in_emailtag: #{which}"
  end
  return ::Office::EmailConversation.where( :wp_term_ids => tag_id ).order_by( latest_at: :desc )
end

.not_in_emailtag(which) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/office/email_conversation.rb', line 61

def self.not_in_emailtag which
  case which.class.name
  when 'String'
    tag_id = WpTag.emailtag(which).id
  when 'WpTag'
    tag_id = which.id
  else
    throw "unsupported in #not_in_emailtag: #{which}"
  end
  return ::Office::EmailConversation.where( :wp_term_ids.ne => tag_id ).order_by( latest_at: :desc )
end

Instance Method Details

#add_tag(tag) ⇒ Object

Tested manually ok, does not pass the spec. @TODO: hire to make pass spec? vp 2023-03-07



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/office/email_conversation.rb', line 33

def add_tag tag
  case tag.class.name
  when 'WpTag'
    ;
  when 'String'
    tag = WpTag.emailtag(tag)
  else
    throw "#add_tag expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
  end
  self[:wp_term_ids] = ( [ tag.id ] + self[:wp_term_ids] ).uniq
  self.save!
end

#email_messagesObject



21
22
23
# File 'lib/office/email_conversation.rb', line 21

def email_messages
  Office::EmailMessage.where( email_conversation_id: self.id )
end

#leadsObject



16
17
18
# File 'lib/office/email_conversation.rb', line 16

def leads
  Lead.find( lead_ids )
end

#remove_tag(tag) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/office/email_conversation.rb', line 46

def remove_tag tag
  case tag.class.name
  when 'WpTag'
    ;
  when 'String'
    tag = WpTag.emailtag(tag)
  else
    throw "#remove_tag expects a WpTag or string (eg WpTag::INBOX) as the only parameter."
  end
  self[:wp_term_ids] = self[:wp_term_ids] - [ tag.id ]
  out = self.save!
  out
end

#rmtag(tag) ⇒ Object



59
# File 'lib/office/email_conversation.rb', line 59

def rmtag tag; remove_tag tag; end

#tagsObject



25
26
27
# File 'lib/office/email_conversation.rb', line 25

def tags
  WpTag.find( wp_term_ids )
end

#wp_term_idsObject

Copied from email_message



30
# File 'lib/office/email_conversation.rb', line 30

field :wp_term_ids, type: Array, default: []