Refactor Conversation model (#134)
* Add Conversation factory with dependent factories * Include FactoryBot methods in rspec config * Add unit tests for public methods of Conversation model * Move Current model into a separate file in lib folder * Disable Metrics/BlockLength rule for db/migrate and spec folders * Get rid of global $dispatcher variable * Create Message#unread_since scope * Refactor callback methods in Conversation model * Create Conversations::EventDataPresenter * Add translation keys for activity messages * Add pry-rails gem * Refactor Conversation#notify_status_change * Add mock_redis for test env
This commit is contained in:
committed by
Sojan Jose
parent
43e54a7bfb
commit
4768aca484
37
app/presenters/conversations/event_data_presenter.rb
Normal file
37
app/presenters/conversations/event_data_presenter.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
module Conversations
|
||||
class EventDataPresenter < SimpleDelegator
|
||||
def lock_data
|
||||
{ id: display_id, locked: locked? }
|
||||
end
|
||||
|
||||
def push_data
|
||||
{
|
||||
id: display_id,
|
||||
inbox_id: inbox_id,
|
||||
messages: push_messages,
|
||||
meta: push_meta,
|
||||
status: status_before_type_cast.to_i,
|
||||
unread_count: unread_incoming_messages.count,
|
||||
**push_timestamps
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def push_messages
|
||||
[messages.chat.last&.push_event_data].compact
|
||||
end
|
||||
|
||||
def push_meta
|
||||
{ sender: sender.push_event_data, assignee: assignee }
|
||||
end
|
||||
|
||||
def push_timestamps
|
||||
{
|
||||
agent_last_seen_at: agent_last_seen_at.to_i,
|
||||
user_last_seen_at: user_last_seen_at.to_i,
|
||||
timestamp: created_at.to_i
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user