aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-08-22 22:27:22 +0200
committerlain <lain@soykaf.club>2020-08-22 22:27:22 +0200
commit967856c784892fd1c7c88aee608931c29fcc5fff (patch)
treeba19458c83726b250f0f32e01ef00275237bd8f2
parentd49fdb315f4ea1a03e22063b14ba804104b8527b (diff)
downloadpleroma-967856c784892fd1c7c88aee608931c29fcc5fff.tar.gz
MatrixController: Actually set the read marker.
-rw-r--r--lib/pleroma/web/matrix_controller.ex9
-rw-r--r--test/web/matrix_controller_test.exs70
2 files changed, 54 insertions, 25 deletions
diff --git a/lib/pleroma/web/matrix_controller.ex b/lib/pleroma/web/matrix_controller.ex
index 00f27924d..23c776ca6 100644
--- a/lib/pleroma/web/matrix_controller.ex
+++ b/lib/pleroma/web/matrix_controller.ex
@@ -428,7 +428,14 @@ defmodule Pleroma.Web.MatrixController do
end
# Just pretend it worked
- def set_read_marker(conn, _) do
+ def set_read_marker(%{assigns: %{user: %{id: user_id}}} = conn, %{
+ "m.fully_read" => read_up_to,
+ "room_id" => chat_id
+ }) do
+ with %Chat{user_id: ^user_id} = chat <- Chat.get_by_id(chat_id) do
+ MessageReference.set_all_seen_for_chat(chat, read_up_to)
+ end
+
conn
|> json(%{})
end
diff --git a/test/web/matrix_controller_test.exs b/test/web/matrix_controller_test.exs
index ec35998f9..ec24855e0 100644
--- a/test/web/matrix_controller_test.exs
+++ b/test/web/matrix_controller_test.exs
@@ -11,38 +11,60 @@ defmodule Pleroma.Web.MatrixControllerTest do
alias Pleroma.Object
import Pleroma.Factory
- describe "sync" do
- setup do
- %{user: user, conn: conn} = oauth_access(["read"])
- other_user = insert(:user)
- third_user = insert(:user)
+ setup do
+ %{user: user, conn: conn} = oauth_access(["read"])
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, chat_activity} = CommonAPI.post_chat_message(user, other_user, "Hey")
+ {:ok, chat_activity_two} = CommonAPI.post_chat_message(third_user, user, "Henlo")
+
+ chat = Chat.get(user.id, other_user.ap_id)
+ chat_two = Chat.get(user.id, third_user.ap_id)
- {:ok, chat_activity} = CommonAPI.post_chat_message(user, other_user, "Hey")
- {:ok, chat_activity_two} = CommonAPI.post_chat_message(third_user, user, "Henlo")
+ chat_object = Object.normalize(chat_activity)
+ cmr = MessageReference.for_chat_and_object(chat, chat_object)
- chat = Chat.get(user.id, other_user.ap_id)
- chat_two = Chat.get(user.id, third_user.ap_id)
+ chat_object_two = Object.normalize(chat_activity_two)
+ cmr_two = MessageReference.for_chat_and_object(chat_two, chat_object_two)
+
+ %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user,
+ conn: conn,
+ chat_activity: chat_activity,
+ chat_activity_two: chat_activity_two,
+ chat: chat,
+ chat_two: chat_two,
+ cmr: cmr,
+ cmr_two: cmr_two
+ }
+ end
+ describe "setting read markers" do
+ test "it sets all messages up to a point as read", %{
+ conn: conn,
+ cmr: cmr,
+ chat: chat,
+ user: user,
+ other_user: other_user
+ } do
+ {:ok, chat_activity} = CommonAPI.post_chat_message(other_user, user, "morning weebs 2")
chat_object = Object.normalize(chat_activity)
- cmr = MessageReference.for_chat_and_object(chat, chat_object)
- chat_object_two = Object.normalize(chat_activity_two)
- cmr_two = MessageReference.for_chat_and_object(chat_two, chat_object_two)
+ conn
+ |> post("/_matrix/client/r0/rooms/#{chat.id}/read_markers", %{"m.fully_read": cmr.id})
- %{
- user: user,
- other_user: other_user,
- third_user: third_user,
- conn: conn,
- chat_activity: chat_activity,
- chat_activity_two: chat_activity_two,
- chat: chat,
- chat_two: chat_two,
- cmr: cmr,
- cmr_two: cmr_two
- }
+ cmr_two = MessageReference.for_chat_and_object(chat, chat_object)
+ assert cmr_two.unread
+
+ cmr = MessageReference.get_by_id(cmr.id)
+ refute cmr.unread
end
+ end
+ describe "sync" do
test "without options, it returns all chat messages the user has", %{
conn: conn,
chat: chat,