forked from OpenGamers/abaddon
show mutual friends
This commit is contained in:
@@ -599,6 +599,16 @@ void DiscordClient::SetUserNote(Snowflake user_id, std::string note, sigc::slot<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiscordClient::FetchUserRelationships(Snowflake user_id, sigc::slot<void(std::vector<UserData>)> callback) {
|
||||||
|
m_http.MakeGET("/users/" + std::to_string(user_id) + "/relationships", [this, callback](const http::response_type &response) {
|
||||||
|
if (!CheckCode(response)) return;
|
||||||
|
RelationshipsData data = nlohmann::json::parse(response.text);
|
||||||
|
for (const auto &user : data.Users)
|
||||||
|
m_store.SetUser(user.ID, user);
|
||||||
|
callback(data.Users);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void DiscordClient::UpdateToken(std::string token) {
|
void DiscordClient::UpdateToken(std::string token) {
|
||||||
if (!IsStarted()) {
|
if (!IsStarted()) {
|
||||||
m_token = token;
|
m_token = token;
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ public:
|
|||||||
void FetchUserNote(Snowflake user_id, sigc::slot<void(std::string note)> callback);
|
void FetchUserNote(Snowflake user_id, sigc::slot<void(std::string note)> callback);
|
||||||
void SetUserNote(Snowflake user_id, std::string note);
|
void SetUserNote(Snowflake user_id, std::string note);
|
||||||
void SetUserNote(Snowflake user_id, std::string note, sigc::slot<void(bool success)> callback);
|
void SetUserNote(Snowflake user_id, std::string note, sigc::slot<void(bool success)> callback);
|
||||||
|
void FetchUserRelationships(Snowflake user_id, sigc::slot<void(std::vector<UserData>)> callback);
|
||||||
|
|
||||||
void UpdateToken(std::string token);
|
void UpdateToken(std::string token);
|
||||||
void SetUserAgent(std::string agent);
|
void SetUserAgent(std::string agent);
|
||||||
|
|||||||
@@ -337,3 +337,7 @@ void from_json(const nlohmann::json &j, UserNoteUpdateMessage &m) {
|
|||||||
JS_D("note", m.Note);
|
JS_D("note", m.Note);
|
||||||
JS_D("id", m.ID);
|
JS_D("id", m.ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void from_json(const nlohmann::json &j, RelationshipsData &m) {
|
||||||
|
j.get_to(m.Users);
|
||||||
|
}
|
||||||
|
|||||||
@@ -473,3 +473,9 @@ struct UserNoteUpdateMessage {
|
|||||||
|
|
||||||
friend void from_json(const nlohmann::json &j, UserNoteUpdateMessage &m);
|
friend void from_json(const nlohmann::json &j, UserNoteUpdateMessage &m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RelationshipsData {
|
||||||
|
std::vector<UserData> Users;
|
||||||
|
|
||||||
|
friend void from_json(const nlohmann::json &j, RelationshipsData &m);
|
||||||
|
};
|
||||||
|
|||||||
54
windows/profile/mutualfriendspane.cpp
Normal file
54
windows/profile/mutualfriendspane.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "mutualfriendspane.hpp"
|
||||||
|
#include "../../abaddon.hpp"
|
||||||
|
|
||||||
|
MutualFriendItem::MutualFriendItem(const UserData &user)
|
||||||
|
: Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) {
|
||||||
|
get_style_context()->add_class("mutual-friend-item");
|
||||||
|
m_name.get_style_context()->add_class("mutual-friend-item-name");
|
||||||
|
m_avatar.get_style_context()->add_class("mutual-friend-item-avatar");
|
||||||
|
|
||||||
|
m_avatar.set_margin_end(10);
|
||||||
|
|
||||||
|
const auto show_animations = Abaddon::Get().GetSettings().GetShowAnimations();
|
||||||
|
auto &img = Abaddon::Get().GetImageManager();
|
||||||
|
m_avatar.property_pixbuf() = img.GetPlaceholder(24);
|
||||||
|
if (user.HasAvatar()) {
|
||||||
|
if (user.HasAnimatedAvatar() && show_animations) {
|
||||||
|
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
|
||||||
|
m_avatar.property_pixbuf_animation() = pb;
|
||||||
|
};
|
||||||
|
img.LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this));
|
||||||
|
} else {
|
||||||
|
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
|
||||||
|
m_avatar.property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
|
||||||
|
};
|
||||||
|
img.LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_name.set_markup("<b>" +
|
||||||
|
Glib::Markup::escape_text(user.Username) +
|
||||||
|
"</b>#" + user.Discriminator);
|
||||||
|
|
||||||
|
m_name.set_valign(Gtk::ALIGN_CENTER);
|
||||||
|
add(m_avatar);
|
||||||
|
add(m_name);
|
||||||
|
show_all_children();
|
||||||
|
}
|
||||||
|
|
||||||
|
MutualFriendsPane::MutualFriendsPane(Snowflake id)
|
||||||
|
: UserID(id) {
|
||||||
|
add(m_list);
|
||||||
|
show_all_children();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MutualFriendsPane::SetMutualFriends(const std::vector<UserData> &users) {
|
||||||
|
for (auto child : m_list.get_children())
|
||||||
|
delete child;
|
||||||
|
|
||||||
|
for (const auto &user : users) {
|
||||||
|
auto *item = Gtk::manage(new MutualFriendItem(user));
|
||||||
|
item->show();
|
||||||
|
m_list.add(*item);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
windows/profile/mutualfriendspane.hpp
Normal file
24
windows/profile/mutualfriendspane.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <gtkmm.h>
|
||||||
|
#include "../../discord/objects.hpp"
|
||||||
|
|
||||||
|
class MutualFriendItem : public Gtk::Box {
|
||||||
|
public:
|
||||||
|
MutualFriendItem(const UserData &user);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gtk::Image m_avatar;
|
||||||
|
Gtk::Label m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MutualFriendsPane : public Gtk::ScrolledWindow {
|
||||||
|
public:
|
||||||
|
MutualFriendsPane(Snowflake id);
|
||||||
|
|
||||||
|
void SetMutualFriends(const std::vector<UserData> &users);
|
||||||
|
|
||||||
|
Snowflake UserID;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Gtk::ListBox m_list;
|
||||||
|
};
|
||||||
@@ -7,11 +7,13 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
|||||||
, m_upper(Gtk::ORIENTATION_HORIZONTAL)
|
, m_upper(Gtk::ORIENTATION_HORIZONTAL)
|
||||||
, m_badges(Gtk::ORIENTATION_HORIZONTAL)
|
, m_badges(Gtk::ORIENTATION_HORIZONTAL)
|
||||||
, m_pane_info(user_id)
|
, m_pane_info(user_id)
|
||||||
, m_pane_guilds(user_id) {
|
, m_pane_guilds(user_id)
|
||||||
const auto &discord = Abaddon::Get().GetDiscordClient();
|
, m_pane_friends(user_id) {
|
||||||
|
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||||
auto user = *discord.GetUser(ID);
|
auto user = *discord.GetUser(ID);
|
||||||
|
|
||||||
Abaddon::Get().GetDiscordClient().FetchUserProfile(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchProfile));
|
discord.FetchUserProfile(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchProfile));
|
||||||
|
discord.FetchUserRelationships(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchRelationships));
|
||||||
|
|
||||||
set_name("user-profile");
|
set_name("user-profile");
|
||||||
set_default_size(450, 375);
|
set_default_size(450, 375);
|
||||||
@@ -72,6 +74,7 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
|||||||
|
|
||||||
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_badges.set_valign(Gtk::ALIGN_CENTER);
|
m_badges.set_valign(Gtk::ALIGN_CENTER);
|
||||||
m_badges_scroll.set_hexpand(true);
|
m_badges_scroll.set_hexpand(true);
|
||||||
@@ -126,3 +129,7 @@ void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
|
|||||||
m_badges.add(*image);
|
m_badges.add(*image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProfileWindow::OnFetchRelationships(const std::vector<UserData> &data) {
|
||||||
|
m_pane_friends.SetMutualFriends(data);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "../discord/snowflake.hpp"
|
#include "../discord/snowflake.hpp"
|
||||||
#include "profile/userinfopane.hpp"
|
#include "profile/userinfopane.hpp"
|
||||||
#include "profile/mutualguildspane.hpp"
|
#include "profile/mutualguildspane.hpp"
|
||||||
|
#include "profile/mutualfriendspane.hpp"
|
||||||
|
|
||||||
class ProfileWindow : public Gtk::Window {
|
class ProfileWindow : public Gtk::Window {
|
||||||
public:
|
public:
|
||||||
@@ -14,6 +15,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void OnFetchProfile(const UserProfileData &data);
|
void OnFetchProfile(const UserProfileData &data);
|
||||||
|
void OnFetchRelationships(const std::vector<UserData> &data);
|
||||||
|
|
||||||
Gtk::Box m_main;
|
Gtk::Box m_main;
|
||||||
Gtk::Box m_upper;
|
Gtk::Box m_upper;
|
||||||
@@ -28,4 +30,5 @@ private:
|
|||||||
|
|
||||||
ProfileUserInfoPane m_pane_info;
|
ProfileUserInfoPane m_pane_info;
|
||||||
UserMutualGuildsPane m_pane_guilds;
|
UserMutualGuildsPane m_pane_guilds;
|
||||||
|
MutualFriendsPane m_pane_friends;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user