feat: Conversation and contact endpoint (#3198)

This commit is contained in:
Tejaswini Chile
2021-10-20 18:14:56 +05:30
committed by GitHub
parent b0041ccf3f
commit 658a511b88
11 changed files with 200 additions and 24 deletions

View File

@@ -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? }

View File

@@ -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

View File

@@ -15,6 +15,10 @@ class ContactPolicy < ApplicationPolicy
true
end
def filter?
true
end
def update?
true
end

View File

@@ -0,0 +1,3 @@
json.array! @contacts do |contact|
json.partial! 'api/v1/models/contact.json.jbuilder', resource: contact
end

View File

@@ -0,0 +1,3 @@
json.array! @conversations do |conversation|
json.partial! 'api/v1/models/conversation.json.jbuilder', conversation: conversation
end

View File

@@ -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

View 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