Progress on deck, dms

This commit is contained in:
mgabdev
2020-12-10 11:51:45 -05:00
parent c35e651b43
commit de0c977950
40 changed files with 660 additions and 274 deletions

View File

@@ -1,11 +1,11 @@
# frozen_string_literal: true
class Api::V1::ChatConversationAccounts::BlockedAccountsController < Api::BaseController
class Api::V1::ChatConversationAccounts::BlockedChatAccountsController < Api::BaseController
before_action -> { doorkeeper_authorize! :follow, :'read:blocks' }
before_action :require_user!
after_action :insert_pagination_headers
def index
def show
@accounts = load_accounts
render json: @accounts, each_serializer: REST::AccountSerializer
end
@@ -32,13 +32,13 @@ class Api::V1::ChatConversationAccounts::BlockedAccountsController < Api::BaseCo
def next_path
if records_continue?
api_v1_chat_conversation_accounts_blocked_accounts_url pagination_params(max_id: pagination_max_id)
api_v1_chat_conversation_accounts_chat_blocked_accounts_url pagination_params(max_id: pagination_max_id)
end
end
def prev_path
unless paginated_blocks.empty?
api_v1_chat_conversation_accounts_blocked_accounts_url pagination_params(since_id: pagination_since_id)
api_v1_chat_conversation_accounts_blocked_chat_accounts_url pagination_params(since_id: pagination_since_id)
end
end

View File

@@ -1,11 +1,11 @@
# frozen_string_literal: true
class Api::V1::ChatConversationAccounts::MutedAccountsController < Api::BaseController
class Api::V1::ChatConversationAccounts::MutedChatAccountsController < Api::BaseController
before_action -> { doorkeeper_authorize! :follow, :'read:mutes' }
before_action :require_user!
after_action :insert_pagination_headers
def index
def show
@accounts = load_accounts
render json: @accounts, each_serializer: REST::AccountSerializer
end
@@ -32,13 +32,13 @@ class Api::V1::ChatConversationAccounts::MutedAccountsController < Api::BaseCont
def next_path
if records_continue?
api_v1_chat_conversation_accounts_muted_accounts_url pagination_params(max_id: pagination_max_id)
api_v1_chat_conversation_accounts_muted_chat_accounts_url pagination_params(max_id: pagination_max_id)
end
end
def prev_path
unless paginated_mutes.empty?
api_v1_chat_conversation_accounts_muted_accounts_url pagination_params(since_id: pagination_since_id)
api_v1_chat_conversation_accounts_muted_chat_accounts_url pagination_params(since_id: pagination_since_id)
end
end

View File

@@ -1,32 +1,36 @@
# frozen_string_literal: true
class Api::V1::ChatConversationAccountsController < Api::BaseController
before_action -> { authorize_if_got_token! :read, :'read:chats' }, except: [:create, :follow, :unfollow, :block, :unblock, :mute, :unmute]
before_action -> { doorkeeper_authorize! :write, :'write:chats' }, only: [:create]
before_action -> { authorize_if_got_token! :read, :'read:chats' }
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
before_action :require_user!
before_action :set_account, except: [:create]
before_action :set_account
def show
def is_messenger_blocked
#
end
def block
def is_messenger_muted
#
end
def block_messenger
BlockMessengerService.new.call(current_user.account, @account)
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
def mute
MuteMessengerService.new.call(current_user.account, @account, notifications: truthy_param?(:notifications))
def mute_messenger
MuteMessengerService.new.call(current_user.account, @account)
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
def unblock
def unblock_messenger
UnblockMessengerService.new.call(current_user.account, @account)
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
def unmute
def unmute_messenger
UnmuteMessegerService.new.call(current_user.account, @account)
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
@@ -34,19 +38,15 @@ class Api::V1::ChatConversationAccountsController < Api::BaseController
private
def set_account
# @account = Account.find(params[:id])
@account = Account.find(params[:id])
end
# def relationships(**options)
# AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
# end
def check_account_suspension
gone if @account.suspended?
end
# def account_params
# params.permit(:username, :email, :password, :agreement, :locale)
# end
def relationships(**options)
AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
end
end

View File

@@ -17,9 +17,9 @@ class Api::V1::ChatConversations::ApprovedConversationsController < Api::BaseCon
end
def unread_count
# : todo : make is_unread into unread_count then count
# count = ChatConversationAccount.where(account: current_account, is_hidden: false, is_approved: true, unread_count: true).count
render json: 1
unreads = ChatConversationAccount.where(account: current_account, is_hidden: false, is_approved: true).where('unread_count > 0')
sum = unreads.sum('unread_count')
render json: sum.to_i
end
private

View File

@@ -17,6 +17,7 @@ class Api::V1::ChatMessagesController < Api::BaseController
# : todo :
# check if blocked
# update unread_count++ if offline
@chat_conversation_recipients.each do |account|
payload = InlineRenderer.render(@chat, account, :chat_message)