From 858fd8ce626d3f3c5ef3c4349612e520f07eff6a Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 11 May 2021 04:06:23 -0400 Subject: friends: accept incoming --- discord/discord.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'discord/discord.cpp') diff --git a/discord/discord.cpp b/discord/discord.cpp index 0cf813a..0e06e39 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -702,17 +702,19 @@ void DiscordClient::SendFriendRequest(const Glib::ustring &username, int discrim obj.Username = username; obj.Discriminator = discriminator; 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); - } else { - auto code = DiscordError::GENERIC; - try { - // pull me somewhere else? - const auto data = nlohmann::json::parse(response.text); - data.at("code").get_to(code); - } catch (...) {} - callback(false, code); - } + else + callback(false, GetCodeFromResponse(response)); + }); +} + +void DiscordClient::PutRelationship(Snowflake id, sigc::slot callback) { + m_http.MakePUT("/users/@me/relationships/" + std::to_string(id), "{}", [this, callback](const http::response_type &response) { + if (CheckCode(response, 204)) + callback(true, DiscordError::NONE); + else + callback(false, GetCodeFromResponse(response)); }); } @@ -1102,6 +1104,15 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) { 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(); + } catch (...) {} + return DiscordError::GENERIC; +} + void DiscordClient::ProcessNewGuild(GuildData &guild) { if (guild.IsUnavailable) { printf("guild (%lld) unavailable\n", static_cast(guild.ID)); -- cgit v1.2.3