From d638ba288777639012674faf1ef509fa49c37eb6 Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 19 Jul 2022 17:04:44 +0200 Subject: [PATCH] Get last possible Msg id --- src/euph/api/types.rs | 5 +++++ src/logger.rs | 4 ++++ src/store.rs | 2 ++ src/vault/euph.rs | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/src/euph/api/types.rs b/src/euph/api/types.rs index 9615167..de050fb 100644 --- a/src/euph/api/types.rs +++ b/src/euph/api/types.rs @@ -284,6 +284,11 @@ pub struct SessionView { #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Snowflake(pub u64); +impl Snowflake { + pub const MIN: Self = Snowflake(u64::MIN); + pub const MAX: Self = Snowflake(u64::MAX); +} + impl Serialize for Snowflake { fn serialize(&self, serializer: S) -> Result { // Convert u64 to base36 string diff --git a/src/logger.rs b/src/logger.rs index 4913b6f..fe0aa91 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -49,6 +49,10 @@ impl Msg for LogMsg { fn content(&self) -> Styled { Styled::new(&self.content) } + + fn last_possible_id() -> Self::Id { + Self::Id::MAX + } } #[derive(Debug, Clone)] diff --git a/src/store.rs b/src/store.rs index 89f757f..a5e312f 100644 --- a/src/store.rs +++ b/src/store.rs @@ -14,6 +14,8 @@ pub trait Msg { fn time(&self) -> DateTime; fn nick(&self) -> Styled; fn content(&self) -> Styled; + + fn last_possible_id() -> Self::Id; } #[derive(PartialEq, Eq, PartialOrd, Ord)] diff --git a/src/vault/euph.rs b/src/vault/euph.rs index 69197f1..ea8cb95 100644 --- a/src/vault/euph.rs +++ b/src/vault/euph.rs @@ -70,6 +70,10 @@ impl Msg for EuphMsg { fn content(&self) -> Styled { self.content.trim().into() } + + fn last_possible_id() -> Self::Id { + Snowflake::MAX + } } impl From for Request {