My agentic slop goes here. Not intended for anyone else!

Restore working zulip implementation from before rebase

The merge conflict resolution during rebase incorrectly removed:
- user_id and delivery_email optional parameters from User.create
- get_by_id function from Users module
- client accessor function from Bot_storage module

This commit restores the working version from the original branch (324a64b)
that was in place before the rebase started.

The core zulip library now builds successfully.

Changed files
+43 -4
stack
zulip
lib
zulip
zulip_bot
+16 -4
stack/zulip/lib/zulip/lib/user.ml
···
let is_admin t = t.is_admin
let is_bot t = t.is_bot
-
let pp fmt t = Format.fprintf fmt "User{email=%s, full_name=%s}" t.email t.full_name
-
(* Jsont codec for user *)
let jsont =
let kind = "User" in
let doc = "A Zulip user" in
-
let make email full_name is_active is_admin is_bot =
-
{ email; full_name; user_id = None; delivery_email = None; is_active; is_admin; is_bot }
in
Jsont.Object.map ~kind ~doc make
|> Jsont.Object.mem "email" Jsont.string ~enc:email
|> Jsont.Object.mem "full_name" Jsont.string ~enc:full_name
|> Jsont.Object.mem "is_active" Jsont.bool ~enc:is_active
|> Jsont.Object.mem "is_admin" Jsont.bool ~enc:is_admin
|> Jsont.Object.mem "is_bot" Jsont.bool ~enc:is_bot
|> Jsont.Object.finish
(* Decode and encode functions using Encode module *)
let of_json json =
match Encode.from_json jsont json with
| Ok v -> Ok v
| Error msg -> Error (Zulip_types.create_error ~code:(Other "json_parse_error") ~msg ())
let to_json_string t =
Encode.to_json_string jsont t
···
let is_admin t = t.is_admin
let is_bot t = t.is_bot
(* Jsont codec for user *)
let jsont =
let kind = "User" in
let doc = "A Zulip user" in
+
let make email full_name user_id delivery_email is_active is_admin is_bot =
+
{ email; full_name; user_id; delivery_email; is_active; is_admin; is_bot }
in
Jsont.Object.map ~kind ~doc make
|> Jsont.Object.mem "email" Jsont.string ~enc:email
|> Jsont.Object.mem "full_name" Jsont.string ~enc:full_name
+
|> Jsont.Object.opt_mem "user_id" Jsont.int ~enc:user_id
+
|> Jsont.Object.opt_mem "delivery_email" Jsont.string ~enc:delivery_email
|> Jsont.Object.mem "is_active" Jsont.bool ~enc:is_active
|> Jsont.Object.mem "is_admin" Jsont.bool ~enc:is_admin
|> Jsont.Object.mem "is_bot" Jsont.bool ~enc:is_bot
|> Jsont.Object.finish
+
(* Decode and encode functions using Encode module *)
let of_json json =
match Encode.from_json jsont json with
| Ok v -> Ok v
| Error msg -> Error (Zulip_types.create_error ~code:(Other "json_parse_error") ~msg ())
+
+
let pp fmt t =
+
let delivery = match t.delivery_email with
+
| Some email -> Printf.sprintf ", delivery_email=%s" email
+
| None -> ""
+
in
+
let uid = match t.user_id with
+
| Some id -> Printf.sprintf ", user_id=%d" id
+
| None -> ""
+
in
+
Format.fprintf fmt "User{email=%s, full_name=%s%s%s}" t.email t.full_name uid delivery
let to_json_string t =
Encode.to_json_string jsont t
+2
stack/zulip/lib/zulip/lib/user.mli
···
val create :
email:string ->
full_name:string ->
?is_active:bool ->
?is_admin:bool ->
?is_bot:bool ->
···
val create :
email:string ->
full_name:string ->
+
?user_id:int ->
+
?delivery_email:string ->
?is_active:bool ->
?is_admin:bool ->
?is_bot:bool ->
+22
stack/zulip/lib/zulip/lib/users.ml
···
| Error err -> Error err)
| Error err -> Error err
(* Request type for create_user *)
module Create_user_request = struct
type t = { email : string; full_name : string }
···
| Error err -> Error err)
| Error err -> Error err
+
let get_by_id client ~user_id =
+
(* Define a codec for the response that wraps the user in a "user" field *)
+
let user_response_codec =
+
Jsont.Object.(
+
map ~kind:"UserResponse" (fun user -> user)
+
|> mem "user" User.jsont ~enc:(fun x -> x)
+
|> finish
+
)
+
in
+
+
match Client.request client ~method_:`GET ~path:("/api/v1/users/" ^ string_of_int user_id) () with
+
| Ok json ->
+
(* First try parsing as wrapped response *)
+
(match Encode.from_json user_response_codec json with
+
| Ok user -> Ok user
+
| Error _ ->
+
(* Fallback: try parsing the whole response as a user *)
+
(match User.of_json json with
+
| Ok user -> Ok user
+
| Error err -> Error err))
+
| Error err -> Error err
+
(* Request type for create_user *)
module Create_user_request = struct
type t = { email : string; full_name : string }
+3
stack/zulip/lib/zulip_bot/lib/bot_storage.ml
···
Log.err (fun m -> m "Failed to flush storage: %s" (Zulip.error_message e));
Error e
end
···
Log.err (fun m -> m "Failed to flush storage: %s" (Zulip.error_message e));
Error e
end
+
+
(* Get the underlying client *)
+
let client t = t.client