From 77b43f0f24540775228608d841379d349f2b1866 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 3 Apr 2021 02:40:37 -0400 Subject: show pending/failed messages css changes: - added .failed - added .pending --- discord/snowflake.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'discord/snowflake.cpp') diff --git a/discord/snowflake.cpp b/discord/snowflake.cpp index 70dee2e..595f87c 100644 --- a/discord/snowflake.cpp +++ b/discord/snowflake.cpp @@ -1,6 +1,9 @@ #include "snowflake.hpp" #include #include +#include + +constexpr static uint64_t DiscordEpochSeconds = 1420070400; Snowflake::Snowflake() : m_num(Invalid) {} @@ -21,6 +24,18 @@ Snowflake::Snowflake(const Glib::ustring &str) { m_num = Invalid; }; +Snowflake Snowflake::FromNow() { + using namespace std::chrono; + // not guaranteed to work but it probably will anyway + static uint64_t counter = 0; + const auto millis_since_epoch = static_cast(duration_cast(system_clock::now().time_since_epoch()).count()); + const auto epoch = millis_since_epoch - DiscordEpochSeconds * 1000; + uint64_t snowflake = epoch << 22; + // worker id and process id would be OR'd in here but there's no point + snowflake |= counter++ % 4096; + return snowflake; +} + bool Snowflake::IsValid() const { return m_num != Invalid; } -- cgit v1.2.3