forked from OpenGamers/abaddon
Merge branch 'master' into channels-list
This commit is contained in:
commit
f60e2cd6bd
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -5,7 +5,7 @@ on: [push, pull_request]
|
||||
jobs:
|
||||
windows:
|
||||
name: windows-${{ matrix.buildtype }}
|
||||
runs-on: windows-2016
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
buildtype: [Debug, RelWithDebInfo, MinSizeRel]
|
||||
|
@ -432,8 +432,7 @@ void Abaddon::ActionConnect() {
|
||||
}
|
||||
|
||||
void Abaddon::ActionDisconnect() {
|
||||
if (m_discord.IsStarted())
|
||||
StopDiscord();
|
||||
StopDiscord();
|
||||
}
|
||||
|
||||
void Abaddon::ActionSetToken() {
|
||||
|
2
ci/vcpkg
2
ci/vcpkg
@ -1 +1 @@
|
||||
Subproject commit a9b27ed5dffbf70b135eddb0c4729f3ca87f106c
|
||||
Subproject commit 50ea8c0ab7aca3bb9245bba7fc877ad2f2a4464c
|
@ -24,6 +24,8 @@ DiscordClient::DiscordClient(bool mem_store)
|
||||
}
|
||||
|
||||
void DiscordClient::Start() {
|
||||
if (m_client_started) return;
|
||||
|
||||
m_http.SetBase(GetAPIURL());
|
||||
|
||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||
@ -32,27 +34,31 @@ void DiscordClient::Start() {
|
||||
m_last_sequence = -1;
|
||||
m_heartbeat_acked = true;
|
||||
m_client_connected = true;
|
||||
m_client_started = true;
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
}
|
||||
|
||||
void DiscordClient::Stop() {
|
||||
if (!m_client_connected) return;
|
||||
if (m_client_started) {
|
||||
inflateEnd(&m_zstream);
|
||||
m_compressed_buf.clear();
|
||||
|
||||
inflateEnd(&m_zstream);
|
||||
m_compressed_buf.clear();
|
||||
m_heartbeat_waiter.kill();
|
||||
if (m_heartbeat_thread.joinable()) m_heartbeat_thread.join();
|
||||
m_client_connected = false;
|
||||
m_reconnecting = false;
|
||||
|
||||
m_heartbeat_waiter.kill();
|
||||
if (m_heartbeat_thread.joinable()) m_heartbeat_thread.join();
|
||||
m_client_connected = false;
|
||||
m_store.ClearAll();
|
||||
m_guild_to_users.clear();
|
||||
|
||||
m_store.ClearAll();
|
||||
m_guild_to_users.clear();
|
||||
m_websocket.Stop();
|
||||
}
|
||||
|
||||
m_websocket.Stop();
|
||||
m_client_started = false;
|
||||
}
|
||||
|
||||
bool DiscordClient::IsStarted() const {
|
||||
return m_client_connected;
|
||||
return m_client_started;
|
||||
}
|
||||
|
||||
bool DiscordClient::IsStoreValid() const {
|
||||
@ -233,19 +239,19 @@ std::optional<RoleData> DiscordClient::GetMemberHighestRole(Snowflake guild_id,
|
||||
});
|
||||
}
|
||||
|
||||
std::unordered_set<Snowflake> DiscordClient::GetUsersInGuild(Snowflake id) const {
|
||||
std::set<Snowflake> DiscordClient::GetUsersInGuild(Snowflake id) const {
|
||||
auto it = m_guild_to_users.find(id);
|
||||
if (it != m_guild_to_users.end())
|
||||
return it->second;
|
||||
|
||||
return std::unordered_set<Snowflake>();
|
||||
return {};
|
||||
}
|
||||
|
||||
std::unordered_set<Snowflake> DiscordClient::GetChannelsInGuild(Snowflake id) const {
|
||||
std::set<Snowflake> DiscordClient::GetChannelsInGuild(Snowflake id) const {
|
||||
auto it = m_guild_to_channels.find(id);
|
||||
if (it != m_guild_to_channels.end())
|
||||
return it->second;
|
||||
return std::unordered_set<Snowflake>();
|
||||
return {};
|
||||
}
|
||||
|
||||
bool DiscordClient::HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const {
|
||||
@ -953,12 +959,12 @@ PresenceStatus DiscordClient::GetUserStatus(Snowflake id) const {
|
||||
return PresenceStatus::Offline;
|
||||
}
|
||||
|
||||
std::unordered_map<Snowflake, RelationshipType> DiscordClient::GetRelationships() const {
|
||||
std::map<Snowflake, RelationshipType> DiscordClient::GetRelationships() const {
|
||||
return m_user_relationships;
|
||||
}
|
||||
|
||||
std::unordered_set<Snowflake> DiscordClient::GetRelationships(RelationshipType type) const {
|
||||
std::unordered_set<Snowflake> ret;
|
||||
std::set<Snowflake> DiscordClient::GetRelationships(RelationshipType type) const {
|
||||
std::set<Snowflake> ret;
|
||||
for (const auto &[id, rtype] : m_user_relationships)
|
||||
if (rtype == type)
|
||||
ret.insert(id);
|
||||
@ -1682,7 +1688,8 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
||||
|
||||
m_websocket.Stop(1000);
|
||||
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
if (m_client_started)
|
||||
Glib::signal_timeout().connect_once([this] { if (m_client_started) m_websocket.StartConnection(GetGatewayURL()); }, 1000);
|
||||
}
|
||||
|
||||
bool IsCompleteMessageObject(const nlohmann::json &j) {
|
||||
@ -1886,6 +1893,11 @@ void DiscordClient::HandleSocketClose(uint16_t code) {
|
||||
m_store.ClearAll();
|
||||
m_guild_to_users.clear();
|
||||
|
||||
if (m_client_started && !m_reconnecting && close_code == GatewayCloseCode::Abnormal) {
|
||||
Glib::signal_timeout().connect_once([this] { if (m_client_started) HandleGatewayReconnect(GatewayMessage()); }, 1000);
|
||||
m_reconnecting = true;
|
||||
}
|
||||
|
||||
m_signal_disconnected.emit(m_reconnecting, close_code);
|
||||
};
|
||||
m_generic_mutex.lock();
|
||||
|
@ -6,9 +6,8 @@
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
#include <mutex>
|
||||
#include <zlib.h>
|
||||
#include <glibmm.h>
|
||||
@ -85,8 +84,8 @@ public:
|
||||
std::optional<BanData> GetBan(Snowflake guild_id, Snowflake user_id) const;
|
||||
Snowflake GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color = false) const;
|
||||
std::optional<RoleData> GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const;
|
||||
std::unordered_set<Snowflake> GetUsersInGuild(Snowflake id) const;
|
||||
std::unordered_set<Snowflake> GetChannelsInGuild(Snowflake id) const;
|
||||
std::set<Snowflake> GetUsersInGuild(Snowflake id) const;
|
||||
std::set<Snowflake> GetChannelsInGuild(Snowflake id) const;
|
||||
|
||||
bool HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const;
|
||||
|
||||
@ -184,8 +183,8 @@ public:
|
||||
|
||||
PresenceStatus GetUserStatus(Snowflake id) const;
|
||||
|
||||
std::unordered_map<Snowflake, RelationshipType> GetRelationships() const;
|
||||
std::unordered_set<Snowflake> GetRelationships(RelationshipType type) const;
|
||||
std::map<Snowflake, RelationshipType> GetRelationships() const;
|
||||
std::set<Snowflake> GetRelationships(RelationshipType type) const;
|
||||
std::optional<RelationshipType> GetRelationship(Snowflake id) const;
|
||||
|
||||
private:
|
||||
@ -255,14 +254,14 @@ private:
|
||||
std::string m_token;
|
||||
|
||||
void AddUserToGuild(Snowflake user_id, Snowflake guild_id);
|
||||
std::unordered_map<Snowflake, std::unordered_set<Snowflake>> m_guild_to_users;
|
||||
std::map<Snowflake, std::set<Snowflake>> m_guild_to_users;
|
||||
|
||||
std::unordered_map<Snowflake, std::unordered_set<Snowflake>> m_guild_to_channels;
|
||||
std::unordered_map<Snowflake, GuildApplicationData> m_guild_join_requests;
|
||||
std::map<Snowflake, std::set<Snowflake>> m_guild_to_channels;
|
||||
std::map<Snowflake, GuildApplicationData> m_guild_join_requests;
|
||||
|
||||
std::unordered_map<Snowflake, PresenceStatus> m_user_to_status;
|
||||
std::map<Snowflake, PresenceStatus> m_user_to_status;
|
||||
|
||||
std::unordered_map<Snowflake, RelationshipType> m_user_relationships;
|
||||
std::map<Snowflake, RelationshipType> m_user_relationships;
|
||||
|
||||
UserData m_user_data;
|
||||
UserSettings m_user_settings;
|
||||
@ -272,8 +271,9 @@ private:
|
||||
Websocket m_websocket;
|
||||
std::atomic<bool> m_client_connected = false;
|
||||
std::atomic<bool> m_ready_received = false;
|
||||
bool m_client_started = false;
|
||||
|
||||
std::unordered_map<std::string, GatewayEvent> m_event_map;
|
||||
std::map<std::string, GatewayEvent> m_event_map;
|
||||
void LoadEventMap();
|
||||
|
||||
std::thread m_heartbeat_thread;
|
||||
|
@ -148,13 +148,6 @@ MainWindow::MainWindow()
|
||||
void MainWindow::UpdateComponents() {
|
||||
bool discord_active = Abaddon::Get().IsDiscordActive();
|
||||
|
||||
std::string token = Abaddon::Get().GetDiscordToken();
|
||||
m_menu_discord_connect.set_sensitive(token.size() > 0 && !discord_active);
|
||||
m_menu_discord_disconnect.set_sensitive(discord_active);
|
||||
m_menu_discord_join_guild.set_sensitive(discord_active);
|
||||
m_menu_discord_set_token.set_sensitive(!discord_active);
|
||||
m_menu_discord_set_status.set_sensitive(discord_active);
|
||||
|
||||
if (!discord_active) {
|
||||
m_chat.Clear();
|
||||
m_members.Clear();
|
||||
@ -258,6 +251,15 @@ void MainWindow::OnDiscordSubmenuPopup(const Gdk::Rectangle *flipped_rect, const
|
||||
m_menu_discord_add_recipient.set_visible(false);
|
||||
if (channel.has_value() && channel->GetDMRecipients().size() + 1 < 10)
|
||||
m_menu_discord_add_recipient.set_visible(channel->Type == ChannelType::GROUP_DM);
|
||||
|
||||
const bool discord_active = Abaddon::Get().GetDiscordClient().IsStarted();
|
||||
|
||||
std::string token = Abaddon::Get().GetDiscordToken();
|
||||
m_menu_discord_connect.set_sensitive(token.size() > 0 && !discord_active);
|
||||
m_menu_discord_disconnect.set_sensitive(discord_active);
|
||||
m_menu_discord_join_guild.set_sensitive(discord_active);
|
||||
m_menu_discord_set_token.set_sensitive(!discord_active);
|
||||
m_menu_discord_set_status.set_sensitive(discord_active);
|
||||
}
|
||||
|
||||
void MainWindow::OnViewSubmenuPopup(const Gdk::Rectangle *flipped_rect, const Gdk::Rectangle *final_rect, bool flipped_x, bool flipped_y) {
|
||||
|
Loading…
Reference in New Issue
Block a user