This commit is contained in:
mgabdev
2020-12-15 19:31:30 -05:00
parent de0c977950
commit 75d52c841e
129 changed files with 2559 additions and 910 deletions

View File

@@ -12,6 +12,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
def update
@account = current_account
# : todo : add link blocking check for bio
UpdateAccountService.new.call(@account, account_params, raise_error: true)
UserSettingsDecorator.new(current_user).update(user_settings_params) if user_settings_params
render json: @account, serializer: REST::CredentialAccountSerializer

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
class Api::V1::AlbumsController < Api::BaseController
before_action :require_user!
before_action :set_albums, only: :index
before_action :set_album, only: [:show, :update, :destroy]
def index
render json: @albums, each_serializer: REST::AlbumSerializer
end
def create
@album = "" #current_account.custom_filters.create!(resource_params)
render json: @album, serializer: REST::AlbumSerializer
end
def show
render json: @album, serializer: REST::AlbumSerializer
end
def update
@album.update!(resource_params)
render json: @album, serializer: REST::AlbumSerializer
end
def destroy
@album.destroy!
render_empty_success
end
private
def set_albums
@albums = "" #current_account.custom_filters
end
def set_album
@album = "" # current_account.custom_filters.find(params[:id])
end
def resource_params
params.permit(:title, :description, :visibility)
end
end

View File

@@ -0,0 +1,44 @@
# frozen_string_literal: true
class Api::V1::BookmarkCollectionsController < Api::BaseController
before_action :require_user!
before_action :set_bookmark_collections, only: :index
before_action :set_bookmark_collection, only: [:show, :update, :destroy]
def index
render json: @bookmark_collections, each_serializer: REST::BookmarkCollectionSerializer
end
def create
@bookmark_collection = "" #current_account.custom_filters.create!(resource_params)
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def show
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def update
@bookmark_collection.update!(resource_params)
render json: @bookmark_collection, serializer: REST::BookmarkCollectionSerializer
end
def destroy
@bookmark_collection.destroy!
render_empty_success
end
private
def set_bookmark_collections
@bookmark_collections = "" #current_account.custom_filters
end
def set_bookmark_collection
@bookmark_collection = "" # current_account.custom_filters.find(params[:id])
end
def resource_params
params.permit(:title)
end
end

View File

@@ -35,6 +35,15 @@ class Api::V1::ChatConversationAccountsController < Api::BaseController
render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
end
def set_expiration_policy
if current_user.account.is_pro
#
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
private
def set_account

View File

@@ -6,7 +6,7 @@ class Api::V1::ChatConversationController < Api::BaseController
before_action :require_user!
before_action :set_account, only: :create
before_action :set_chat_conversation, only: [:show, :mark_chat_conversation_approved, :mark_chat_conversation_hidden, :mark_chat_conversation_unread]
before_action :set_chat_conversation, only: [:show, :mark_chat_conversation_approved, :mark_chat_conversation_hidden, :mark_chat_conversation_read]
def show
render json: {}, each_serializer: REST::ChatConversationAccountSerializer
@@ -23,8 +23,8 @@ class Api::V1::ChatConversationController < Api::BaseController
render json: chat_conversation_account, each_serializer: REST::ChatConversationAccountSerializer
end
def mark_chat_conversation_unread
@chat_conversation_account.update!(unread_count: 1)
def mark_chat_conversation_read
@chat_conversation_account.update!(unread_count: 0)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end
@@ -34,8 +34,13 @@ class Api::V1::ChatConversationController < Api::BaseController
end
def mark_chat_conversation_approved
@chat_conversation_account.update!(is_approved: true)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
approved_conversation_count = ChatConversationAccount.where(account: @account, is_hidden: false, is_approved: true).count
if approved_conversation_count >= ChatConversationAccount::PER_ACCOUNT_APPROVED_LIMIT
render json: { error: true, message: "You have #{approved_conversation_count} active chat conversations. The limit is #{ChatConversationAccount::PER_ACCOUNT_APPROVED_LIMIT}. Delete some conversations first before approving any more requests." }
else
@chat_conversation_account.update!(is_approved: true)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end
end
private

