rudimentary guild unread indicator

This commit is contained in:
ouwou 2021-12-09 02:54:59 -05:00
parent bcfb2146cd
commit 511fb445d1
4 changed files with 35 additions and 5 deletions

View File

@ -701,6 +701,11 @@ void ChannelList::OnMessageAck(const MessageAckData &data) {
// trick renderer into redrawing
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);
if (channel.has_value() && channel->GuildID.has_value()) {
iter = GetIteratorForGuildFromID(*channel->GuildID);
if (iter) m_model->row_changed(m_model->get_path(iter), iter);
}
}
void ChannelList::OnMessageCreate(const Message &msg) {

View File

@ -198,7 +198,7 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context
const double icon_w = pixbuf_w;
const double icon_h = pixbuf_h;
const double icon_x = background_area.get_x();
const double icon_x = background_area.get_x() + 3;
const double icon_y = background_area.get_y() + background_area.get_height() / 2.0 - icon_h / 2.0;
const double text_x = icon_x + icon_w + 5.0;
@ -239,6 +239,8 @@ void CellRendererChannels::render_vfunc_guild(const Cairo::RefPtr<Cairo::Context
cr->rectangle(icon_x, icon_y, icon_w, icon_h);
cr->fill();
}
UnreadRenderer::RenderUnreadOnGuild(m_property_id.get_value(), cr, background_area, cell_area);
}
// category

View File

@ -1,14 +1,36 @@
#include "unreadrenderer.hpp"
#include "abaddon.hpp"
void UnreadRenderer::RenderUnreadOnGuild(Snowflake id, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area) {
// maybe have DiscordClient track this?
auto &discord = Abaddon::Get().GetDiscordClient();
const auto channels = discord.GetChannelsInGuild(id);
bool has_unread = false;
for (const auto &id : channels) {
if (Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id) >= 0) {
has_unread = true;
break;
}
}
if (!has_unread) return;
cr->set_source_rgb(1.0, 1.0, 1.0);
const auto x = background_area.get_x();
const auto y = background_area.get_y();
const auto w = background_area.get_width();
const auto h = background_area.get_height();
cr->rectangle(x, y + h / 2 - 24 / 2, 3, 24);
cr->fill();
}
void UnreadRenderer::RenderUnreadOnChannel(Snowflake id, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area) {
const auto state = Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id);
if (state >= 0) {
cr->set_source_rgb(1.0, 1.0, 1.0);
const auto x = cell_area.get_x() + 1;
const auto y = cell_area.get_y();
const auto w = cell_area.get_width();
const auto h = cell_area.get_height();
const auto x = background_area.get_x();
const auto y = background_area.get_y();
const auto w = background_area.get_width();
const auto h = background_area.get_height();
cr->rectangle(x, y, 3, h);
cr->fill();
}

View File

@ -5,5 +5,6 @@
class UnreadRenderer {
public:
static void RenderUnreadOnGuild(Snowflake id, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area);
static void RenderUnreadOnChannel(Snowflake id, const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area);
};