summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-05-10 02:13:12 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-05-10 02:13:12 -0400
commit06ba3acc93ed57cb41e319eb5f7da06d15b72ec2 (patch)
tree13b208f4f0372d1d670fca1e7eb4e374fa1c2971 /components
parent81ae2b3a83e5c9e1f34714f7ba004638b3beeeb0 (diff)
downloadabaddon-portaudio-06ba3acc93ed57cb41e319eb5f7da06d15b72ec2.tar.gz
abaddon-portaudio-06ba3acc93ed57cb41e319eb5f7da06d15b72ec2.zip
friends: send friend requests
Diffstat (limited to 'components')
-rw-r--r--components/friendslist.cpp40
-rw-r--r--components/friendslist.hpp5
2 files changed, 45 insertions, 0 deletions
diff --git a/components/friendslist.cpp b/components/friendslist.cpp
index 014f8ba..4486d97 100644
--- a/components/friendslist.cpp
+++ b/components/friendslist.cpp
@@ -2,6 +2,8 @@
#include "../abaddon.hpp"
#include "lazyimage.hpp"
+using namespace std::string_literals;
+
FriendsList::FriendsList()
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, m_filter_mode(FILTER_FRIENDS) {
@@ -167,9 +169,12 @@ FriendsListAddComponent::FriendsListAddComponent()
m_box.add(m_add);
m_box.add(m_status);
+ m_add.signal_clicked().connect(sigc::mem_fun(*this, &FriendsListAddComponent::Submit));
+
m_label.set_halign(Gtk::ALIGN_CENTER);
m_entry.set_placeholder_text("Enter a Username#1234");
+ m_entry.signal_key_press_event().connect(sigc::mem_fun(*this, &FriendsListAddComponent::OnKeyPress), false);
add(m_label);
add(m_box);
@@ -177,6 +182,41 @@ FriendsListAddComponent::FriendsListAddComponent()
show_all_children();
}
+void FriendsListAddComponent::Submit() {
+ if (m_requesting) return;
+
+ auto text = m_entry.get_text();
+ m_label.set_text("Invalid input"); // cheeky !!
+ m_entry.set_text("");
+ const auto hashpos = text.find("#");
+ if (hashpos == Glib::ustring::npos) return;
+ const auto username = text.substr(0, hashpos);
+ const auto discriminator = text.substr(hashpos + 1);
+ if (username.size() == 0 || discriminator.size() != 4) return;
+ if (discriminator.find_first_not_of("0123456789") != Glib::ustring::npos) return;
+
+ m_requesting = true;
+ m_label.set_text("Hang on...");
+
+ const auto cb = [this](bool success, DiscordError code) {
+ m_requesting = false;
+ if (success) {
+ m_label.set_text("Success!");
+ } else {
+ m_label.set_text("Failed: "s + GetDiscordErrorDisplayString(code));
+ }
+ };
+ Abaddon::Get().GetDiscordClient().SendFriendRequest(username, std::stoul(discriminator), sigc::track_obj(cb, *this));
+}
+
+bool FriendsListAddComponent::OnKeyPress(GdkEventKey *e) {
+ if (e->keyval == GDK_KEY_Return) {
+ Submit();
+ return true;
+ }
+ return false;
+}
+
FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData &data)
: Name(data.Username + "#" + data.Discriminator)
, Type(type)
diff --git a/components/friendslist.hpp b/components/friendslist.hpp
index 0e5afe3..5582e26 100644
--- a/components/friendslist.hpp
+++ b/components/friendslist.hpp
@@ -7,11 +7,16 @@ public:
FriendsListAddComponent();
private:
+ void Submit();
+ bool OnKeyPress(GdkEventKey *e);
+
Gtk::Label m_label;
Gtk::Label m_status;
Gtk::Entry m_entry;
Gtk::Button m_add;
Gtk::Box m_box;
+
+ bool m_requesting = false;
};
class FriendsListFriendRow;