diff options
-rw-r--r-- | src/lib.rs | 29 | ||||
-rw-r--r-- | src/list.rs | 23 |
2 files changed, 37 insertions, 15 deletions
diff --git a/src/lib.rs b/src/lib.rs index 5f80c1c..ea0c8ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -406,7 +406,12 @@ pub use valid_context::ValidContext; #[derive(Clone)] pub struct EventAttrs<'a> { /// Server time. + #[deprecated(since="2.3.0", note="Use raw_server_time instead")] pub server_time: Option<SystemTime>, + /// Raw server time. Only does anything if `use_raw_server_time` is set. + pub raw_server_time: libc::time_t, + /// Whether to pass `server_time` or `raw_server_time` to hexchat. + pub use_raw_server_time: bool, _dummy: PhantomData<&'a ()>, } @@ -1589,18 +1594,25 @@ impl<'ph> PluginHandle<'ph> { impl<'a> EventAttrs<'a> { /// Creates a new `EventAttrs`. + #[allow(deprecated)] pub fn new() -> EventAttrs<'a> { EventAttrs { server_time: None, + raw_server_time: 0, + use_raw_server_time: false, _dummy: PhantomData, } } } impl<'a> From<&'a RawAttrs> for EventAttrs<'a> { + #[allow(deprecated)] fn from(other: &'a RawAttrs) -> EventAttrs<'a> { EventAttrs { server_time: if other.server_time_utc > 0 { Some(UNIX_EPOCH + Duration::from_secs(other.server_time_utc as u64)) } else { None }, + raw_server_time: other.server_time_utc, + // Defaults to false for API compatibility. + use_raw_server_time: false, _dummy: PhantomData, } } @@ -2106,10 +2118,19 @@ impl<'a, 'ph> HexchatEventAttrsHelper<'a, 'ph> where 'ph: 'a { /// `ph` must be a valid raw plugin handle. unsafe fn new_with(ph: &'a PluginHandle<'ph>, attrs: EventAttrs<'_>) -> Self { let helper = Self::new(ph); - let v = attrs.server_time.or(Some(UNIX_EPOCH)).map(|st| match st.duration_since(UNIX_EPOCH) { - Ok(n) => n.as_secs(), - Err(_) => 0 - }).filter(|&st| st < (time_t::max_value() as u64)).unwrap() as time_t; + #[allow(deprecated)] + let v = if attrs.use_raw_server_time { + attrs.raw_server_time + } else { + attrs.server_time.or(Some(UNIX_EPOCH)).map(|st| { + match st.duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => 0 + } + }).filter(|&st| { + st < (time_t::max_value() as u64) + }).unwrap() as time_t + }; (*helper.0).server_time_utc = v; helper } diff --git a/src/list.rs b/src/list.rs index d042d21..8a7c632 100644 --- a/src/list.rs +++ b/src/list.rs @@ -183,10 +183,11 @@ macro_rules! field_str { macro_rules! field_time { + ($(#[$m:meta])* $f:ident, unsafe { $n:expr }) => { + field!($(#[$m])* $f, unsafe { $n }, libc::time_t, ph, hexchat_list_time, r => r as libc::time_t); + }; ($(#[$m:meta])* $f:ident) => { - $(#[$m])* pub fn $f(&self) -> ! { - todo!() - } + field_time!($(#[$m])* $f, unsafe { ::std::concat!(::std::stringify!($f), "\0") }); }; } @@ -347,16 +348,16 @@ impl<'a, 'ph> Fields<'a, 'ph, Notify> { raw_flags, unsafe { "flags\0" } ); field_time!( - /// Time when the user went online. [NYI] - on + /// Time when the user went online. + raw_on, unsafe { "on\0" } ); field_time!( - /// Time when the user went offline. [NYI] - off + /// Time when the user went offline. + raw_off, unsafe { "off\0" } ); field_time!( - /// Time when the user was last seen. [NYI] - seen + /// Time when the user was last seen. + raw_seen, unsafe { "seen\0" } ); } @@ -371,8 +372,8 @@ impl<'a, 'ph> Fields<'a, 'ph, Users> { away ); field_time!( - /// Time when the user last talked. [NYI] - lasttalk + /// Time when the user last talked. + raw_lasttalk, unsafe { "lasttalk\0" } ); field_str!( /// User's nick. |