projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'fix_486' into 'develop'
[akkoma]
/
lib
/
pleroma
/
web
/
twitter_api
/
views
/
activity_view.ex
diff --git
a/lib/pleroma/web/twitter_api/views/activity_view.ex
b/lib/pleroma/web/twitter_api/views/activity_view.ex
index 909eefdd886d6386b8c0db1bc0199e10154333f9..ad0cc76edf72adac00a899c19a7f6b052fec5e0d 100644
(file)
--- a/
lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/
lib/pleroma/web/twitter_api/views/activity_view.ex
@@
-1,3
+1,7
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.TwitterAPI.ActivityView do
use Pleroma.Web, :view
alias Pleroma.Web.CommonAPI.Utils
defmodule Pleroma.Web.TwitterAPI.ActivityView do
use Pleroma.Web, :view
alias Pleroma.Web.CommonAPI.Utils
@@
-7,12
+11,14
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.Activity
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
alias Pleroma.Activity
+ alias Pleroma.HTML
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Formatter
import Ecto.Query
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Formatter
import Ecto.Query
+ require Logger
defp query_context_ids([]), do: []
defp query_context_ids([]), do: []
@@
-189,6
+195,11
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
text = "#{user.nickname} favorited a status."
text = "#{user.nickname} favorited a status."
+ favorited_status =
+ if liked_activity,
+ do: render("activity.json", Map.merge(opts, %{activity: liked_activity})),
+ else: nil
+
%{
"id" => activity.id,
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
%{
"id" => activity.id,
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
@@
-198,6
+209,7
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
"is_post_verb" => false,
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
"created_at" => created_at,
"is_post_verb" => false,
"uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
"created_at" => created_at,
+ "favorited_status" => favorited_status,
"in_reply_to_status_id" => liked_activity_id,
"external_url" => activity.data["id"],
"activity_type" => "like"
"in_reply_to_status_id" => liked_activity_id,
"external_url" => activity.data["id"],
"activity_type" => "like"
@@
-232,19
+244,39
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
{summary, content} = render_content(object)
html =
{summary, content} = render_content(object)
html =
- HtmlSanitizeEx.basic_html(content)
+ content
+ |> HTML.get_cached_scrubbed_html_for_object(
+ User.html_filter_policy(opts[:for]),
+ activity,
+ __MODULE__
+ )
|> Formatter.emojify(object["emoji"])
|> Formatter.emojify(object["emoji"])
+ text =
+ if content do
+ content
+ |> String.replace(~r/<br\s?\/?>/, "\n")
+ |> HTML.get_cached_stripped_html_for_object(activity, __MODULE__)
+ end
+
+ reply_parent = Activity.get_in_reply_to_activity(activity)
+
+ reply_user = reply_parent && User.get_cached_by_ap_id(reply_parent.actor)
+
%{
"id" => activity.id,
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => html,
%{
"id" => activity.id,
"uri" => activity.data["object"]["id"],
"user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
"statusnet_html" => html,
- "text" =>
HtmlSanitizeEx.strip_tags(content)
,
+ "text" =>
text
,
"is_local" => activity.local,
"is_post_verb" => true,
"created_at" => created_at,
"in_reply_to_status_id" => object["inReplyToStatusId"],
"is_local" => activity.local,
"is_post_verb" => true,
"created_at" => created_at,
"in_reply_to_status_id" => object["inReplyToStatusId"],
+ "in_reply_to_screen_name" => reply_user && reply_user.nickname,
+ "in_reply_to_profileurl" => User.profile_url(reply_user),
+ "in_reply_to_ostatus_uri" => reply_user && reply_user.ap_id,
+ "in_reply_to_user_id" => reply_user && reply_user.id,
"statusnet_conversation_id" => conversation_id,
"attachments" => (object["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
"attentions" => attentions,
"statusnet_conversation_id" => conversation_id,
"attachments" => (object["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
"attentions" => attentions,
@@
-257,10
+289,15
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
"visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
"activity_type" => "post",
"possibly_sensitive" => possibly_sensitive,
"visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
- "summary" =>
summary
+ "summary" =>
HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"])
}
end
}
end
+ def render("activity.json", %{activity: unhandled_activity}) do
+ Logger.warn("#{__MODULE__} unhandled activity: #{inspect(unhandled_activity)}")
+ nil
+ end
+
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
def render_content(%{"type" => "Note"} = object) do
summary = object["summary"]
@@
-274,11
+311,12
@@
defmodule Pleroma.Web.TwitterAPI.ActivityView do
{summary, content}
end
{summary, content}
end
- def render_content(%{"type" => "Article"} = object) do
+ def render_content(%{"type" => object_type} = object)
+ when object_type in ["Article", "Page", "Video"] do
summary = object["name"] || object["summary"]
content =
summary = object["name"] || object["summary"]
content =
- if !!summary and summary != "" do
+ if !!summary and summary != ""
and is_bitstring(object["url"])
do
"<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
else
object["content"]
"<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
else
object["content"]