mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
Use SystemTime instead of i64
This clarifies some behaviour with negative times and propagates errors a bit better around places.
This commit is contained in:
@@ -20,6 +20,7 @@ use std::fmt::Write;
|
||||
use std::ptr;
|
||||
use std::str::FromStr;
|
||||
use std::sync::RwLock;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use libc::uintptr_t;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
@@ -34,9 +35,6 @@ use deltachat::message::MsgId;
|
||||
use deltachat::stock::StockMessage;
|
||||
use deltachat::*;
|
||||
|
||||
mod tools;
|
||||
use crate::tools::time;
|
||||
|
||||
mod dc_array;
|
||||
|
||||
mod string;
|
||||
@@ -1421,14 +1419,18 @@ pub unsafe extern "C" fn dc_set_chat_mute_duration(
|
||||
eprintln!("ignoring careless call to dc_set_chat_mute_duration()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ffi_context = &*context;
|
||||
let muteDuration = match duration {
|
||||
0 => MuteDuration::NotMuted,
|
||||
-1 => MuteDuration::Forever,
|
||||
_ => MuteDuration::Until(time() + duration),
|
||||
n if n > 0 => MuteDuration::Until(SystemTime::now() + Duration::from_secs(duration as u64)),
|
||||
_ => {
|
||||
ffi_context.warning(
|
||||
"dc_chat_set_mute_duration(): Can not use negative duration other than -1",
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
let ffi_context = &*context;
|
||||
ffi_context
|
||||
.with_inner(|ctx| {
|
||||
chat::set_muted(ctx, ChatId::new(chat_id), muteDuration)
|
||||
@@ -2532,10 +2534,14 @@ pub unsafe extern "C" fn dc_chat_get_remaining_mute_duration(chat: *mut dc_chat_
|
||||
if !ffi_chat.chat.is_muted() {
|
||||
return 0;
|
||||
}
|
||||
// If the chat was muted to before the epoch, it is not muted.
|
||||
match ffi_chat.chat.mute_duration {
|
||||
MuteDuration::NotMuted => 0,
|
||||
MuteDuration::Forever => -1,
|
||||
MuteDuration::Until(timestamp) => timestamp - time(),
|
||||
MuteDuration::Until(when) => when
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.map(|d| d.as_secs() as i64)
|
||||
.unwrap_or(0),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub(crate) fn time() -> i64 {
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs() as i64
|
||||
}
|
||||
Reference in New Issue
Block a user