From 34bc83e12bfa9cfc9f4838c3c8f98cb71c3deb8c Mon Sep 17 00:00:00 2001 From: tali Date: Wed, 31 Jan 2024 16:54:22 -0500 Subject: [PATCH] record and display topic who + time --- lib/server/chan.ml | 20 ++++++++++---------- lib/server/connection.ml | 18 ++++++++++++++---- lib/server/router_types.ml | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/server/chan.ml b/lib/server/chan.ml index a2f7aeb..135f43d 100644 --- a/lib/server/chan.ml +++ b/lib/server/chan.ml @@ -3,16 +3,15 @@ include Router_types type t = chan -let make ?creation_time name = - let creation_time = match creation_time with - | None -> Ptime_clock.now () - | Some ts -> ts - in - { +let value_or_now = function + | None -> Ptime_clock.now () + | Some ts -> ts + +let make ?time name = { name; name_key = string_ci name; - creation_time; - topic = None; + creation_time = value_or_now time; + topic = None, None; members = Dllist.create (); member_count = 0; chan_mode = Mode.Set.empty; @@ -22,8 +21,9 @@ let make ?creation_time name = let name t = t.name let creation_time t = t.creation_time -let topic t = t.topic -let set_topic t s = t.topic <- s +let topic t = fst t.topic +let topic_who_time t = snd t.topic +let set_topic ~who ?time t text = t.topic <- text, Some (who, value_or_now time) let mode t = t.chan_mode let set_mode t new_mode = t.chan_mode <- new_mode let limit t = t.chan_limit diff --git a/lib/server/connection.ml b/lib/server/connection.ml index ec51efb..0e7efd1 100644 --- a/lib/server/connection.ml +++ b/lib/server/connection.ml @@ -386,14 +386,23 @@ let on_msg_names t name = list_names t me chan; Ok () +let get_topic_who_time t chan = + Option.iter + (fun (who, time) -> + reply t ("333", [Chan.name chan; who; Fmt.str "%a" pp_unixtime time])) + (Chan.topic_who_time chan) + let get_topic ?(reply_if_missing=true) t chan = match Chan.topic chan with | Some topic -> - reply t ("332", [Chan.name chan; topic]) - (* TODO: RPL_TOPICWHOTIME ? *) + reply t ("332", [Chan.name chan; topic]); + get_topic_who_time t chan | None -> if reply_if_missing then - reply t ("331", [Chan.name chan; "No topic is set"]) + begin + reply t ("331", [Chan.name chan; "No topic is set"]); + get_topic_who_time t chan + end let set_topic chan topic = Chan.set_topic chan topic @@ -421,7 +430,8 @@ let on_msg_topic t name args = let topic = String.concat " " args in let msg = Msg.make "TOPIC" [Chan.name chan; topic] ~always_trailing:true in Router.relay msg ~from:me [`to_chan chan; `to_self]; - set_topic chan (if args = [""] then None else Some topic); + set_topic chan (if args = [""] then None else Some topic) + ~who:(User.nick me); Ok () let join t user chan = diff --git a/lib/server/router_types.ml b/lib/server/router_types.ml index 6f9c0a8..c87fe83 100644 --- a/lib/server/router_types.ml +++ b/lib/server/router_types.ml @@ -17,7 +17,7 @@ and chan = { name : name; name_key : string_ci; creation_time : Ptime.t; - mutable topic : string option; + mutable topic : string option * (name * Ptime.t) option; mutable members : membership Dllist.t; mutable member_count : int; mutable chan_mode : Mode.Set.t; (* +imstn *)