Progress with DMs

Progress with DMs
This commit is contained in:
mgabdev
2020-12-03 17:13:11 -05:00
parent a129b3ce3b
commit 137a36b810
53 changed files with 539 additions and 182 deletions

View File

@@ -70,12 +70,7 @@ module Admin
end
def filter_params
params.permit(
:local,
:remote,
:by_domain,
:shortcode
)
params.permit(:shortcode)
end
end
end

View File

@@ -26,7 +26,7 @@ class Api::V1::ChatConversationController < Api::BaseController
end
def mark_chat_conversation_unread
@chat_conversation_account.update!(is_unread: true)
@chat_conversation_account.update!(unread_count: 1)
render json: @chat_conversation_account, serializer: REST::ChatConversationAccountSerializer
end

View File

@@ -4,22 +4,30 @@ class Api::V1::ChatConversations::ApprovedConversationsController < Api::BaseCon
before_action -> { authorize_if_got_token! :read, :'read:chats' }
before_action :require_user!
before_action :set_chat_conversation, only: :create
after_action :insert_pagination_headers
def index
puts "tilly ApprovedConversationsController-0"
@chat_conversations = load_chat_conversations
render json: @chat_conversations, each_serializer: REST::ChatConversationAccountSerializer
end
def show
puts "tilly ApprovedConversationsController-1"
@chat_conversations = load_chat_conversations
render json: @chat_conversations, each_serializer: REST::ChatConversationAccountSerializer
render json: @chat_conversation, serializer: REST::ChatConversationAccountSerializer
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
end
private
def set_chat_conversation
@chat_conversation = ChatConversationAccount.where(account: current_account).find(params[:id]).first
end
def load_chat_conversations
paginated_chat_conversations
end

View File

@@ -15,6 +15,22 @@ class Api::V1::ChatConversations::MessagesController < Api::BaseController
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
end
private
def set_chat_conversation

View File

@@ -5,25 +5,33 @@ class Api::V1::ChatMessagesController < Api::BaseController
before_action -> { doorkeeper_authorize! :write, :'write:chats' }
before_action :require_user!
before_action :set_chat_conversation
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: params[:text]
text: ActionController::Base.helpers.strip_tags(params[:text])
)
# : todo :
# Redis.current.publish("chat_messages:10", 'hi')
Redis.current.publish("chat_messages:10", Oj.dump(event: :chat_message, payload: InlineRenderer.render(@chat, current_user.account, :chat_message)))
# check if blocked
@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
render json: @chat, serializer: REST::ChatMessageSerializer
end
def destroy
@chat = ChatMessage.where(account: current_user.account).find(params[:id])
authorize @chat, :destroy?
puts "tilly destry chat"
@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
@@ -39,6 +47,12 @@ class Api::V1::ChatMessagesController < Api::BaseController
@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
puts "tilly account_conversation - " + account_conversation.inspect
@chat_conversation_recipients = Account.where(id: account_conversation.participant_account_ids)
end
def chat_params
params.permit(:text, :chat_conversation_id)
end