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
|
type t = chan
|
||||||
|
|
||||||
let make ?creation_time name =
|
let value_or_now = function
|
||||||
let creation_time = match creation_time with
|
|
||||||
| None -> Ptime_clock.now ()
|
| None -> Ptime_clock.now ()
|
||||||
| Some ts -> ts
|
| Some ts -> ts
|
||||||
in
|
|
||||||
{
|
let make ?time name = {
|
||||||
name;
|
name;
|
||||||
name_key = string_ci name;
|
name_key = string_ci name;
|
||||||
creation_time;
|
creation_time = value_or_now time;
|
||||||
topic = None;
|
topic = None, None;
|
||||||
members = Dllist.create ();
|
members = Dllist.create ();
|
||||||
member_count = 0;
|
member_count = 0;
|
||||||
chan_mode = Mode.Set.empty;
|
chan_mode = Mode.Set.empty;
|
||||||
|
@ -22,8 +21,9 @@ let make ?creation_time name =
|
||||||
|
|
||||||
let name t = t.name
|
let name t = t.name
|
||||||
let creation_time t = t.creation_time
|
let creation_time t = t.creation_time
|
||||||
let topic t = t.topic
|
let topic t = fst t.topic
|
||||||
let set_topic t s = t.topic <- s
|
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 mode t = t.chan_mode
|
||||||
let set_mode t new_mode = t.chan_mode <- new_mode
|
let set_mode t new_mode = t.chan_mode <- new_mode
|
||||||
let limit t = t.chan_limit
|
let limit t = t.chan_limit
|
||||||
|
|
|
@ -386,14 +386,23 @@ let on_msg_names t name =
|
||||||
list_names t me chan;
|
list_names t me chan;
|
||||||
Ok ()
|
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 =
|
let get_topic ?(reply_if_missing=true) t chan =
|
||||||
match Chan.topic chan with
|
match Chan.topic chan with
|
||||||
| Some topic ->
|
| Some topic ->
|
||||||
reply t ("332", [Chan.name chan; topic])
|
reply t ("332", [Chan.name chan; topic]);
|
||||||
(* TODO: RPL_TOPICWHOTIME ? *)
|
get_topic_who_time t chan
|
||||||
| None ->
|
| None ->
|
||||||
if reply_if_missing then
|
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 =
|
let set_topic chan topic =
|
||||||
Chan.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 topic = String.concat " " args in
|
||||||
let msg = Msg.make "TOPIC" [Chan.name chan; topic] ~always_trailing:true in
|
let msg = Msg.make "TOPIC" [Chan.name chan; topic] ~always_trailing:true in
|
||||||
Router.relay msg ~from:me [`to_chan chan; `to_self];
|
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 ()
|
Ok ()
|
||||||
|
|
||||||
let join t user chan =
|
let join t user chan =
|
||||||
|
|
|
@ -17,7 +17,7 @@ and chan = {
|
||||||
name : name;
|
name : name;
|
||||||
name_key : string_ci;
|
name_key : string_ci;
|
||||||
creation_time : Ptime.t;
|
creation_time : Ptime.t;
|
||||||
mutable topic : string option;
|
mutable topic : string option * (name * Ptime.t) option;
|
||||||
mutable members : membership Dllist.t;
|
mutable members : membership Dllist.t;
|
||||||
mutable member_count : int;
|
mutable member_count : int;
|
||||||
mutable chan_mode : Mode.Set.t; (* +imstn *)
|
mutable chan_mode : Mode.Set.t; (* +imstn *)
|
||||||
|
|
Loading…
Reference in New Issue