alias Pleroma.User
alias Pleroma.UserRelationship
alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
{:ok, activity} = CommonAPI.post(user, %{status: "dae cofe??"})
{:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "☕")
+ {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, ":dinosaur:")
{:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵")
{:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")
+ {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, ":dinosaur:")
+
activity = Repo.get(Activity, activity.id)
status = StatusView.render("show.json", activity: activity)
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 2, me: false},
- %{name: "🍵", count: 1, me: false}
+ %{name: "☕", count: 2, me: false, url: nil, account_ids: [other_user.id, user.id]},
+ %{
+ count: 2,
+ me: false,
+ name: "dinosaur",
+ url: "http://localhost:4001/emoji/dino walking.gif",
+ account_ids: [other_user.id, user.id]
+ },
+ %{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
]
status = StatusView.render("show.json", activity: activity, for: user)
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 2, me: true},
- %{name: "🍵", count: 1, me: false}
+ %{name: "☕", count: 2, me: true, url: nil, account_ids: [other_user.id, user.id]},
+ %{
+ count: 2,
+ me: true,
+ name: "dinosaur",
+ url: "http://localhost:4001/emoji/dino walking.gif",
+ account_ids: [other_user.id, user.id]
+ },
+ %{name: "🍵", count: 1, me: false, url: nil, account_ids: [third_user.id]}
]
end
|> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}})
activity = Activity.get_by_id(activity.id)
-
status = StatusView.render("show.json", activity: activity, for: user)
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 1, me: true}
+ %{name: "☕", count: 1, me: true, url: nil, account_ids: [user.id]}
]
end
status = StatusView.render("show.json", activity: activity)
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 1, me: false}
+ %{name: "☕", count: 1, me: false, url: nil, account_ids: [other_user.id]}
]
status = StatusView.render("show.json", activity: activity, for: user)
status = StatusView.render("show.json", activity: activity)
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 2, me: false}
+ %{
+ name: "☕",
+ count: 2,
+ me: false,
+ url: nil,
+ account_ids: [third_user.id, other_user.id]
+ }
]
status = StatusView.render("show.json", activity: activity, for: user)
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 1, me: false}
+ %{name: "☕", count: 1, me: false, url: nil, account_ids: [third_user.id]}
]
status = StatusView.render("show.json", activity: activity, for: other_user)
assert status[:pleroma][:emoji_reactions] == [
- %{name: "☕", count: 1, me: true}
+ %{name: "☕", count: 1, me: true, url: nil, account_ids: [other_user.id]}
]
end
object_data = Object.normalize(note, fetch: false).data
user = User.get_cached_by_ap_id(note.data["actor"])
- convo_id = Utils.context_to_conversation_id(object_data["context"])
+ convo_id = :erlang.crc32(object_data["context"]) |> Bitwise.band(Bitwise.bnot(0x8000_0000))
status = StatusView.render("show.json", %{activity: note})
content: HTML.filter_tags(object_data["content"]),
text: nil,
created_at: created_at,
+ edited_at: nil,
reblogs_count: 0,
replies_count: 0,
favourites_count: 0,
spoiler_text: HTML.filter_tags(object_data["summary"]),
visibility: "public",
media_attachments: [],
+ emoji_reactions: [],
mentions: [],
tags: [
%{
- name: "#{object_data["tag"]}",
- url: "http://localhost:4001/tag/#{object_data["tag"]}"
+ name: "#{hd(object_data["tag"])}",
+ url: "http://localhost:4001/tag/#{hd(object_data["tag"])}"
}
],
application: nil,
pleroma: %{
local: true,
conversation_id: convo_id,
+ context: object_data["context"],
in_reply_to_account_acct: nil,
content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
direct_conversation_id: nil,
thread_muted: false,
emoji_reactions: [],
- parent_visible: false
- }
+ parent_visible: false,
+ pinned_at: nil
+ },
+ akkoma: %{
+ source: HTML.filter_tags(object_data["content"])
+ },
+ quote_id: nil,
+ quote: nil
}
assert status == expected
assert status.in_reply_to_id == to_string(note.id)
end
+ test "a quote" do
+ note = insert(:note_activity)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "hehe", quote_id: note.id})
+
+ status = StatusView.render("show.json", %{activity: activity})
+
+ assert status.quote_id == to_string(note.id)
+
+ [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
+
+ assert status.quote_id == to_string(note.id)
+ end
+
+ test "a quote that we can't resolve" do
+ note = insert(:note_activity, quoteUri: "oopsie")
+
+ status = StatusView.render("show.json", %{activity: note})
+
+ assert is_nil(status.quote_id)
+ assert is_nil(status.quote)
+ end
+
+ test "a quote from a user we block" do
+ user = insert(:user)
+ other_user = insert(:user)
+ blocked_user = insert(:user)
+
+ {:ok, _relationship} = User.block(user, blocked_user)
+
+ {:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
+ {:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
+
+ status = StatusView.render("show.json", %{activity: quote_activity, for: user})
+ assert is_nil(status.quote)
+ end
+
+ test "a quote from a user we mute" do
+ user = insert(:user)
+ other_user = insert(:user)
+ blocked_user = insert(:user)
+
+ {:ok, _relationship} = User.mute(user, blocked_user)
+
+ {:ok, activity} = CommonAPI.post(blocked_user, %{status: ":< i am ANGERY"})
+ {:ok, quote_activity} = CommonAPI.post(other_user, %{status: "hehe", quote_id: activity.id})
+
+ status = StatusView.render("show.json", %{activity: quote_activity, for: user})
+ assert is_nil(status.quote)
+ end
+
test "contains mentions" do
user = insert(:user)
mentioned = insert(:user)
"url" => [
%{
"mediaType" => "image/png",
- "href" => "someurl"
+ "href" => "someurl",
+ "width" => 200,
+ "height" => 100
}
],
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
text_url: "someurl",
description: nil,
pleroma: %{mime_type: "image/png"},
+ meta: %{original: %{width: 200, height: 100, aspect: 2}},
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
}
status = StatusView.render("show.json", activity: visible, for: poster)
assert status.pleroma.parent_visible
end
+
+ test "it shows edited_at" do
+ poster = insert(:user)
+
+ {:ok, post} = CommonAPI.post(poster, %{status: "hey"})
+
+ status = StatusView.render("show.json", activity: post)
+ refute status.edited_at
+
+ {:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"})
+ edited = Pleroma.Activity.normalize(post)
+
+ status = StatusView.render("show.json", activity: edited)
+ assert status.edited_at
+ end
+
+ test "with a source object" do
+ note =
+ insert(:note,
+ data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
+ )
+
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("show.json", activity: activity, with_source: true)
+ assert status.text == "object source"
+ end
+
+ describe "source.json" do
+ test "with a source object, renders both source and content type" do
+ note =
+ insert(:note,
+ data: %{"source" => %{"content" => "object source", "mediaType" => "text/markdown"}}
+ )
+
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("source.json", activity: activity)
+ assert status.text == "object source"
+ assert status.content_type == "text/markdown"
+ end
+
+ test "with a source string, renders source and put text/plain as the content type" do
+ note = insert(:note, data: %{"source" => "string source"})
+ activity = insert(:note_activity, note: note)
+
+ status = StatusView.render("source.json", activity: activity)
+ assert status.text == "string source"
+ assert status.content_type == "text/plain"
+ end
+ end
end