mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-23 09:44:52 +00:00
[OStatus] adds status to pleroma instance if the url given is a status
This commit is contained in:
parent
9e3899bf36
commit
1d01e8e656
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Comeonin.Pbkdf2
|
alias Comeonin.Pbkdf2
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Emoji
|
alias Pleroma.Emoji
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.PasswordResetToken
|
alias Pleroma.PasswordResetToken
|
||||||
|
@ -73,26 +74,39 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
|
def remote_follow(%{assigns: %{user: user}} = conn, %{"acct" => acct}) do
|
||||||
{err, followee} = OStatus.find_or_make_user(acct)
|
case is_status?(acct) do
|
||||||
avatar = User.avatar_url(followee)
|
true ->
|
||||||
name = followee.nickname
|
{:ok, object} = ActivityPub.fetch_object_from_id(acct)
|
||||||
id = followee.id
|
%Activity{id: activity_id} = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||||
|
redirect(conn, to: "/notice/#{activity_id}")
|
||||||
|
|
||||||
if !!user do
|
false ->
|
||||||
conn
|
{err, followee} = OStatus.find_or_make_user(acct)
|
||||||
|> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id})
|
avatar = User.avatar_url(followee)
|
||||||
else
|
name = followee.nickname
|
||||||
conn
|
id = followee.id
|
||||||
|> render("follow_login.html", %{
|
|
||||||
error: false,
|
if !!user do
|
||||||
acct: acct,
|
conn
|
||||||
avatar: avatar,
|
|> render("follow.html", %{error: err, acct: acct, avatar: avatar, name: name, id: id})
|
||||||
name: name,
|
else
|
||||||
id: id
|
conn
|
||||||
})
|
|> render("follow_login.html", %{
|
||||||
|
error: false,
|
||||||
|
acct: acct,
|
||||||
|
avatar: avatar,
|
||||||
|
name: name,
|
||||||
|
id: id
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp is_status?(acct) do
|
||||||
|
%URI{path: path} = URI.parse(acct)
|
||||||
|
Regex.match?(~r/\/users\/[^\/]+\/statuses\/([0-9]+)$/, path)
|
||||||
|
end
|
||||||
|
|
||||||
def do_remote_follow(conn, %{
|
def do_remote_follow(conn, %{
|
||||||
"authorization" => %{"name" => username, "password" => password, "id" => id}
|
"authorization" => %{"name" => username, "password" => password, "id" => id}
|
||||||
}) do
|
}) do
|
||||||
|
|
106
test/fixtures/httpoison_mock/emelie.json
vendored
Normal file
106
test/fixtures/httpoison_mock/emelie.json
vendored
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"featured": {
|
||||||
|
"@id": "toot:featured",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"alsoKnownAs": {
|
||||||
|
"@id": "as:alsoKnownAs",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"movedTo": {
|
||||||
|
"@id": "as:movedTo",
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"schema": "http://schema.org#",
|
||||||
|
"PropertyValue": "schema:PropertyValue",
|
||||||
|
"value": "schema:value",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji",
|
||||||
|
"IdentityProof": "toot:IdentityProof",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container": "@list",
|
||||||
|
"@id": "toot:focalPoint"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://mastodon.social/users/emelie",
|
||||||
|
"type": "Person",
|
||||||
|
"following": "https://mastodon.social/users/emelie/following",
|
||||||
|
"followers": "https://mastodon.social/users/emelie/followers",
|
||||||
|
"inbox": "https://mastodon.social/users/emelie/inbox",
|
||||||
|
"outbox": "https://mastodon.social/users/emelie/outbox",
|
||||||
|
"featured": "https://mastodon.social/users/emelie/collections/featured",
|
||||||
|
"preferredUsername": "emelie",
|
||||||
|
"name": "emelie 🎨",
|
||||||
|
"summary": "<p>23 / <a href=\"https://mastodon.social/tags/sweden\" class=\"mention hashtag\" rel=\"tag\">#<span>Sweden</span></a> / <a href=\"https://mastodon.social/tags/artist\" class=\"mention hashtag\" rel=\"tag\">#<span>Artist</span></a> / <a href=\"https://mastodon.social/tags/equestrian\" class=\"mention hashtag\" rel=\"tag\">#<span>Equestrian</span></a> / <a href=\"https://mastodon.social/tags/gamedev\" class=\"mention hashtag\" rel=\"tag\">#<span>GameDev</span></a></p><p>If I ain't spending time with my pets, I'm probably drawing. 🐴 🐱 🐰</p>",
|
||||||
|
"url": "https://mastodon.social/@emelie",
|
||||||
|
"manuallyApprovesFollowers": false,
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://mastodon.social/users/emelie#main-key",
|
||||||
|
"owner": "https://mastodon.social/users/emelie",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3CWs1oAJPE3ZJ9sj6Ut\n/Mu+mTE7MOijsQc8/6c73XVVuhIEomiozJIH7l8a7S1n5SYL4UuiwcubSOi7u1bb\nGpYnp5TYhN+Cxvq/P80V4/ncNIPSQzS49it7nSLeG5pA21lGPDA44huquES1un6p\n9gSmbTwngVX9oe4MYuUeh0Z7vijjU13Llz1cRq/ZgPQPgfz+2NJf+VeXnvyDZDYx\nZPVBBlrMl3VoGbu0M5L8SjY35559KCZ3woIvqRolcoHXfgvJMdPcJgSZVYxlCw3d\nA95q9jQcn6s87CPSUs7bmYEQCrDVn5m5NER5TzwBmP4cgJl9AaDVWQtRd4jFZNTx\nlQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||||
|
},
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://mastodon.social/explore/sweden",
|
||||||
|
"name": "#sweden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://mastodon.social/explore/gamedev",
|
||||||
|
"name": "#gamedev"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://mastodon.social/explore/artist",
|
||||||
|
"name": "#artist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://mastodon.social/explore/equestrian",
|
||||||
|
"name": "#equestrian"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attachment": [
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Ko-fi",
|
||||||
|
"value": "<a href=\"https://ko-fi.com/emeliepng\" rel=\"me nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">ko-fi.com/emeliepng</span><span class=\"invisible\"></span></a>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Instagram",
|
||||||
|
"value": "<a href=\"https://www.instagram.com/emelie_png/\" rel=\"me nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://www.</span><span class=\"\">instagram.com/emelie_png/</span><span class=\"invisible\"></span></a>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Carrd",
|
||||||
|
"value": "<a href=\"https://emelie.carrd.co/\" rel=\"me nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">emelie.carrd.co/</span><span class=\"invisible\"></span></a>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PropertyValue",
|
||||||
|
"name": "Artstation",
|
||||||
|
"value": "<a href=\"https://emiri.artstation.com\" rel=\"me nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">emiri.artstation.com</span><span class=\"invisible\"></span></a>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"endpoints": {
|
||||||
|
"sharedInbox": "https://mastodon.social/inbox"
|
||||||
|
},
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://files.mastodon.social/accounts/avatars/000/015/657/original/e7163f98280da1a4.png"
|
||||||
|
},
|
||||||
|
"image": {
|
||||||
|
"type": "Image",
|
||||||
|
"mediaType": "image/png",
|
||||||
|
"url": "https://files.mastodon.social/accounts/headers/000/015/657/original/847f331f3dd9e38b.png"
|
||||||
|
}
|
||||||
|
}
|
64
test/fixtures/httpoison_mock/status.emelie.json
vendored
Normal file
64
test/fixtures/httpoison_mock/status.emelie.json
vendored
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"Emoji": "toot:Emoji",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container": "@list",
|
||||||
|
"@id": "toot:focalPoint"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://mastodon.social/users/emelie/statuses/101849165031453009",
|
||||||
|
"type": "Note",
|
||||||
|
"summary": null,
|
||||||
|
"inReplyTo": null,
|
||||||
|
"published": "2019-04-01T05:02:05Z",
|
||||||
|
"url": "https://mastodon.social/@emelie/101849165031453009",
|
||||||
|
"attributedTo": "https://mastodon.social/users/emelie",
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://mastodon.social/users/emelie/followers"
|
||||||
|
],
|
||||||
|
"sensitive": false,
|
||||||
|
"atomUri": "https://mastodon.social/users/emelie/statuses/101849165031453009",
|
||||||
|
"inReplyToAtomUri": null,
|
||||||
|
"conversation": "tag:mastodon.social,2019-04-01:objectId=94350309:objectType=Conversation",
|
||||||
|
"content": "<p>You gotta take whatever bellyrubbing opportunity you can get before she changes her mind 🦁 <a href=\"https://mastodon.social/tags/mastocats\" class=\"mention hashtag\" rel=\"tag\">#<span>mastocats</span></a></p>",
|
||||||
|
"contentMap": {
|
||||||
|
"en": "<p>You gotta take whatever bellyrubbing opportunity you can get before she changes her mind 🦁 <a href=\"https://mastodon.social/tags/mastocats\" class=\"mention hashtag\" rel=\"tag\">#<span>mastocats</span></a></p>"
|
||||||
|
},
|
||||||
|
"attachment": [
|
||||||
|
{
|
||||||
|
"type": "Document",
|
||||||
|
"mediaType": "video/mp4",
|
||||||
|
"url": "https://files.mastodon.social/media_attachments/files/013/049/816/original/e7831178a5e0d6d4.mp4",
|
||||||
|
"name": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tag": [
|
||||||
|
{
|
||||||
|
"type": "Hashtag",
|
||||||
|
"href": "https://mastodon.social/tags/mastocats",
|
||||||
|
"name": "#mastocats"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"replies": {
|
||||||
|
"id": "https://mastodon.social/users/emelie/statuses/101849165031453009/replies",
|
||||||
|
"type": "Collection",
|
||||||
|
"first": {
|
||||||
|
"type": "CollectionPage",
|
||||||
|
"partOf": "https://mastodon.social/users/emelie/statuses/101849165031453009/replies",
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,22 @@ defmodule HttpRequestMock do
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/httpoison_mock/status.emelie.json")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get("https://mastodon.social/users/emelie", _, _, _) do
|
||||||
|
{:ok,
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: File.read!("test/fixtures/httpoison_mock/emelie.json")
|
||||||
|
}}
|
||||||
|
end
|
||||||
|
|
||||||
def get(
|
def get(
|
||||||
"https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
|
"https://osada.macgirvin.com/.well-known/webfinger?resource=acct:mike@osada.macgirvin.com",
|
||||||
_,
|
_,
|
||||||
|
|
|
@ -6,6 +6,11 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
setup do
|
||||||
|
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "POST /api/pleroma/follow_import" do
|
describe "POST /api/pleroma/follow_import" do
|
||||||
test "it returns HTTP 200", %{conn: conn} do
|
test "it returns HTTP 200", %{conn: conn} do
|
||||||
user1 = insert(:user)
|
user1 = insert(:user)
|
||||||
|
@ -164,4 +169,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||||
assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
|
assert response == Jason.encode!(config |> Enum.into(%{})) |> Jason.decode!()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /ostatus_subscribe?acct=...." do
|
||||||
|
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
get(
|
||||||
|
conn,
|
||||||
|
"/ostatus_subscribe?acct=https://mastodon.social/users/emelie/statuses/101849165031453009"
|
||||||
|
)
|
||||||
|
|
||||||
|
assert redirected_to(conn) =~ "/notice/"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue