forked from OpenGamers/abaddon
fix some crashes when switching to DM channels sometimes
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
constexpr static const int MaxMemberListRows = 200;
|
constexpr static const int MaxMemberListRows = 200;
|
||||||
|
|
||||||
MemberListUserRow::MemberListUserRow(const GuildData &guild, const UserData *data) {
|
MemberListUserRow::MemberListUserRow(const GuildData *guild, const UserData &data) {
|
||||||
ID = data->ID;
|
ID = data.ID;
|
||||||
m_ev = Gtk::manage(new Gtk::EventBox);
|
m_ev = Gtk::manage(new Gtk::EventBox);
|
||||||
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||||
m_label = Gtk::manage(new Gtk::Label);
|
m_label = Gtk::manage(new Gtk::Label);
|
||||||
@@ -15,7 +15,7 @@ MemberListUserRow::MemberListUserRow(const GuildData &guild, const UserData *dat
|
|||||||
m_status_indicator = Gtk::manage(new StatusIndicator(ID));
|
m_status_indicator = Gtk::manage(new StatusIndicator(ID));
|
||||||
|
|
||||||
static bool crown = Abaddon::Get().GetSettings().GetShowOwnerCrown();
|
static bool crown = Abaddon::Get().GetSettings().GetShowOwnerCrown();
|
||||||
if (crown && guild.OwnerID == data->ID) {
|
if (crown && guild != nullptr && guild->OwnerID == data.ID) {
|
||||||
try {
|
try {
|
||||||
auto pixbuf = Gdk::Pixbuf::create_from_file("./res/crown.png", 12, 12);
|
auto pixbuf = Gdk::Pixbuf::create_from_file("./res/crown.png", 12, 12);
|
||||||
m_crown = Gtk::manage(new Gtk::Image(pixbuf));
|
m_crown = Gtk::manage(new Gtk::Image(pixbuf));
|
||||||
@@ -26,8 +26,8 @@ MemberListUserRow::MemberListUserRow(const GuildData &guild, const UserData *dat
|
|||||||
|
|
||||||
m_status_indicator->set_margin_start(3);
|
m_status_indicator->set_margin_start(3);
|
||||||
|
|
||||||
if (data->HasAvatar())
|
if (data.HasAvatar())
|
||||||
m_avatar->SetURL(data->GetAvatarURL("png"));
|
m_avatar->SetURL(data.GetAvatarURL("png"));
|
||||||
|
|
||||||
get_style_context()->add_class("members-row");
|
get_style_context()->add_class("members-row");
|
||||||
get_style_context()->add_class("members-row-member");
|
get_style_context()->add_class("members-row-member");
|
||||||
@@ -36,23 +36,21 @@ MemberListUserRow::MemberListUserRow(const GuildData &guild, const UserData *dat
|
|||||||
|
|
||||||
m_label->set_single_line_mode(true);
|
m_label->set_single_line_mode(true);
|
||||||
m_label->set_ellipsize(Pango::ELLIPSIZE_END);
|
m_label->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||||
if (data != nullptr) {
|
|
||||||
static bool show_discriminator = Abaddon::Get().GetSettings().GetShowMemberListDiscriminators();
|
static bool show_discriminator = Abaddon::Get().GetSettings().GetShowMemberListDiscriminators();
|
||||||
std::string display = data->Username;
|
std::string display = data.Username;
|
||||||
if (show_discriminator)
|
if (show_discriminator)
|
||||||
display += "#" + data->Discriminator;
|
display += "#" + data.Discriminator;
|
||||||
auto col_id = data->GetHoistedRole(guild.ID, true);
|
if (guild != nullptr) {
|
||||||
if (col_id.IsValid()) {
|
if (const auto col_id = data.GetHoistedRole(guild->ID, true); col_id.IsValid()) {
|
||||||
auto color = Abaddon::Get().GetDiscordClient().GetRole(col_id)->Color;
|
auto color = Abaddon::Get().GetDiscordClient().GetRole(col_id)->Color;
|
||||||
m_label->set_use_markup(true);
|
m_label->set_use_markup(true);
|
||||||
m_label->set_markup("<span color='#" + IntToCSSColor(color) + "'>" + Glib::Markup::escape_text(display) + "</span>");
|
m_label->set_markup("<span color='#" + IntToCSSColor(color) + "'>" + Glib::Markup::escape_text(display) + "</span>");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_label->set_text(display);
|
m_label->set_text(display);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_label->set_use_markup(true);
|
m_label->set_text(display);
|
||||||
m_label->set_markup("<i>[unknown user]</i>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_label->set_halign(Gtk::ALIGN_START);
|
m_label->set_halign(Gtk::ALIGN_START);
|
||||||
@@ -113,15 +111,21 @@ void MemberList::UpdateMemberList() {
|
|||||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||||
const auto chan = discord.GetChannel(m_chan_id);
|
const auto chan = discord.GetChannel(m_chan_id);
|
||||||
if (!chan.has_value()) return;
|
if (!chan.has_value()) return;
|
||||||
std::unordered_set<Snowflake> ids;
|
|
||||||
if (chan->Type == ChannelType::DM || chan->Type == ChannelType::GROUP_DM) {
|
if (chan->Type == ChannelType::DM || chan->Type == ChannelType::GROUP_DM) {
|
||||||
for (const auto &user : chan->GetDMRecipients())
|
int num_rows = 0;
|
||||||
ids.insert(user.ID);
|
for (const auto &user : chan->GetDMRecipients()) {
|
||||||
ids.insert(discord.GetUserData().ID);
|
if (num_rows++ > MaxMemberListRows) break;
|
||||||
} else {
|
auto *row = Gtk::manage(new MemberListUserRow(nullptr, user));
|
||||||
ids = discord.GetUsersInGuild(m_guild_id);
|
m_id_to_row[user.ID] = row;
|
||||||
|
AttachUserMenuHandler(row, user.ID);
|
||||||
|
m_listbox->add(*row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ids = discord.GetUsersInGuild(m_guild_id);
|
||||||
|
|
||||||
// process all the shit first so its in proper order
|
// process all the shit first so its in proper order
|
||||||
std::map<int, RoleData> pos_to_role;
|
std::map<int, RoleData> pos_to_role;
|
||||||
std::map<int, std::vector<UserData>> pos_to_users;
|
std::map<int, std::vector<UserData>> pos_to_users;
|
||||||
@@ -151,11 +155,11 @@ void MemberList::UpdateMemberList() {
|
|||||||
|
|
||||||
int num_rows = 0;
|
int num_rows = 0;
|
||||||
const auto guild = *discord.GetGuild(m_guild_id);
|
const auto guild = *discord.GetGuild(m_guild_id);
|
||||||
auto add_user = [this, &user_to_color, &num_rows, guild](const UserData *data) -> bool {
|
auto add_user = [this, &user_to_color, &num_rows, guild](const UserData &data) -> bool {
|
||||||
if (num_rows++ > MaxMemberListRows) return false;
|
if (num_rows++ > MaxMemberListRows) return false;
|
||||||
auto *row = Gtk::manage(new MemberListUserRow(guild, data));
|
auto *row = Gtk::manage(new MemberListUserRow(&guild, data));
|
||||||
m_id_to_row[data->ID] = row;
|
m_id_to_row[data.ID] = row;
|
||||||
AttachUserMenuHandler(row, data->ID);
|
AttachUserMenuHandler(row, data.ID);
|
||||||
m_listbox->add(*row);
|
m_listbox->add(*row);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -189,8 +193,8 @@ void MemberList::UpdateMemberList() {
|
|||||||
auto &users = pos_to_users.at(pos);
|
auto &users = pos_to_users.at(pos);
|
||||||
AlphabeticalSort(users.begin(), users.end(), [](const auto &e) { return e.Username; });
|
AlphabeticalSort(users.begin(), users.end(), [](const auto &e) { return e.Username; });
|
||||||
|
|
||||||
for (const auto data : users)
|
for (const auto &data : users)
|
||||||
if (!add_user(&data)) return;
|
if (!add_user(data)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan->Type == ChannelType::DM || chan->Type == ChannelType::GROUP_DM)
|
if (chan->Type == ChannelType::DM || chan->Type == ChannelType::GROUP_DM)
|
||||||
@@ -200,7 +204,7 @@ void MemberList::UpdateMemberList() {
|
|||||||
for (const auto &id : roleless_users) {
|
for (const auto &id : roleless_users) {
|
||||||
const auto user = discord.GetUser(id);
|
const auto user = discord.GetUser(id);
|
||||||
if (user.has_value())
|
if (user.has_value())
|
||||||
if (!add_user(&*user)) return;
|
if (!add_user(*user)) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <optional>
|
||||||
#include "../discord/discord.hpp"
|
#include "../discord/discord.hpp"
|
||||||
|
|
||||||
class LazyImage;
|
class LazyImage;
|
||||||
class StatusIndicator;
|
class StatusIndicator;
|
||||||
class MemberListUserRow : public Gtk::ListBoxRow {
|
class MemberListUserRow : public Gtk::ListBoxRow {
|
||||||
public:
|
public:
|
||||||
MemberListUserRow(const GuildData& guild, const UserData *data);
|
MemberListUserRow(const GuildData *guild, const UserData &data);
|
||||||
|
|
||||||
Snowflake ID;
|
Snowflake ID;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user