mark guild as read

This commit is contained in:
ouwou 2021-12-06 03:04:22 -05:00
parent d63941797f
commit d288989386
6 changed files with 48 additions and 4 deletions

View File

@ -13,6 +13,7 @@ ChannelList::ChannelList()
, m_menu_guild_copy_id("_Copy ID", true)
, m_menu_guild_settings("View _Settings", true)
, m_menu_guild_leave("_Leave", true)
, m_menu_guild_mark_as_read("Mark as _Read", true)
, m_menu_category_copy_id("_Copy ID", true)
, m_menu_channel_copy_id("_Copy ID", true)
, m_menu_channel_mark_as_read("Mark as _Read", true)
@ -43,7 +44,7 @@ ChannelList::ChannelList()
if (type == RenderType::TextChannel || type == RenderType::DM || type == RenderType::Thread) {
const auto id = static_cast<Snowflake>(row[m_columns.m_id]);
m_signal_action_channel_item_select.emit(id);
Abaddon::Get().GetDiscordClient().MarkAsRead(id, [](...) {});
Abaddon::Get().GetDiscordClient().MarkChannelAsRead(id, [](...) {});
}
};
m_view.signal_row_activated().connect(cb, false);
@ -94,9 +95,13 @@ ChannelList::ChannelList()
m_menu_guild_leave.signal_activate().connect([this] {
m_signal_action_guild_leave.emit(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]));
});
m_menu_guild_mark_as_read.signal_activate().connect([this] {
Abaddon::Get().GetDiscordClient().MarkGuildAsRead(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {});
});
m_menu_guild.append(m_menu_guild_copy_id);
m_menu_guild.append(m_menu_guild_settings);
m_menu_guild.append(m_menu_guild_leave);
m_menu_guild.append(m_menu_guild_mark_as_read);
m_menu_guild.show_all();
m_menu_category_copy_id.signal_activate().connect([this] {
@ -110,7 +115,7 @@ ChannelList::ChannelList()
Gtk::Clipboard::get()->set_text(std::to_string((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]));
});
m_menu_channel_mark_as_read.signal_activate().connect([this] {
Abaddon::Get().GetDiscordClient().MarkAsRead(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {});
Abaddon::Get().GetDiscordClient().MarkChannelAsRead(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), [](...) {});
});
m_menu_channel.append(m_menu_channel_copy_id);
m_menu_channel.append(m_menu_channel_mark_as_read);

View File

@ -101,6 +101,7 @@ protected:
Gtk::MenuItem m_menu_guild_copy_id;
Gtk::MenuItem m_menu_guild_settings;
Gtk::MenuItem m_menu_guild_leave;
Gtk::MenuItem m_menu_guild_mark_as_read;
Gtk::Menu m_menu_category;
Gtk::MenuItem m_menu_category_copy_id;

View File

@ -874,7 +874,7 @@ void DiscordClient::UnArchiveThread(Snowflake channel_id, sigc::slot<void(Discor
});
}
void DiscordClient::MarkAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback) {
void DiscordClient::MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> 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<void(DiscordErro
});
}
void DiscordClient::MarkGuildAsRead(Snowflake guild_id, sigc::slot<void(DiscordError code)> 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<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()) {

View File

@ -138,7 +138,8 @@ public:
void LeaveThread(Snowflake channel_id, const std::string &location, sigc::slot<void(DiscordError code)> callback);
void ArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void UnArchiveThread(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void MarkAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void MarkChannelAsRead(Snowflake channel_id, sigc::slot<void(DiscordError code)> callback);
void MarkGuildAsRead(Snowflake guild_id, 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;

View File

@ -125,6 +125,11 @@ void from_json(const nlohmann::json &j, ReadStateEntry &m) {
JS_D("id", m.ID);
}
void to_json(nlohmann::json &j, const ReadStateEntry &m) {
j["channel_id"] = m.ID;
j["message_id"] = m.LastMessageID;
}
void from_json(const nlohmann::json &j, ReadStateData &m) {
JS_ON("version", m.Version);
JS_ON("partial", m.IsPartial);
@ -551,3 +556,7 @@ void from_json(const nlohmann::json &j, MessageAckData &m) {
JS_D("message_id", m.MessageID);
JS_D("channel_id", m.ChannelID);
}
void to_json(nlohmann::json &j, const AckBulkData &m) {
j["read_states"] = m.ReadStates;
}

View File

@ -232,6 +232,7 @@ struct ReadStateEntry {
// std::string LastPinTimestamp; iso
friend void from_json(const nlohmann::json &j, ReadStateEntry &m);
friend void to_json(nlohmann::json &j, const ReadStateEntry &m);
};
struct ReadStateData {
@ -772,3 +773,9 @@ struct MessageAckData {
friend void from_json(const nlohmann::json &j, MessageAckData &m);
};
struct AckBulkData {
std::vector<ReadStateEntry> ReadStates;
friend void to_json(nlohmann::json &j, const AckBulkData &m);
};