forked from OpenGamers/abaddon
friends: handle presence updates
This commit is contained in:
@@ -5,8 +5,10 @@
|
|||||||
FriendsList::FriendsList()
|
FriendsList::FriendsList()
|
||||||
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
|
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
|
||||||
, m_filter_mode(FILTER_FRIENDS) {
|
, m_filter_mode(FILTER_FRIENDS) {
|
||||||
for (const auto &[id, type] : Abaddon::Get().GetDiscordClient().GetRelationships()) {
|
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||||
const auto user = Abaddon::Get().GetDiscordClient().GetUser(id);
|
|
||||||
|
for (const auto &[id, type] : discord.GetRelationships()) {
|
||||||
|
const auto user = discord.GetUser(id);
|
||||||
if (!user.has_value()) continue;
|
if (!user.has_value()) continue;
|
||||||
auto *row = Gtk::manage(new FriendsListFriendRow(type, *user));
|
auto *row = Gtk::manage(new FriendsListFriendRow(type, *user));
|
||||||
m_list.add(*row);
|
m_list.add(*row);
|
||||||
@@ -81,7 +83,7 @@ bool FriendsList::ListFilterFunc(Gtk::ListBoxRow *row_) {
|
|||||||
case FILTER_FRIENDS:
|
case FILTER_FRIENDS:
|
||||||
return row->Type == RelationshipType::Friend;
|
return row->Type == RelationshipType::Friend;
|
||||||
case FILTER_ONLINE:
|
case FILTER_ONLINE:
|
||||||
return false; // blah
|
return row->Type == RelationshipType::Friend && row->Status != PresenceStatus::Offline;
|
||||||
case FILTER_PENDING:
|
case FILTER_PENDING:
|
||||||
return row->Type == RelationshipType::PendingIncoming || row->Type == RelationshipType::PendingOutgoing;
|
return row->Type == RelationshipType::PendingIncoming || row->Type == RelationshipType::PendingOutgoing;
|
||||||
case FILTER_BLOCKED:
|
case FILTER_BLOCKED:
|
||||||
@@ -115,14 +117,18 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
|
|||||||
: Name(data.Username + "#" + data.Discriminator)
|
: Name(data.Username + "#" + data.Discriminator)
|
||||||
, Type(type)
|
, Type(type)
|
||||||
, ID(data.ID)
|
, ID(data.ID)
|
||||||
|
, Status(Abaddon::Get().GetDiscordClient().GetUserStatus(data.ID))
|
||||||
, m_accept("Accept") {
|
, m_accept("Accept") {
|
||||||
auto *ev = Gtk::manage(new Gtk::EventBox);
|
auto *ev = Gtk::manage(new Gtk::EventBox);
|
||||||
auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||||
auto *img = Gtk::manage(new LazyImage(32, 32, true));
|
auto *img = Gtk::manage(new LazyImage(32, 32, true));
|
||||||
auto *namelbl = Gtk::manage(new Gtk::Label(Name, Gtk::ALIGN_START));
|
auto *namelbl = Gtk::manage(new Gtk::Label(Name, Gtk::ALIGN_START));
|
||||||
auto *statuslbl = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
|
m_status_lbl = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
|
||||||
auto *lblbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
|
auto *lblbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
|
||||||
|
|
||||||
|
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||||
|
discord.signal_presence_update().connect(sigc::mem_fun(*this, &FriendsListFriendRow::OnPresenceUpdate));
|
||||||
|
|
||||||
if (data.HasAnimatedAvatar()) {
|
if (data.HasAnimatedAvatar()) {
|
||||||
img->SetAnimated(true);
|
img->SetAnimated(true);
|
||||||
img->SetURL(data.GetAvatarURL("gif", "32"));
|
img->SetURL(data.GetAvatarURL("gif", "32"));
|
||||||
@@ -130,17 +136,7 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
|
|||||||
img->SetURL(data.GetAvatarURL("png", "32"));
|
img->SetURL(data.GetAvatarURL("png", "32"));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Type) {
|
UpdatePresenceLabel();
|
||||||
case RelationshipType::PendingIncoming:
|
|
||||||
statuslbl->set_text("Incoming Friend Request");
|
|
||||||
break;
|
|
||||||
case RelationshipType::PendingOutgoing:
|
|
||||||
statuslbl->set_text("Outgoing Friend Request");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
statuslbl->set_text(GetPresenceDisplayString(Abaddon::Get().GetDiscordClient().GetUserStatus(data.ID)));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddWidgetMenuHandler(ev, m_menu, [this] {
|
AddWidgetMenuHandler(ev, m_menu, [this] {
|
||||||
m_accept.set_visible(Type == RelationshipType::PendingIncoming);
|
m_accept.set_visible(Type == RelationshipType::PendingIncoming);
|
||||||
@@ -178,7 +174,7 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
|
|||||||
img->set_margin_end(5);
|
img->set_margin_end(5);
|
||||||
|
|
||||||
lblbox->add(*namelbl);
|
lblbox->add(*namelbl);
|
||||||
lblbox->add(*statuslbl);
|
lblbox->add(*m_status_lbl);
|
||||||
|
|
||||||
box->add(*img);
|
box->add(*img);
|
||||||
box->add(*lblbox);
|
box->add(*lblbox);
|
||||||
@@ -188,6 +184,27 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
|
|||||||
show_all_children();
|
show_all_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendsListFriendRow::UpdatePresenceLabel() {
|
||||||
|
switch (Type) {
|
||||||
|
case RelationshipType::PendingIncoming:
|
||||||
|
m_status_lbl->set_text("Incoming Friend Request");
|
||||||
|
break;
|
||||||
|
case RelationshipType::PendingOutgoing:
|
||||||
|
m_status_lbl->set_text("Outgoing Friend Request");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
m_status_lbl->set_text(GetPresenceDisplayString(Status));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendsListFriendRow::OnPresenceUpdate(const UserData &user, PresenceStatus status) {
|
||||||
|
if (user.ID != ID) return;
|
||||||
|
Status = status;
|
||||||
|
UpdatePresenceLabel();
|
||||||
|
changed();
|
||||||
|
}
|
||||||
|
|
||||||
FriendsListFriendRow::type_signal_remove FriendsListFriendRow::signal_action_remove() {
|
FriendsListFriendRow::type_signal_remove FriendsListFriendRow::signal_action_remove() {
|
||||||
return m_signal_remove;
|
return m_signal_remove;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include "../discord/relationship.hpp"
|
#include "../discord/relationship.hpp"
|
||||||
|
#include "../discord/activity.hpp"
|
||||||
|
|
||||||
class FriendsListAddComponent : public Gtk::Box {
|
class FriendsListAddComponent : public Gtk::Box {
|
||||||
public:
|
public:
|
||||||
@@ -45,8 +46,14 @@ public:
|
|||||||
Snowflake ID;
|
Snowflake ID;
|
||||||
RelationshipType Type;
|
RelationshipType Type;
|
||||||
Glib::ustring Name;
|
Glib::ustring Name;
|
||||||
|
PresenceStatus Status;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void UpdatePresenceLabel();
|
||||||
|
void OnPresenceUpdate(const UserData &user, PresenceStatus status);
|
||||||
|
|
||||||
|
Gtk::Label *m_status_lbl;
|
||||||
|
|
||||||
Gtk::Menu m_menu;
|
Gtk::Menu m_menu;
|
||||||
Gtk::MenuItem m_remove; // or cancel or ignore
|
Gtk::MenuItem m_remove; // or cancel or ignore
|
||||||
Gtk::MenuItem m_accept; // incoming
|
Gtk::MenuItem m_accept; // incoming
|
||||||
|
|||||||
Reference in New Issue
Block a user