Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pleroma
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
402
Issues
402
List
Boards
Labels
Service Desk
Milestones
Merge Requests
61
Merge Requests
61
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
1fc28a4b
Verified
Commit
1fc28a4b
authored
Nov 26, 2019
by
minibikini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a view for the move notification
parent
3c0abfca
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
25 deletions
+77
-25
docs/API/differences_in_mastoapi_responses.md
docs/API/differences_in_mastoapi_responses.md
+6
-0
lib/pleroma/activity.ex
lib/pleroma/activity.ex
+2
-1
lib/pleroma/web/mastodon_api/views/notification_view.ex
lib/pleroma/web/mastodon_api/views/notification_view.ex
+15
-23
lib/pleroma/web/push/impl.ex
lib/pleroma/web/push/impl.ex
+1
-1
test/notification_test.exs
test/notification_test.exs
+29
-0
test/web/mastodon_api/views/notification_view_test.exs
test/web/mastodon_api/views/notification_view_test.exs
+24
-0
No files found.
docs/API/differences_in_mastoapi_responses.md
View file @
1fc28a4b
...
...
@@ -92,6 +92,12 @@ Has these additional fields under the `pleroma` object:
-
`is_seen`
: true if the notification was read by the user
### Move Notification
The
`type`
value is
`move`
. Has an additional field:
-
`target`
: new account
## GET `/api/v1/notifications`
Accepts additional parameters:
...
...
lib/pleroma/activity.ex
View file @
1fc28a4b
...
...
@@ -28,7 +28,8 @@ defmodule Pleroma.Activity do
"Create"
=>
"mention"
,
"Follow"
=>
"follow"
,
"Announce"
=>
"reblog"
,
"Like"
=>
"favourite"
"Like"
=>
"favourite"
,
"Move"
=>
"move"
}
@mastodon_to_ap_notification_types
for
{
k
,
v
}
<-
@mastodon_notification_types
,
...
...
lib/pleroma/web/mastodon_api/views/notification_view.ex
View file @
1fc28a4b
...
...
@@ -37,32 +37,24 @@ def render("show.json", %{
}
case
mastodon_type
do
"mention"
->
response
|>
Map
.
merge
(%{
status:
StatusView
.
render
(
"show.json"
,
%{
activity:
activity
,
for:
user
})
})
"favourite"
->
response
|>
Map
.
merge
(%{
status:
StatusView
.
render
(
"show.json"
,
%{
activity:
parent_activity
,
for:
user
})
})
"reblog"
->
response
|>
Map
.
merge
(%{
status:
StatusView
.
render
(
"show.json"
,
%{
activity:
parent_activity
,
for:
user
})
})
"follow"
->
response
_
->
nil
"mention"
->
put_status
(
response
,
activity
,
user
)
"favourite"
->
put_status
(
response
,
parent_activity
,
user
)
"reblog"
->
put_status
(
response
,
parent_activity
,
user
)
"move"
->
put_target
(
response
,
activity
,
user
)
"follow"
->
response
_
->
nil
end
else
_
->
nil
end
end
defp
put_status
(
response
,
activity
,
user
)
do
Map
.
put
(
response
,
:status
,
StatusView
.
render
(
"show.json"
,
%{
activity:
activity
,
for:
user
}))
end
defp
put_target
(
response
,
activity
,
user
)
do
target
=
User
.
get_cached_by_ap_id
(
activity
.
data
[
"target"
])
Map
.
put
(
response
,
:target
,
AccountView
.
render
(
"show.json"
,
%{
user:
target
,
for:
user
}))
end
end
lib/pleroma/web/push/impl.ex
View file @
1fc28a4b
...
...
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.Push.Impl do
require
Logger
import
Ecto
.
Query
@types
[
"Create"
,
"Follow"
,
"Announce"
,
"Like"
]
@types
[
"Create"
,
"Follow"
,
"Announce"
,
"Like"
,
"Move"
]
@doc
"Performs sending notifications for user subscriptions"
@spec
perform
(
Notification
.
t
())
::
list
(
any
)
|
:error
...
...
test/notification_test.exs
View file @
1fc28a4b
...
...
@@ -630,6 +630,35 @@ test "notifications are deleted if a remote user is deleted" do
assert
Enum
.
empty?
(
Notification
.
for_user
(
local_user
))
end
test
"move activity generates a notification"
do
%{
ap_id:
old_ap_id
}
=
old_user
=
insert
(
:user
)
%{
ap_id:
new_ap_id
}
=
new_user
=
insert
(
:user
,
also_known_as:
[
old_ap_id
])
follower
=
insert
(
:user
)
other_follower
=
insert
(
:user
,
%{
allow_following_move:
false
})
User
.
follow
(
follower
,
old_user
)
User
.
follow
(
other_follower
,
old_user
)
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
.
move
(
old_user
,
new_user
)
ObanHelpers
.
perform_all
()
assert
[
%{
activity:
%{
data:
%{
"type"
=>
"Move"
,
"actor"
=>
^
old_ap_id
,
"target"
=>
^
new_ap_id
}
}
}
]
=
Notification
.
for_user
(
follower
)
assert
[
%{
activity:
%{
data:
%{
"type"
=>
"Move"
,
"actor"
=>
^
old_ap_id
,
"target"
=>
^
new_ap_id
}
}
}
]
=
Notification
.
for_user
(
other_follower
)
end
end
describe
"for_user"
do
...
...
test/web/mastodon_api/views/notification_view_test.exs
View file @
1fc28a4b
...
...
@@ -107,4 +107,28 @@ test "Follow notification" do
assert
[]
==
NotificationView
.
render
(
"index.json"
,
%{
notifications:
[
notification
],
for:
followed
})
end
test
"Move notification"
do
%{
ap_id:
old_ap_id
}
=
old_user
=
insert
(
:user
)
%{
ap_id:
_new_ap_id
}
=
new_user
=
insert
(
:user
,
also_known_as:
[
old_ap_id
])
follower
=
insert
(
:user
)
User
.
follow
(
follower
,
old_user
)
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
.
move
(
old_user
,
new_user
)
Pleroma
.
Tests
.
ObanHelpers
.
perform_all
()
[
notification
]
=
Notification
.
for_user
(
follower
)
expected
=
%{
id:
to_string
(
notification
.
id
),
pleroma:
%{
is_seen:
false
},
type:
"move"
,
account:
AccountView
.
render
(
"show.json"
,
%{
user:
old_user
,
for:
follower
}),
target:
AccountView
.
render
(
"show.json"
,
%{
user:
new_user
,
for:
follower
}),
created_at:
Utils
.
to_masto_date
(
notification
.
inserted_at
)
}
assert
[
expected
]
==
NotificationView
.
render
(
"index.json"
,
%{
notifications:
[
notification
],
for:
follower
})
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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