forked from OpenGamers/abaddon
open dm tries to bring you to new dm if it doesnt exist now
This commit is contained in:
parent
14138ca568
commit
b1c7ac7120
10
abaddon.cpp
10
abaddon.cpp
@ -324,7 +324,15 @@ void Abaddon::on_user_menu_open_dm() {
|
||||
if (existing.has_value())
|
||||
ActionChannelOpened(*existing);
|
||||
else
|
||||
m_discord.CreateDM(m_shown_user_menu_id);
|
||||
m_discord.CreateDM(m_shown_user_menu_id, [this](bool success, Snowflake channel_id) {
|
||||
if (success) {
|
||||
// give the gateway a little window to send CHANNEL_CREATE
|
||||
auto cb = [this, channel_id] {
|
||||
ActionChannelOpened(channel_id);
|
||||
};
|
||||
Glib::signal_timeout().connect_once(sigc::track_obj(cb, *this), 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Abaddon::ActionConnect() {
|
||||
|
@ -420,10 +420,20 @@ void DiscordClient::UpdateStatus(PresenceStatus status, bool is_afk, const Activ
|
||||
}
|
||||
|
||||
void DiscordClient::CreateDM(Snowflake user_id) {
|
||||
// actual client uses an array called recipients
|
||||
CreateDM(user_id, [](...) {});
|
||||
}
|
||||
|
||||
void DiscordClient::CreateDM(Snowflake user_id, sigc::slot<void(bool success, Snowflake channel_id)> callback) {
|
||||
CreateDMObject obj;
|
||||
obj.Recipients.push_back(user_id);
|
||||
m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [](auto) {});
|
||||
m_http.MakePOST("/users/@me/channels", nlohmann::json(obj).dump(), [this, callback](const http::response &response) {
|
||||
if (!CheckCode(response)) {
|
||||
callback(false, Snowflake::Invalid);
|
||||
return;
|
||||
}
|
||||
auto channel = nlohmann::json::parse(response.text).get<ChannelData>();
|
||||
callback(response.status_code == 200, channel.ID);
|
||||
});
|
||||
}
|
||||
|
||||
std::optional<Snowflake> DiscordClient::FindDM(Snowflake user_id) {
|
||||
|
@ -108,6 +108,7 @@ public:
|
||||
void UpdateStatus(PresenceStatus status, bool is_afk);
|
||||
void UpdateStatus(PresenceStatus status, bool is_afk, const ActivityData &obj);
|
||||
void CreateDM(Snowflake user_id);
|
||||
void CreateDM(Snowflake user_id, sigc::slot<void(bool success, Snowflake channel_id)> callback);
|
||||
std::optional<Snowflake> FindDM(Snowflake user_id); // wont find group dms
|
||||
void AddReaction(Snowflake id, Glib::ustring param);
|
||||
void RemoveReaction(Snowflake id, Glib::ustring param);
|
||||
|
Loading…
Reference in New Issue
Block a user