pass message object through signal instead of just the id

This commit is contained in:
ouwou 2021-04-13 04:33:19 -04:00
parent 42d38a89b2
commit b6c6c03f87
7 changed files with 16 additions and 21 deletions

View File

@ -45,12 +45,10 @@ Abaddon::Abaddon()
m_discord.signal_message_sent().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnMessageSent));
m_discord.signal_disconnected().connect(sigc::mem_fun(*this, &Abaddon::DiscordOnDisconnect));
if (m_settings.GetPrefetch())
m_discord.signal_message_create().connect([this](Snowflake id) {
const auto msg = m_discord.GetMessage(id);
const auto author = m_discord.GetUser(msg->Author.ID);
if (author.has_value() && author->HasAvatar())
m_img_mgr.Prefetch(author->GetAvatarURL());
for (const auto &attachment : msg->Attachments) {
m_discord.signal_message_create().connect([this](const Message &message) {
if (message.Author.HasAvatar())
m_img_mgr.Prefetch(message.Author.GetAvatarURL());
for (const auto &attachment : message.Attachments) {
if (IsURLViewableImage(attachment.ProxyURL))
m_img_mgr.Prefetch(attachment.ProxyURL);
}
@ -177,8 +175,8 @@ void Abaddon::DiscordOnReady() {
m_main_window->UpdateComponents();
}
void Abaddon::DiscordOnMessageCreate(Snowflake id) {
m_main_window->UpdateChatNewMessage(id);
void Abaddon::DiscordOnMessageCreate(const Message &message) {
m_main_window->UpdateChatNewMessage(message.ID); // todo ill fix you later :^)
}
void Abaddon::DiscordOnMessageDelete(Snowflake id, Snowflake channel_id) {

View File

@ -62,7 +62,7 @@ public:
DiscordClient &GetDiscordClient();
const DiscordClient &GetDiscordClient() const;
void DiscordOnReady();
void DiscordOnMessageCreate(Snowflake id);
void DiscordOnMessageCreate(const Message &message);
void DiscordOnMessageDelete(Snowflake id, Snowflake channel_id);
void DiscordOnMessageUpdate(Snowflake id, Snowflake channel_id);
void DiscordOnGuildMemberListUpdate(Snowflake guild_id);

View File

@ -299,12 +299,11 @@ ChannelList::ChannelList() {
// maybe will regret doing it this way
auto &discord = Abaddon::Get().GetDiscordClient();
auto cb = [this, &discord](Snowflake message_id) {
const auto message = discord.GetMessage(message_id);
const auto channel = discord.GetChannel(message->ChannelID);
auto cb = [this, &discord](const Message &message) {
const auto channel = discord.GetChannel(message.ChannelID);
if (!channel.has_value()) return;
if (channel->Type == ChannelType::DM || channel->Type == ChannelType::GROUP_DM)
CheckBumpDM(message->ChannelID);
CheckBumpDM(message.ChannelID);
};
discord.signal_message_create().connect(sigc::track_obj(cb, *this));
}

View File

@ -76,10 +76,8 @@ void ChatInputIndicator::OnUserTypingStart(Snowflake user_id, Snowflake channel_
AddUser(channel_id, *user, 10);
}
void ChatInputIndicator::OnMessageCreate(Snowflake message_id) {
const auto msg = Abaddon::Get().GetDiscordClient().GetMessage(message_id);
if (!msg.has_value()) return;
m_typers[msg->ChannelID].erase(msg->Author.ID);
void ChatInputIndicator::OnMessageCreate(const Message &message) {
m_typers[message.ChannelID].erase(message.Author.ID);
ComputeTypingString();
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <gtkmm.h>
#include <unordered_map>
#include "../discord/snowflake.hpp"
#include "../discord/message.hpp"
#include "../discord/user.hpp"
class ChatInputIndicator : public Gtk::Box {
@ -14,7 +14,7 @@ public:
private:
void AddUser(Snowflake channel_id, const UserData &user, int timeout);
void OnUserTypingStart(Snowflake user_id, Snowflake channel_id);
void OnMessageCreate(Snowflake message_id);
void OnMessageCreate(const Message &message);
void SetTypingString(const Glib::ustring &str);
void ComputeTypingString();

View File

@ -1119,7 +1119,7 @@ void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
StoreMessageData(data);
AddMessageToChannel(data.ID, data.ChannelID);
AddUserToGuild(data.Author.ID, *data.GuildID);
m_signal_message_create.emit(data.ID);
m_signal_message_create.emit(data);
}
void DiscordClient::HandleGatewayMessageDelete(const GatewayMessage &msg) {

View File

@ -283,7 +283,7 @@ private:
// signals
public:
typedef sigc::signal<void> type_signal_gateway_ready;
typedef sigc::signal<void, Snowflake> type_signal_message_create;
typedef sigc::signal<void, Message> 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;