gab-social/app/controllers/api/v1/chat_conversation_accounts_controller.rb

75 lines
2.7 KiB
Ruby
Raw Normal View History

2020-11-25 21:22:37 +00:00
# frozen_string_literal: true
class Api::V1::ChatConversationAccountsController < Api::BaseController
2020-12-10 16:51:45 +00:00
before_action -> { authorize_if_got_token! :read, :'read:chats' }
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
before_action :require_user!
2020-12-19 06:33:33 +00:00
before_action :set_account, only: [:block_messenger, :unblock_messenger, :messenger_block_relationships]
before_action :check_account_suspension, only: [:block_messenger, :unblock_messenger, :messenger_block_relationships]
before_action :set_chat_conversation, except: [:block_messenger, :unblock_messenger, :messenger_block_relationships, :search]
2020-11-25 21:22:37 +00:00
2020-12-10 16:51:45 +00:00
def block_messenger
2020-12-19 06:33:33 +00:00
@block = BlockChatMessengerService.new.call(current_user.account, @account)
render json: @account,
serializer: REST::ChatMessengerBlockedSerializer,
chat_blocking: true
2020-11-25 21:22:37 +00:00
end
2020-12-10 16:51:45 +00:00
def unblock_messenger
2020-12-19 06:33:33 +00:00
UnblockChatMessengerService.new.call(current_user.account, @account)
render json: @account,
serializer: REST::ChatMessengerBlockedSerializer,
chat_blocking: false
end
def messenger_block_relationships
chat_blocking = current_user.account.chat_blocking?(@account)
chat_blocked_by = current_user.account.chat_blocked_by?(@account, current_account)
render json: @account,
serializer: REST::ChatMessengerBlockedSerializer,
chat_blocking: chat_blocking,
chat_blocked_by: chat_blocked_by
2020-11-25 21:22:37 +00:00
end
2020-12-16 07:39:07 +00:00
def mute_chat_conversation
2020-12-19 06:33:33 +00:00
@chat_conversation_account.update!(is_muted: true)
2020-12-16 07:39:07 +00:00
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end
def unmute_chat_conversation
2020-12-19 06:33:33 +00:00
@chat_conversation_account.update!(is_muted: false)
2020-12-16 07:39:07 +00:00
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
2020-11-25 21:22:37 +00:00
end
def search
# : todo :
search_conversations = [] #ChatConversationAccount.where(account: current_account, is_hidden: false, is_approved: true).map(&:participant_account_ids)
# .joins(:account).where("accounts.display_name ILIKE ?", "%#{params[:q]}%")
render json: search_conversations, each_serializer: REST::ChatConversationAccountSerializer
end
2020-11-25 21:22:37 +00:00
private
def set_account
2020-12-19 06:33:33 +00:00
@account = Account.find(params[:account_id])
2020-11-25 21:22:37 +00:00
end
2020-12-16 07:39:07 +00:00
def set_chat_conversation
@chat_conversation = ChatConversation.find(params[:id])
@chat_conversation_account = ChatConversationAccount.where(
account: current_account,
chat_conversation: @chat_conversation
).first
end
2020-11-25 21:22:37 +00:00
def check_account_suspension
gone if @account.suspended?
end
2020-12-10 16:51:45 +00:00
def relationships(**options)
AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
end
2020-11-25 21:22:37 +00:00
end