This reverts commit 75f7f9930e
.
This commit is contained in:
parent
75f7f9930e
commit
b9b0313c78
|
@ -67,6 +67,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
sensitive: @object['sensitive'] || false,
|
sensitive: @object['sensitive'] || false,
|
||||||
visibility: visibility_from_audience,
|
visibility: visibility_from_audience,
|
||||||
thread: replied_to_status,
|
thread: replied_to_status,
|
||||||
|
conversation: conversation_from_uri(@object['conversation']),
|
||||||
media_attachment_ids: process_attachments.take(4).map(&:id),
|
media_attachment_ids: process_attachments.take(4).map(&:id),
|
||||||
poll: process_poll,
|
poll: process_poll,
|
||||||
}
|
}
|
||||||
|
@ -261,6 +262,16 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||||
ActivityPub::FetchRepliesWorker.perform_async(status.id, uri) unless uri.nil?
|
ActivityPub::FetchRepliesWorker.perform_async(status.id, uri) unless uri.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def conversation_from_uri(uri)
|
||||||
|
return nil if uri.nil?
|
||||||
|
return Conversation.find_by(id: OStatus::TagManager.instance.unique_tag_to_local_id(uri, 'Conversation')) if OStatus::TagManager.instance.local_id?(uri)
|
||||||
|
begin
|
||||||
|
Conversation.find_or_create_by!(uri: uri)
|
||||||
|
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def visibility_from_audience
|
def visibility_from_audience
|
||||||
if equals_or_includes?(@object['to'], ActivityPub::TagManager::COLLECTIONS[:public])
|
if equals_or_includes?(@object['to'], ActivityPub::TagManager::COLLECTIONS[:public])
|
||||||
:public
|
:public
|
||||||
|
|
|
@ -4,10 +4,17 @@
|
||||||
# Table name: conversations
|
# Table name: conversations
|
||||||
#
|
#
|
||||||
# id :bigint(8) not null, primary key
|
# id :bigint(8) not null, primary key
|
||||||
|
# uri :string
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
|
|
||||||
class Conversation < ApplicationRecord
|
class Conversation < ApplicationRecord
|
||||||
|
validates :uri, uniqueness: true, if: :uri?
|
||||||
|
|
||||||
has_many :statuses
|
has_many :statuses
|
||||||
|
|
||||||
|
def local?
|
||||||
|
uri.nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||||
context_extensions :atom_uri, :sensitive,
|
context_extensions :atom_uri, :conversation, :sensitive,
|
||||||
:hashtag, :emoji, :focal_point, :blurhash
|
:hashtag, :emoji, :focal_point, :blurhash
|
||||||
|
|
||||||
attributes :id, :type, :summary,
|
attributes :id, :type, :summary,
|
||||||
:in_reply_to, :published, :url,
|
:in_reply_to, :published, :url,
|
||||||
:attributed_to, :to, :cc, :sensitive,
|
:attributed_to, :to, :cc, :sensitive,
|
||||||
:atom_uri, :in_reply_to_atom_uri
|
:atom_uri, :in_reply_to_atom_uri,
|
||||||
|
:conversation
|
||||||
|
|
||||||
attribute :content
|
attribute :content
|
||||||
attribute :content_map, if: :language?
|
attribute :content_map, if: :language?
|
||||||
|
@ -109,6 +110,16 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
|
||||||
OStatus::TagManager.instance.uri_for(object.thread)
|
OStatus::TagManager.instance.uri_for(object.thread)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def conversation
|
||||||
|
return if object.conversation.nil?
|
||||||
|
|
||||||
|
if object.conversation.uri?
|
||||||
|
object.conversation.uri
|
||||||
|
else
|
||||||
|
OStatus::TagManager.instance.unique_tag(object.conversation.created_at, object.conversation.id, 'Conversation')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def local?
|
def local?
|
||||||
object.account.local?
|
object.account.local?
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class RemoveBoostsWideningAudience < ActiveRecord::Migration[5.2]
|
class RemoveBoostsWideningAudience < ActiveRecord::Migration[5.2]
|
||||||
disable_ddl_transaction!
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class RemoveUriFromConversations < ActiveRecord::Migration[5.2]
|
|
||||||
def up
|
|
||||||
safety_assured { remove_column :conversations, :uri, :string }
|
|
||||||
end
|
|
||||||
|
|
||||||
def down
|
|
||||||
add_column :conversations, :uri, :string
|
|
||||||
add_index :conversations, :uri, unique: true
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_07_28_084117) do
|
ActiveRecord::Schema.define(version: 2019_07_26_175042) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -203,8 +203,10 @@ ActiveRecord::Schema.define(version: 2019_07_28_084117) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "conversations", force: :cascade do |t|
|
create_table "conversations", force: :cascade do |t|
|
||||||
|
t.string "uri"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["uri"], name: "index_conversations_on_uri", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "custom_emoji_categories", force: :cascade do |t|
|
create_table "custom_emoji_categories", force: :cascade do |t|
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Conversation, type: :model do
|
RSpec.describe Conversation, type: :model do
|
||||||
|
describe '#local?' do
|
||||||
|
it 'returns true when URI is nil' do
|
||||||
|
expect(Fabricate(:conversation).local?).to be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when URI is not nil' do
|
||||||
|
expect(Fabricate(:conversation, uri: 'abc').local?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue