forked from OpenGamers/abaddon
friends: accept incoming
This commit is contained in:
@@ -77,6 +77,7 @@ FriendsList::FriendsList()
|
|||||||
FriendsListFriendRow *FriendsList::MakeRow(const UserData &user, RelationshipType type) {
|
FriendsListFriendRow *FriendsList::MakeRow(const UserData &user, RelationshipType type) {
|
||||||
auto *row = Gtk::manage(new FriendsListFriendRow(type, user));
|
auto *row = Gtk::manage(new FriendsListFriendRow(type, user));
|
||||||
row->signal_action_remove().connect(sigc::bind(sigc::mem_fun(*this, &FriendsList::OnActionRemove), user.ID));
|
row->signal_action_remove().connect(sigc::bind(sigc::mem_fun(*this, &FriendsList::OnActionRemove), user.ID));
|
||||||
|
row->signal_action_accept().connect(sigc::bind(sigc::mem_fun(*this, &FriendsList::OnActionAccept), user.ID));
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +103,17 @@ void FriendsList::OnRelationshipRemove(Snowflake id, RelationshipType type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendsList::OnActionAccept(Snowflake id) {
|
||||||
|
const auto cb = [this](bool success, DiscordError code) {
|
||||||
|
if (!success) {
|
||||||
|
Gtk::MessageDialog dlg(*dynamic_cast<Gtk::Window *>(get_toplevel()), "Failed to accept", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
|
||||||
|
dlg.set_position(Gtk::WIN_POS_CENTER);
|
||||||
|
dlg.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Abaddon::Get().GetDiscordClient().PutRelationship(id, sigc::track_obj(cb, *this));
|
||||||
|
}
|
||||||
|
|
||||||
void FriendsList::OnActionRemove(Snowflake id) {
|
void FriendsList::OnActionRemove(Snowflake id) {
|
||||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||||
const auto user = discord.GetUser(id);
|
const auto user = discord.GetUser(id);
|
||||||
@@ -316,7 +328,7 @@ FriendsListFriendRow::type_signal_remove FriendsListFriendRow::signal_action_rem
|
|||||||
}
|
}
|
||||||
|
|
||||||
FriendsListFriendRow::type_signal_accept FriendsListFriendRow::signal_action_accept() {
|
FriendsListFriendRow::type_signal_accept FriendsListFriendRow::signal_action_accept() {
|
||||||
return type_signal_accept();
|
return m_signal_accept;
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendsListWindow::FriendsListWindow() {
|
FriendsListWindow::FriendsListWindow() {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ private:
|
|||||||
void OnRelationshipAdd(const RelationshipAddData &data);
|
void OnRelationshipAdd(const RelationshipAddData &data);
|
||||||
void OnRelationshipRemove(Snowflake id, RelationshipType type);
|
void OnRelationshipRemove(Snowflake id, RelationshipType type);
|
||||||
|
|
||||||
|
void OnActionAccept(Snowflake id);
|
||||||
void OnActionRemove(Snowflake id);
|
void OnActionRemove(Snowflake id);
|
||||||
|
|
||||||
enum FilterMode {
|
enum FilterMode {
|
||||||
|
|||||||
@@ -702,17 +702,19 @@ void DiscordClient::SendFriendRequest(const Glib::ustring &username, int discrim
|
|||||||
obj.Username = username;
|
obj.Username = username;
|
||||||
obj.Discriminator = discriminator;
|
obj.Discriminator = discriminator;
|
||||||
m_http.MakePOST("/users/@me/relationships", nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) {
|
m_http.MakePOST("/users/@me/relationships", nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) {
|
||||||
if (CheckCode(response, 204)) {
|
if (CheckCode(response, 204))
|
||||||
callback(true, DiscordError::NONE);
|
callback(true, DiscordError::NONE);
|
||||||
} else {
|
else
|
||||||
auto code = DiscordError::GENERIC;
|
callback(false, GetCodeFromResponse(response));
|
||||||
try {
|
});
|
||||||
// pull me somewhere else?
|
}
|
||||||
const auto data = nlohmann::json::parse(response.text);
|
|
||||||
data.at("code").get_to(code);
|
void DiscordClient::PutRelationship(Snowflake id, sigc::slot<void(bool success, DiscordError code)> callback) {
|
||||||
} catch (...) {}
|
m_http.MakePUT("/users/@me/relationships/" + std::to_string(id), "{}", [this, callback](const http::response_type &response) {
|
||||||
callback(false, code);
|
if (CheckCode(response, 204))
|
||||||
}
|
callback(true, DiscordError::NONE);
|
||||||
|
else
|
||||||
|
callback(false, GetCodeFromResponse(response));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1102,6 +1104,15 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) {
|
|||||||
SendIdentify();
|
SendIdentify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiscordError DiscordClient::GetCodeFromResponse(const http::response_type &response) {
|
||||||
|
try {
|
||||||
|
// pull me somewhere else?
|
||||||
|
const auto data = nlohmann::json::parse(response.text);
|
||||||
|
return data.at("code").get<DiscordError>();
|
||||||
|
} catch (...) {}
|
||||||
|
return DiscordError::GENERIC;
|
||||||
|
}
|
||||||
|
|
||||||
void DiscordClient::ProcessNewGuild(GuildData &guild) {
|
void DiscordClient::ProcessNewGuild(GuildData &guild) {
|
||||||
if (guild.IsUnavailable) {
|
if (guild.IsUnavailable) {
|
||||||
printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID));
|
printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID));
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ public:
|
|||||||
std::optional<GuildApplicationData> GetGuildApplication(Snowflake guild_id) const;
|
std::optional<GuildApplicationData> GetGuildApplication(Snowflake guild_id) const;
|
||||||
void RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback);
|
void RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback);
|
||||||
void SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(bool success, DiscordError code)> callback);
|
void SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(bool success, DiscordError code)> callback);
|
||||||
|
void PutRelationship(Snowflake id, sigc::slot<void(bool success, DiscordError code)> callback); // send fr by id, accept incoming
|
||||||
|
|
||||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const;
|
bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const;
|
||||||
bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;
|
bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;
|
||||||
@@ -190,6 +191,8 @@ private:
|
|||||||
std::vector<uint8_t> m_decompress_buf;
|
std::vector<uint8_t> m_decompress_buf;
|
||||||
z_stream m_zstream;
|
z_stream m_zstream;
|
||||||
|
|
||||||
|
static DiscordError GetCodeFromResponse(const http::response_type &response);
|
||||||
|
|
||||||
void ProcessNewGuild(GuildData &guild);
|
void ProcessNewGuild(GuildData &guild);
|
||||||
|
|
||||||
void HandleGatewayMessageRaw(std::string str);
|
void HandleGatewayMessageRaw(std::string str);
|
||||||
|
|||||||
@@ -468,3 +468,7 @@ void to_json(nlohmann::json &j, const FriendRequestObject &m) {
|
|||||||
j["username"] = m.Username;
|
j["username"] = m.Username;
|
||||||
j["discriminator"] = m.Discriminator;
|
j["discriminator"] = m.Discriminator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void to_json(nlohmann::json &j, const PutRelationshipObject &m) {
|
||||||
|
JS_IF("type", m.Type);
|
||||||
|
}
|
||||||
|
|||||||
@@ -653,3 +653,9 @@ struct FriendRequestObject {
|
|||||||
|
|
||||||
friend void to_json(nlohmann::json &j, const FriendRequestObject &m);
|
friend void to_json(nlohmann::json &j, const FriendRequestObject &m);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PutRelationshipObject {
|
||||||
|
std::optional<RelationshipType> Type;
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json &j, const PutRelationshipObject &m);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user