From d288989386acbade608fd02da7f078a99efa8578 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 6 Dec 2021 03:04:22 -0500 Subject: mark guild as read --- src/discord/discord.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/discord/discord.cpp') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 27d162c..09463b8 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -874,7 +874,7 @@ void DiscordClient::UnArchiveThread(Snowflake channel_id, sigc::slot callback) { +void DiscordClient::MarkChannelAsRead(Snowflake channel_id, sigc::slot callback) { if (m_unread.find(channel_id) == m_unread.end()) return; const auto iter = m_last_message_id.find(channel_id); if (iter == m_last_message_id.end()) return; @@ -886,6 +886,27 @@ void DiscordClient::MarkAsRead(Snowflake channel_id, sigc::slot callback) { + AckBulkData data; + const auto channels = GetChannelsInGuild(guild_id); + for (const auto &[unread, mention_count] : m_unread) { + const auto iter = m_last_message_id.find(unread); + if (iter == m_last_message_id.end()) continue; + auto &e = data.ReadStates.emplace_back(); + e.ID = unread; + e.LastMessageID = iter->second; + } + + if (data.ReadStates.empty()) return; + + m_http.MakePOST("/read-states/ack-bulk", nlohmann::json(data).dump(), [this, callback](const http::response_type &response) { + if (CheckCode(response)) + callback(DiscordError::NONE); + else + callback(GetCodeFromResponse(response)); + }); +} + void DiscordClient::FetchPinned(Snowflake id, sigc::slot, DiscordError code)> callback) { // return from db if we know the pins have already been requested if (m_channels_pinned_requested.find(id) != m_channels_pinned_requested.end()) { -- cgit v1.2.3