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
29be70c0
Commit
29be70c0
authored
Feb 02, 2018
by
eal
Browse files
Add remote following of local profiles.
parent
ab83e0de
Pipeline
#596
passed with stage
in 2 minutes and 3 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/router.ex
View file @
29be70c0
...
...
@@ -62,6 +62,7 @@ def user_fetcher(username) do
pipe_through
:pleroma_html
get
"/ostatus_subscribe"
,
UtilController
,
:remote_follow
post
"/ostatus_subscribe"
,
UtilController
,
:do_remote_follow
post
"/main/ostatus"
,
UtilController
,
:remote_subscribe
end
scope
"/api/pleroma"
,
Pleroma
.
Web
.
TwitterAPI
do
...
...
lib/pleroma/web/templates/twitter_api/util/subscribe.html.eex
0 → 100644
View file @
29be70c0
<%=
if
@error
do
%>
<h2>
Error:
<%=
@error
%>
</h2>
<%
else
%>
<h2>
Remotely follow
<%=
@nickname
%>
</h2>
<%=
form_for
@conn
,
util_path
(
@conn
,
:remote_subscribe
),
[
as:
"user"
],
fn
f
->
%>
<%=
hidden_input
f
,
:nickname
,
value:
@nickname
%>
<%=
text_input
f
,
:profile
,
placeholder:
"Your account ID, e.g. lain@quitter.se"
%>
<%=
submit
"Follow"
%>
<%
end
%>
<%
end
%>
lib/pleroma/web/twitter_api/controllers/util_controller.ex
View file @
29be70c0
...
...
@@ -3,6 +3,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
require
Logger
alias
Pleroma
.
Web
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Web
.
WebFinger
alias
Comeonin
.
Pbkdf2
alias
Pleroma
.
Formatter
alias
Pleroma
.
Web
.
ActivityPub
.
ActivityPub
...
...
@@ -32,6 +33,26 @@ def help_test(conn, _params) do
json
(
conn
,
"ok"
)
end
def
remote_subscribe
(
conn
,
%{
"nickname"
=>
nick
,
"profile"
=>
_
})
do
with
%
User
{}
=
user
<-
User
.
get_cached_by_nickname
(
nick
),
avatar
=
User
.
avatar_url
(
user
)
do
conn
|>
render
(
"subscribe.html"
,
%{
nickname:
nick
,
avatar:
avatar
,
error:
false
})
else
_e
->
render
(
conn
,
"subscribe.html"
,
%{
nickname:
nick
,
avatar:
nil
,
error:
"Could not find user"
})
end
end
def
remote_subscribe
(
conn
,
%{
"user"
=>
%{
"nickname"
=>
nick
,
"profile"
=>
profile
}})
do
with
{
:ok
,
%{
"subscribe_address"
=>
template
}}
<-
WebFinger
.
finger
(
profile
),
%
User
{
ap_id:
ap_id
}
<-
User
.
get_cached_by_nickname
(
nick
)
do
conn
|>
Phoenix
.
Controller
.
redirect
(
external:
String
.
replace
(
template
,
"{uri}"
,
ap_id
))
else
_e
->
render
(
conn
,
"subscribe.html"
,
%{
nickname:
nick
,
avatar:
nil
,
error:
"Something went wrong."
})
end
end
def
remote_follow
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
"acct"
=>
acct
})
do
{
err
,
followee
}
=
OStatus
.
find_or_make_user
(
acct
)
avatar
=
User
.
avatar_url
(
followee
)
...
...
lib/pleroma/web/web_finger/web_finger.ex
View file @
29be70c0
...
...
@@ -69,11 +69,13 @@ defp webfinger_from_xml(doc) do
topic
=
XML
.
string_from_xpath
(
~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href}
,
doc
)
subject
=
XML
.
string_from_xpath
(
"//Subject"
,
doc
)
salmon
=
XML
.
string_from_xpath
(
~s{//Link[@rel="salmon"]/@href}
,
doc
)
subscribe_address
=
XML
.
string_from_xpath
(
~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template}
,
doc
)
data
=
%{
"magic_key"
=>
magic_key
,
"topic"
=>
topic
,
"subject"
=>
subject
,
"salmon"
=>
salmon
"salmon"
=>
salmon
,
"subscribe_address"
=>
subscribe_address
}
{
:ok
,
data
}
end
...
...
test/web/ostatus/ostatus_test.exs
View file @
29be70c0
...
...
@@ -302,7 +302,8 @@ test "it returns user info in a hash" do
"host"
=>
"social.heldscal.la"
,
"fqn"
=>
user
,
"bio"
=>
"cofe"
,
"avatar"
=>
%{
"type"
=>
"Image"
,
"url"
=>
[%{
"href"
=>
"https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg"
,
"mediaType"
=>
"image/jpeg"
,
"type"
=>
"Link"
}]}
"avatar"
=>
%{
"type"
=>
"Image"
,
"url"
=>
[%{
"href"
=>
"https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg"
,
"mediaType"
=>
"image/jpeg"
,
"type"
=>
"Link"
}]},
"subscribe_address"
=>
"https://social.heldscal.la/main/ostatussub?profile={uri}"
}
assert
data
==
expected
end
...
...
@@ -325,7 +326,8 @@ test "it works with the uri" do
"host"
=>
"social.heldscal.la"
,
"fqn"
=>
user
,
"bio"
=>
"cofe"
,
"avatar"
=>
%{
"type"
=>
"Image"
,
"url"
=>
[%{
"href"
=>
"https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg"
,
"mediaType"
=>
"image/jpeg"
,
"type"
=>
"Link"
}]}
"avatar"
=>
%{
"type"
=>
"Image"
,
"url"
=>
[%{
"href"
=>
"https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg"
,
"mediaType"
=>
"image/jpeg"
,
"type"
=>
"Link"
}]},
"subscribe_address"
=>
"https://social.heldscal.la/main/ostatussub?profile={uri}"
}
assert
data
==
expected
end
...
...
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