diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-05-09 02:55:35 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-05-09 02:55:35 -0400 |
commit | e6a20e59840a111ab94aaa55974bb43989571344 (patch) | |
tree | 11148b68f896ec1244007a3c7b110ca717f88f27 /components | |
parent | ae3b25674635257b70f5ad59b71abaf0019c6b4e (diff) | |
download | abaddon-portaudio-e6a20e59840a111ab94aaa55974bb43989571344.tar.gz abaddon-portaudio-e6a20e59840a111ab94aaa55974bb43989571344.zip |
add ability to remove relationships
Diffstat (limited to 'components')
-rw-r--r-- | components/friendslist.cpp | 43 | ||||
-rw-r--r-- | components/friendslist.hpp | 5 |
2 files changed, 46 insertions, 2 deletions
diff --git a/components/friendslist.cpp b/components/friendslist.cpp index 14e4538..014f8ba 100644 --- a/components/friendslist.cpp +++ b/components/friendslist.cpp @@ -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_); diff --git a/components/friendslist.hpp b/components/friendslist.hpp index dcd5e74..0e5afe3 100644 --- a/components/friendslist.hpp +++ b/components/friendslist.hpp @@ -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, |