mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-19 20:11:59 +03:00
better member list, role color, some fixes
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
ChatMessageContainer::ChatMessageContainer(const MessageData *data) {
|
||||
UserID = data->Author.ID;
|
||||
ChannelID = data->ChannelID;
|
||||
|
||||
m_main_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_content_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
|
||||
@@ -49,6 +50,27 @@ ChatMessageContainer::ChatMessageContainer(const MessageData *data) {
|
||||
show();
|
||||
}
|
||||
|
||||
void ChatMessageContainer::SetAbaddon(Abaddon *ptr) {
|
||||
m_abaddon = ptr;
|
||||
}
|
||||
|
||||
void ChatMessageContainer::Update() {
|
||||
if (m_abaddon == nullptr) return;
|
||||
auto &discord = m_abaddon->GetDiscordClient();
|
||||
auto guild_id = discord.GetChannel(ChannelID)->GuildID;
|
||||
auto role_id = discord.GetMemberHoistedRole(guild_id, UserID, true);
|
||||
auto *user = discord.GetUser(UserID);
|
||||
std::string md;
|
||||
if (role_id.IsValid()) {
|
||||
auto *role = discord.GetRole(role_id);
|
||||
if (role != nullptr)
|
||||
md = "<span weight='bold' color='#" + IntToCSSColor(role->Color) + "'>" + Glib::Markup::escape_text(user->Username) + "</span>";
|
||||
} else {
|
||||
md = "<span weight='bold'>" + Glib::Markup::escape_text(user->Username) + "</span>";
|
||||
}
|
||||
m_author->set_markup(md);
|
||||
}
|
||||
|
||||
void ChatMessageContainer::AddNewContent(Gtk::Widget *widget, bool prepend) {
|
||||
if (prepend)
|
||||
m_content_box->pack_end(*widget);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include <string>
|
||||
#include "../discord/discord.hpp"
|
||||
|
||||
enum class ChatDisplayType {
|
||||
@@ -14,11 +15,16 @@ class Abaddon;
|
||||
class ChatMessageContainer : public Gtk::ListBoxRow {
|
||||
public:
|
||||
Snowflake UserID;
|
||||
Snowflake ChannelID;
|
||||
|
||||
ChatMessageContainer(const MessageData *data);
|
||||
void SetAbaddon(Abaddon *ptr);
|
||||
void AddNewContent(Gtk::Widget *widget, bool prepend = false);
|
||||
void Update();
|
||||
|
||||
protected:
|
||||
Abaddon *m_abaddon = nullptr;
|
||||
|
||||
Gtk::Box *m_main_box;
|
||||
Gtk::Box *m_content_box;
|
||||
Gtk::Box *m_meta_box;
|
||||
|
||||
@@ -112,6 +112,8 @@ void ChatWindow::ProcessMessage(const MessageData *data, bool prepend) {
|
||||
container = last_row;
|
||||
} else {
|
||||
container = Gtk::manage(new ChatMessageContainer(data)); // only accesses timestamp and user
|
||||
container->SetAbaddon(m_abaddon);
|
||||
container->Update();
|
||||
m_num_rows++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "memberlist.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
#include "../util.hpp"
|
||||
|
||||
MemberList::MemberList() {
|
||||
m_update_member_list_dispatcher.connect(sigc::mem_fun(*this, &MemberList::UpdateMemberListInternal));
|
||||
@@ -7,6 +8,8 @@ MemberList::MemberList() {
|
||||
m_main = Gtk::manage(new Gtk::ScrolledWindow);
|
||||
m_listbox = Gtk::manage(new Gtk::ListBox);
|
||||
|
||||
m_listbox->set_selection_mode(Gtk::SELECTION_NONE);
|
||||
|
||||
m_main->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
||||
m_main->add(*m_listbox);
|
||||
m_main->show_all();
|
||||
@@ -24,6 +27,7 @@ void MemberList::SetActiveChannel(Snowflake id) {
|
||||
|
||||
void MemberList::UpdateMemberList() {
|
||||
std::scoped_lock<std::mutex> guard(m_mutex);
|
||||
printf("update member list\n");
|
||||
m_update_member_list_dispatcher.emit();
|
||||
}
|
||||
|
||||
@@ -47,20 +51,95 @@ void MemberList::UpdateMemberListInternal() {
|
||||
ids = discord.GetUsersInGuild(m_guild_id);
|
||||
}
|
||||
|
||||
// process all the shit first so its in proper order
|
||||
std::map<int, const RoleData *> pos_to_role;
|
||||
std::map<int, std::vector<const UserData *>> pos_to_users;
|
||||
std::unordered_map<Snowflake, int> user_to_color;
|
||||
std::vector<Snowflake> roleless_users;
|
||||
|
||||
for (const auto &id : ids) {
|
||||
auto *user = discord.GetUser(id);
|
||||
auto *row = Gtk::manage(new Gtk::ListBoxRow);
|
||||
auto *label = Gtk::manage(new Gtk::Label);
|
||||
label->set_single_line_mode(true);
|
||||
label->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||
if (user == nullptr)
|
||||
label->set_text("[unknown user]");
|
||||
else
|
||||
label->set_text(user->Username + "#" + user->Discriminator);
|
||||
label->set_halign(Gtk::ALIGN_START);
|
||||
row->add(*label);
|
||||
row->show_all();
|
||||
m_listbox->add(*row);
|
||||
if (user == nullptr) {
|
||||
roleless_users.push_back(id);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto pos_role_id = discord.GetMemberHoistedRole(m_guild_id, id); // role for positioning
|
||||
auto col_role_id = discord.GetMemberHoistedRole(m_guild_id, id, true); // role for color
|
||||
auto pos_role = discord.GetRole(pos_role_id);
|
||||
auto col_role = discord.GetRole(col_role_id);
|
||||
|
||||
if (pos_role == nullptr) {
|
||||
roleless_users.push_back(id);
|
||||
continue;
|
||||
};
|
||||
|
||||
pos_to_role[pos_role->Position] = pos_role;
|
||||
pos_to_users[pos_role->Position].push_back(user);
|
||||
if (col_role != nullptr) {
|
||||
if (ColorDistance(col_role->Color, 0xFFFFFF) < 15)
|
||||
user_to_color[id] = 0x000000;
|
||||
else
|
||||
user_to_color[id] = col_role->Color;
|
||||
}
|
||||
}
|
||||
|
||||
auto add_user = [this, &user_to_color](const UserData *data) {
|
||||
auto *user_row = Gtk::manage(new Gtk::ListBoxRow);
|
||||
auto *user_lbl = Gtk::manage(new Gtk::Label);
|
||||
user_lbl->set_single_line_mode(true);
|
||||
user_lbl->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||
if (data != nullptr) {
|
||||
std::string display = data->Username + "#" + data->Discriminator;
|
||||
if (user_to_color.find(data->ID) != user_to_color.end()) {
|
||||
auto color = user_to_color.at(data->ID);
|
||||
user_lbl->set_use_markup(true);
|
||||
user_lbl->set_markup("<span color='#" + IntToCSSColor(color) + "'>" + Glib::Markup::escape_text(display) + "</span>");
|
||||
|
||||
} else {
|
||||
user_lbl->set_text(display);
|
||||
}
|
||||
} else {
|
||||
user_lbl->set_use_markup(true);
|
||||
user_lbl->set_markup("<i>[unknown user]</i>");
|
||||
}
|
||||
user_lbl->set_halign(Gtk::ALIGN_START);
|
||||
user_row->add(*user_lbl);
|
||||
user_row->show_all();
|
||||
m_listbox->add(*user_row);
|
||||
};
|
||||
|
||||
auto add_role = [this](std::string name) {
|
||||
auto *role_row = Gtk::manage(new Gtk::ListBoxRow);
|
||||
auto *role_lbl = Gtk::manage(new Gtk::Label);
|
||||
role_lbl->set_single_line_mode(true);
|
||||
role_lbl->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||
role_lbl->set_use_markup(true);
|
||||
role_lbl->set_markup("<b>" + Glib::Markup::escape_text(name) + "</b>");
|
||||
role_lbl->set_halign(Gtk::ALIGN_START);
|
||||
role_row->add(*role_lbl);
|
||||
role_row->show_all();
|
||||
m_listbox->add(*role_row);
|
||||
};
|
||||
|
||||
for (auto it = pos_to_role.crbegin(); it != pos_to_role.crend(); it++) {
|
||||
auto pos = it->first;
|
||||
auto role = it->second;
|
||||
|
||||
add_role(role->Name);
|
||||
|
||||
if (pos_to_users.find(pos) == pos_to_users.end()) continue;
|
||||
|
||||
auto &users = pos_to_users.at(pos);
|
||||
AlphabeticalSort(users.begin(), users.end(), [](auto e) { return e->Username; });
|
||||
|
||||
for (const auto data : users)
|
||||
add_user(data);
|
||||
}
|
||||
|
||||
add_role("@everyone");
|
||||
for (const auto &id : roleless_users) {
|
||||
add_user(discord.GetUser(id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user