diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-04-03 02:40:37 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-04-03 02:40:37 -0400 |
commit | 77b43f0f24540775228608d841379d349f2b1866 (patch) | |
tree | ea376943da8068a1772e546a58be864d1cc9db5f /discord/snowflake.cpp | |
parent | 88c91495c34ab75003807e563378fda5fe3f6e57 (diff) | |
download | abaddon-portaudio-77b43f0f24540775228608d841379d349f2b1866.tar.gz abaddon-portaudio-77b43f0f24540775228608d841379d349f2b1866.zip |
show pending/failed messages
css changes:
- added .failed
- added .pending
Diffstat (limited to 'discord/snowflake.cpp')
-rw-r--r-- | discord/snowflake.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
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 <ctime> #include <iomanip> +#include <chrono> + +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<uint64_t>(duration_cast<milliseconds>(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; } |