(** Typing notifications. *) type typing_request = { typing : bool; timeout : int option; } [@@warning "-69"] let typing_request_jsont = Jsont.Object.( map (fun typing timeout -> { typing; timeout }) |> mem "typing" Jsont.bool |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout) |> finish) let set_typing client ~room_id ~typing ?timeout () = match Client.user_id client with | None -> Error (Error.Network_error "Not logged in") | Some user_id -> let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in let user_id_str = Matrix_proto.Id.User_id.to_string user_id in let path = Printf.sprintf "/rooms/%s/typing/%s" (Uri.pct_encode room_id_str) (Uri.pct_encode user_id_str) in let request = { typing; timeout } in match Client.encode_body typing_request_jsont request with | Error e -> Error e | Ok body -> match Client.put client ~path ~body () with | Error e -> Error e | Ok _ -> Ok ()