Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
d8c842a7
Commit
d8c842a7
authored
May 17, 2018
by
normandy
Browse files
Add support for incoming remote unfollows
parent
1d4bbec6
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/user.ex
View file @
d8c842a7
...
...
@@ -404,18 +404,22 @@ def search(query, resolve) do
from
(
u
in
User
,
select_merge:
%{
search_distance:
fragment
(
"? <-> (? || ?)"
,
^
query
,
u
.
nickname
,
u
.
name
)}
search_distance:
fragment
(
"? <-> (? || ?)"
,
^
query
,
u
.
nickname
,
u
.
name
)
}
)
q
=
from
(
s
in
subquery
(
inner
),
order_by:
s
.
search_distance
,
limit:
20
)
q
=
from
(
s
in
subquery
(
inner
),
order_by:
s
.
search_distance
,
limit:
20
)
Repo
.
all
(
q
)
end
...
...
lib/pleroma/web/activity_pub/transmogrifier.ex
View file @
d8c842a7
...
...
@@ -241,6 +241,24 @@ def handle_incoming(
end
end
def
handle_incoming
(
%{
"type"
=>
"Undo"
,
"object"
=>
%{
"type"
=>
"Follow"
,
"object"
=>
followed
},
"actor"
=>
follower
,
"id"
=>
id
}
=
data
)
do
with
%
User
{
local:
true
}
=
followed
=
User
.
get_cached_by_ap_id
(
followed
),
%
User
{}
=
follower
=
User
.
get_or_fetch_by_ap_id
(
follower
),
{
:ok
,
activity
}
<-
ActivityPub
.
unfollow
(
follower
,
followed
,
false
)
do
User
.
unfollow
(
follower
,
followed
)
{
:ok
,
activity
}
else
e
->
:error
end
end
# TODO
# Accept
# Undo for non-Announce
...
...
test/fixtures/mastodon-unfollow-activity.json
0 → 100644
View file @
d8c842a7
{
"@context"
:
[
"https://www.w3.org/ns/activitystreams"
,
"https://w3id.org/security/v1"
,
{
"toot"
:
"http://joinmastodon.org/ns#"
,
"sensitive"
:
"as:sensitive"
,
"ostatus"
:
"http://ostatus.org#"
,
"movedTo"
:
"as:movedTo"
,
"manuallyApprovesFollowers"
:
"as:manuallyApprovesFollowers"
,
"inReplyToAtomUri"
:
"ostatus:inReplyToAtomUri"
,
"conversation"
:
"ostatus:conversation"
,
"atomUri"
:
"ostatus:atomUri"
,
"Hashtag"
:
"as:Hashtag"
,
"Emoji"
:
"toot:Emoji"
}
],
"signature"
:
{
"type"
:
"RsaSignature2017"
,
"signatureValue"
:
"Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig=="
,
"creator"
:
"http://mastodon.example.org/users/admin#main-key"
,
"created"
:
"2018-02-17T13:29:31Z"
},
"type"
:
"Undo"
,
"object"
:
{
"type"
:
"Follow"
,
"object"
:
"http://localtesting.pleroma.lol/users/lain"
,
"nickname"
:
"lain"
,
"id"
:
"http://mastodon.example.org/users/admin#follows/2"
,
"actor"
:
"http://mastodon.example.org/users/admin"
},
"actor"
:
"http://mastodon.example.org/users/admin"
}
test/web/activity_pub/transmogrifier_test.exs
View file @
d8c842a7
...
...
@@ -260,6 +260,30 @@ test "it works for incoming unannounces with an existing notice" do
assert
data
[
"object"
][
"id"
]
==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
end
test
"it works for incomming unfollows"
do
user
=
insert
(
:user
)
follow_data
=
File
.
read!
(
"test/fixtures/mastodon-follow-activity.json"
)
|>
Poison
.
decode!
()
|>
Map
.
put
(
"object"
,
user
.
ap_id
)
{
:ok
,
%
Activity
{
data:
_
,
local:
false
}}
=
Transmogrifier
.
handle_incoming
(
follow_data
)
data
=
File
.
read!
(
"test/fixtures/mastodon-unfollow-activity.json"
)
|>
Poison
.
decode!
()
|>
Map
.
put
(
"object"
,
follow_data
)
{
:ok
,
%
Activity
{
data:
data
,
local:
false
}}
=
Transmogrifier
.
handle_incoming
(
data
)
assert
data
[
"type"
]
==
"Undo"
assert
data
[
"object"
][
"type"
]
==
"Follow"
assert
data
[
"actor"
]
==
"http://mastodon.example.org/users/admin"
refute
User
.
following?
(
User
.
get_by_ap_id
(
data
[
"actor"
]),
user
)
end
end
describe
"prepare outgoing"
do
...
...
Write
Preview
Supports
Markdown
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