View File

@@ -11,24 +11,16 @@ class Api::V1::ChatConversations::MessagesController < Api::BaseController
after_action :insert_pagination_headers, unless: -> { @chats.empty? }
def show
puts "tilly chat_message_conversations - 1: " + @chats.count.inspect
render json: @chats, each_serializer: REST::ChatMessageSerializer
end
def destroy_all
puts "tilly destry all chat"
# : todo :
# check if is pro
# @chat = ChatMessage.where(from_account: current_user.account).find(params[:id])
puts "tilly @chat: " + @chat.inspect
# : todo :
# make sure last_chat_message_id in chat_account_conversation gets set to last
# @chat.destroy!
# render json: @chat, serializer: REST::ChatMessageSerializer
if current_user.account.is_pro
@chat_conversation_account = PurgeChatMessagesService.new.call(current_user.account, @chat_conversation)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
else
render json: { error: 'You need to be a GabPRO member to access this' }, status: 422
end
end
private

View File

@@ -5,50 +5,20 @@ class Api::V1::ChatMessagesController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
before_action :require_user!
before_action :set_chat_conversation, only: :create
before_action :set_chat_conversation_recipients, only: :create
def create
@chat = ChatMessage.create!(
from_account: current_account,
chat_conversation: @chat_conversation,
text: ActionController::Base.helpers.strip_tags(params[:text])
)
# : todo :
# check if blocked
# update unread_count++ if offline
@chat_conversation_recipients.each do |account|
payload = InlineRenderer.render(@chat, account, :chat_message)
Redis.current.publish("chat_messages:#{account.id}", Oj.dump(event: :notification, payload: payload))
end
@chat_conversation = ChatConversation.find(chat_params[:chat_conversation_id])
@chat = PostChatMessageService.new.call(current_user.account, text: chat_params[:text], chat_conversation: @chat_conversation)
render json: @chat, serializer: REST::ChatMessageSerializer
end
def destroy
@chat = ChatMessage.where(from_account: current_user.account).find(params[:id])
# : todo :
# make sure last_chat_message_id in chat_account_conversation gets set to last
@chat.destroy!
@chat = DeleteChatMessageService.new.call(current_user.account, params[:id])
render json: @chat, serializer: REST::ChatMessageSerializer
end
private
def set_chat_conversation
@chat_conversation = ChatConversation.find(params[:chat_conversation_id])
end
def set_chat_conversation_recipients
account_conversation = ChatConversationAccount.where(account: current_user.account, chat_conversation: @chat_conversation).first
@chat_conversation_recipients = Account.where(id: account_conversation.participant_account_ids)
end
def chat_params
params.permit(:text, :chat_conversation_id)
end

View File

@@ -46,7 +46,7 @@ class Api::V1::GroupsController < Api::BaseController
@groups = []
if !@groupCategory.nil?
@groups = Group.where(is_archived: false, group_categories: @groupCategory).all
@groups = Group.where(is_archived: false, group_categories: @groupCategory).order('member_count DESC').all
end
render json: @groups, each_serializer: REST::GroupSerializer
@@ -59,7 +59,7 @@ class Api::V1::GroupsController < Api::BaseController
@groups = []
if !params[:tag].empty?
@groups = Group.where(is_archived: false).where("array_to_string(tags, '||') ILIKE :tag", tag: "%#{params[:tag]}%").all
@groups = Group.where(is_archived: false).where("array_to_string(tags, '||') ILIKE :tag", tag: "%#{params[:tag]}%").order('member_count DESC').all
end
render json: @groups, each_serializer: REST::GroupSerializer

View File

@@ -62,6 +62,6 @@ class Api::V1::Timelines::HomeController < Api::BaseController
end
def regeneration_in_progress?
Redis.current.exists("account:#{current_account.id}:regeneration")
Redis.current.exists?("account:#{current_account.id}:regeneration")
end
end