mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-23 17:54:22 +00:00
ChatMessageReferenceView: Display preview cards.
This commit is contained in:
parent
873ff5ce14
commit
781b270863
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
|
||||||
%{
|
%{
|
||||||
chat_message_reference: %{
|
chat_message_reference: %{
|
||||||
id: id,
|
id: id,
|
||||||
object: %{data: chat_message},
|
object: %{data: chat_message} = object,
|
||||||
chat_id: chat_id,
|
chat_id: chat_id,
|
||||||
unread: unread
|
unread: unread
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,12 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do
|
||||||
attachment:
|
attachment:
|
||||||
chat_message["attachment"] &&
|
chat_message["attachment"] &&
|
||||||
StatusView.render("attachment.json", attachment: chat_message["attachment"]),
|
StatusView.render("attachment.json", attachment: chat_message["attachment"]),
|
||||||
unread: unread
|
unread: unread,
|
||||||
|
card:
|
||||||
|
StatusView.render(
|
||||||
|
"card.json",
|
||||||
|
Pleroma.Web.RichMedia.Helpers.fetch_data_for_object(object)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,11 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
|> hd
|
|> hd
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
def fetch_data_for_object(object) do
|
||||||
with true <- Config.get([:rich_media, :enabled]),
|
with true <- Config.get([:rich_media, :enabled]),
|
||||||
%Object{} = object <- Object.normalize(activity),
|
|
||||||
false <- object.data["sensitive"] || false,
|
false <- object.data["sensitive"] || false,
|
||||||
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
|
{:ok, page_url} <-
|
||||||
|
HTML.extract_first_external_url(object, object.data["content"]),
|
||||||
:ok <- validate_page_url(page_url),
|
:ok <- validate_page_url(page_url),
|
||||||
{:ok, rich_media} <- Parser.parse(page_url) do
|
{:ok, rich_media} <- Parser.parse(page_url) do
|
||||||
%{page_url: page_url, rich_media: rich_media}
|
%{page_url: page_url, rich_media: rich_media}
|
||||||
|
@ -62,6 +62,15 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
|
||||||
|
with true <- Config.get([:rich_media, :enabled]),
|
||||||
|
%Object{} = object <- Object.normalize(activity) do
|
||||||
|
fetch_data_for_object(object)
|
||||||
|
else
|
||||||
|
_ -> %{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def fetch_data_for_activity(_), do: %{}
|
def fetch_data_for_activity(_), do: %{}
|
||||||
|
|
||||||
def perform(:fetch, %Activity{} = activity) do
|
def perform(:fetch, %Activity{} = activity) do
|
||||||
|
|
|
@ -43,7 +43,17 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceViewTest do
|
||||||
assert chat_message[:unread] == false
|
assert chat_message[:unread] == false
|
||||||
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post_chat_message(recipient, user, "gkgkgk", media_id: upload.id)
|
clear_config([:rich_media, :enabled], true)
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{url: "https://example.com/ogp"} ->
|
||||||
|
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post_chat_message(recipient, user, "gkgkgk https://example.com/ogp",
|
||||||
|
media_id: upload.id
|
||||||
|
)
|
||||||
|
|
||||||
object = Object.normalize(activity)
|
object = Object.normalize(activity)
|
||||||
|
|
||||||
|
@ -52,10 +62,11 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceViewTest do
|
||||||
chat_message_two = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
chat_message_two = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
||||||
|
|
||||||
assert chat_message_two[:id] == cm_ref.id
|
assert chat_message_two[:id] == cm_ref.id
|
||||||
assert chat_message_two[:content] == "gkgkgk"
|
assert chat_message_two[:content] == object.data["content"]
|
||||||
assert chat_message_two[:account_id] == recipient.id
|
assert chat_message_two[:account_id] == recipient.id
|
||||||
assert chat_message_two[:chat_id] == chat_message[:chat_id]
|
assert chat_message_two[:chat_id] == chat_message[:chat_id]
|
||||||
assert chat_message_two[:attachment]
|
assert chat_message_two[:attachment]
|
||||||
assert chat_message_two[:unread] == true
|
assert chat_message_two[:unread] == true
|
||||||
|
assert chat_message_two[:card]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue