)
end
+ def last_message_for_chat(chat) do
+ chat
+ |> for_chat_query()
+ |> limit(1)
+ |> Repo.one()
+ end
+
def create(chat, object, seen) do
params = %{
chat_id: chat.id,
use Pleroma.Web, :view
alias Pleroma.Activity
+ alias Pleroma.ChatMessageReference
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.NotificationView
alias Pleroma.Web.MastodonAPI.StatusView
- alias Pleroma.Web.PleromaAPI.ChatMessageView
+ alias Pleroma.Web.PleromaAPI.ChatMessageReferenceView
@parent_types ~w{Like Announce EmojiReact}
object = Object.normalize(activity)
author = User.get_cached_by_ap_id(object.data["actor"])
chat = Pleroma.Chat.get(reading_user.id, author.ap_id)
- render_opts = Map.merge(opts, %{object: object, for: reading_user, chat: chat})
- chat_message_render = ChatMessageView.render("show.json", render_opts)
+ cm_ref = ChatMessageReference.for_chat_and_object(chat, object)
+ render_opts = Map.merge(opts, %{for: reading_user, chat_message_reference: cm_ref})
+ chat_message_render = ChatMessageReferenceView.render("show.json", render_opts)
Map.put(response, :chat_message, chat_message_render)
end
use Pleroma.Web, :view
alias Pleroma.Chat
+ alias Pleroma.ChatMessageReference
alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
- alias Pleroma.Web.PleromaAPI.ChatMessageView
+ alias Pleroma.Web.PleromaAPI.ChatMessageReferenceView
def render("show.json", %{chat: %Chat{} = chat} = opts) do
recipient = User.get_cached_by_ap_id(chat.recipient)
- last_message = opts[:message] || Chat.last_message_for_chat(chat)
+ last_message = opts[:last_message] || ChatMessageReference.last_message_for_chat(chat)
%{
id: chat.id |> to_string(),
account: AccountView.render("show.json", Map.put(opts, :user, recipient)),
unread: chat.unread,
last_message:
- last_message && ChatMessageView.render("show.json", chat: chat, object: last_message),
+ last_message &&
+ ChatMessageReferenceView.render("show.json", chat_message_reference: last_message),
updated_at: Utils.to_masto_date(chat.updated_at)
}
end
alias Pleroma.Activity
alias Pleroma.Chat
+ alias Pleroma.ChatMessageReference
alias Pleroma.Conversation.Participation
alias Pleroma.Notification
alias Pleroma.User
def render("chat_update.json", object, user, recipients) do
chat = Chat.get(user.id, hd(recipients -- [user.ap_id]))
+ # Explicitly giving the cmr for the object here, so we don't accidentally
+ # send a later 'last_message' that was inserted between inserting this and
+ # streaming it out
+ cm_ref = ChatMessageReference.for_chat_and_object(chat, object)
+
representation =
Pleroma.Web.PleromaAPI.ChatView.render(
"show.json",
- %{message: object, chat: chat}
+ %{last_message: cm_ref, chat: chat}
)
%{
alias Pleroma.Activity
alias Pleroma.Chat
+ alias Pleroma.ChatMessageReference
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.NotificationView
alias Pleroma.Web.MastodonAPI.StatusView
- alias Pleroma.Web.PleromaAPI.ChatMessageView
+ alias Pleroma.Web.PleromaAPI.ChatMessageReferenceView
import Pleroma.Factory
defp test_notifications_rendering(notifications, user, expected_result) do
object = Object.normalize(activity)
chat = Chat.get(recipient.id, user.ap_id)
+ cm_ref = ChatMessageReference.for_chat_and_object(chat, object)
+
expected = %{
id: to_string(notification.id),
pleroma: %{is_seen: false},
type: "pleroma:chat_mention",
account: AccountView.render("show.json", %{user: user, for: recipient}),
chat_message:
- ChatMessageView.render("show.json", %{object: object, for: recipient, chat: chat}),
+ ChatMessageReferenceView.render("show.json", %{chat_message_reference: cm_ref}),
created_at: Utils.to_masto_date(notification.inserted_at)
}
use Pleroma.DataCase
alias Pleroma.Chat
+ alias Pleroma.ChatMessageReference
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
- alias Pleroma.Web.PleromaAPI.ChatMessageView
+ alias Pleroma.Web.PleromaAPI.ChatMessageReferenceView
alias Pleroma.Web.PleromaAPI.ChatView
import Pleroma.Factory
represented_chat = ChatView.render("show.json", chat: chat)
+ cm_ref = ChatMessageReference.for_chat_and_object(chat, chat_message)
+
assert represented_chat[:last_message] ==
- ChatMessageView.render("show.json", chat: chat, object: chat_message)
+ ChatMessageReferenceView.render("show.json", chat_message_reference: cm_ref)
end
end