Progress on DMs

Progress on DMs
This commit is contained in:
mgabdev
2020-12-19 01:33:33 -05:00
parent 47cd60f851
commit 7ec426e3d8
38 changed files with 447 additions and 197 deletions

View File

@@ -1,12 +1,23 @@
# frozen_string_literal: true
class DeleteChatMessageService < BaseService
def call(account, chatMessageId)
@chat = ChatMessage.where(from_account: account).find(chatMessageId)
# : todo :
# make sure last_chat_message_id in chat_account_conversation gets set to last
@chat.destroy!
include Redisable
def call(chat_message)
return if chat_message.nil?
@chat_message = chat_message
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
@chat_message.destroy!
else
raise GabSocial::RaceConditionError
end
end
end
def lock_options
{ redis: Redis.current, key: "distribute_chat_message:#{@chat_message.id}" }
end
end

View File

@@ -49,14 +49,13 @@ class PostChatMessageService < BaseService
end
def postprocess_chat!
@chat_conversation_recipients_accounts = ChatConversationAccount.where(chat_conversation: @chat_conversation)
@chat_conversation_recipients_accounts.each do |recipient|
recipient.last_chat_message_id = @chat.id
recipient.is_hidden = false # : todo : reset to show unless blocked
# Get not mine
if @account_conversation.id != recipient.id
recipient.unread_count = recipient.unread_count + 1
recipient.is_hidden = false
# check if muting
unless recipient.is_muted
@@ -72,33 +71,46 @@ class PostChatMessageService < BaseService
end
def set_chat_conversation_recipients!
# : todo :
# check if chat blocked
# check if normal blocked
@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
rescue ArgumentError
raise ActiveRecord::RecordInvalid
end
def set_message_expiration_date!
@expires_at = nil
unless @account.is_pro
return @expires_at
end
case @account_conversation.chat_message_expiration_policy
when :five_minutes
@expires_at = 5.minutes
when :sixty_minutes
@expires_at = 1.hour
when :six_hours
@expires_at = 6.hours
when :one_day
@expires_at = 1.day
when :three_days
@expires_at = 3.days
when :one_week
@expires_at = 1.week
else
@expires_at = nil
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:five_minutes]
@expires_at = Time.now + 5.minutes
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_hour]
@expires_at = Time.now + 1.hour
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:six_hours]
@expires_at = Time.now + 6.hours
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_day]
@expires_at = Time.now + 1.day
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:three_days]
@expires_at = Time.now + 3.days
when ChatConversationAccount::EXPIRATION_POLICY_MAP[:one_week]
@expires_at = Time.now + 1.week
end
@expires_at

View File

@@ -59,7 +59,23 @@ class PostStatusService < BaseService
@visibility = @options[:visibility] || @account.user&.setting_default_privacy
@visibility = :unlisted if @visibility == :public && @account.silenced?
@visibility = :private_group if @isPrivateGroup
@expires_at = @options[:expires_at]&.to_datetime if @account.is_pro
@expires_at = nil
if @account.is_pro
case @options[:expires_at]
when 'five_minutes'
@expires_at = Time.now + 5.minutes
when 'one_hour'
@expires_at = Time.now + 1.hour
when 'six_hours'
@expires_at = Time.now + 6.hours
when 'one_day'
@expires_at = Time.now + 1.day
when 'three_days'
@expires_at = Time.now + 3.days
when 'one_week'
@expires_at = Time.now + 1.week
end
end
@scheduled_at = @options[:scheduled_at]&.to_datetime
@scheduled_at = nil if scheduled_in_the_past?
rescue ArgumentError