mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-04 11:33:27 +03:00
add ability to remove relationships
This commit is contained in:
@@ -13,7 +13,7 @@ FriendsList::FriendsList()
|
||||
for (const auto &[id, type] : discord.GetRelationships()) {
|
||||
const auto user = discord.GetUser(id);
|
||||
if (!user.has_value()) continue;
|
||||
auto *row = Gtk::manage(new FriendsListFriendRow(type, *user));
|
||||
auto *row = MakeRow(*user, type);
|
||||
m_list.add(*row);
|
||||
row->show();
|
||||
}
|
||||
@@ -72,6 +72,12 @@ FriendsList::FriendsList()
|
||||
m_list.show();
|
||||
}
|
||||
|
||||
FriendsListFriendRow *FriendsList::MakeRow(const UserData &user, RelationshipType type) {
|
||||
auto *row = Gtk::manage(new FriendsListFriendRow(type, user));
|
||||
row->signal_action_remove().connect(sigc::bind(sigc::mem_fun(*this, &FriendsList::OnActionRemove), user.ID));
|
||||
return row;
|
||||
}
|
||||
|
||||
void FriendsList::OnRelationshipAdd(const RelationshipAddData &data) {
|
||||
for (auto *row_ : m_list.get_children()) {
|
||||
auto *row = dynamic_cast<FriendsListFriendRow *>(row_);
|
||||
@@ -80,7 +86,7 @@ void FriendsList::OnRelationshipAdd(const RelationshipAddData &data) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto *row = Gtk::manage(new FriendsListFriendRow(data.Type, data.User));
|
||||
auto *row = MakeRow(data.User, data.Type);
|
||||
m_list.add(*row);
|
||||
row->show();
|
||||
}
|
||||
@@ -94,6 +100,39 @@ void FriendsList::OnRelationshipRemove(Snowflake id, RelationshipType type) {
|
||||
}
|
||||
}
|
||||
|
||||
void FriendsList::OnActionRemove(Snowflake id) {
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto user = discord.GetUser(id);
|
||||
if (auto *window = dynamic_cast<Gtk::Window *>(get_toplevel())) {
|
||||
Glib::ustring str;
|
||||
switch (*discord.GetRelationship(id)) {
|
||||
case RelationshipType::Blocked:
|
||||
str = "Are you sure you want to unblock " + user->Username + "#" + user->Discriminator + "?";
|
||||
break;
|
||||
case RelationshipType::Friend:
|
||||
str = "Are you sure you want to remove " + user->Username + "#" + user->Discriminator + "?";
|
||||
break;
|
||||
case RelationshipType::PendingIncoming:
|
||||
str = "Are you sure you want to ignore " + user->Username + "#" + user->Discriminator + "?";
|
||||
break;
|
||||
case RelationshipType::PendingOutgoing:
|
||||
str = "Are you sure you want to cancel your request to " + user->Username + "#" + user->Discriminator + "?";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (Abaddon::Get().ShowConfirm(str, window)) {
|
||||
const auto cb = [this, window](bool success) {
|
||||
if (success) return;
|
||||
Gtk::MessageDialog dlg(*window, "Failed to remove user", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
|
||||
dlg.set_position(Gtk::WIN_POS_CENTER);
|
||||
dlg.run();
|
||||
};
|
||||
discord.RemoveRelationship(id, sigc::track_obj(cb, *this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int FriendsList::ListSortFunc(Gtk::ListBoxRow *a_, Gtk::ListBoxRow *b_) {
|
||||
auto *a = dynamic_cast<FriendsListFriendRow *>(a_);
|
||||
auto *b = dynamic_cast<FriendsListFriendRow *>(b_);
|
||||
|
||||
@@ -14,14 +14,19 @@ private:
|
||||
Gtk::Box m_box;
|
||||
};
|
||||
|
||||
class FriendsListFriendRow;
|
||||
class FriendsList : public Gtk::Box {
|
||||
public:
|
||||
FriendsList();
|
||||
|
||||
private:
|
||||
FriendsListFriendRow *MakeRow(const UserData &user, RelationshipType type);
|
||||
|
||||
void OnRelationshipAdd(const RelationshipAddData &data);
|
||||
void OnRelationshipRemove(Snowflake id, RelationshipType type);
|
||||
|
||||
void OnActionRemove(Snowflake id);
|
||||
|
||||
enum FilterMode {
|
||||
FILTER_FRIENDS,
|
||||
FILTER_ONLINE,
|
||||
|
||||
@@ -691,6 +691,12 @@ std::optional<GuildApplicationData> DiscordClient::GetGuildApplication(Snowflake
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void DiscordClient::RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback) {
|
||||
m_http.MakeDELETE("/users/@me/relationships/" + std::to_string(id), [this, callback](const http::response_type &response) {
|
||||
callback(CheckCode(response));
|
||||
});
|
||||
}
|
||||
|
||||
bool DiscordClient::CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const {
|
||||
const auto guild = *GetGuild(guild_id);
|
||||
if (guild.OwnerID == user_id) return true;
|
||||
@@ -862,6 +868,12 @@ std::unordered_set<Snowflake> DiscordClient::GetRelationships(RelationshipType t
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<RelationshipType> DiscordClient::GetRelationship(Snowflake id) const {
|
||||
if (auto it = m_user_relationships.find(id); it != m_user_relationships.end())
|
||||
return it->second;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayMessageRaw(std::string str) {
|
||||
// handles multiple zlib compressed messages, calling HandleGatewayMessage when a full message is received
|
||||
std::vector<uint8_t> buf(str.begin(), str.end());
|
||||
|
||||
@@ -138,6 +138,7 @@ public:
|
||||
void ModifyEmojiName(Snowflake guild_id, Snowflake emoji_id, const Glib::ustring &name, sigc::slot<void(bool success)> callback);
|
||||
void DeleteEmoji(Snowflake guild_id, Snowflake emoji_id, sigc::slot<void(bool success)> callback);
|
||||
std::optional<GuildApplicationData> GetGuildApplication(Snowflake guild_id) const;
|
||||
void RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback);
|
||||
|
||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const;
|
||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;
|
||||
@@ -180,6 +181,7 @@ public:
|
||||
|
||||
std::unordered_map<Snowflake, RelationshipType> GetRelationships() const;
|
||||
std::unordered_set<Snowflake> GetRelationships(RelationshipType type) const;
|
||||
std::optional<RelationshipType> GetRelationship(Snowflake id) const;
|
||||
|
||||
private:
|
||||
static const constexpr int InflateChunkSize = 0x10000;
|
||||
|
||||
Reference in New Issue
Block a user