revert the current unfinished chat implementation

staging
multiple creatures 2019-07-24 13:01:12 -05:00
parent d83fcfd1f1
commit 25d628fca3
24 changed files with 28 additions and 149 deletions

View File

@ -207,8 +207,6 @@ module StreamEntriesHelper
fa_icon 'unlock fw'
when 'local'
fa_icon 'users fw'
when 'chat'
fa_icon 'paper-plane fw'
when 'private'
fa_icon 'lock fw'
when 'direct'

View File

@ -116,10 +116,6 @@ function statusToTextMentions(state, status) {
set = set.add(`@${status.getIn(['account', 'acct'])} `);
}
set = set.union(status.get('tags').filter(
tag => tag.get('name') && tag.get('name').startsWith("chat.")
).map(tag => `#${tag.get('name')} `));
return set.union(status.get('mentions').filterNot(mention => mention.get('id') === me).map(mention => `@${mention.get('acct')} `)).join('');
};
@ -130,10 +126,6 @@ function apiStatusToTextMentions (state, status) {
set = set.add(`@${status.account.acct} `);
}
set = set.union(status.tags.filter(
tag => tag.name && tag.name.startsWith("chat.")
).map(tag => `#${tag.name} `));
return set.union(status.mentions.filter(
mention => mention.id !== me
).map(

View File

@ -159,9 +159,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
def attach_tags(status)
@tags.each do |tag|
status.tags << tag
tag.chatters.find_or_create_by(account_id: status.account) if tag.chat?
next unless status.distributable? && !tag.chat?
TrendingTags.record_use!(tag, status.account, status.created_at)
TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?
end
@mentions.each do |mention|
@ -190,15 +188,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
hashtag = tag['name'].gsub(/\A#/, '').gsub(':', '.').mb_chars.downcase
return if !@options[:imported] && (
hashtag.in?(%w(self .self local .local chat.local .chat.local)) ||
hashtag.starts_with?('self.', '.self', 'local.', '.local', 'chat.local.', '.chat.local.')
hashtag.in?(%w(self .self local .local)) ||
hashtag.starts_with?('self.', '.self', 'local.', '.local')
)
if tag['name'].starts_with?('chat.', '.chat.')
@params[:visibility] = :chat
@params[:thread] = nil
end
hashtag = Tag.where(name: hashtag).first_or_create!(name: hashtag)
return if @tags.include?(hashtag)

View File

@ -32,10 +32,6 @@ class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
'mp' => 'https://monsterpit.net/ns#',
'kobold' => 'mp:kobold'
},
supports_chat: {
'mp' => 'https://monsterpit.net/ns#',
'supportsChat' => 'mp:supportsChat'
},
froze: {
'mp' => 'https://monsterpit.net/ns#',
'froze' => 'mp:froze'

View File

@ -17,7 +17,7 @@ class ActivityPub::TagManager
case target.object_type
when :person
short_account_url(target)
target.instance_actor? ? about_more_url(instance_actor: true) : short_account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?
short_account_status_url(target.account, target)
@ -29,7 +29,7 @@ class ActivityPub::TagManager
case target.object_type
when :person
account_url(target)
target.instance_actor? ? instance_actor_url : account_url(target)
when :note, :comment, :activity
return activity_account_status_url(target.account, target) if target.reblog?
account_status_url(target.account, target)
@ -51,7 +51,7 @@ class ActivityPub::TagManager
def replies_uri_for(target, page_params = nil)
raise ArgumentError, 'target must be a local activity' unless %i(note comment activity).include?(target.object_type) && target.local?
replies_account_status_url(target.account, target, page_params)
account_status_replies_url(target.account, target, page_params)
end
# Primary audience of a status
@ -64,7 +64,7 @@ class ActivityPub::TagManager
[COLLECTIONS[:public]]
when 'unlisted', 'private', 'local'
[account_followers_url(status.account)]
when 'direct', 'limited', 'chat'
when 'direct', 'limited'
if status.account.silenced?
# Only notify followers if the account is locally silenced
account_ids = status.active_mentions.pluck(:account_id)
@ -93,7 +93,7 @@ class ActivityPub::TagManager
cc << COLLECTIONS[:public]
end
unless status.direct_visibility? || status.limited_visibility? || status.chat_visibility?
unless status.direct_visibility? || status.limited_visibility?
if status.account.silenced?
# Only notify followers if the account is locally silenced
account_ids = status.active_mentions.pluck(:account_id)
@ -119,6 +119,7 @@ class ActivityPub::TagManager
def uri_to_local_id(uri, param = :id)
path_params = Rails.application.routes.recognize_path(uri)
path_params[:username] = Rails.configuration.x.local_domain if path_params[:controller] == 'instance_actors'
path_params[param]
end

View File

@ -48,7 +48,6 @@
# adult_content :boolean default(FALSE), not null
# silenced_at :datetime
# suspended_at :datetime
# supports_chat :boolean default(FALSE), not null
# gently :boolean default(FALSE), not null
# kobold :boolean default(FALSE), not null
# froze :boolean
@ -75,9 +74,6 @@ class Account < ApplicationRecord
LOCAL_DOMAINS = ENV.fetch('LOCAL_DOMAINS', '').chomp.split(/\.?\s+/).freeze
has_many :chat_accounts, dependent: :destroy, inverse_of: :account
has_many :chat_tags, through: :chat_accounts, source: :tag
validates :username, presence: true
# Remote user validations
@ -559,7 +555,6 @@ class Account < ApplicationRecord
before_create :generate_keys
before_create :set_domain_from_inbox_url
before_create :set_chat_support
before_validation :prepare_contents, if: :local?
before_validation :prepare_username, on: :create
before_destroy :clean_feed_manager
@ -582,11 +577,6 @@ class Account < ApplicationRecord
nil
end
def set_chat_support
return unless local?
self.supports_chat = true
end
def generate_keys
return unless local? && !Rails.env.test?

View File

@ -1,17 +0,0 @@
# == Schema Information
#
# Table name: chat_accounts
#
# id :bigint(8) not null, primary key
# account_id :bigint(8) not null
# tag_id :bigint(8) not null
# created_at :datetime not null
# updated_at :datetime not null
#
class ChatAccount < ApplicationRecord
belongs_to :account, inverse_of: :chat_accounts
belongs_to :tag, inverse_of: :chat_accounts
validates :account_id, uniqueness: { scope: :tag_id }
end

View File

@ -52,7 +52,7 @@ class Status < ApplicationRecord
update_index('statuses#status', :proper) if Chewy.enabled?
enum visibility: [:public, :unlisted, :private, :direct, :limited, :local, :chat], _suffix: :visibility
enum visibility: [:public, :unlisted, :private, :direct, :limited, :local], _suffix: :visibility
belongs_to :application, class_name: 'Doorkeeper::Application', optional: true
@ -104,7 +104,7 @@ class Status < ApplicationRecord
scope :reblogs, -> { where('statuses.reblog_of_id IS NOT NULL') } # all reblogs
scope :with_public_visibility, -> { where(visibility: :public) }
scope :public_local_visibility, -> { where(visibility: [:public, :local]) }
scope :public_browsable, -> { where(visibility: [:public, :unlisted, :local, :chat]) }
scope :public_browsable, -> { where(visibility: [:public, :unlisted, :local]) }
scope :tagged_with, ->(tag) { joins(:statuses_tags).where(statuses_tags: { tag_id: tag }) }
scope :excluding_silenced_accounts, -> { left_outer_joins(:account).where(accounts: { silenced_at: nil }) }
scope :including_silenced_accounts, -> { left_outer_joins(:account).where.not(accounts: { silenced_at: nil }) }
@ -262,11 +262,6 @@ class Status < ApplicationRecord
@emojis = CustomEmoji.from_text(fields.join(' '), account.domain)
end
def chat_tags
return @chat_tags if defined?(@chat_tags)
@chat_tags = tags.only_chat
end
def delete_after
destructing_status&.delete_after
end

View File

@ -10,7 +10,6 @@
# local :boolean default(FALSE), not null
# private :boolean default(FALSE), not null
# unlisted :boolean default(FALSE), not null
# chat :boolean default(FALSE), not null
#
class Tag < ApplicationRecord
@ -19,8 +18,6 @@ class Tag < ApplicationRecord
has_and_belongs_to_many :sample_accounts, -> { searchable.discoverable.popular.limit(3) }, class_name: 'Account'
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
has_many :chat_accounts, dependent: :destroy, inverse_of: :tag
has_many :chatters, through: :chat_accounts, source: :account
has_one :account_tag_stat, dependent: :destroy
@ -37,7 +34,6 @@ class Tag < ApplicationRecord
scope :only_global, -> { where(local: false, unlisted: false) }
scope :only_private, -> { where(private: true) }
scope :only_unlisted, -> { where(unlisted: true) }
scope :only_chat, -> { where(chat: true) }
scope :only_public, -> { where(unlisted: false) }
delegate :accounts_count,
@ -109,9 +105,8 @@ class Tag < ApplicationRecord
def set_scope
self.private = true if name.in?(%w(self .self)) || name.starts_with?('self.', '.self.')
self.unlisted = true if self.private || name.starts_with?('.')
self.chat = true if name.starts_with?('chat.', '.chat')
self.local = true if self.private ||
name.in?(%w(local .local chat.local .chat.local)) ||
name.starts_with?('local.', '.local', 'chat.local.' '.chat.local')
name.in?(%w(local .local)) ||
name.starts_with?('local.', '.local')
end
end

View File

@ -7,14 +7,14 @@ class ActivityPub::ActorSerializer < ActivityPub::Serializer
context_extensions :manually_approves_followers, :featured, :also_known_as,
:moved_to, :property_value, :hashtag, :emoji, :identity_proof,
:adult_content, :gently, :kobold, :supports_chat, :froze
:adult_content, :gently, :kobold, :froze
attributes :id, :type, :following, :followers,
:inbox, :outbox, :featured,
:preferred_username, :name, :summary,
:url, :manually_approves_followers,
:gently, :kobold, :adult_content,
:supports_chat, :froze
:froze
has_one :public_key, serializer: ActivityPub::PublicKeySerializer

View File

@ -6,7 +6,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
attributes :id, :username, :acct, :display_name, :locked, :bot, :created_at,
:note, :url, :avatar, :avatar_static, :header, :header_static,
:followers_count, :following_count, :statuses_count, :replies,
:adult_content, :supports_chat, :gently, :kobold, :role, :froze
:adult_content, :gently, :kobold, :role, :froze
has_one :moved_to_account, key: :moved, serializer: REST::AccountSerializer, if: :moved_and_not_nested?
has_many :emojis, serializer: REST::CustomEmojiSerializer

View File

@ -58,7 +58,7 @@ class REST::StatusSerializer < ActiveModel::Serializer
def visibility
if object.limited_visibility?
'private'
elsif object.local_visibility? || object.chat_visibility?
elsif object.local_visibility?
'unlisted'
else
object.visibility

View File

@ -81,7 +81,6 @@ class ActivityPub::ProcessAccountService < BaseService
@account.locked = @json['manuallyApprovesFollowers'] || false
@account.froze = @json['froze'] || false
@account.adult_content = @json['adultContent'] || (@json['suggestedMinAge'].to_i >= 18)
@account.supports_chat = @json['supportsChat'] || false
@account.gently = @json['gently'] || false
@account.kobold = @json['kobold'] || false
@account.fields = property_values || {}

View File

@ -6,7 +6,7 @@ class FanOutOnWriteService < BaseService
def call(status)
raise Mastodon::RaceConditionError if status.visibility.nil?
deliver_to_self(status) if status.account.local? && !status.chat_visibility?
deliver_to_self(status) if status.account.local?
render_anonymous_payload(status)
@ -16,9 +16,6 @@ class FanOutOnWriteService < BaseService
deliver_to_own_conversation(status)
elsif status.limited_visibility?
deliver_to_mentioned_followers(status)
elsif status.chat_visibility?
deliver_to_mentioned_followers(status)
deliver_to_hashtags(status)
elsif status.local_visibility?
deliver_to_followers(status)
return if status.reblog? && !Setting.show_reblogs_in_public_timelines

View File

@ -13,7 +13,6 @@ class PostStatusService < BaseService
'private' => 2,
'direct' => 3,
'limited' => 3,
'chat' => 4
}
# Post a text status update, fetch and notify remote users mentioned
@ -92,19 +91,6 @@ class PostStatusService < BaseService
@local_only = true if @account.user_always_local_only? || @in_reply_to&.local_only
end
def set_chat
if @in_reply_to.present?
unless @in_reply_to.chat_tags.blank?
@preloaded_tags |= @in_reply_to.chat_tags
@visibility = :chat
@in_reply_to = nil
end
elsif @tags.present? && @tags.any? { |t| t.start_with?('chat.', '.chat.') }
@visibility = :chat
@local_only = true if @tags.any? { |t| t.in?(%w(chat.local .chat.local)) || t.start_with?('chat.local.', '.chat.local.') }
end
end
# move tags out of body so we can format them later
def extract_tags
@text.gsub!(/^##/, "\uf666")
@ -124,14 +110,10 @@ class PostStatusService < BaseService
set_footer_from_i_am
extract_tags
set_chat
set_local_only
unless @visibility == :chat
set_initial_visibility
limit_visibility_if_silenced
limit_visibility_to_reply
end
set_initial_visibility
limit_visibility_if_silenced
limit_visibility_to_reply
@sensitive = (@account.user_defaults_to_sensitive? || @options[:spoiler_text].present?) if @sensitive.nil?
@ -166,6 +148,7 @@ class PostStatusService < BaseService
process_hashtags_service.call(@status, @tags, @preloaded_tags)
process_mentions_service.call(@status)
return true
end

View File

@ -13,20 +13,13 @@ class ProcessHashtagsService < BaseService
name.gsub!(/[:.]+/, '.')
next if name.blank? || name == '.'
chat = name.starts_with?('chat.', '.chat.')
if chat
component_indices = [name.size - 1]
else
component_indices = 1.upto(name.size).select { |i| name[i] == '.' }
component_indices << name.size - 1
end
component_indices = 1.upto(name.size).select { |i| name[i] == '.' }
component_indices << name.size - 1
component_indices.take(6).each_with_index do |i, nest|
frag = (nest != 5) ? name[0..i] : name
tag = Tag.where(name: frag).first_or_create(name: frag)
tag.chatters.find_or_create_by(id: status.account_id) if chat
next if status.tags.include?(tag)
status.tags << tag
next if tag.unlisted || component_indices.size > 1

View File

@ -25,7 +25,6 @@
= f.input :hidden, as: :boolean, wrapper: :with_label
= f.input :unlisted, as: :boolean, wrapper: :with_label, hint: t('simple_form.hints.defaults.unlisted')
= f.input :replies, as: :boolean, wrapper: :with_label
= f.input :supports_chat, as: :boolean, wrapper: :with_label
.fields-group
= f.input :adult_content, as: :boolean, wrapper: :with_label

View File

@ -35,7 +35,7 @@ class ActivityPub::DistributePollUpdateWorker
end
end
@inboxes.concat(@account.followers.inboxes) unless @status.direct_visibility? || @status.chat_visibility?
@inboxes.concat(@account.followers.inboxes) unless @status.direct_visibility?
@inboxes.uniq!
@inboxes.compact!
@inboxes

View File

@ -23,7 +23,7 @@ class ActivityPub::DistributionWorker
private
def skip_distribution?
@status.direct_visibility? || @status.limited_visibility? || @status.chat_visibility?
@status.direct_visibility? || @status.limited_visibility?
end
def relayable?

View File

@ -75,7 +75,6 @@ en:
defaults:
hidden: Invisible mode (affects outgoing federation and discovery!)
adult_content: Contains adult content
supports_chat: Allow chat messages
gently: Gently the kobolds
kobold: I am a kobold
unlisted: Exclude from public interaction lists

View File

@ -1,11 +0,0 @@
class CreateChatAccounts < ActiveRecord::Migration[5.2]
def change
create_table :chat_accounts do |t|
t.references :account, foreign_key: { on_delete: :cascade }, null: false
t.references :tag, foreign_key: { on_delete: :cascade }, null: false
t.index [:account_id, :tag_id], unique: true
t.index [:tag_id, :account_id]
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_07_23_152514) do
ActiveRecord::Schema.define(version: 2019_07_24_175247) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -151,7 +151,6 @@ ActiveRecord::Schema.define(version: 2019_07_23_152514) do
t.boolean "adult_content", default: false, null: false
t.datetime "silenced_at"
t.datetime "suspended_at"
t.boolean "supports_chat", default: false, null: false
t.boolean "gently", default: false, null: false
t.boolean "kobold", default: false, null: false
t.boolean "froze"
@ -212,17 +211,6 @@ ActiveRecord::Schema.define(version: 2019_07_23_152514) do
t.index ["status_id"], name: "index_bookmarks_on_status_id"
end
create_table "chat_accounts", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "tag_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "tag_id"], name: "index_chat_accounts_on_account_id_and_tag_id", unique: true
t.index ["account_id"], name: "index_chat_accounts_on_account_id"
t.index ["tag_id", "account_id"], name: "index_chat_accounts_on_tag_id_and_account_id"
t.index ["tag_id"], name: "index_chat_accounts_on_tag_id"
end
create_table "conversation_mutes", force: :cascade do |t|
t.bigint "conversation_id", null: false
t.bigint "account_id", null: false
@ -676,7 +664,7 @@ ActiveRecord::Schema.define(version: 2019_07_23_152514) do
t.string "origin"
t.tsvector "tsv"
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
t.index ["account_id", "id", "visibility"], name: "index_statuses_on_account_id_and_id_and_visibility", where: "(visibility = ANY (ARRAY[0, 1, 2, 4, 5]))"
t.index ["account_id", "id", "visibility"], name: "index_statuses_on_account_id_and_id_and_visibility", order: { id: :desc }, where: "(visibility = ANY (ARRAY[0, 1, 2, 4]))"
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
t.index ["network"], name: "index_statuses_on_network", where: "network"
@ -711,9 +699,7 @@ ActiveRecord::Schema.define(version: 2019_07_23_152514) do
t.boolean "local", default: false, null: false
t.boolean "private", default: false, null: false
t.boolean "unlisted", default: false, null: false
t.boolean "chat", default: false, null: false
t.index "lower((name)::text) text_pattern_ops", name: "hashtag_search_index"
t.index ["chat"], name: "index_tags_on_chat", where: "chat"
t.index ["name"], name: "index_tags_on_name", unique: true
t.index ["unlisted"], name: "index_tags_on_unlisted", where: "unlisted"
end
@ -819,8 +805,6 @@ ActiveRecord::Schema.define(version: 2019_07_23_152514) do
add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
add_foreign_key "bookmarks", "accounts", on_delete: :cascade
add_foreign_key "bookmarks", "statuses", on_delete: :cascade
add_foreign_key "chat_accounts", "accounts", on_delete: :cascade
add_foreign_key "chat_accounts", "tags", on_delete: :cascade
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
add_foreign_key "conversation_mutes", "conversations", on_delete: :cascade
add_foreign_key "custom_filters", "accounts", on_delete: :cascade

View File

@ -1,2 +0,0 @@
Fabricator(:chat_account) do
end

View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe ChatAccount, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end