wallet: force recent messages to always appear sequential

This commit is contained in:
darkfi
2024-09-25 10:44:04 +02:00
parent c9a24d0d07
commit d477a10f08

View File

@@ -62,6 +62,10 @@ const EVGRDB_PATH: &str = "~/.local/darkfi/darkwallet/evgr/";
const ENDPOINT: &str = "tcp://agorism.dev:5588";
const CHANNEL: &str = "#random";
/// Due to drift between different machine's clocks, if the message timestamp is recent
/// then we will just correct it to the current time so messages appear sequential in the UI.
const RECENT_TIME_DIST: u64 = 10;
#[derive(Clone, Debug, SerialEncodable, SerialDecodable)]
pub struct Privmsg {
pub channel: String,
@@ -320,6 +324,12 @@ impl LocalDarkIRC {
return Ok(())
}
// This is a hack to make messages appear sequentially in the UI
let now_timest = UNIX_EPOCH.elapsed().unwrap().as_millis() as u64;
if timest.abs_diff(now_timest) < RECENT_TIME_DIST {
timest = now_timest;
}
let mut arg_data = vec![];
timest.encode_async(&mut arg_data).await.unwrap();
ev.id().as_bytes().encode_async(&mut arg_data).await.unwrap();