Progress on dms, code cleanup
Progress on dms, code cleanup
This commit is contained in:
@@ -297,6 +297,11 @@ class Account < ApplicationRecord
|
||||
username
|
||||
end
|
||||
|
||||
def excluded_from_chat_account_ids
|
||||
# : todo :
|
||||
# Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) }
|
||||
end
|
||||
|
||||
def excluded_from_timeline_account_ids
|
||||
Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) }
|
||||
end
|
||||
|
||||
30
app/models/chat_block.rb
Normal file
30
app/models/chat_block.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: chat_blocks
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class ChatBlock < ApplicationRecord
|
||||
include Paginable
|
||||
include RelationshipCacheable
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
|
||||
after_commit :remove_blocking_cache
|
||||
|
||||
private
|
||||
|
||||
def remove_blocking_cache
|
||||
Rails.cache.delete("exclude_chat_account_ids_for:#{account_id}")
|
||||
Rails.cache.delete("exclude_chat_account_ids_for:#{target_account_id}")
|
||||
end
|
||||
end
|
||||
13
app/models/chat_conversation.rb
Normal file
13
app/models/chat_conversation.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: chat_conversations
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ChatConversation < ApplicationRecord
|
||||
|
||||
end
|
||||
43
app/models/chat_conversation_account.rb
Normal file
43
app/models/chat_conversation_account.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: chat_conversation_accounts
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8)
|
||||
# chat_conversation_id :bigint(8)
|
||||
# participant_account_ids :bigint(8) default([]), not null, is an Array
|
||||
# last_chat_message_id :bigint(8)
|
||||
# is_unread :boolean default(FALSE), not null
|
||||
# is_hidden :boolean default(FALSE), not null
|
||||
# is_approved :boolean default(FALSE), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ChatConversationAccount < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :chat_conversation
|
||||
belongs_to :last_chat_message, class_name: 'ChatMessage', optional: true
|
||||
|
||||
# before_validation :set_last_chat_message
|
||||
|
||||
def participant_accounts
|
||||
if participant_account_ids.empty?
|
||||
[account]
|
||||
else
|
||||
# : todo : dont include current_account
|
||||
participants = Account.where(id: participant_account_ids)
|
||||
participants.empty? ? [account] : participants
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_last_chat_message
|
||||
self.last_chat_message_id = nil # : todo :
|
||||
end
|
||||
|
||||
end
|
||||
27
app/models/chat_message.rb
Normal file
27
app/models/chat_message.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: chat_messages
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# account_id :bigint(8) not null
|
||||
# chat_conversation_id :bigint(8) not null
|
||||
# text :text default(""), not null
|
||||
# language :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ChatMessage < ApplicationRecord
|
||||
include Paginable
|
||||
|
||||
belongs_to :from_account, class_name: 'Account'
|
||||
belongs_to :chat_conversation
|
||||
|
||||
validates_with ChatMessageLengthValidator
|
||||
|
||||
default_scope { recent }
|
||||
|
||||
scope :recent, -> { reorder(created_at: :desc) }
|
||||
|
||||
end
|
||||
29
app/models/chat_mute.rb
Normal file
29
app/models/chat_mute.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: chat_mutes
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :bigint(8) not null
|
||||
# target_account_id :bigint(8) not null
|
||||
#
|
||||
|
||||
class ChatMute < ApplicationRecord
|
||||
include Paginable
|
||||
include RelationshipCacheable
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :target_account, class_name: 'Account'
|
||||
|
||||
validates :account_id, uniqueness: { scope: :target_account_id }
|
||||
|
||||
after_commit :remove_blocking_cache
|
||||
|
||||
private
|
||||
|
||||
def remove_blocking_cache
|
||||
Rails.cache.delete("exclude_chat_account_ids_for:#{account_id}")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user