show count of unread dms in header

This commit is contained in:
ouwou
2022-01-08 20:03:12 -05:00
parent 4e0b22375f
commit 604f2ffe3d
4 changed files with 17 additions and 0 deletions

View File

@@ -770,6 +770,7 @@ void ChannelList::UpdateCreateDMChannel(const ChannelData &dm) {
void ChannelList::OnMessageAck(const MessageAckData &data) {
// trick renderer into redrawing
m_model->row_changed(Gtk::TreeModel::Path("0"), m_model->get_iter("0")); // 0 is always path for dm header
auto iter = GetIteratorForChannelFromID(data.ChannelID);
if (iter) m_model->row_changed(m_model->get_path(iter), iter);
auto channel = Abaddon::Get().GetDiscordClient().GetChannel(data.ChannelID);

View File

@@ -465,6 +465,13 @@ void CellRendererChannels::render_vfunc_dmheader(const Cairo::RefPtr<Cairo::Cont
cell_area.get_x() + 9, cell_area.get_y(), // maybe theres a better way to align this ?
cell_area.get_width(), cell_area.get_height());
m_renderer_text.render(cr, widget, background_area, text_cell_area, flags);
auto *paned = static_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type()));
if (paned != nullptr) {
const auto edge = std::min(paned->get_position(), background_area.get_width());
if (const auto unread = Abaddon::Get().GetDiscordClient().GetUnreadDMsCount(); unread > 0)
unread_render_mentions(cr, widget, unread, edge, background_area);
}
}
// dm (basically the same thing as guild)

View File

@@ -1202,6 +1202,14 @@ bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) co
return has_any_unread;
}
int DiscordClient::GetUnreadDMsCount() const {
const auto channels = GetPrivateChannels();
int count = 0;
for (const auto channel_id : channels)
if (GetUnreadStateForChannel(channel_id) > -1) count++;
return count;
}
PresenceStatus DiscordClient::GetUserStatus(Snowflake id) const {
auto it = m_user_to_status.find(id);
if (it != m_user_to_status.end())

View File

@@ -194,6 +194,7 @@ public:
bool IsGuildMuted(Snowflake id) const noexcept;
int GetUnreadStateForChannel(Snowflake id) const noexcept;
bool GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept;
int GetUnreadDMsCount() const;
PresenceStatus GetUserStatus(Snowflake id) const;