diff options
author | multi prise <korokoko.toi@gmail.com> | 2020-12-26 22:46:17 +0000 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-12-26 22:46:17 +0000 |
commit | d3f257a3a3399361a0bb48cbfa1b1cfcba447e61 (patch) | |
tree | ee4a68d05956f0188aa28c6e74bb6fd8c9337897 /lib | |
parent | release 0.3.1 (diff) |
wrote functions
corrected the tests
Diffstat (limited to 'lib')
-rw-r--r-- | lib/polyjuice/client/endpoint/post_rooms_read_markers.ex | 68 | ||||
-rw-r--r-- | lib/polyjuice/client/room.ex | 28 |
2 files changed, 96 insertions, 0 deletions
diff --git a/lib/polyjuice/client/endpoint/post_rooms_read_markers.ex b/lib/polyjuice/client/endpoint/post_rooms_read_markers.ex new file mode 100644 index 0000000..420e293 --- /dev/null +++ b/lib/polyjuice/client/endpoint/post_rooms_read_markers.ex @@ -0,0 +1,68 @@ +# Copyright 2020 Multi Prise <multiestunhappydev@gmail.com> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule Polyjuice.Client.Endpoint.PostRoomsReadMarkers do + @moduledoc """ + Sets the position of the read marker for a given room, and optionally the read receipt's location. + https://matrix.org/docs/spec/client_server/r0.5.0#post-matrix-client-r0-rooms-roomid-read-markers + """ + + @type t :: %__MODULE__{ + room: String.t(), + fully_read: String.t(), + read: String.t() | nil + } + + @enforce_keys [:room, :fully_read] + + defstruct [ + :room, + :fully_read, + :read + ] + + defimpl Polyjuice.Client.Endpoint.Proto do + def http_spec(%Polyjuice.Client.Endpoint.PostRoomsReadMarkers{ + room: room, + fully_read: fully_read, + read: read + }) do + e = &URI.encode_www_form/1 + + query = + case read do + nil -> %{"m.fully_read": fully_read} + _ -> %{"m.fully_read": fully_read, "m.read": read} + end + + {:ok, body} = query |> Jason.encode() + + Polyjuice.Client.Endpoint.HttpSpec.post( + :r0, + "rooms/#{e.(room)}/read_markers", + body: body + ) + end + + def transform_http_result(req, status_code, resp_headers, body) do + Polyjuice.Client.Endpoint.parse_response(req, status_code, resp_headers, body) + end + end + + defimpl Polyjuice.Client.Endpoint.BodyParser do + def parse(_req, _body) do + :ok + end + end +end diff --git a/lib/polyjuice/client/room.ex b/lib/polyjuice/client/room.ex index 62009f9..7435244 100644 --- a/lib/polyjuice/client/room.ex +++ b/lib/polyjuice/client/room.ex @@ -334,4 +334,32 @@ defmodule Polyjuice.Client.Room do } ) end + + @doc """ + Set up the read receipt marker positions for a given room + The history for a given room may be split into three sections: + messages the user has read (or indicated they aren't interested in them), + messages the user might have read some but not others, and messages the user hasn't seen yet. + The "fully read marker" (also known as a "read marker") marks the last event of the first section, + whereas the user's read receipt marks the last event of the second section. + it takes: + `fully_read`: the event id the read marker should be located at + `read`: the event id the to which the read receipt should be be up to + """ + @spec update_read_markers( + client_api :: Polyjuice.Client.API.t(), + room :: String.t(), + fully_read :: String.t(), + read :: String.t() | nil + ) :: {:ok} | any + def update_read_markers(client_api, room, fully_read, read \\ nil) do + Polyjuice.Client.API.call( + client_api, + %Polyjuice.Client.Endpoint.PostRoomsReadMarkers{ + room: room, + fully_read: fully_read, + read: read + } + ) + end end |