Merge branch 'master' into friends

This commit is contained in:
ouwou
2021-05-14 03:18:05 -04:00
17 changed files with 161 additions and 83 deletions

View File

@@ -1,8 +0,0 @@
#pragma once
// for things that are used in stackswitchers to be able to be told when they're switched to
class INotifySwitched {
public:
virtual void on_switched_to() {};
};

View File

@@ -20,7 +20,7 @@ void from_json(const nlohmann::json &j, AuditLogOptions &m) {
void from_json(const nlohmann::json &j, AuditLogEntry &m) { void from_json(const nlohmann::json &j, AuditLogEntry &m) {
JS_N("target_id", m.TargetID); JS_N("target_id", m.TargetID);
JS_O("changes", m.Changes); JS_O("changes", m.Changes);
JS_D("user_id", m.UserID); JS_N("user_id", m.UserID);
JS_D("id", m.ID); JS_D("id", m.ID);
JS_D("action_type", m.Type); JS_D("action_type", m.Type);
JS_O("options", m.Options); JS_O("options", m.Options);

View File

@@ -40,6 +40,9 @@ enum class AuditLogActionType {
INTEGRATION_CREATE = 80, INTEGRATION_CREATE = 80,
INTEGRATION_UPDATE = 81, INTEGRATION_UPDATE = 81,
INTEGRATION_DELETE = 82, INTEGRATION_DELETE = 82,
STAGE_INSTANCE_CREATE = 83,
STAGE_INSTANCE_UPDATE = 84,
STAGE_INSTANCE_DELETE = 85,
}; };
struct AuditLogChange { struct AuditLogChange {
@@ -66,7 +69,7 @@ struct AuditLogOptions {
struct AuditLogEntry { struct AuditLogEntry {
Snowflake ID; Snowflake ID;
std::string TargetID; // null std::string TargetID; // null
Snowflake UserID; std::optional<Snowflake> UserID;
AuditLogActionType Type; AuditLogActionType Type;
std::optional<std::string> Reason; std::optional<std::string> Reason;
std::optional<std::vector<AuditLogChange>> Changes; std::optional<std::vector<AuditLogChange>> Changes;

View File

@@ -21,6 +21,22 @@ enum class ChannelType : int {
GUILD_STAGE_VOICE = 13, GUILD_STAGE_VOICE = 13,
}; };
enum class StagePrivacy {
PUBLIC = 1,
GUILD_ONLY = 2,
};
constexpr const char *GetStagePrivacyDisplayString(StagePrivacy e) {
switch (e) {
case StagePrivacy::PUBLIC:
return "Public";
case StagePrivacy::GUILD_ONLY:
return "Guild Only";
default:
return "Unknown";
}
}
struct ChannelData { struct ChannelData {
Snowflake ID; Snowflake ID;
ChannelType Type; ChannelType Type;

View File

@@ -102,7 +102,7 @@ void to_json(nlohmann::json &j, const UpdateStatusMessage &m) {
j["d"]["status"] = "online"; j["d"]["status"] = "online";
break; break;
case PresenceStatus::Offline: case PresenceStatus::Offline:
j["d"]["status"] = "offline"; j["d"]["status"] = "invisible";
break; break;
case PresenceStatus::Idle: case PresenceStatus::Idle:
j["d"]["status"] = "idle"; j["d"]["status"] = "idle";

View File

@@ -5,6 +5,7 @@ using namespace std::string_literals;
GuildSettingsAuditLogPane::GuildSettingsAuditLogPane(Snowflake id) GuildSettingsAuditLogPane::GuildSettingsAuditLogPane(Snowflake id)
: GuildID(id) { : GuildID(id) {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsAuditLogPane::OnMap));
set_name("guild-audit-log-pane"); set_name("guild-audit-log-pane");
set_hexpand(true); set_hexpand(true);
set_vexpand(true); set_vexpand(true);
@@ -14,7 +15,7 @@ GuildSettingsAuditLogPane::GuildSettingsAuditLogPane(Snowflake id)
add(m_list); add(m_list);
} }
void GuildSettingsAuditLogPane::on_switched_to() { void GuildSettingsAuditLogPane::OnMap() {
if (m_requested) return; if (m_requested) return;
m_requested = true; m_requested = true;
@@ -33,7 +34,11 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
auto label = Gtk::manage(new Gtk::Label); auto label = Gtk::manage(new Gtk::Label);
label->set_ellipsize(Pango::ELLIPSIZE_END); label->set_ellipsize(Pango::ELLIPSIZE_END);
auto user = *discord.GetUser(entry.UserID); Glib::ustring user_markup = "<b>Unknown User</b>";
if (entry.UserID.has_value()) {
if (auto user = discord.GetUser(*entry.UserID); user.has_value())
user_markup = discord.GetUser(*entry.UserID)->GetEscapedBoldString<false>();
}
// spaghetti moment // spaghetti moment
Glib::ustring markup; Glib::ustring markup;
@@ -41,7 +46,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
switch (entry.Type) { switch (entry.Type) {
case AuditLogActionType::GUILD_UPDATE: { case AuditLogActionType::GUILD_UPDATE: {
markup = markup =
user.GetEscapedBoldString<false>() + user_markup +
" made changes to <b>" + " made changes to <b>" +
Glib::Markup::escape_text(guild.Name) + Glib::Markup::escape_text(guild.Name) +
"</b>"; "</b>";
@@ -63,7 +68,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} break; } break;
case AuditLogActionType::CHANNEL_CREATE: { case AuditLogActionType::CHANNEL_CREATE: {
const auto type = *entry.GetNewFromKey<ChannelType>("type"); const auto type = *entry.GetNewFromKey<ChannelType>("type");
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created a " + (type == ChannelType::GUILD_VOICE ? "voice" : "text") + " created a " + (type == ChannelType::GUILD_VOICE ? "voice" : "text") +
" channel <b>#" + " channel <b>#" +
Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) +
@@ -83,12 +88,12 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
case AuditLogActionType::CHANNEL_UPDATE: { case AuditLogActionType::CHANNEL_UPDATE: {
const auto target_channel = discord.GetChannel(entry.TargetID); const auto target_channel = discord.GetChannel(entry.TargetID);
if (target_channel.has_value()) { if (target_channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" made changes to <b>#" + " made changes to <b>#" +
Glib::Markup::escape_text(*target_channel->Name) + Glib::Markup::escape_text(*target_channel->Name) +
"</b>"; "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" made changes to <b>&lt;#" + " made changes to <b>&lt;#" +
entry.TargetID + entry.TargetID +
"&gt;</b>"; "&gt;</b>";
@@ -126,7 +131,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} }
} break; } break;
case AuditLogActionType::CHANNEL_DELETE: { case AuditLogActionType::CHANNEL_DELETE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" removed <b>#" + " removed <b>#" +
Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) +
"</b>"; "</b>";
@@ -134,11 +139,11 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
case AuditLogActionType::CHANNEL_OVERWRITE_CREATE: { case AuditLogActionType::CHANNEL_OVERWRITE_CREATE: {
const auto channel = discord.GetChannel(entry.TargetID); const auto channel = discord.GetChannel(entry.TargetID);
if (channel.has_value()) { if (channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created channel overrides for <b>#" + " created channel overrides for <b>#" +
Glib::Markup::escape_text(*channel->Name) + "</b>"; Glib::Markup::escape_text(*channel->Name) + "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created channel overrides for <b>&lt;#" + " created channel overrides for <b>&lt;#" +
entry.TargetID + "&gt;</b>"; entry.TargetID + "&gt;</b>";
} }
@@ -146,11 +151,11 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
case AuditLogActionType::CHANNEL_OVERWRITE_UPDATE: { case AuditLogActionType::CHANNEL_OVERWRITE_UPDATE: {
const auto channel = discord.GetChannel(entry.TargetID); const auto channel = discord.GetChannel(entry.TargetID);
if (channel.has_value()) { if (channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated channel overrides for <b>#" + " updated channel overrides for <b>#" +
Glib::Markup::escape_text(*channel->Name) + "</b>"; Glib::Markup::escape_text(*channel->Name) + "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated channel overrides for <b>&lt;#" + " updated channel overrides for <b>&lt;#" +
entry.TargetID + "&gt;</b>"; entry.TargetID + "&gt;</b>";
} }
@@ -158,24 +163,24 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
case AuditLogActionType::CHANNEL_OVERWRITE_DELETE: { case AuditLogActionType::CHANNEL_OVERWRITE_DELETE: {
const auto channel = discord.GetChannel(entry.TargetID); const auto channel = discord.GetChannel(entry.TargetID);
if (channel.has_value()) { if (channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" removed channel overrides for <b>#" + " removed channel overrides for <b>#" +
Glib::Markup::escape_text(*channel->Name) + "</b>"; Glib::Markup::escape_text(*channel->Name) + "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" removed channel overrides for <b>&lt;#" + " removed channel overrides for <b>&lt;#" +
entry.TargetID + "&gt;</b>"; entry.TargetID + "&gt;</b>";
} }
} break; } break;
case AuditLogActionType::MEMBER_KICK: { case AuditLogActionType::MEMBER_KICK: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" kicked <b>" + " kicked <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::MEMBER_PRUNE: { case AuditLogActionType::MEMBER_PRUNE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" pruned <b>" + " pruned <b>" +
*entry.Options->MembersRemoved + *entry.Options->MembersRemoved +
"</b> members"; "</b> members";
@@ -185,21 +190,21 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} break; } break;
case AuditLogActionType::MEMBER_BAN_ADD: { case AuditLogActionType::MEMBER_BAN_ADD: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" banned <b>" + " banned <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::MEMBER_BAN_REMOVE: { case AuditLogActionType::MEMBER_BAN_REMOVE: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" removed the ban for <b>" + " removed the ban for <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::MEMBER_UPDATE: { case AuditLogActionType::MEMBER_UPDATE: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated <b>" + " updated <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
@@ -221,7 +226,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} break; } break;
case AuditLogActionType::MEMBER_ROLE_UPDATE: { case AuditLogActionType::MEMBER_ROLE_UPDATE: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated roles for <b>" + " updated roles for <b>" +
target_user->GetEscapedString() + "</b>"; target_user->GetEscapedString() + "</b>";
if (entry.Changes.has_value()) if (entry.Changes.has_value())
@@ -239,7 +244,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} break; } break;
case AuditLogActionType::MEMBER_MOVE: { case AuditLogActionType::MEMBER_MOVE: {
const auto channel = discord.GetChannel(*entry.Options->ChannelID); const auto channel = discord.GetChannel(*entry.Options->ChannelID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" moved <b>" + " moved <b>" +
*entry.Options->Count + *entry.Options->Count +
" user" + " user" +
@@ -249,27 +254,27 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::MEMBER_DISCONNECT: { case AuditLogActionType::MEMBER_DISCONNECT: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" disconnected <b>" + " disconnected <b>" +
*entry.Options->Count + *entry.Options->Count +
"</b> users from voice"; "</b> users from voice";
} break; } break;
case AuditLogActionType::BOT_ADD: { case AuditLogActionType::BOT_ADD: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" added <b>" + " added <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b> to the server"; "</b> to the server";
} break; } break;
case AuditLogActionType::ROLE_CREATE: { case AuditLogActionType::ROLE_CREATE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created the role <b>" + " created the role <b>" +
*entry.GetNewFromKey<std::string>("name") + *entry.GetNewFromKey<std::string>("name") +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::ROLE_UPDATE: { case AuditLogActionType::ROLE_UPDATE: {
const auto role = discord.GetRole(entry.TargetID); const auto role = discord.GetRole(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated the role <b>" + " updated the role <b>" +
(role.has_value() ? Glib::Markup::escape_text(role->Name) : Glib::ustring(entry.TargetID)) + (role.has_value() ? Glib::Markup::escape_text(role->Name) : Glib::ustring(entry.TargetID)) +
"</b>"; "</b>";
@@ -297,14 +302,14 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} }
} break; } break;
case AuditLogActionType::ROLE_DELETE: { case AuditLogActionType::ROLE_DELETE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted the role <b>" + " deleted the role <b>" +
*entry.GetOldFromKey<std::string>("name") + *entry.GetOldFromKey<std::string>("name") +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::INVITE_CREATE: { case AuditLogActionType::INVITE_CREATE: {
const auto code = *entry.GetNewFromKey<std::string>("code"); const auto code = *entry.GetNewFromKey<std::string>("code");
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created an invite <b>" + code + "</b>"; " created an invite <b>" + code + "</b>";
if (entry.Changes.has_value()) if (entry.Changes.has_value())
for (const auto &change : *entry.Changes) { for (const auto &change : *entry.Changes) {
@@ -328,13 +333,13 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} }
} break; } break;
case AuditLogActionType::INVITE_DELETE: { case AuditLogActionType::INVITE_DELETE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted an invite <b>" + " deleted an invite <b>" +
*entry.GetOldFromKey<std::string>("code") + *entry.GetOldFromKey<std::string>("code") +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::WEBHOOK_CREATE: { case AuditLogActionType::WEBHOOK_CREATE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created the webhook <b>" + " created the webhook <b>" +
Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) +
"</b>"; "</b>";
@@ -356,12 +361,12 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
webhookptr = &webhook; webhookptr = &webhook;
} }
if (webhookptr != nullptr) { if (webhookptr != nullptr) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated the webhook <b>" + " updated the webhook <b>" +
Glib::Markup::escape_text(webhookptr->Name) + Glib::Markup::escape_text(webhookptr->Name) +
"</b>"; "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated a webhook"; " updated a webhook";
} }
if (entry.Changes.has_value()) if (entry.Changes.has_value())
@@ -385,19 +390,19 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} }
} break; } break;
case AuditLogActionType::WEBHOOK_DELETE: { case AuditLogActionType::WEBHOOK_DELETE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted the webhook <b>" + " deleted the webhook <b>" +
Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::EMOJI_CREATE: { case AuditLogActionType::EMOJI_CREATE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" created the emoji <b>" + " created the emoji <b>" +
Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetNewFromKey<std::string>("name")) +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::EMOJI_UPDATE: { case AuditLogActionType::EMOJI_UPDATE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" updated the emoji <b>" + " updated the emoji <b>" +
Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) +
"</b>"; "</b>";
@@ -408,7 +413,7 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
"</b>"); "</b>");
} break; } break;
case AuditLogActionType::EMOJI_DELETE: { case AuditLogActionType::EMOJI_DELETE: {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted the emoji <b>" + " deleted the emoji <b>" +
Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) + Glib::Markup::escape_text(*entry.GetOldFromKey<std::string>("name")) +
"</b>"; "</b>";
@@ -417,26 +422,26 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
const auto channel = discord.GetChannel(*entry.Options->ChannelID); const auto channel = discord.GetChannel(*entry.Options->ChannelID);
const auto count = *entry.Options->Count; const auto count = *entry.Options->Count;
if (channel.has_value()) { if (channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted <b>" + count + "</b> messages in <b>#" + " deleted <b>" + count + "</b> messages in <b>#" +
Glib::Markup::escape_text(*channel->Name) + Glib::Markup::escape_text(*channel->Name) +
"</b>"; "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted <b>" + count + "</b> messages"; " deleted <b>" + count + "</b> messages";
} }
} break; } break;
case AuditLogActionType::MESSAGE_BULK_DELETE: { case AuditLogActionType::MESSAGE_BULK_DELETE: {
const auto channel = discord.GetChannel(entry.TargetID); const auto channel = discord.GetChannel(entry.TargetID);
if (channel.has_value()) { if (channel.has_value()) {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted <b>" + " deleted <b>" +
*entry.Options->Count + *entry.Options->Count +
"</b> messages in <b>#" + "</b> messages in <b>#" +
Glib::Markup::escape_text(*channel->Name) + Glib::Markup::escape_text(*channel->Name) +
"</b>"; "</b>";
} else { } else {
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" deleted <b>" + " deleted <b>" +
*entry.Options->Count + *entry.Options->Count +
"</b> messages"; "</b> messages";
@@ -444,18 +449,94 @@ void GuildSettingsAuditLogPane::OnAuditLogFetch(const AuditLogData &data) {
} break; } break;
case AuditLogActionType::MESSAGE_PIN: { case AuditLogActionType::MESSAGE_PIN: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" pinned a message by <b>" + " pinned a message by <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::MESSAGE_UNPIN: { case AuditLogActionType::MESSAGE_UNPIN: {
const auto target_user = discord.GetUser(entry.TargetID); const auto target_user = discord.GetUser(entry.TargetID);
markup = user.GetEscapedBoldString<false>() + markup = user_markup +
" unpinned a message by <b>" + " unpinned a message by <b>" +
target_user->GetEscapedString() + target_user->GetEscapedString() +
"</b>"; "</b>";
} break; } break;
case AuditLogActionType::STAGE_INSTANCE_CREATE: {
const auto channel = discord.GetChannel(*entry.Options->ChannelID);
if (channel.has_value()) {
markup = user_markup +
" started the stage for <b>" +
Glib::Markup::escape_text(*channel->Name) +
"</b>";
} else {
markup = user_markup +
" started the stage for <b>" +
std::to_string(*entry.Options->ChannelID) +
"</b>";
}
if (entry.Changes.has_value()) {
for (const auto &change : *entry.Changes) {
if (change.Key == "topic" && change.NewValue.has_value()) {
extra_markup.push_back(
"Set the topic to <b>" +
Glib::Markup::escape_text(change.NewValue->get<std::string>()) +
"</b>");
} else if (change.Key == "privacy_level" && change.NewValue.has_value()) {
Glib::ustring str = Glib::Markup::escape_text(GetStagePrivacyDisplayString(change.NewValue->get<StagePrivacy>()));
extra_markup.push_back(
"Set the privacy level to <b>" +
str +
"</b>");
}
}
}
} break;
case AuditLogActionType::STAGE_INSTANCE_UPDATE: {
const auto channel = discord.GetChannel(*entry.Options->ChannelID);
if (channel.has_value()) {
markup = user_markup +
" updated the stage for <b>" +
Glib::Markup::escape_text(*channel->Name) +
"</b>";
} else {
markup = user_markup +
" updated the stage for <b>" +
std::to_string(*entry.Options->ChannelID) +
"</b>";
}
if (entry.Changes.has_value()) {
for (const auto &change : *entry.Changes) {
if (change.Key == "topic" && change.NewValue.has_value()) {
extra_markup.push_back(
"Set the topic to <b>" +
Glib::Markup::escape_text(change.NewValue->get<std::string>()) +
"</b>");
} else if (change.Key == "privacy_level" && change.NewValue.has_value()) {
Glib::ustring str = Glib::Markup::escape_text(GetStagePrivacyDisplayString(change.NewValue->get<StagePrivacy>()));
extra_markup.push_back(
"Set the privacy level to <b>" +
str +
"</b>");
}
}
}
} break;
case AuditLogActionType::STAGE_INSTANCE_DELETE: {
const auto channel = discord.GetChannel(*entry.Options->ChannelID);
if (channel.has_value()) {
markup = user_markup +
" ended the stage for <b>" +
Glib::Markup::escape_text(*channel->Name) +
"</b>";
} else {
markup = user_markup +
" ended the stage for <b>" +
std::to_string(*entry.Options->ChannelID) +
"</b>";
}
} break;
default: default:
markup = "<i>Unknown action</i>"; markup = "<i>Unknown action</i>";
break; break;

View File

@@ -1,14 +1,13 @@
#pragma once #pragma once
#include <gtkmm.h> #include <gtkmm.h>
#include "../../components//inotifyswitched.hpp"
#include "../../discord/objects.hpp" #include "../../discord/objects.hpp"
class GuildSettingsAuditLogPane : public Gtk::ScrolledWindow, public INotifySwitched { class GuildSettingsAuditLogPane : public Gtk::ScrolledWindow {
public: public:
GuildSettingsAuditLogPane(Snowflake id); GuildSettingsAuditLogPane(Snowflake id);
private: private:
void on_switched_to() override; void OnMap();
bool m_requested = false; bool m_requested = false;

View File

@@ -10,6 +10,7 @@ GuildSettingsBansPane::GuildSettingsBansPane(Snowflake id)
, m_menu_unban("Unban") , m_menu_unban("Unban")
, m_menu_copy_id("Copy ID") , m_menu_copy_id("Copy ID")
, m_model(Gtk::ListStore::create(m_columns)) { , m_model(Gtk::ListStore::create(m_columns)) {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsBansPane::OnMap));
set_name("guild-bans-pane"); set_name("guild-bans-pane");
set_hexpand(true); set_hexpand(true);
set_vexpand(true); set_vexpand(true);
@@ -54,7 +55,7 @@ GuildSettingsBansPane::GuildSettingsBansPane(Snowflake id)
m_view.append_column("Reason", m_columns.m_col_reason); m_view.append_column("Reason", m_columns.m_col_reason);
} }
void GuildSettingsBansPane::on_switched_to() { void GuildSettingsBansPane::OnMap() {
if (m_requested) return; if (m_requested) return;
m_requested = true; m_requested = true;

View File

@@ -1,15 +1,14 @@
#pragma once #pragma once
#include <gtkmm.h> #include <gtkmm.h>
#include "../../components/inotifyswitched.hpp"
#include "../../discord/snowflake.hpp" #include "../../discord/snowflake.hpp"
#include "../../discord/ban.hpp" #include "../../discord/ban.hpp"
class GuildSettingsBansPane : public Gtk::Box, public INotifySwitched { class GuildSettingsBansPane : public Gtk::Box {
public: public:
GuildSettingsBansPane(Snowflake id); GuildSettingsBansPane(Snowflake id);
private: private:
void on_switched_to() override; void OnMap();
bool m_requested = false; bool m_requested = false;

View File

@@ -11,6 +11,7 @@ GuildSettingsEmojisPane::GuildSettingsEmojisPane(Snowflake guild_id)
, m_menu_delete("Delete") , m_menu_delete("Delete")
, m_menu_copy_emoji_url("Copy Emoji URL") , m_menu_copy_emoji_url("Copy Emoji URL")
, m_menu_show_emoji("Open in Browser") { , m_menu_show_emoji("Open in Browser") {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsEmojisPane::OnMap));
set_name("guild-emojis-pane"); set_name("guild-emojis-pane");
m_view_scroll.set_hexpand(true); m_view_scroll.set_hexpand(true);
@@ -97,7 +98,7 @@ GuildSettingsEmojisPane::GuildSettingsEmojisPane(Snowflake guild_id)
column->set_resizable(true); column->set_resizable(true);
} }
void GuildSettingsEmojisPane::on_switched_to() { void GuildSettingsEmojisPane::OnMap() {
m_view.grab_focus(); m_view.grab_focus();
if (m_requested) return; if (m_requested) return;

View File

@@ -1,15 +1,13 @@
#pragma once #pragma once
#include <gtkmm.h> #include <gtkmm.h>
#include "../../components/inotifyswitched.hpp"
#include "../../discord/emoji.hpp" #include "../../discord/emoji.hpp"
class GuildSettingsEmojisPane : public Gtk::Box class GuildSettingsEmojisPane : public Gtk::Box {
, public INotifySwitched {
public: public:
GuildSettingsEmojisPane(Snowflake guild_id); GuildSettingsEmojisPane(Snowflake guild_id);
private: private:
void on_switched_to() override; void OnMap();
bool m_requested = false; bool m_requested = false;

View File

@@ -5,6 +5,7 @@ GuildSettingsInvitesPane::GuildSettingsInvitesPane(Snowflake id)
: GuildID(id) : GuildID(id)
, m_model(Gtk::ListStore::create(m_columns)) , m_model(Gtk::ListStore::create(m_columns))
, m_menu_delete("Delete") { , m_menu_delete("Delete") {
signal_map().connect(sigc::mem_fun(*this, &GuildSettingsInvitesPane::OnMap));
set_name("guild-invites-pane"); set_name("guild-invites-pane");
set_hexpand(true); set_hexpand(true);
set_vexpand(true); set_vexpand(true);
@@ -36,7 +37,7 @@ GuildSettingsInvitesPane::GuildSettingsInvitesPane(Snowflake id)
column->set_resizable(true); column->set_resizable(true);
} }
void GuildSettingsInvitesPane::on_switched_to() { void GuildSettingsInvitesPane::OnMap() {
if (m_requested) return; if (m_requested) return;
m_requested = true; m_requested = true;

View File

@@ -1,14 +1,13 @@
#pragma once #pragma once
#include <gtkmm.h> #include <gtkmm.h>
#include "../../components/inotifyswitched.hpp"
#include "../../discord/objects.hpp" #include "../../discord/objects.hpp"
class GuildSettingsInvitesPane : public Gtk::ScrolledWindow, public INotifySwitched { class GuildSettingsInvitesPane : public Gtk::ScrolledWindow {
public: public:
GuildSettingsInvitesPane(Snowflake id); GuildSettingsInvitesPane(Snowflake id);
private: private:
void on_switched_to() override; void OnMap();
bool m_requested = false; bool m_requested = false;

View File

@@ -1,6 +1,5 @@
#include "guildsettingswindow.hpp" #include "guildsettingswindow.hpp"
#include "../abaddon.hpp" #include "../abaddon.hpp"
#include "../components/inotifyswitched.hpp"
GuildSettingsWindow::GuildSettingsWindow(Snowflake id) GuildSettingsWindow::GuildSettingsWindow(Snowflake id)
: m_main(Gtk::ORIENTATION_VERTICAL) : m_main(Gtk::ORIENTATION_VERTICAL)
@@ -42,11 +41,6 @@ GuildSettingsWindow::GuildSettingsWindow(Snowflake id)
m_switcher.set_margin_top(10); m_switcher.set_margin_top(10);
m_switcher.show(); m_switcher.show();
m_stack.property_visible_child().signal_changed().connect([this]() {
if (auto *w = dynamic_cast<INotifySwitched *>(m_stack.property_visible_child().get_value()))
w->on_switched_to();
});
m_pane_info.show(); m_pane_info.show();
m_pane_members.show(); m_pane_members.show();
m_pane_roles.show(); m_pane_roles.show();

View File

@@ -34,6 +34,7 @@ MutualFriendItem::MutualFriendItem(const UserData &user)
MutualFriendsPane::MutualFriendsPane(Snowflake id) MutualFriendsPane::MutualFriendsPane(Snowflake id)
: UserID(id) { : UserID(id) {
signal_map().connect(sigc::mem_fun(*this, &MutualFriendsPane::OnMap));
add(m_list); add(m_list);
show_all_children(); show_all_children();
} }
@@ -49,7 +50,7 @@ void MutualFriendsPane::OnFetchRelationships(const std::vector<UserData> &users)
} }
} }
void MutualFriendsPane::on_switched_to() { void MutualFriendsPane::OnMap() {
if (m_requested) return; if (m_requested) return;
m_requested = true; m_requested = true;

View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <gtkmm.h> #include <gtkmm.h>
#include "../../components/inotifyswitched.hpp"
#include "../../discord/objects.hpp" #include "../../discord/objects.hpp"
class MutualFriendItem : public Gtk::Box { class MutualFriendItem : public Gtk::Box {
@@ -12,14 +11,14 @@ private:
Gtk::Label m_name; Gtk::Label m_name;
}; };
class MutualFriendsPane : public Gtk::ScrolledWindow, public INotifySwitched { class MutualFriendsPane : public Gtk::ScrolledWindow {
public: public:
MutualFriendsPane(Snowflake id); MutualFriendsPane(Snowflake id);
Snowflake UserID; Snowflake UserID;
private: private:
void on_switched_to() override; void OnMap();
bool m_requested = false; bool m_requested = false;

View File

@@ -1,6 +1,5 @@
#include "profilewindow.hpp" #include "profilewindow.hpp"
#include "../abaddon.hpp" #include "../abaddon.hpp"
#include "../components/inotifyswitched.hpp"
ProfileWindow::ProfileWindow(Snowflake user_id) ProfileWindow::ProfileWindow(Snowflake user_id)
: ID(user_id) : ID(user_id)
@@ -71,11 +70,6 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
m_switcher.set_halign(Gtk::ALIGN_START); m_switcher.set_halign(Gtk::ALIGN_START);
m_switcher.set_hexpand(true); m_switcher.set_hexpand(true);
m_stack.property_visible_child().signal_changed().connect([this]() {
if (auto *w = dynamic_cast<INotifySwitched *>(m_stack.property_visible_child().get_value()))
w->on_switched_to();
});
m_stack.add(m_pane_info, "info", "User Info"); m_stack.add(m_pane_info, "info", "User Info");
m_stack.add(m_pane_guilds, "guilds", "Mutual Servers"); m_stack.add(m_pane_guilds, "guilds", "Mutual Servers");
m_stack.add(m_pane_friends, "friends", "Mutual Friends"); m_stack.add(m_pane_friends, "friends", "Mutual Friends");