Matrix protocol in OCaml, Eio specialised
1(** Typing notifications. *)
2
3type typing_request = {
4 typing : bool;
5 timeout : int option;
6} [@@warning "-69"]
7
8let typing_request_jsont =
9 Jsont.Object.(
10 map (fun typing timeout -> { typing; timeout })
11 |> mem "typing" Jsont.bool
12 |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout)
13 |> finish)
14
15let set_typing client ~room_id ~typing ?timeout () =
16 match Client.user_id client with
17 | None -> Error (Error.Network_error "Not logged in")
18 | Some user_id ->
19 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in
20 let user_id_str = Matrix_proto.Id.User_id.to_string user_id in
21 let path = Printf.sprintf "/rooms/%s/typing/%s"
22 (Uri.pct_encode room_id_str)
23 (Uri.pct_encode user_id_str)
24 in
25 let request = { typing; timeout } in
26 match Client.encode_body typing_request_jsont request with
27 | Error e -> Error e
28 | Ok body ->
29 match Client.put client ~path ~body () with
30 | Error e -> Error e
31 | Ok _ -> Ok ()