forked from OpenGamers/abaddon
DiscordClient uses signals now
This commit is contained in:
parent
66cc4b3cc7
commit
3832ff9a15
20
abaddon.cpp
20
abaddon.cpp
@ -13,8 +13,14 @@
|
||||
|
||||
Abaddon::Abaddon()
|
||||
: m_settings("abaddon.ini") {
|
||||
m_discord.SetAbaddon(this);
|
||||
LoadFromSettings();
|
||||
|
||||
m_discord.signal_gateway_ready().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnReady));
|
||||
m_discord.signal_channel_list_refresh().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnChannelListRefresh));
|
||||
m_discord.signal_message_create().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnMessageCreate));
|
||||
m_discord.signal_message_delete().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnMessageDelete));
|
||||
m_discord.signal_message_update().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnMessageUpdate));
|
||||
m_discord.signal_guild_member_list_update().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnGuildMemberListUpdate));
|
||||
}
|
||||
|
||||
Abaddon::~Abaddon() {
|
||||
@ -81,27 +87,27 @@ const DiscordClient &Abaddon::GetDiscordClient() const {
|
||||
return m_discord;
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyReady() {
|
||||
void Abaddon::DiscordOnReady() {
|
||||
m_main_window->UpdateComponents();
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyChannelListFullRefresh() {
|
||||
void Abaddon::DiscordOnChannelListRefresh() {
|
||||
m_main_window->UpdateChannelListing();
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyMessageCreate(Snowflake id) {
|
||||
void Abaddon::DiscordOnMessageCreate(Snowflake id) {
|
||||
m_main_window->UpdateChatNewMessage(id);
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyMessageDelete(Snowflake id, Snowflake channel_id) {
|
||||
void Abaddon::DiscordOnMessageDelete(Snowflake id, Snowflake channel_id) {
|
||||
m_main_window->UpdateChatMessageDeleted(id, channel_id);
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyMessageUpdateContent(Snowflake id, Snowflake channel_id) {
|
||||
void Abaddon::DiscordOnMessageUpdate(Snowflake id, Snowflake channel_id) {
|
||||
m_main_window->UpdateChatMessageEditContent(id, channel_id);
|
||||
}
|
||||
|
||||
void Abaddon::DiscordNotifyGuildMemberListUpdate(Snowflake guild_id) {
|
||||
void Abaddon::DiscordOnGuildMemberListUpdate(Snowflake guild_id) {
|
||||
m_main_window->UpdateMembers();
|
||||
}
|
||||
|
||||
|
12
abaddon.hpp
12
abaddon.hpp
@ -39,12 +39,12 @@ public:
|
||||
bool IsDiscordActive() const;
|
||||
|
||||
const DiscordClient &GetDiscordClient() const;
|
||||
void DiscordNotifyReady();
|
||||
void DiscordNotifyChannelListFullRefresh();
|
||||
void DiscordNotifyMessageCreate(Snowflake id);
|
||||
void DiscordNotifyMessageDelete(Snowflake id, Snowflake channel_id);
|
||||
void DiscordNotifyMessageUpdateContent(Snowflake id, Snowflake channel_id);
|
||||
void DiscordNotifyGuildMemberListUpdate(Snowflake guild_id);
|
||||
void DiscordOnReady();
|
||||
void DiscordOnChannelListRefresh();
|
||||
void DiscordOnMessageCreate(Snowflake id);
|
||||
void DiscordOnMessageDelete(Snowflake id, Snowflake channel_id);
|
||||
void DiscordOnMessageUpdate(Snowflake id, Snowflake channel_id);
|
||||
void DiscordOnGuildMemberListUpdate(Snowflake guild_id);
|
||||
|
||||
private:
|
||||
DiscordClient m_discord;
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include "../abaddon.hpp"
|
||||
#include "discord.hpp"
|
||||
#include <cassert>
|
||||
#include "../util.hpp"
|
||||
@ -9,10 +8,6 @@ DiscordClient::DiscordClient()
|
||||
LoadEventMap();
|
||||
}
|
||||
|
||||
void DiscordClient::SetAbaddon(Abaddon *ptr) {
|
||||
m_abaddon = ptr;
|
||||
}
|
||||
|
||||
void DiscordClient::Start() {
|
||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
||||
@ -53,7 +48,7 @@ const UserData &DiscordClient::GetUserData() const {
|
||||
}
|
||||
|
||||
std::vector<Snowflake> DiscordClient::GetUserSortedGuilds() const {
|
||||
std::vector<std::pair<Snowflake, const GuildData*>> sorted_guilds;
|
||||
std::vector<std::pair<Snowflake, const GuildData *>> sorted_guilds;
|
||||
|
||||
if (m_user_settings.GuildPositions.size()) {
|
||||
std::unordered_set<Snowflake> positioned_guilds(m_user_settings.GuildPositions.begin(), m_user_settings.GuildPositions.end());
|
||||
@ -109,7 +104,7 @@ void DiscordClient::UpdateSettingsGuildPositions(const std::vector<Snowflake> &p
|
||||
if (!CheckCode(r)) return;
|
||||
|
||||
m_user_settings.GuildPositions = pos;
|
||||
m_abaddon->DiscordNotifyChannelListFullRefresh();
|
||||
m_signal_channel_list_refresh.emit();
|
||||
});
|
||||
}
|
||||
|
||||
@ -357,7 +352,7 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
|
||||
m_store.SetChannel(dm.ID, dm);
|
||||
}
|
||||
|
||||
m_abaddon->DiscordNotifyReady();
|
||||
m_signal_gateway_ready.emit();
|
||||
m_user_data = data.User;
|
||||
m_user_settings = data.UserSettings;
|
||||
}
|
||||
@ -368,12 +363,12 @@ void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
|
||||
AddMessageToChannel(data.ID, data.ChannelID);
|
||||
m_store.SetUser(data.Author.ID, data.Author);
|
||||
AddUserToGuild(data.Author.ID, data.GuildID);
|
||||
m_abaddon->DiscordNotifyMessageCreate(data.ID);
|
||||
m_signal_message_create.emit(data.ID);
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayMessageDelete(const GatewayMessage &msg) {
|
||||
MessageDeleteData data = msg.Data;
|
||||
m_abaddon->DiscordNotifyMessageDelete(data.ID, data.ChannelID);
|
||||
m_signal_message_delete.emit(data.ID, data.ChannelID);
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||
@ -389,7 +384,7 @@ void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||
auto copy = *current;
|
||||
copy.Content = data.Content;
|
||||
m_store.SetMessage(copy.ID, copy);
|
||||
m_abaddon->DiscordNotifyMessageUpdateContent(data.ID, data.ChannelID);
|
||||
m_signal_message_update.emit(data.ID, data.ChannelID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -409,7 +404,7 @@ void DiscordClient::HandleGatewayGuildMemberListUpdate(const GatewayMessage &msg
|
||||
}
|
||||
}
|
||||
|
||||
m_abaddon->DiscordNotifyGuildMemberListUpdate(data.GuildID);
|
||||
m_signal_guild_member_list_update.emit(data.GuildID);
|
||||
}
|
||||
|
||||
void DiscordClient::AddMessageToChannel(Snowflake msg_id, Snowflake channel_id) {
|
||||
@ -474,3 +469,27 @@ void DiscordClient::LoadEventMap() {
|
||||
m_event_map["MESSAGE_UPDATE"] = GatewayEvent::MESSAGE_UPDATE;
|
||||
m_event_map["GUILD_MEMBER_LIST_UPDATE"] = GatewayEvent::GUILD_MEMBER_LIST_UPDATE;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_gateway_ready DiscordClient::signal_gateway_ready() {
|
||||
return m_signal_gateway_ready;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_channel_list_refresh DiscordClient::signal_channel_list_refresh() {
|
||||
return m_signal_channel_list_refresh;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_create DiscordClient::signal_message_create() {
|
||||
return m_signal_message_create;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_delete DiscordClient::signal_message_delete() {
|
||||
return m_signal_message_delete;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_update DiscordClient::signal_message_update() {
|
||||
return m_signal_message_update;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_guild_member_list_update DiscordClient::signal_guild_member_list_update() {
|
||||
return m_signal_guild_member_list_update;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "http.hpp"
|
||||
#include "objects.hpp"
|
||||
#include "store.hpp"
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
@ -48,7 +49,6 @@ public:
|
||||
|
||||
public:
|
||||
DiscordClient();
|
||||
void SetAbaddon(Abaddon *ptr);
|
||||
void Start();
|
||||
void Stop();
|
||||
bool IsStarted() const;
|
||||
@ -128,4 +128,28 @@ private:
|
||||
std::atomic<int> m_heartbeat_msec = 0;
|
||||
HeartbeatWaiter m_heartbeat_waiter;
|
||||
std::atomic<bool> m_heartbeat_acked = true;
|
||||
|
||||
// signals
|
||||
public:
|
||||
typedef sigc::signal<void> type_signal_gateway_ready;
|
||||
typedef sigc::signal<void> type_signal_channel_list_refresh;
|
||||
typedef sigc::signal<void, Snowflake> type_signal_message_create;
|
||||
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_message_delete;
|
||||
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_message_update;
|
||||
typedef sigc::signal<void, Snowflake> type_signal_guild_member_list_update;
|
||||
|
||||
type_signal_gateway_ready signal_gateway_ready();
|
||||
type_signal_channel_list_refresh signal_channel_list_refresh();
|
||||
type_signal_message_create signal_message_create();
|
||||
type_signal_message_delete signal_message_delete();
|
||||
type_signal_message_update signal_message_update();
|
||||
type_signal_guild_member_list_update signal_guild_member_list_update();
|
||||
|
||||
protected:
|
||||
type_signal_gateway_ready m_signal_gateway_ready;
|
||||
type_signal_channel_list_refresh m_signal_channel_list_refresh;
|
||||
type_signal_message_create m_signal_message_create;
|
||||
type_signal_message_delete m_signal_message_delete;
|
||||
type_signal_message_update m_signal_message_update;
|
||||
type_signal_guild_member_list_update m_signal_guild_member_list_update;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user