hashtag in top of tag feed, scroll to comment, chat blocking, muting, filtering
This commit is contained in:
mgabdev
2020-12-21 18:30:46 -05:00
parent ee91809e8d
commit 67d94858dc
39 changed files with 576 additions and 179 deletions

View File

@@ -15,26 +15,36 @@ class CreateChatConversationService < BaseService
# : todo :
# check if allow anyone to message then create with approved:true
# unique account id, participants
chat_conversation = ChatConversation.create
@chat_conversation = ChatConversation.create
my_chat = ChatConversationAccount.create!(
account: current_account,
participant_account_ids: [@account.id.to_s],
chat_conversation: chat_conversation,
account: @current_account,
participant_account_ids: account_ids_as_array,
chat_conversation: @chat_conversation,
is_approved: true
)
# : todo : if multiple ids
if @account.id != current_account.id
their_chat = ChatConversationAccount.create!(
account: @account,
participant_account_ids: [current_account.id.to_s],
chat_conversation: chat_conversation,
is_approved: false # : todo : check if allow all else default as request
)
if @other_accounts.length == 1 && @other_accounts[0].id == @current_account.id
# dont create two conversations if you are chatting with yourself
else
for other_account in @other_accounts
this_conversation_participants = @other_accounts.map { |account|
account.id.to_s
}.reject { |id| id == other_account.id.to_s } << @current_account.id.to_s
# is_approved = other_account&.user&.setting_chat_messages_restrict_non_followers == true
ChatConversationAccount.create!(
account: other_account,
participant_account_ids: this_conversation_participants,
chat_conversation: @chat_conversation,
is_approved: false
)
end
end
my_chat
end
def account_ids_as_array

View File

@@ -54,13 +54,16 @@ class PostChatMessageService < BaseService
# Get not mine
if @account_conversation.id != recipient.id
recipient.unread_count = recipient.unread_count + 1
recipient.is_hidden = false
# check if recipient is blocking me
unless recipient.account.chat_blocking?(@account)
recipient.unread_count = recipient.unread_count + 1
recipient.is_hidden = false
# check if muting
unless recipient.is_muted
payload = InlineRenderer.render(@chat, recipient.account, :chat_message)
Redis.current.publish("chat_messages:#{recipient.account.id}", Oj.dump(event: :notification, payload: payload))
# check if muting
unless recipient.is_muted
payload = InlineRenderer.render(@chat, recipient.account, :chat_message)
Redis.current.publish("chat_messages:#{recipient.account.id}", Oj.dump(event: :notification, payload: payload))
end
end
else
recipient.unread_count = 0
@@ -72,21 +75,7 @@ class PostChatMessageService < BaseService
def set_chat_conversation_recipients!
@account_conversation = ChatConversationAccount.where(account: @account, chat_conversation: @chat_conversation).first
@chat_conversation_recipients_accounts = ChatConversationAccount.where(chat_conversation: @chat_conversation)
# if 1-to-1 chat, check for blocking and dont allow message to send if blocking
# if 1-to-many let chat go through but keep is_hidden
@chat_conversation_recipients_accounts.each do |recipient|
# : todo :
# check if chat blocked
# check if normal blocked
if recipient.account.blocking?(@account) || recipient.account.chat_blocking?(@account)
raise GabSocial::NotPermittedError
end
end
@chat_conversation_recipients_accounts = ChatConversationAccount.where(chat_conversation: @chat_conversation)
rescue ArgumentError
raise ActiveRecord::RecordInvalid
end