Class: WcoEmail::Conversation
- Inherits:
-
Object
- Object
- WcoEmail::Conversation
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/wco_email/conversation.rb
Constant Summary collapse
- PAGE_PARAM_NAME =
'conv_page'- STATUS_UNREAD =
'status_unread'- STATUS_READ =
'status_read'- STATUSES =
[ STATUS_UNREAD, STATUS_READ ]
Class Method Summary collapse
-
.load_conversations_messages_tag_by_params_and_profile(params, current_profile) ⇒ Object
current_profile = OpenStruct.new per_page: 25 params = { tagname: 'inbox' }.
Instance Method Summary collapse
- #cache_key ⇒ Object
-
#deleted_at ⇒ Object
just in case...
- #to_s ⇒ Object
- #unread? ⇒ Boolean
Class Method Details
.load_conversations_messages_tag_by_params_and_profile(params, current_profile) ⇒ Object
current_profile = OpenStruct.new per_page: 25 params = { tagname: 'inbox' }
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/wco_email/conversation.rb', line 42 def self. params, current_profile @conversations = WcoEmail::Conversation.all if params[:tagname] @tag = Wco::Tag.find_by slug: params[:tagname] @conversations = @conversations.where( :tag_ids.in => [ @tag.id ] ) end if params[:tagname_not] @tag_not = Wco::Tag.find_by slug: params[:tagname_not] @conversations = @conversations.where( :tag_ids.nin => [ @tag_not.id ] ) end if params[:subject].present? @conversations = @conversations.where({ subject: /.*#{params[:subject]}.*/i }) end if params[:from_email].present? @conversations = @conversations.where({ from_emails: /.*#{params[:from_email]}.*/i }) end if params[:lead_id].present? @conversations = @conversations.where( lead_ids: params[:lead_id] ) end @conversations = @conversations.where( ).includes( :leads, # :messages, :tags ).order_by( latest_at: :desc ).page( params[:conv_page] ).per( current_profile.per_page ) conversation_ids = @conversations.map &:id = WcoEmail::Message.where( :conversation_id.in => conversation_ids, read_at: nil, ) @messages_hash = {} .map do |msg| @messages_hash[msg.id.to_s] = msg end return [ @conversations, @messages_hash, @tag ] end |
Instance Method Details
#cache_key ⇒ Object
87 88 89 |
# File 'app/models/wco_email/conversation.rb', line 87 def cache_key "#{self.class.name} #{id.to_s} #{updated_at}" end |
#deleted_at ⇒ Object
just in case... should be unused. vp 2026-07-19
24 |
# File 'app/models/wco_email/conversation.rb', line 24 field :deleted_at, type: Time |
#to_s ⇒ Object
91 92 93 |
# File 'app/models/wco_email/conversation.rb', line 91 def to_s "#{subject} (#{.length})" end |
#unread? ⇒ Boolean
14 15 16 |
# File 'app/models/wco_email/conversation.rb', line 14 def unread? status == STATUS_UNREAD end |