Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
mastodon
Commits
7cd4ed7d
Commit
7cd4ed7d
authored
4 years ago
by
Eugen Rochko
Browse files
Options
Download
Email Patches
Plain Diff
Add conversation-based forwarding for limited visibility statuses through bearcaps
parent
52157fdc
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
app/controllers/activitypub/contexts_controller.rb
+16
-0
app/controllers/activitypub/contexts_controller.rb
app/controllers/concerns/cache_concern.rb
+1
-1
app/controllers/concerns/cache_concern.rb
app/controllers/statuses_controller.rb
+6
-1
app/controllers/statuses_controller.rb
app/helpers/jsonld_helper.rb
+5
-6
app/helpers/jsonld_helper.rb
app/lib/activitypub/activity/create.rb
+48
-9
app/lib/activitypub/activity/create.rb
app/lib/activitypub/tag_manager.rb
+16
-6
app/lib/activitypub/tag_manager.rb
app/models/conversation.rb
+31
-5
app/models/conversation.rb
app/models/status.rb
+13
-8
app/models/status.rb
app/models/status_capability_token.rb
+25
-0
app/models/status_capability_token.rb
app/presenters/activitypub/activity_presenter.rb
+2
-0
app/presenters/activitypub/activity_presenter.rb
app/serializers/activitypub/context_serializer.rb
+19
-0
app/serializers/activitypub/context_serializer.rb
app/serializers/activitypub/note_serializer.rb
+7
-1
app/serializers/activitypub/note_serializer.rb
app/services/post_status_service.rb
+4
-10
app/services/post_status_service.rb
app/services/process_mentions_service.rb
+12
-0
app/services/process_mentions_service.rb
app/workers/activitypub/distribution_worker.rb
+35
-11
app/workers/activitypub/distribution_worker.rb
app/workers/activitypub/forward_distribution_worker.rb
+27
-0
app/workers/activitypub/forward_distribution_worker.rb
config/routes.rb
+1
-0
config/routes.rb
db/migrate/20200825232828_create_status_capability_tokens.rb
+10
-0
db/migrate/20200825232828_create_status_capability_tokens.rb
db/migrate/20200827204602_add_inbox_url_to_conversations.rb
+7
-0
db/migrate/20200827204602_add_inbox_url_to_conversations.rb
db/migrate/20200827205543_conversation_ids_to_timestamp_ids.rb
+15
-0
...grate/20200827205543_conversation_ids_to_timestamp_ids.rb
with
300 additions
and
58 deletions
+300
-58
app/controllers/activitypub/contexts_controller.rb
0 → 100644
+
16
-
0
View file @
7cd4ed7d
# frozen_string_literal: true
class
ActivityPub::ContextsController
<
ActivityPub
::
BaseController
before_action
:set_conversation
def
show
expires_in
3
.
minutes
,
public:
public_fetch_mode?
render_with_cache
json:
@conversation
,
serializer:
ActivityPub
::
ContextSerializer
,
adapter:
ActivityPub
::
Adapter
,
content_type:
'application/activity+json'
end
private
def
set_conversation
@conversation
=
Conversation
.
local
.
find
(
params
[
:id
])
end
end
This diff is collapsed.
Click to expand it.
app/controllers/concerns/cache_concern.rb
+
1
-
1
View file @
7cd4ed7d
...
...
@@ -25,7 +25,7 @@ module CacheConcern
end
def
set_cache_headers
response
.
headers
[
'Vary'
]
=
public_fetch_mode?
?
'Accept'
:
'Accept, Signature'
response
.
headers
[
'Vary'
]
=
public_fetch_mode?
?
'Accept
, Authorization
'
:
'Accept, Signature
, Authorization
'
end
def
cache_collection
(
raw
,
klass
)
...
...
This diff is collapsed.
Click to expand it.
app/controllers/statuses_controller.rb
+
6
-
1
View file @
7cd4ed7d
...
...
@@ -66,7 +66,12 @@ class StatusesController < ApplicationController
def
set_status
@status
=
@account
.
statuses
.
find
(
params
[
:id
])
authorize
@status
,
:show?
if
request
.
authorization
.
present?
&&
request
.
authorization
.
match
(
/^Bearer /i
)
raise
Mastodon
::
NotPermittedError
unless
@status
.
capability_tokens
.
find_by
(
token:
request
.
authorization
.
gsub
(
/^Bearer /i
,
''
))
else
authorize
@status
,
:show?
end
rescue
Mastodon
::
NotPermittedError
not_found
end
...
...
This diff is collapsed.
Click to expand it.
app/helpers/jsonld_helper.rb
+
5
-
6
View file @
7cd4ed7d
...
...
@@ -49,13 +49,12 @@ module JsonLdHelper
!
uri
.
start_with?
(
'http://'
,
'https://'
)
end
def
invalid_origin?
(
url
)
return
true
if
unsupported_uri_scheme?
(
url
)
needle
=
Addressable
::
URI
.
parse
(
url
).
host
haystack
=
Addressable
::
URI
.
parse
(
@account
.
uri
).
host
def
same_origin?
(
url_a
,
url_b
)
Addressable
::
URI
.
parse
(
url_a
).
host
.
casecmp
(
Addressable
::
URI
.
parse
(
url_b
).
host
).
zero?
end
!
haystack
.
casecmp
(
needle
).
zero?
def
invalid_origin?
(
url
)
unsupported_uri_scheme?
(
url
)
||
!
same_origin?
(
url
,
@account
.
uri
)
end
def
canonicalize
(
json
)
...
...
This diff is collapsed.
Click to expand it.
app/lib/activitypub/activity/create.rb
+
48
-
9
View file @
7cd4ed7d
...
...
@@ -90,6 +90,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
fetch_replies
(
@status
)
check_for_spam
distribute
(
@status
)
forward_for_conversation
forward_for_reply
end
...
...
@@ -114,7 +115,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
sensitive:
@object
[
'sensitive'
]
||
false
,
visibility:
visibility_from_audience
,
thread:
replied_to_status
,
conversation:
conversation_from_
uri
(
@object
[
'conversation'
])
,
conversation:
conversation_from_
context
,
media_attachment_ids:
process_attachments
.
take
(
4
).
map
(
&
:id
),
poll:
process_poll
,
}
...
...
@@ -122,8 +123,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
end
def
process_audience
conversation_uri
=
value_or_id
(
@object
[
'context'
])
(
audience_to
+
audience_cc
).
uniq
.
each
do
|
audience
|
next
if
audience
==
ActivityPub
::
TagManager
::
COLLECTIONS
[
:public
]
next
if
audience
==
ActivityPub
::
TagManager
::
COLLECTIONS
[
:public
]
||
audience
==
conversation_uri
# Unlike with tags, there is no point in resolving accounts we don't already
# know here, because silent mentions would only be used for local access
...
...
@@ -340,15 +343,45 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
ActivityPub
::
FetchRepliesWorker
.
perform_async
(
status
.
id
,
uri
)
unless
uri
.
nil?
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
)
def
conversation_from_context
atom_uri
=
@object
[
'conversation'
]
begin
Conversation
.
find_or_create_by!
(
uri:
uri
)
rescue
ActiveRecord
::
RecordInvalid
,
ActiveRecord
::
RecordNotUnique
retry
conversation
=
begin
if
atom_uri
.
present?
&&
OStatus
::
TagManager
.
instance
.
local_id?
(
atom_uri
)
Conversation
.
find_by
(
id:
OStatus
::
TagManager
.
instance
.
unique_tag_to_local_id
(
atom_uri
,
'Conversation'
))
elsif
atom_uri
.
present?
&&
@object
[
'context'
].
present?
Conversation
.
find_by
(
uri:
atom_uri
)
elsif
atom_uri
.
present?
begin
Conversation
.
find_or_create_by!
(
uri:
atom_uri
)
rescue
ActiveRecord
::
RecordInvalid
,
ActiveRecord
::
RecordNotUnique
retry
end
end
end
return
conversation
if
@object
[
'context'
].
nil?
uri
=
value_or_id
(
@object
[
'context'
])
conversation
||=
ActivityPub
::
TagManager
.
instance
.
uri_to_resource
(
uri
,
Conversation
)
return
conversation
if
(
conversation
.
present?
&&
conversation
.
uri
==
uri
)
||
!
uri
.
start_with?
(
'https://'
)
conversation_json
=
begin
if
@object
[
'context'
].
is_a?
(
Hash
)
&&
!
invalid_origin?
(
uri
)
@object
[
'context'
]
else
fetch_resource
(
uri
,
true
)
end
end
return
conversation
if
conversation_json
.
blank?
conversation
||=
Conversation
.
new
conversation
.
uri
=
uri
conversation
.
inbox_url
=
conversation_json
[
'inbox'
]
conversation
.
save!
if
conversation
.
changed?
conversation
end
def
visibility_from_audience
...
...
@@ -492,6 +525,12 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
SpamCheck
.
perform
(
@status
)
end
def
forward_for_conversation
return
unless
audience_to
.
include?
(
value_or_id
(
@object
[
'context'
]))
&&
@json
[
'signature'
].
present?
&&
@status
.
conversation
.
local?
ActivityPub
::
ForwardDistributionWorker
.
perform_async
(
@status
.
conversation_id
,
Oj
.
dump
(
@json
))
end
def
forward_for_reply
return
unless
@status
.
distributable?
&&
@json
[
'signature'
].
present?
&&
reply_to_local?
...
...
This diff is collapsed.
Click to expand it.
app/lib/activitypub/tag_manager.rb
+
16
-
6
View file @
7cd4ed7d
...
...
@@ -21,8 +21,11 @@ class ActivityPub::TagManager
when
:person
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
)
if
target
.
reblog?
activity_account_status_url
(
target
.
account
,
target
)
else
short_account_status_url
(
target
.
account
,
target
)
end
end
end
...
...
@@ -33,10 +36,15 @@ class ActivityPub::TagManager
when
:person
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
)
if
target
.
reblog?
activity_account_status_url
(
target
.
account
,
target
)
else
account_status_url
(
target
.
account
,
target
)
end
when
:emoji
emoji_url
(
target
)
when
:conversation
context_url
(
target
)
end
end
...
...
@@ -66,7 +74,9 @@ class ActivityPub::TagManager
[
COLLECTIONS
[
:public
]]
when
'unlisted'
,
'private'
[
account_followers_url
(
status
.
account
)]
when
'direct'
,
'limited'
when
'limited'
status
.
conversation_id
.
present?
?
[
uri_for
(
status
.
conversation
)]
:
[]
when
'direct'
if
status
.
account
.
silenced?
# Only notify followers if the account is locally silenced
account_ids
=
status
.
active_mentions
.
pluck
(
:account_id
)
...
...
@@ -104,7 +114,7 @@ class ActivityPub::TagManager
cc
<<
COLLECTIONS
[
:public
]
end
unless
status
.
direct_visibility?
||
status
.
limited_visibility?
unless
status
.
direct_visibility?
if
status
.
account
.
silenced?
# Only notify followers if the account is locally silenced
account_ids
=
status
.
active_mentions
.
pluck
(
:account_id
)
...
...
This diff is collapsed.
Click to expand it.
app/models/conversation.rb
+
31
-
5
View file @
7cd4ed7d
...
...
@@ -3,18 +3,44 @@
#
# Table name: conversations
#
# id :bigint(8) not null, primary key
# uri :string
# created_at :datetime not null
# updated_at :datetime not null
# id :bigint(8) not null, primary key
# uri :string
# created_at :datetime not null
# updated_at :datetime not null
# parent_status_id :bigint(8)
# parent_account_id :bigint(8)
# inbox_url :string
#
class
Conversation
<
ApplicationRecord
validates
:uri
,
uniqueness:
true
,
if: :uri?
has_many
:statuses
belongs_to
:parent_status
,
class_name:
'Status'
,
optional:
true
,
inverse_of: :conversation
belongs_to
:parent_account
,
class_name:
'Account'
,
optional:
true
has_many
:statuses
,
inverse_of: :conversation
scope
:local
,
->
{
where
(
uri:
nil
)
}
before_validation
:set_parent_account
,
on: :create
after_create
:set_conversation_on_parent_status
def
local?
uri
.
nil?
end
def
object_type
:conversation
end
private
def
set_parent_account
self
.
parent_account
=
parent_status
.
account
if
parent_status
.
present?
end
def
set_conversation_on_parent_status
parent_status
.
update_column
(
:conversation_id
,
id
)
if
parent_status
.
present?
end
end
This diff is collapsed.
Click to expand it.
app/models/status.rb
+
13
-
8
View file @
7cd4ed7d
...
...
@@ -50,9 +50,11 @@ class Status < ApplicationRecord
belongs_to
:account
,
inverse_of: :statuses
belongs_to
:in_reply_to_account
,
foreign_key:
'in_reply_to_account_id'
,
class_name:
'Account'
,
optional:
true
belongs_to
:conversation
,
optional:
true
belongs_to
:conversation
,
optional:
true
,
inverse_of: :statuses
belongs_to
:preloadable_poll
,
class_name:
'Poll'
,
foreign_key:
'poll_id'
,
optional:
true
has_one
:owned_conversation
,
class_name:
'Conversation'
,
foreign_key:
'parent_status_id'
,
inverse_of: :parent_status
belongs_to
:thread
,
foreign_key:
'in_reply_to_id'
,
class_name:
'Status'
,
inverse_of: :replies
,
optional:
true
belongs_to
:reblog
,
foreign_key:
'reblog_of_id'
,
class_name:
'Status'
,
inverse_of: :reblogs
,
optional:
true
...
...
@@ -63,6 +65,7 @@ class Status < ApplicationRecord
has_many
:mentions
,
dependent: :destroy
,
inverse_of: :status
has_many
:active_mentions
,
->
{
active
},
class_name:
'Mention'
,
inverse_of: :status
has_many
:media_attachments
,
dependent: :nullify
has_many
:capability_tokens
,
class_name:
'StatusCapabilityToken'
,
inverse_of: :status
,
dependent: :destroy
has_and_belongs_to_many
:tags
has_and_belongs_to_many
:preview_cards
...
...
@@ -205,7 +208,9 @@ class Status < ApplicationRecord
public_visibility?
||
unlisted_visibility?
end
alias
sign?
distributable?
def
sign?
distributable?
||
limited_visibility?
end
def
with_media?
media_attachments
.
any?
...
...
@@ -264,11 +269,11 @@ class Status < ApplicationRecord
around_create
Mastodon
::
Snowflake
::
Callbacks
before_validation
:prepare_contents
,
if: :local?
before_validation
:set_reblog
before_validation
:set_visibility
before_validation
:set_conversation
before_validation
:set_local
before_validation
:prepare_contents
,
on: :create
,
if: :local?
before_validation
:set_reblog
,
on: :create
before_validation
:set_visibility
,
on: :create
before_validation
:set_conversation
,
on: :create
before_validation
:set_local
,
on: :create
after_create
:set_poll_id
...
...
@@ -464,7 +469,7 @@ class Status < ApplicationRecord
self
.
in_reply_to_account_id
=
carried_over_reply_to_account_id
self
.
conversation_id
=
thread
.
conversation_id
if
conversation_id
.
nil?
elsif
conversation_id
.
nil?
self
.
conversation
=
C
onversation
.
new
build_owned_c
onversation
end
end
...
...
This diff is collapsed.
Click to expand it.
app/models/status_capability_token.rb
0 → 100644
+
25
-
0
View file @
7cd4ed7d
# frozen_string_literal: true
# == Schema Information
#
# Table name: status_capability_tokens
#
# id :bigint(8) not null, primary key
# status_id :bigint(8)
# token :string
# created_at :datetime not null
# updated_at :datetime not null
#
class
StatusCapabilityToken
<
ApplicationRecord
belongs_to
:status
validates
:token
,
presence:
true
before_validation
:generate_token
,
on: :create
private
def
generate_token
self
.
token
=
Doorkeeper
::
OAuth
::
Helpers
::
UniqueToken
.
generate
end
end
This diff is collapsed.
Click to expand it.
app/presenters/activitypub/activity_presenter.rb
+
2
-
0
View file @
7cd4ed7d
...
...
@@ -20,6 +20,8 @@ class ActivityPub::ActivityPresenter < ActiveModelSerializers::Model
else
ActivityPub
::
TagManager
.
instance
.
uri_for
(
status
.
proper
)
end
elsif
status
.
limited_visibility?
"bear:?
#{
{
u:
ActivityPub
::
TagManager
.
instance
.
uri_for
(
status
.
proper
),
t:
status
.
capability_tokens
.
first
.
token
}
.to_query}"
else
status
.
proper
end
...
...
This diff is collapsed.
Click to expand it.
app/serializers/activitypub/context_serializer.rb
0 → 100644
+
19
-
0
View file @
7cd4ed7d
# frozen_string_literal: true
class
ActivityPub::ContextSerializer
<
ActivityPub
::
Serializer
include
RoutingHelper
attributes
:id
,
:type
,
:inbox
def
id
ActivityPub
::
TagManager
.
instance
.
uri_for
(
object
)
end
def
type
'Group'
end
def
inbox
account_inbox_url
(
object
.
parent_account
)
end
end
This diff is collapsed.
Click to expand it.
app/serializers/activitypub/note_serializer.rb
+
7
-
1
View file @
7cd4ed7d
...
...
@@ -7,7 +7,7 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
:in_reply_to
,
:published
,
:url
,
:attributed_to
,
:to
,
:cc
,
:sensitive
,
:atom_uri
,
:in_reply_to_atom_uri
,
:conversation
:conversation
,
:context
attribute
:content
attribute
:content_map
,
if: :language?
...
...
@@ -121,6 +121,12 @@ class ActivityPub::NoteSerializer < ActivityPub::Serializer
end
end
def
context
return
if
object
.
conversation
.
nil?
ActivityPub
::
TagManager
.
instance
.
uri_for
(
object
.
conversation
)
end
def
local?
object
.
account
.
local?
end
...
...
This diff is collapsed.
Click to expand it.
app/services/post_status_service.rb
+
4
-
10
View file @
7cd4ed7d
...
...
@@ -52,6 +52,7 @@ class PostStatusService < BaseService
@text
=
@options
.
delete
(
:spoiler_text
)
if
@text
.
blank?
&&
@options
[
:spoiler_text
].
present?
@visibility
=
@options
[
:visibility
]
||
@account
.
user
&
.
setting_default_privacy
@visibility
=
:unlisted
if
@visibility
&
.
to_sym
==
:public
&&
@account
.
silenced?
@visibility
=
:limited
if
@visibility
&
.
to_sym
!=
:direct
&&
@in_reply_to
&
.
limited_visibility?
@scheduled_at
=
@options
[
:scheduled_at
]
&
.
to_datetime
@scheduled_at
=
nil
if
scheduled_in_the_past?
rescue
ArgumentError
...
...
@@ -64,10 +65,11 @@ class PostStatusService < BaseService
ApplicationRecord
.
transaction
do
@status
=
@account
.
statuses
.
create!
(
status_attributes
)
@status
.
capability_tokens
.
create!
if
@status
.
limited_visibility?
end
p
rocess
_h
ashtags
_s
ervice
.
call
(
@status
)
p
rocess
_m
entions
_s
ervice
.
call
(
@status
)
P
rocess
H
ashtags
S
ervice
.
new
.
call
(
@status
)
P
rocess
M
entions
S
ervice
.
new
.
call
(
@status
)
end
def
schedule_status!
...
...
@@ -109,14 +111,6 @@ class PostStatusService < BaseService
ISO_639
.
find
(
str
)
&
.
alpha2
end
def
process_mentions_service
ProcessMentionsService
.
new
end
def
process_hashtags_service
ProcessHashtagsService
.
new
end
def
scheduled?
@scheduled_at
.
present?
end
...
...
This diff is collapsed.
Click to expand it.
app/services/process_mentions_service.rb
+
12
-
0
View file @
7cd4ed7d
...
...
@@ -42,9 +42,21 @@ class ProcessMentionsService < BaseService
"@
#{
mentioned_account
.
acct
}
"
end
if
status
.
limited_visibility?
&&
status
.
thread
&
.
limited_visibility?
# If we are replying to a local status, then we'll have the complete
# audience copied here, both local and remote. If we are replying
# to a remote status, only local audience will be copied. Then we
# need to send our reply to the remote author's inbox for distribution
status
.
thread
.
mentions
.
includes
(
:account
).
find_each
do
|
mention
|
status
.
mentions
.
create
(
silent:
true
,
account:
mention
.
account
)
end
end
status
.
save!
check_for_spam
(
status
)
# Silent mentions need to be delivered separately
mentions
.
each
{
|
mention
|
create_notification
(
mention
)
}
end
...
...
This diff is collapsed.
Click to expand it.
app/workers/activitypub/distribution_worker.rb
+
35
-
11
View file @
7cd4ed7d
...
...
@@ -12,8 +12,10 @@ class ActivityPub::DistributionWorker
return
if
skip_distribution?
ActivityPub
::
DeliveryWorker
.
push_bulk
(
inboxes
)
do
|
inbox_url
|
[
payload
,
@account
.
id
,
inbox_url
]
if
delegate_distribution?
deliver_to_parent!
else
deliver_to_inboxes!
end
relay!
if
relayable?
...
...
@@ -24,22 +26,44 @@ class ActivityPub::DistributionWorker
private
def
skip_distribution?
@status
.
direct_visibility?
||
@status
.
limited_visibility?
@status
.
direct_visibility?
end
def
delegate_distribution?
@status
.
limited_visibility?
&&
@status
.
reply?
&&
!
@status
.
conversation
.
local?
end
def
relayable?
@status
.
public_visibility?
end
def
deliver_to_parent!
return
if
@status
.
conversation
.
inbox_url
.
blank?
ActivityPub
::
DeliveryWorker
.
perform_async
(
payload
,
@account
.
id
,
@status
.
conversation
.
inbox_url
)
end
def
deliver_to_inboxes!
ActivityPub
::
DeliveryWorker
.
push_bulk
(
inboxes
)
do
|
inbox_url
|
[
payload
,
@account
.
id
,
inbox_url
]
end
end
def
inboxes
# Deliver the status to all followers.
# If the status is a reply to another local status, also forward it to that
# status' authors' followers.
@inboxes
||=
if
@status
.
reply?
&&
@status
.
thread
.
account
.
local?
&&
@status
.
distributable?
@account
.
followers
.
or
(
@status
.
thread
.
account
.
followers
).
inboxes
else
@account
.
followers
.
inboxes
end
# Deliver the status to all followers. If the status is a reply
# to another local status, also forward it to that status'
# authors' followers. If the status has limited visibility,
# deliver it to inboxes of people mentioned (no shared ones)
@inboxes
||=
begin
if
@status
.
limited_visibility?
DeliveryFailureTracker
.
without_unavailable
(
Account
.
remote
.
joins
(
:mentions
).
merge
(
@status
.
mentions
).
pluck
(
:inbox_url
))
elsif
@status
.
reply?
&&
@status
.
thread
.
account
.
local?
&&
@status
.
distributable?
@account
.
followers
.
or
(
@status
.
thread
.
account
.
followers
).
inboxes
else
@account
.
followers
.
inboxes
end
end
end
def
payload
...
...
This diff is collapsed.
Click to expand it.
app/workers/activitypub/forward_distribution_worker.rb
0 → 100644
+
27
-
0
View file @
7cd4ed7d
# frozen_string_literal: true
class
ActivityPub::ForwardDistributionWorker
<
ActivityPub
::
DistributionWorker
include
Sidekiq
::
Worker
sidekiq_options
queue:
'push'
def
perform
(
conversation_id
,
json
)
conversation
=
Conversation
.
find
(
conversation_id
)
@status
=
conversation
.
parent_status
@account
=
conversation
.
parent_account
@json
=
json
return
if
@status
.
nil?
||
@account
.
nil?
deliver_to_inboxes!
rescue
ActiveRecord
::
RecordNotFound
true
end
private
def
payload
@json
end
end
This diff is collapsed.
Click to expand it.
config/routes.rb
+
1
-
0
View file @
7cd4ed7d
...
...
@@ -85,6 +85,7 @@ Rails.application.routes.draw do
end
resource
:inbox
,
only:
[
:create
],
module: :activitypub
resources
:contexts
,
only:
[
:show
],
module: :activitypub
get
'/@:username'
,
to:
'accounts#show'
,
as: :short_account
get
'/@:username/with_replies'
,
to:
'accounts#show'
,
as: :short_account_with_replies
...
...
This diff is collapsed.
Click to expand it.
db/migrate/20200825232828_create_status_capability_tokens.rb
0 → 100644
+
10
-
0
View file @
7cd4ed7d
class
CreateStatusCapabilityTokens
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:status_capability_tokens
do
|
t
|
t
.
belongs_to
:status
,
foreign_key:
true
t
.
string
:token
t
.
timestamps
end
end
end
This diff is collapsed.
Click to expand it.
db/migrate/20200827204602_add_inbox_url_to_conversations.rb
0 → 100644
+
7
-
0
View file @
7cd4ed7d
class
AddInboxUrlToConversations
<
ActiveRecord
::
Migration
[
5.2
]
def
change
add_column
:conversations
,
:parent_status_id
,
:bigint
,
null:
true
,
default:
nil
add_column
:conversations
,
:parent_account_id
,
:bigint
,
null:
true
,
default:
nil
add_column
:conversations
,
:inbox_url
,
:string
,
null:
true
,
default:
nil
end
end
This diff is collapsed.
Click to expand it.
db/migrate/20200827205543_conversation_ids_to_timestamp_ids.rb
0 → 100644
+
15
-
0
View file @
7cd4ed7d
class
ConversationIdsToTimestampIds
<
ActiveRecord
::
Migration
[
5.2
]
def
up
safety_assured
do
execute
(
"ALTER TABLE conversations ALTER COLUMN id SET DEFAULT timestamp_id('conversations')"
)
end
Mastodon
::
Snowflake
.
ensure_id_sequences_exist
end
def
down
execute
(
"LOCK conversations"
)
execute
(
"SELECT setval('conversations_id_seq', (SELECT MAX(id) FROM conversations))"
)
execute
(
"ALTER TABLE conversations ALTER COLUMN id SET DEFAULT nextval('conversations_id_seq')"
)
end
end
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment