mirror of
https://github.com/uowuo/abaddon.git
synced 2025-08-14 01:30:06 +00:00
fix some reaction stuff
This commit is contained in:
parent
2667a4b30d
commit
315a4a8df8
@ -465,7 +465,11 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message *d
|
||||
// image
|
||||
if (is_stock) { // unicode/stock
|
||||
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);
|
||||
box->add(*img);
|
||||
} else { // custom
|
||||
|
@ -121,9 +121,8 @@ void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function<void(cons
|
||||
|
||||
m_store.BeginTransaction();
|
||||
for (const auto &msg : msgs) {
|
||||
m_store.SetMessage(msg.ID, msg);
|
||||
StoreMessageData(msg);
|
||||
AddMessageToChannel(msg.ID, id);
|
||||
m_store.SetUser(msg.Author.ID, msg.Author);
|
||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||
ids.push_back(msg.ID);
|
||||
}
|
||||
@ -145,9 +144,8 @@ void DiscordClient::FetchMessagesInChannelBefore(Snowflake channel_id, Snowflake
|
||||
|
||||
m_store.BeginTransaction();
|
||||
for (const auto &msg : msgs) {
|
||||
m_store.SetMessage(msg.ID, msg);
|
||||
StoreMessageData(msg);
|
||||
AddMessageToChannel(msg.ID, channel_id);
|
||||
m_store.SetUser(msg.Author.ID, msg.Author);
|
||||
AddUserToGuild(msg.Author.ID, *msg.GuildID);
|
||||
ids.push_back(msg.ID);
|
||||
}
|
||||
@ -664,9 +662,8 @@ void DiscordClient::HandleGatewayReady(const GatewayMessage &msg) {
|
||||
|
||||
void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
|
||||
Message data = msg.Data;
|
||||
m_store.SetMessage(data.ID, data);
|
||||
StoreMessageData(data);
|
||||
AddMessageToChannel(data.ID, data.ChannelID);
|
||||
m_store.SetUser(data.Author.ID, data.Author);
|
||||
AddUserToGuild(data.Author.ID, *data.GuildID);
|
||||
m_signal_message_create.emit(data.ID);
|
||||
}
|
||||
@ -772,6 +769,11 @@ void DiscordClient::HandleGatewayGuildRoleDelete(const GatewayMessage &msg) {
|
||||
void DiscordClient::HandleGatewayMessageReactionAdd(const GatewayMessage &msg) {
|
||||
MessageReactionAddObject data = msg.Data;
|
||||
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->Reactions.has_value()) to->Reactions.emplace();
|
||||
// add if present
|
||||
@ -1018,6 +1020,18 @@ bool DiscordClient::CheckCode(const cpr::Response &r) {
|
||||
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() {
|
||||
m_event_map["READY"] = GatewayEvent::READY;
|
||||
m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE;
|
||||
|
@ -154,6 +154,8 @@ private:
|
||||
|
||||
bool CheckCode(const cpr::Response &r);
|
||||
|
||||
void StoreMessageData(const Message &msg);
|
||||
|
||||
std::string m_token;
|
||||
|
||||
void AddMessageToChannel(Snowflake msg_id, Snowflake channel_id);
|
||||
|
@ -328,11 +328,17 @@ std::optional<Emoji> Store::GetEmoji(Snowflake id) const {
|
||||
Emoji ret;
|
||||
ret.ID = id;
|
||||
Get(m_get_emote_stmt, 1, ret.Name);
|
||||
std::string tmp;
|
||||
Get(m_get_emote_stmt, 2, tmp);
|
||||
ret.Roles = nlohmann::json::parse(tmp).get<std::vector<Snowflake>>();
|
||||
ret.Creator = std::optional<User>(User());
|
||||
Get(m_get_emote_stmt, 3, ret.Creator->ID);
|
||||
|
||||
if (!IsNull(m_get_emote_stmt, 2)) {
|
||||
std::string tmp;
|
||||
Get(m_get_emote_stmt, 2, tmp);
|
||||
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, 4, ret.IsManaged);
|
||||
Get(m_get_emote_stmt, 5, ret.IsAnimated);
|
||||
|
Loading…
Reference in New Issue
Block a user