record and display topic who + time
This commit is contained in:
parent
6fdd47cd12
commit
34bc83e12b
|
@ -3,16 +3,15 @@ include Router_types
|
|||
|
||||
type t = chan
|
||||
|
||||
let make ?creation_time name =
|
||||
let creation_time = match creation_time with
|
||||
let value_or_now = function
|
||||
| None -> Ptime_clock.now ()
|
||||
| Some ts -> ts
|
||||
in
|
||||
{
|
||||
|
||||
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
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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 *)
|
||||
|
|
Loading…
Reference in New Issue