Sha256: cde6d5c90bbfb335239636179aedfc2eb8105decacdbf048eda19e805170c287

Contents?: true

Size: 1.08 KB

Versions: 40

Compression:

Stored size: 1.08 KB

Contents

class WcoEmail::Conversation
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'office_email_conversations'

  STATUS_UNREAD = 'status_unread'
  STATUS_READ   = 'status_read'
  STATUSES      = [ STATUS_UNREAD, STATUS_READ ]
  field :status
  scope :unread, ->{ where( status: WcoEmail::Conversation::STATUS_UNREAD ) }
  def unread?
    status == STATUS_UNREAD
  end

  field :subject
  index({ subject: -1 })

  field :latest_at
  index({ latest_at: -1 })

  field :from_emails, type: :array, default: []
  index({ from_emails: -1 })

  field :preview, default: ''

  has_many :messages,             class_name: '::WcoEmail::Message'

  has_and_belongs_to_many :tags,  class_name: 'Wco::Tag', index: true
  has_and_belongs_to_many :leads, class_name: 'Wco::Lead', index: true

  belongs_to :filter, class_name: 'WcoEmail::EmailFilter', inverse_of: :conversations, optional: true

  def cache_key
    "#{self.class.name} #{id.to_s} #{updated_at}"
  end

  def to_s
    "#{subject} (#{messages.length})"
  end
end
Conv = WcoEmail::Conversation

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
wco_models-3.1.0.164 app/models/wco_email/conversation.rb
wco_models-3.1.0.163 app/models/wco_email/conversation.rb
wco_models-3.1.0.162 app/models/wco_email/conversation.rb
wco_models-3.1.0.161 app/models/wco_email/conversation.rb
wco_models-3.1.0.155 app/models/wco_email/conversation.rb
wco_models-3.1.0.154 app/models/wco_email/conversation.rb
wco_models-3.1.0.153 app/models/wco_email/conversation.rb
wco_models-3.1.0.152 app/models/wco_email/conversation.rb
wco_models-3.1.0.151 app/models/wco_email/conversation.rb
wco_models-3.1.0.150 app/models/wco_email/conversation.rb
wco_models-3.1.0.149 app/models/wco_email/conversation.rb
wco_models-3.1.0.148 app/models/wco_email/conversation.rb
wco_models-3.1.0.147 app/models/wco_email/conversation.rb
wco_models-3.1.0.146 app/models/wco_email/conversation.rb
wco_models-3.1.0.145 app/models/wco_email/conversation.rb
wco_models-3.1.0.144 app/models/wco_email/conversation.rb
wco_models-3.1.0.143 app/models/wco_email/conversation.rb
wco_models-3.1.0.142 app/models/wco_email/conversation.rb
wco_models-3.1.0.141 app/models/wco_email/conversation.rb
wco_models-3.1.0.140 app/models/wco_email/conversation.rb