aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-05-10 18:46:23 +0200
committerRoger Braun <roger@rogerbraun.net>2017-05-10 18:46:23 +0200
commit05f2cd0d930e93d1eb80a8a4ba3952f8ba46f5ce (patch)
tree752c9bddc7ccfbf738439a8b9ea4ead878d4c7c2 /lib
parent34a1ce00ecc6f19827638fc311e4e76d3c4cb162 (diff)
downloadpleroma-05f2cd0d930e93d1eb80a8a4ba3952f8ba46f5ce.tar.gz
Handle incoming follows.
Also Mastodon CWs.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/ostatus/handlers/follow_handler.ex16
-rw-r--r--lib/pleroma/web/ostatus/ostatus.ex15
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/pleroma/web/ostatus/handlers/follow_handler.ex b/lib/pleroma/web/ostatus/handlers/follow_handler.ex
new file mode 100644
index 000000000..f5db5582b
--- /dev/null
+++ b/lib/pleroma/web/ostatus/handlers/follow_handler.ex
@@ -0,0 +1,16 @@
+defmodule Pleroma.Web.OStatus.FollowHandler do
+ alias Pleroma.Web.{XML, OStatus}
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.User
+
+ def handle(entry, doc) do
+ with {:ok, actor} <- OStatus.find_make_or_update_user(doc),
+ id when not is_nil(id) <- XML.string_from_xpath("/entry/id", entry),
+ followed_uri when not is_nil(followed_uri) <- XML.string_from_xpath("/entry/activity:object/id", entry),
+ {:ok, followed} <- OStatus.find_or_make_user(followed_uri),
+ {:ok, activity} <- ActivityPub.follow(actor, followed, id, false) do
+ User.follow(actor, followed)
+ {:ok, activity}
+ end
+ end
+end
diff --git a/lib/pleroma/web/ostatus/ostatus.ex b/lib/pleroma/web/ostatus/ostatus.ex
index da0407aeb..b19f0172a 100644
--- a/lib/pleroma/web/ostatus/ostatus.ex
+++ b/lib/pleroma/web/ostatus/ostatus.ex
@@ -8,6 +8,7 @@ defmodule Pleroma.Web.OStatus do
alias Pleroma.{Repo, User, Web, Object, Activity}
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.{WebFinger, Websub}
+ alias Pleroma.Web.OStatus.FollowHandler
def feed_path(user) do
"#{user.ap_id}/feed.atom"
@@ -30,6 +31,8 @@ defmodule Pleroma.Web.OStatus do
{:xmlObj, :string, verb} = :xmerl_xpath.string('string(/entry/activity:verb[1])', entry)
case verb do
+ 'http://activitystrea.ms/schema/1.0/follow' ->
+ with {:ok, activity} <- FollowHandler.handle(entry, doc), do: activity
'http://activitystrea.ms/schema/1.0/share' ->
with {:ok, activity, retweeted_activity} <- handle_share(entry, doc), do: [activity, retweeted_activity]
'http://activitystrea.ms/schema/1.0/favorite' ->
@@ -116,8 +119,18 @@ defmodule Pleroma.Web.OStatus do
|> Enum.filter(&(&1))
end
+ def get_content(entry) do
+ base_content = string_from_xpath("/entry/content", entry)
+
+ with scope when not is_nil(scope) <- string_from_xpath("//mastodon:scope", entry),
+ cw when not is_nil(cw) <- string_from_xpath("/entry/summary", entry) do
+ "<span class='mastodon-cw'>#{cw}</span><br>#{base_content}"
+ else _e -> base_content
+ end
+ end
+
def handle_note(entry, doc \\ nil) do
- content_html = string_from_xpath("//content[1]", entry)
+ content_html = get_content(entry)
[author] = :xmerl_xpath.string('//author[1]', doc)
{:ok, actor} = find_make_or_update_user(author)