feat: Conversation and contact endpoint (#3198)
This commit is contained in:
@@ -50,6 +50,10 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
||||
|
||||
def show; end
|
||||
|
||||
def filter
|
||||
@contacts = Current.account.contacts.limit(10)
|
||||
end
|
||||
|
||||
def contactable_inboxes
|
||||
@all_contactable_inboxes = Contacts::ContactableInboxesService.new(contact: @contact).get
|
||||
@contactable_inboxes = @all_contactable_inboxes.select { |contactable_inbox| policy(contactable_inbox[:inbox]).show? }
|
||||
|
||||
@@ -2,7 +2,7 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||
include Events::Types
|
||||
include DateRangeHelper
|
||||
|
||||
before_action :conversation, except: [:index, :meta, :search, :create]
|
||||
before_action :conversation, except: [:index, :meta, :search, :create, :filter]
|
||||
before_action :contact_inbox, only: [:create]
|
||||
|
||||
def index
|
||||
@@ -31,6 +31,10 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
|
||||
|
||||
def show; end
|
||||
|
||||
def filter
|
||||
@conversations = Current.account.conversations.limit(10)
|
||||
end
|
||||
|
||||
def mute
|
||||
@conversation.mute!
|
||||
head :ok
|
||||
|
||||
@@ -15,6 +15,10 @@ class ContactPolicy < ApplicationPolicy
|
||||
true
|
||||
end
|
||||
|
||||
def filter?
|
||||
true
|
||||
end
|
||||
|
||||
def update?
|
||||
true
|
||||
end
|
||||
|
||||
3
app/views/api/v1/accounts/contacts/filter.json.jbuilder
Normal file
3
app/views/api/v1/accounts/contacts/filter.json.jbuilder
Normal file
@@ -0,0 +1,3 @@
|
||||
json.array! @contacts do |contact|
|
||||
json.partial! 'api/v1/models/contact.json.jbuilder', resource: contact
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
json.array! @conversations do |conversation|
|
||||
json.partial! 'api/v1/models/conversation.json.jbuilder', conversation: conversation
|
||||
end
|
||||
@@ -5,26 +5,6 @@ json.meta do
|
||||
end
|
||||
json.payload do
|
||||
json.array! @conversations do |conversation|
|
||||
json.id conversation.display_id
|
||||
json.created_at conversation.created_at.to_i
|
||||
json.contact do
|
||||
json.id conversation.contact.id
|
||||
json.name conversation.contact.name
|
||||
end
|
||||
json.inbox do
|
||||
json.id conversation.inbox.id
|
||||
json.name conversation.inbox.name
|
||||
json.channel_type conversation.inbox.channel_type
|
||||
end
|
||||
json.messages do
|
||||
json.array! conversation.messages do |message|
|
||||
json.content message.content
|
||||
json.id message.id
|
||||
json.sender_name message.sender.name if message.sender
|
||||
json.message_type message.message_type_before_type_cast
|
||||
json.created_at message.created_at.to_i
|
||||
end
|
||||
end
|
||||
json.account_id conversation.account_id
|
||||
json.partial! 'api/v1/models/conversation.json.jbuilder', conversation: conversation
|
||||
end
|
||||
end
|
||||
|
||||
21
app/views/api/v1/models/_conversation.json.jbuilder
Normal file
21
app/views/api/v1/models/_conversation.json.jbuilder
Normal file
@@ -0,0 +1,21 @@
|
||||
json.id conversation.display_id
|
||||
json.created_at conversation.created_at.to_i
|
||||
json.contact do
|
||||
json.id conversation.contact.id
|
||||
json.name conversation.contact.name
|
||||
end
|
||||
json.inbox do
|
||||
json.id conversation.inbox.id
|
||||
json.name conversation.inbox.name
|
||||
json.channel_type conversation.inbox.channel_type
|
||||
end
|
||||
json.messages do
|
||||
json.array! conversation.messages do |message|
|
||||
json.content message.content
|
||||
json.id message.id
|
||||
json.sender_name message.sender.name if message.sender
|
||||
json.message_type message.message_type_before_type_cast
|
||||
json.created_at message.created_at.to_i
|
||||
end
|
||||
end
|
||||
json.account_id conversation.account_id
|
||||
Reference in New Issue
Block a user