mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-06 20:15:19 +03:00
friends: accept incoming
This commit is contained in:
@@ -77,6 +77,7 @@ FriendsList::FriendsList()
|
||||
FriendsListFriendRow *FriendsList::MakeRow(const UserData &user, RelationshipType type) {
|
||||
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_accept().connect(sigc::bind(sigc::mem_fun(*this, &FriendsList::OnActionAccept), user.ID));
|
||||
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) {
|
||||
auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
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() {
|
||||
return type_signal_accept();
|
||||
return m_signal_accept;
|
||||
}
|
||||
|
||||
FriendsListWindow::FriendsListWindow() {
|
||||
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
void OnRelationshipAdd(const RelationshipAddData &data);
|
||||
void OnRelationshipRemove(Snowflake id, RelationshipType type);
|
||||
|
||||
void OnActionAccept(Snowflake id);
|
||||
void OnActionRemove(Snowflake id);
|
||||
|
||||
enum FilterMode {
|
||||
|
||||
@@ -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<void(bool success, DiscordError code)> 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<DiscordError>();
|
||||
} catch (...) {}
|
||||
return DiscordError::GENERIC;
|
||||
}
|
||||
|
||||
void DiscordClient::ProcessNewGuild(GuildData &guild) {
|
||||
if (guild.IsUnavailable) {
|
||||
printf("guild (%lld) unavailable\n", static_cast<uint64_t>(guild.ID));
|
||||
|
||||
@@ -140,6 +140,7 @@ public:
|
||||
std::optional<GuildApplicationData> GetGuildApplication(Snowflake guild_id) const;
|
||||
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 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, Snowflake user_id) const;
|
||||
@@ -190,6 +191,8 @@ private:
|
||||
std::vector<uint8_t> m_decompress_buf;
|
||||
z_stream m_zstream;
|
||||
|
||||
static DiscordError GetCodeFromResponse(const http::response_type &response);
|
||||
|
||||
void ProcessNewGuild(GuildData &guild);
|
||||
|
||||
void HandleGatewayMessageRaw(std::string str);
|
||||
|
||||
@@ -468,3 +468,7 @@ void to_json(nlohmann::json &j, const FriendRequestObject &m) {
|
||||
j["username"] = m.Username;
|
||||
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);
|
||||
};
|
||||
|
||||
struct PutRelationshipObject {
|
||||
std::optional<RelationshipType> Type;
|
||||
|
||||
friend void to_json(nlohmann::json &j, const PutRelationshipObject &m);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user