forked from OpenGamers/abaddon
add mark all as read
This commit is contained in:
parent
9fd0d404a1
commit
145504bdd6
@ -940,6 +940,26 @@ void DiscordClient::UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordE
|
||||
});
|
||||
}
|
||||
|
||||
void DiscordClient::MarkAllAsRead(sigc::slot<void(DiscordError code)> callback) {
|
||||
AckBulkData data;
|
||||
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<void(std::vector<Message>, 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()) {
|
||||
|
@ -142,6 +142,7 @@ public:
|
||||
void MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordError code)> callback);
|
||||
void MuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
|
||||
void UnmuteChannel(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
|
||||
void MarkAllAsRead(sigc::slot<void(DiscordError code)> callback);
|
||||
|
||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const;
|
||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <type_traits>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#define NOOP_CALLBACK [](...) {}
|
||||
|
||||
namespace util {
|
||||
template<typename T>
|
||||
struct is_optional : ::std::false_type {};
|
||||
|
@ -47,10 +47,12 @@ MainWindow::MainWindow()
|
||||
m_menu_view_threads.set_label("Threads");
|
||||
m_menu_view_mark_guild_as_read.set_label("Mark Server as Read");
|
||||
m_menu_view_mark_guild_as_read.add_accelerator("activate", m_accels, GDK_KEY_Escape, Gdk::SHIFT_MASK, Gtk::ACCEL_VISIBLE);
|
||||
m_menu_view_mark_all_as_read.set_label("Mark All as Read");
|
||||
m_menu_view_sub.append(m_menu_view_friends);
|
||||
m_menu_view_sub.append(m_menu_view_pins);
|
||||
m_menu_view_sub.append(m_menu_view_threads);
|
||||
m_menu_view_sub.append(m_menu_view_mark_guild_as_read);
|
||||
m_menu_view_sub.append(m_menu_view_mark_all_as_read);
|
||||
m_menu_view_sub.signal_popped_up().connect(sigc::mem_fun(*this, &MainWindow::OnViewSubmenuPopup));
|
||||
|
||||
m_menu_bar.append(m_menu_file);
|
||||
@ -109,10 +111,14 @@ MainWindow::MainWindow()
|
||||
const auto channel_id = GetChatActiveChannel();
|
||||
const auto channel = discord.GetChannel(channel_id);
|
||||
if (channel.has_value() && channel->GuildID.has_value()) {
|
||||
discord.MarkGuildAsRead(*channel->GuildID, [](...) {});
|
||||
discord.MarkGuildAsRead(*channel->GuildID, NOOP_CALLBACK);
|
||||
}
|
||||
});
|
||||
|
||||
m_menu_view_mark_all_as_read.signal_activate().connect([this] {
|
||||
Abaddon::Get().GetDiscordClient().MarkAllAsRead(NOOP_CALLBACK);
|
||||
});
|
||||
|
||||
m_content_box.set_hexpand(true);
|
||||
m_content_box.set_vexpand(true);
|
||||
m_content_box.show();
|
||||
@ -262,13 +268,18 @@ void MainWindow::OnDiscordSubmenuPopup(const Gdk::Rectangle *flipped_rect, const
|
||||
}
|
||||
|
||||
void MainWindow::OnViewSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y) {
|
||||
m_menu_view_friends.set_sensitive(Abaddon::Get().GetDiscordClient().IsStarted());
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const bool discord_active = discord.IsStarted();
|
||||
|
||||
m_menu_view_friends.set_sensitive(discord_active);
|
||||
m_menu_view_mark_guild_as_read.set_sensitive(discord_active);
|
||||
m_menu_view_mark_all_as_read.set_sensitive(discord_active);
|
||||
|
||||
auto channel_id = GetChatActiveChannel();
|
||||
m_menu_view_pins.set_sensitive(false);
|
||||
m_menu_view_threads.set_sensitive(false);
|
||||
if (channel_id.IsValid()) {
|
||||
auto channel = Abaddon::Get().GetDiscordClient().GetChannel(channel_id);
|
||||
if (channel.has_value()) {
|
||||
if (auto channel = discord.GetChannel(channel_id); channel.has_value()) {
|
||||
m_menu_view_threads.set_sensitive(channel->Type == ChannelType::GUILD_TEXT || channel->IsThread());
|
||||
m_menu_view_pins.set_sensitive(channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM || channel->IsThread());
|
||||
}
|
||||
|
@ -98,5 +98,6 @@ protected:
|
||||
Gtk::MenuItem m_menu_view_pins;
|
||||
Gtk::MenuItem m_menu_view_threads;
|
||||
Gtk::MenuItem m_menu_view_mark_guild_as_read;
|
||||
Gtk::MenuItem m_menu_view_mark_all_as_read;
|
||||
void OnViewSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user