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 ]

Instance Method Summary collapse

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
# File 'lib/office/email_conversation.rb', line 33

def add_tag tag
  if WpTag == tag.class
    self[:wp_term_ids] = self[:wp_term_ids].push(tag.id).uniq
    self.save!
  else
    throw "#add_tag expects a WpTag as the only parameter."
  end
end

#email_messagesObject



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

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



41
42
43
44
45
46
47
48
# File 'lib/office/email_conversation.rb', line 41

def remove_tag tag
  if WpTag == tag.class
    self[:wp_term_ids].delete( tag.id )
    self.save!
  else
    throw "#remove_tag expects a WpTag as the only parameter."
  end
end

#tagsObject



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

def tags
  WpTag.find( term_ids )
end

#wp_term_idsObject

Copied from email_message



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

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