forked from OpenGamers/abaddon
fix some reaction stuff
This commit is contained in:
@@ -465,7 +465,11 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message *d
|
|||||||
// image
|
// image
|
||||||
if (is_stock) { // unicode/stock
|
if (is_stock) { // unicode/stock
|
||||||
const auto &pb = emojis.GetPixBuf(reaction.Emoji.Name);
|
const auto &pb = emojis.GetPixBuf(reaction.Emoji.Name);
|
||||||
auto *img = Gtk::manage(new Gtk::Image(pb->scale_simple(16, 16, Gdk::INTERP_BILINEAR)));
|
Gtk::Image *img;
|
||||||
|
if (pb)
|
||||||
|
img = Gtk::manage(new Gtk::Image(pb->scale_simple(16, 16, Gdk::INTERP_BILINEAR)));
|
||||||
|
else
|
||||||
|
img = Gtk::manage(new Gtk::Image(placeholder));
|
||||||
img->set_can_focus(false);
|
img->set_can_focus(false);
|
||||||
box->add(*img);
|
box->add(*img);
|
||||||
} else { // custom
|
} else { // custom
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(cons
|
|||||||
|
|
||||||
m_store.BeginTransaction();
|
m_store.BeginTransaction();
|
||||||
for (const auto &msg : msgs) {
|
for (const auto &msg : msgs) {
|
||||||
m_store.SetMessage(msg.ID, msg);
|
StoreMessageData(msg);
|
||||||
AddMessageToChannel(msg.ID, id);
|
AddMessageToChannel(msg.ID, id);
|
||||||
m_store.SetUser(msg.Author.ID, msg.Author);
|
|
||||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||||
ids.push_back(msg.ID);
|
ids.push_back(msg.ID);
|
||||||
}
|
}
|
||||||
@@ -145,9 +144,8 @@ void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake
|
|||||||
|
|
||||||
m_store.BeginTransaction();
|
m_store.BeginTransaction();
|
||||||
for (const auto &msg : msgs) {
|
for (const auto &msg : msgs) {
|
||||||
m_store.SetMessage(msg.ID, msg);
|
StoreMessageData(msg);
|
||||||
AddMessageToChannel(msg.ID, channel_id);
|
AddMessageToChannel(msg.ID, channel_id);
|
||||||
m_store.SetUser(msg.Author.ID, msg.Author);
|
|
||||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||||
ids.push_back(msg.ID);
|
ids.push_back(msg.ID);
|
||||||
}
|
}
|
||||||
@@ -664,9 +662,8 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
|
|||||||
|
|
||||||
void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
|
||||||
Message data = msg.Data;
|
Message data = msg.Data;
|
||||||
m_store.SetMessage(data.ID, data);
|
StoreMessageData(data);
|
||||||
AddMessageToChannel(data.ID, data.ChannelID);
|
AddMessageToChannel(data.ID, data.ChannelID);
|
||||||
m_store.SetUser(data.Author.ID, data.Author);
|
|
||||||
AddUserToGuild(data.Author.ID, *data.GuildID);
|
AddUserToGuild(data.Author.ID, *data.GuildID);
|
||||||
m_signal_message_create.emit(data.ID);
|
m_signal_message_create.emit(data.ID);
|
||||||
}
|
}
|
||||||
@@ -772,6 +769,11 @@ void DiscordClient::HandleGatewayGuildRoleDelete(const GatewayMessage &msg) {
|
|||||||
void DiscordClient::HandleGatewayMessageReactionAdd(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayMessageReactionAdd(const GatewayMessage &msg) {
|
||||||
MessageReactionAddObject data = msg.Data;
|
MessageReactionAddObject data = msg.Data;
|
||||||
auto to = m_store.GetMessage(data.MessageID);
|
auto to = m_store.GetMessage(data.MessageID);
|
||||||
|
if (data.Emoji.ID.IsValid()) {
|
||||||
|
const auto cur_emoji = m_store.GetEmoji(data.Emoji.ID);
|
||||||
|
if (!cur_emoji.has_value())
|
||||||
|
m_store.SetEmoji(data.Emoji.ID, data.Emoji);
|
||||||
|
}
|
||||||
if (!to.has_value()) return;
|
if (!to.has_value()) return;
|
||||||
if (!to->Reactions.has_value()) to->Reactions.emplace();
|
if (!to->Reactions.has_value()) to->Reactions.emplace();
|
||||||
// add if present
|
// add if present
|
||||||
@@ -1018,6 +1020,18 @@ bool DiscordClient::CheckCode(const cpr::Response &r) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiscordClient::StoreMessageData(const Message &msg) {
|
||||||
|
m_store.SetMessage(msg.ID, msg);
|
||||||
|
m_store.SetUser(msg.Author.ID, msg.Author);
|
||||||
|
if (msg.Reactions.has_value())
|
||||||
|
for (const auto &r : *msg.Reactions) {
|
||||||
|
if (!r.Emoji.ID.IsValid()) continue;
|
||||||
|
const auto cur = m_store.GetEmoji(r.Emoji.ID);
|
||||||
|
if (!cur.has_value())
|
||||||
|
m_store.SetEmoji(r.Emoji.ID, r.Emoji);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DiscordClient::LoadEventMap() {
|
void DiscordClient::LoadEventMap() {
|
||||||
m_event_map["READY"] = GatewayEvent::READY;
|
m_event_map["READY"] = GatewayEvent::READY;
|
||||||
m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE;
|
m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE;
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ private:
|
|||||||
|
|
||||||
bool CheckCode(const cpr::Response &r);
|
bool CheckCode(const cpr::Response &r);
|
||||||
|
|
||||||
|
void StoreMessageData(const Message &msg);
|
||||||
|
|
||||||
std::string m_token;
|
std::string m_token;
|
||||||
|
|
||||||
void AddMessageToChannel(Snowflake msg_id, Snowflake channel_id);
|
void AddMessageToChannel(Snowflake msg_id, Snowflake channel_id);
|
||||||
|
|||||||
@@ -328,11 +328,17 @@ std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
|||||||
Emoji ret;
|
Emoji ret;
|
||||||
ret.ID = id;
|
ret.ID = id;
|
||||||
Get(m_get_emote_stmt, 1, ret.Name);
|
Get(m_get_emote_stmt, 1, ret.Name);
|
||||||
std::string tmp;
|
|
||||||
Get(m_get_emote_stmt, 2, tmp);
|
if (!IsNull(m_get_emote_stmt, 2)) {
|
||||||
ret.Roles = nlohmann::json::parse(tmp).get<std::vector<Snowflake>>();
|
std::string tmp;
|
||||||
ret.Creator = std::optional<User>(User());
|
Get(m_get_emote_stmt, 2, tmp);
|
||||||
Get(m_get_emote_stmt, 3, ret.Creator->ID);
|
ret.Roles = nlohmann::json::parse(tmp).get<std::vector<Snowflake>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsNull(m_get_emote_stmt, 3)) {
|
||||||
|
ret.Creator = std::optional<User>(User());
|
||||||
|
Get(m_get_emote_stmt, 3, ret.Creator->ID);
|
||||||
|
}
|
||||||
Get(m_get_emote_stmt, 3, ret.NeedsColons);
|
Get(m_get_emote_stmt, 3, ret.NeedsColons);
|
||||||
Get(m_get_emote_stmt, 4, ret.IsManaged);
|
Get(m_get_emote_stmt, 4, ret.IsManaged);
|
||||||
Get(m_get_emote_stmt, 5, ret.IsAnimated);
|
Get(m_get_emote_stmt, 5, ret.IsAnimated);
|
||||||
|
|||||||
Reference in New Issue
Block a user