Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
1d34eff6
Unverified
Commit
1d34eff6
authored
2 years ago
by
Takeshi Umeda
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add featured tag add/remove activity handler (#19408)
parent
7c152acb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/activitypub/activity/add.rb
+21
-1
21 additions, 1 deletion
app/lib/activitypub/activity/add.rb
app/lib/activitypub/activity/remove.rb
+24
-1
24 additions, 1 deletion
app/lib/activitypub/activity/remove.rb
app/models/featured_tag.rb
+2
-0
2 additions, 0 deletions
app/models/featured_tag.rb
with
47 additions
and
2 deletions
app/lib/activitypub/activity/add.rb
+
21
−
1
View file @
1d34eff6
...
...
@@ -2,12 +2,32 @@
class
ActivityPub::Activity::Add
<
ActivityPub
::
Activity
def
perform
return
unless
@json
[
'target'
].
present?
&&
value_or_id
(
@json
[
'target'
])
==
@account
.
featured_collection_url
return
if
@json
[
'target'
].
blank?
case
value_or_id
(
@json
[
'target'
])
when
@account
.
featured_collection_url
case
@object
[
'type'
]
when
'Hashtag'
add_featured_tags
else
add_featured
end
end
end
private
def
add_featured
status
=
status_from_object
return
unless
!
status
.
nil?
&&
status
.
account_id
==
@account
.
id
&&
!
@account
.
pinned?
(
status
)
StatusPin
.
create!
(
account:
@account
,
status:
status
)
end
def
add_featured_tags
name
=
@object
[
'name'
]
&
.
delete_prefix
(
'#'
)
FeaturedTag
.
create!
(
account:
@account
,
name:
name
)
if
name
.
present?
end
end
This diff is collapsed.
Click to expand it.
app/lib/activitypub/activity/remove.rb
+
24
−
1
View file @
1d34eff6
...
...
@@ -2,8 +2,22 @@
class
ActivityPub::Activity::Remove
<
ActivityPub
::
Activity
def
perform
return
unless
@json
[
'target'
].
present?
&&
value_or_id
(
@json
[
'target'
])
==
@account
.
featured_collection_url
return
if
@json
[
'target'
].
blank?
case
value_or_id
(
@json
[
'target'
])
when
@account
.
featured_collection_url
case
@object
[
'type'
]
when
'Hashtag'
remove_featured_tags
else
remove_featured
end
end
end
private
def
remove_featured
status
=
status_from_uri
(
object_uri
)
return
unless
!
status
.
nil?
&&
status
.
account_id
==
@account
.
id
...
...
@@ -11,4 +25,13 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
pin
=
StatusPin
.
find_by
(
account:
@account
,
status:
status
)
pin
&
.
destroy!
end
def
remove_featured_tags
name
=
@object
[
'name'
]
&
.
delete_prefix
(
'#'
)
return
if
name
.
blank?
featured_tag
=
FeaturedTag
.
by_name
(
name
).
find_by
(
account:
@account
)
featured_tag
&
.
destroy!
end
end
This diff is collapsed.
Click to expand it.
app/models/featured_tag.rb
+
2
−
0
View file @
1d34eff6
...
...
@@ -22,6 +22,8 @@ class FeaturedTag < ApplicationRecord
before_create
:set_tag
before_create
:reset_data
scope
:by_name
,
->
(
name
)
{
joins
(
:tag
).
where
(
tag:
{
name:
HashtagNormalizer
.
new
.
normalize
(
name
)
})
}
delegate
:display_name
,
to: :tag
attr_writer
:name
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment