mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
Merge branch 'master' into folders
This commit is contained in:
@@ -79,6 +79,10 @@ the result of fundamental issues with Discord's thread implementation.
|
||||
```Shell
|
||||
$ sudo pacman -S gcc cmake gtkmm3 libcurl-gnutls lib32-sqlite lib32-openssl nlohmann-json libhandy
|
||||
```
|
||||
* On Fedora Linux:
|
||||
```Shell
|
||||
$ sudo dnf install g++ cmake gtkmm3.0-devel libcurl-devel sqlite-devel openssl-devel json-devel libsecret-devel libhandy-devel
|
||||
```
|
||||
2. `git clone https://github.com/uowuo/abaddon --recurse-submodules="subprojects" && cd abaddon`
|
||||
3. `mkdir build && cd build`
|
||||
4. `cmake ..`
|
||||
|
||||
@@ -844,14 +844,10 @@ void ChannelList::AddPrivateChannels() {
|
||||
auto row = *iter;
|
||||
row[m_columns.m_type] = RenderType::DM;
|
||||
row[m_columns.m_id] = dm_id;
|
||||
row[m_columns.m_name] = Glib::Markup::escape_text(dm->GetDisplayName());
|
||||
row[m_columns.m_sort] = static_cast<int64_t>(-(dm->LastMessageID.has_value() ? *dm->LastMessageID : dm_id));
|
||||
row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize);
|
||||
|
||||
if (dm->Type == ChannelType::DM && top_recipient.has_value())
|
||||
row[m_columns.m_name] = Glib::Markup::escape_text(top_recipient->Username);
|
||||
else if (dm->Type == ChannelType::GROUP_DM)
|
||||
row[m_columns.m_name] = std::to_string(recipients.size()) + " members";
|
||||
|
||||
if (dm->HasIcon()) {
|
||||
const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
|
||||
if (iter)
|
||||
@@ -881,14 +877,10 @@ void ChannelList::UpdateCreateDMChannel(const ChannelData &dm) {
|
||||
auto row = *iter;
|
||||
row[m_columns.m_type] = RenderType::DM;
|
||||
row[m_columns.m_id] = dm.ID;
|
||||
row[m_columns.m_name] = Glib::Markup::escape_text(dm.GetDisplayName());
|
||||
row[m_columns.m_sort] = static_cast<int64_t>(-(dm.LastMessageID.has_value() ? *dm.LastMessageID : dm.ID));
|
||||
row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize);
|
||||
|
||||
if (dm.Type == ChannelType::DM && top_recipient.has_value())
|
||||
row[m_columns.m_name] = Glib::Markup::escape_text(top_recipient->Username);
|
||||
else if (dm.Type == ChannelType::GROUP_DM)
|
||||
row[m_columns.m_name] = std::to_string(recipients.size()) + " members";
|
||||
|
||||
if (top_recipient.has_value()) {
|
||||
const auto cb = [this, iter](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
|
||||
if (iter)
|
||||
|
||||
@@ -84,6 +84,10 @@ bool ChannelData::IsCategory() const noexcept {
|
||||
return Type == ChannelType::GUILD_CATEGORY;
|
||||
}
|
||||
|
||||
bool ChannelData::IsText() const noexcept {
|
||||
return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS;
|
||||
}
|
||||
|
||||
bool ChannelData::HasIcon() const noexcept {
|
||||
return Icon.has_value();
|
||||
}
|
||||
@@ -102,15 +106,14 @@ std::string ChannelData::GetIconURL() const {
|
||||
|
||||
std::string ChannelData::GetDisplayName() const {
|
||||
if (Name.has_value()) {
|
||||
return "#" + *Name;
|
||||
if (IsDM()) {
|
||||
return *Name;
|
||||
} else {
|
||||
return "#" + *Name;
|
||||
}
|
||||
} else {
|
||||
const auto recipients = GetDMRecipients();
|
||||
if (Type == ChannelType::DM && !recipients.empty())
|
||||
return recipients[0].Username;
|
||||
else if (Type == ChannelType::GROUP_DM)
|
||||
return std::to_string(recipients.size()) + " members";
|
||||
return GetRecipientsDisplay();
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
std::vector<Snowflake> ChannelData::GetChildIDs() const {
|
||||
@@ -139,6 +142,25 @@ std::vector<UserData> ChannelData::GetDMRecipients() const {
|
||||
|
||||
return {};
|
||||
}
|
||||
bool ChannelData::IsText() const noexcept {
|
||||
return Type == ChannelType::GUILD_TEXT || Type == ChannelType::GUILD_NEWS;
|
||||
|
||||
std::string ChannelData::GetRecipientsDisplay() const {
|
||||
const auto self_id = Abaddon::Get().GetDiscordClient().GetUserData().ID;
|
||||
const auto recipients = GetDMRecipients();
|
||||
|
||||
if (Type == ChannelType::DM && !recipients.empty()) {
|
||||
return recipients[0].Username;
|
||||
}
|
||||
|
||||
Glib::ustring r;
|
||||
for (size_t i = 0; i < recipients.size(); i++) {
|
||||
const auto &recipient = recipients[i];
|
||||
r += recipient.Username;
|
||||
if (i < recipients.size() - 1) {
|
||||
r += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
if (r.empty()) r = "Unnamed";
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -106,4 +106,5 @@ struct ChannelData {
|
||||
[[nodiscard]] std::vector<Snowflake> GetChildIDs() const;
|
||||
[[nodiscard]] std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const;
|
||||
[[nodiscard]] std::vector<UserData> GetDMRecipients() const;
|
||||
[[nodiscard]] std::string GetRecipientsDisplay() const;
|
||||
};
|
||||
|
||||
@@ -341,12 +341,10 @@ bool DiscordClient::HasChannelPermission(Snowflake user_id, Snowflake channel_id
|
||||
}
|
||||
|
||||
Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guild_id) const {
|
||||
const auto member = GetMember(member_id, guild_id);
|
||||
const auto guild = GetGuild(guild_id);
|
||||
if (!member.has_value() || !guild.has_value())
|
||||
return Permission::NONE;
|
||||
const auto member_roles = m_store.GetMemberRoles(guild_id, member_id);
|
||||
const auto guild_owner = m_store.GetGuildOwner(guild_id);
|
||||
|
||||
if (guild->OwnerID == member_id)
|
||||
if (guild_owner == member_id)
|
||||
return Permission::ALL;
|
||||
|
||||
const auto everyone = GetRole(guild_id);
|
||||
@@ -354,7 +352,7 @@ Permission DiscordClient::ComputePermissions(Snowflake member_id, Snowflake guil
|
||||
return Permission::NONE;
|
||||
|
||||
Permission perms = everyone->Permissions;
|
||||
for (const auto role_id : member->Roles) {
|
||||
for (const auto role_id : member_roles) {
|
||||
const auto role = GetRole(role_id);
|
||||
if (role.has_value())
|
||||
perms |= role->Permissions;
|
||||
@@ -371,8 +369,8 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
|
||||
return Permission::ALL;
|
||||
|
||||
const auto channel = GetChannel(channel_id);
|
||||
const auto member = GetMember(member_id, *channel->GuildID);
|
||||
if (!member.has_value() || !channel.has_value())
|
||||
const auto member_roles = m_store.GetMemberRoles(*channel->GuildID, member_id);
|
||||
if (!channel.has_value())
|
||||
return Permission::NONE;
|
||||
|
||||
Permission perms = base;
|
||||
@@ -384,7 +382,7 @@ Permission DiscordClient::ComputeOverwrites(Permission base, Snowflake member_id
|
||||
|
||||
Permission allow = Permission::NONE;
|
||||
Permission deny = Permission::NONE;
|
||||
for (const auto role_id : member->Roles) {
|
||||
for (const auto role_id : member_roles) {
|
||||
const auto overwrite = GetPermissionOverwrite(channel_id, role_id);
|
||||
if (overwrite.has_value()) {
|
||||
allow |= overwrite->Allow;
|
||||
|
||||
@@ -473,6 +473,40 @@ std::vector<BanData> Store::GetBans(Snowflake guild_id) const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Snowflake Store::GetGuildOwner(Snowflake guild_id) const {
|
||||
auto &s = m_stmt_get_guild_owner;
|
||||
|
||||
s->Bind(1, guild_id);
|
||||
if (s->FetchOne()) {
|
||||
Snowflake ret;
|
||||
s->Get(0, ret);
|
||||
s->Reset();
|
||||
return ret;
|
||||
}
|
||||
|
||||
s->Reset();
|
||||
|
||||
return Snowflake::Invalid;
|
||||
}
|
||||
|
||||
std::vector<Snowflake> Store::GetMemberRoles(Snowflake guild_id, Snowflake user_id) const {
|
||||
std::vector<Snowflake> ret;
|
||||
|
||||
auto &s = m_stmt_get_member_roles;
|
||||
|
||||
s->Bind(1, user_id);
|
||||
s->Bind(2, guild_id);
|
||||
|
||||
while (s->FetchOne()) {
|
||||
auto &f = ret.emplace_back();
|
||||
s->Get(0, f);
|
||||
}
|
||||
|
||||
s->Reset();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Message> Store::GetLastMessages(Snowflake id, size_t num) const {
|
||||
auto &s = m_stmt_get_last_msgs;
|
||||
std::vector<Message> msgs;
|
||||
@@ -2198,6 +2232,14 @@ bool Store::CreateStatements() {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_stmt_get_guild_owner = std::make_unique<Statement>(m_db, R"(
|
||||
SELECT owner_id FROM guilds WHERE id = ?
|
||||
)");
|
||||
if (!m_stmt_get_guild_owner->OK()) {
|
||||
fprintf(stderr, "failed to prepare get guild owner statement: %s\n", m_db.ErrStr());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ public:
|
||||
std::optional<BanData> GetBan(Snowflake guild_id, Snowflake user_id) const;
|
||||
std::vector<BanData> GetBans(Snowflake guild_id) const;
|
||||
|
||||
Snowflake GetGuildOwner(Snowflake guild_id) const;
|
||||
std::vector<Snowflake> GetMemberRoles(Snowflake guild_id, Snowflake user_id) const;
|
||||
|
||||
std::vector<Message> GetLastMessages(Snowflake id, size_t num) const;
|
||||
std::vector<Message> GetMessagesBefore(Snowflake channel_id, Snowflake message_id, size_t limit) const;
|
||||
std::vector<Message> GetPinnedMessages(Snowflake channel_id) const;
|
||||
@@ -308,5 +311,6 @@ private:
|
||||
STMT(get_chan_ids_parent);
|
||||
STMT(get_guild_member_ids);
|
||||
STMT(clr_role);
|
||||
STMT(get_guild_owner);
|
||||
#undef STMT
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user