fix edited/deleted being reset on channel change
This commit is contained in:
@@ -183,19 +183,15 @@ void ChatMessageTextItem::on_menu_copy_content() {
|
|||||||
Gtk::Clipboard::get()->set_text(m_content);
|
Gtk::Clipboard::get()->set_text(m_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatMessageTextItem::MarkAsDeleted() {
|
void ChatMessageTextItem::Update() {
|
||||||
m_was_deleted = true;
|
|
||||||
UpdateAttributes();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatMessageTextItem::MarkAsEdited() {
|
|
||||||
m_was_edited = true;
|
|
||||||
UpdateAttributes();
|
UpdateAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatMessageTextItem::UpdateAttributes() {
|
void ChatMessageTextItem::UpdateAttributes() {
|
||||||
bool deleted = m_was_deleted;
|
const auto *data = Abaddon::Get().GetDiscordClient().GetMessage(ID);
|
||||||
bool edited = m_was_edited && !m_was_deleted;
|
if (data == nullptr) return;
|
||||||
|
bool deleted = data->IsDeleted();
|
||||||
|
bool edited = data->IsEdited();
|
||||||
|
|
||||||
auto buf = get_buffer();
|
auto buf = get_buffer();
|
||||||
buf->set_text(m_content);
|
buf->set_text(m_content);
|
||||||
@@ -334,14 +330,16 @@ void ChatMessageEmbedItem::DoLayout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ChatMessageEmbedItem::UpdateAttributes() {
|
void ChatMessageEmbedItem::UpdateAttributes() {
|
||||||
bool deleted = m_was_deleted;
|
const auto *data = Abaddon::Get().GetDiscordClient().GetMessage(ID);
|
||||||
bool edited = m_was_edited && !m_was_deleted;
|
if (data == nullptr) return;
|
||||||
|
bool deleted = data->IsDeleted();
|
||||||
|
bool edited = data->IsEdited();
|
||||||
|
|
||||||
if (m_attrib_label == nullptr) {
|
if (m_attrib_label == nullptr) {
|
||||||
m_attrib_label = Gtk::manage(new Gtk::Label);
|
m_attrib_label = Gtk::manage(new Gtk::Label);
|
||||||
m_attrib_label->set_use_markup(true);
|
m_attrib_label->set_use_markup(true);
|
||||||
m_attrib_label->show();
|
m_attrib_label->show();
|
||||||
m_main->pack_end(*m_attrib_label);
|
m_main->pack_start(*m_attrib_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@@ -350,12 +348,6 @@ void ChatMessageEmbedItem::UpdateAttributes() {
|
|||||||
m_attrib_label->set_markup(" <span color='#999999'> [edited]</span>");
|
m_attrib_label->set_markup(" <span color='#999999'> [edited]</span>");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatMessageEmbedItem::MarkAsDeleted() {
|
void ChatMessageEmbedItem::Update() {
|
||||||
m_was_deleted = true;
|
UpdateAttributes();
|
||||||
// UpdateAttributes(); untested
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatMessageEmbedItem::MarkAsEdited() {
|
|
||||||
m_was_edited = true;
|
|
||||||
// UpdateAttributes();
|
|
||||||
}
|
}
|
||||||
|
@@ -40,8 +40,7 @@ public:
|
|||||||
|
|
||||||
virtual void ShowMenu(const GdkEvent *event);
|
virtual void ShowMenu(const GdkEvent *event);
|
||||||
void AddMenuItem(Gtk::MenuItem *item);
|
void AddMenuItem(Gtk::MenuItem *item);
|
||||||
virtual void MarkAsDeleted() = 0;
|
virtual void Update() = 0;
|
||||||
virtual void MarkAsEdited() = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void AttachMenuHandler(Gtk::Widget *widget);
|
void AttachMenuHandler(Gtk::Widget *widget);
|
||||||
@@ -74,17 +73,13 @@ public:
|
|||||||
|
|
||||||
void EditContent(std::string content);
|
void EditContent(std::string content);
|
||||||
|
|
||||||
virtual void MarkAsDeleted();
|
virtual void Update();
|
||||||
virtual void MarkAsEdited();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void UpdateAttributes();
|
void UpdateAttributes();
|
||||||
|
|
||||||
std::string m_content;
|
std::string m_content;
|
||||||
|
|
||||||
bool m_was_deleted = false;
|
|
||||||
bool m_was_edited = false;
|
|
||||||
|
|
||||||
void on_menu_copy_content();
|
void on_menu_copy_content();
|
||||||
Gtk::MenuItem *m_menu_copy_content;
|
Gtk::MenuItem *m_menu_copy_content;
|
||||||
Gtk::MenuItem *m_menu_delete_message;
|
Gtk::MenuItem *m_menu_delete_message;
|
||||||
@@ -96,16 +91,12 @@ class ChatMessageEmbedItem
|
|||||||
public:
|
public:
|
||||||
ChatMessageEmbedItem(const Message *data);
|
ChatMessageEmbedItem(const Message *data);
|
||||||
|
|
||||||
virtual void MarkAsDeleted();
|
virtual void Update();
|
||||||
virtual void MarkAsEdited();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void DoLayout();
|
void DoLayout();
|
||||||
void UpdateAttributes();
|
void UpdateAttributes();
|
||||||
|
|
||||||
bool m_was_deleted = false;
|
|
||||||
bool m_was_edited = false;
|
|
||||||
|
|
||||||
EmbedData m_embed;
|
EmbedData m_embed;
|
||||||
Gtk::Box *m_main;
|
Gtk::Box *m_main;
|
||||||
Gtk::Label *m_attrib_label = nullptr;
|
Gtk::Label *m_attrib_label = nullptr;
|
||||||
|
@@ -129,12 +129,14 @@ void ChatWindow::ProcessMessage(const Message *data, bool prepend) {
|
|||||||
text->signal_action_message_edit().connect([this](Snowflake channel_id, Snowflake id) {
|
text->signal_action_message_edit().connect([this](Snowflake channel_id, Snowflake id) {
|
||||||
m_signal_action_message_edit.emit(channel_id, id);
|
m_signal_action_message_edit.emit(channel_id, id);
|
||||||
});
|
});
|
||||||
|
text->Update();
|
||||||
container->AddNewContent(text, prepend);
|
container->AddNewContent(text, prepend);
|
||||||
m_id_to_widget[data->ID] = text;
|
m_id_to_widget[data->ID] = text;
|
||||||
} else if (type == ChatDisplayType::Embed) {
|
} else if (type == ChatDisplayType::Embed) {
|
||||||
auto *widget = Gtk::manage(new ChatMessageEmbedItem(data));
|
auto *widget = Gtk::manage(new ChatMessageEmbedItem(data));
|
||||||
widget->ID = data->ID;
|
widget->ID = data->ID;
|
||||||
widget->ChannelID = m_active_channel;
|
widget->ChannelID = m_active_channel;
|
||||||
|
widget->Update();
|
||||||
container->AddNewContent(widget, prepend);
|
container->AddNewContent(widget, prepend);
|
||||||
m_id_to_widget[data->ID] = widget;
|
m_id_to_widget[data->ID] = widget;
|
||||||
}
|
}
|
||||||
@@ -266,7 +268,7 @@ void ChatWindow::DeleteMessageInternal() {
|
|||||||
// todo actually delete it when it becomes setting
|
// todo actually delete it when it becomes setting
|
||||||
|
|
||||||
auto *item = m_id_to_widget.at(id);
|
auto *item = m_id_to_widget.at(id);
|
||||||
item->MarkAsDeleted();
|
item->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatWindow::UpdateMessageContentInternal() {
|
void ChatWindow::UpdateMessageContentInternal() {
|
||||||
@@ -284,7 +286,7 @@ void ChatWindow::UpdateMessageContentInternal() {
|
|||||||
auto *item = dynamic_cast<ChatMessageTextItem *>(m_id_to_widget.at(id));
|
auto *item = dynamic_cast<ChatMessageTextItem *>(m_id_to_widget.at(id));
|
||||||
if (item != nullptr) {
|
if (item != nullptr) {
|
||||||
item->EditContent(msg->Content);
|
item->EditContent(msg->Content);
|
||||||
item->MarkAsEdited();
|
item->Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -373,6 +373,9 @@ void DiscordClient::HandleGatewayMessageCreate(const GatewayMessage &msg) {
|
|||||||
void DiscordClient::HandleGatewayMessageDelete(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayMessageDelete(const GatewayMessage &msg) {
|
||||||
MessageDeleteData data = msg.Data;
|
MessageDeleteData data = msg.Data;
|
||||||
m_signal_message_delete.emit(data.ID, data.ChannelID);
|
m_signal_message_delete.emit(data.ID, data.ChannelID);
|
||||||
|
auto *cur = m_store.GetMessage(data.ID);
|
||||||
|
if (cur != nullptr)
|
||||||
|
cur->SetDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||||
@@ -385,9 +388,7 @@ void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (data.Content != current->Content) {
|
if (data.Content != current->Content) {
|
||||||
auto copy = *current;
|
current->SetEdited(data.Content);
|
||||||
copy.Content = data.Content;
|
|
||||||
m_store.SetMessage(copy.ID, copy);
|
|
||||||
m_signal_message_update.emit(data.ID, data.ChannelID);
|
m_signal_message_update.emit(data.ID, data.ChannelID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -115,3 +115,20 @@ void Message::from_json_edited(const nlohmann::json &j) {
|
|||||||
JS_O("type", Type);
|
JS_O("type", Type);
|
||||||
JS_O("flags", Flags);
|
JS_O("flags", Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Message::SetDeleted() {
|
||||||
|
m_deleted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Message::SetEdited(std::string new_content) {
|
||||||
|
m_edited = true;
|
||||||
|
Content = new_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Message::IsDeleted() const {
|
||||||
|
return m_deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Message::IsEdited() const {
|
||||||
|
return m_edited;
|
||||||
|
}
|
||||||
|
@@ -147,4 +147,14 @@ struct Message {
|
|||||||
|
|
||||||
friend void from_json(const nlohmann::json &j, Message &m);
|
friend void from_json(const nlohmann::json &j, Message &m);
|
||||||
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
|
void from_json_edited(const nlohmann::json &j); // for MESSAGE_UPDATE
|
||||||
|
|
||||||
|
// custom fields to track changes
|
||||||
|
void SetDeleted();
|
||||||
|
void SetEdited(std::string new_content);
|
||||||
|
bool IsDeleted() const;
|
||||||
|
bool IsEdited() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_deleted = false;
|
||||||
|
bool m_edited = false;
|
||||||
};
|
};
|
||||||
|
@@ -24,6 +24,13 @@ void Store::SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const Guil
|
|||||||
m_members[guild_id][user_id] = data;
|
m_members[guild_id][user_id] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User *Store::GetUser(Snowflake id) {
|
||||||
|
auto it = m_users.find(id);
|
||||||
|
if (it == m_users.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
const User *Store::GetUser(Snowflake id) const {
|
const User *Store::GetUser(Snowflake id) const {
|
||||||
auto it = m_users.find(id);
|
auto it = m_users.find(id);
|
||||||
if (it == m_users.end())
|
if (it == m_users.end())
|
||||||
@@ -31,6 +38,13 @@ const User *Store::GetUser(Snowflake id) const {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel *Store::GetChannel(Snowflake id) {
|
||||||
|
auto it = m_channels.find(id);
|
||||||
|
if (it == m_channels.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
const Channel *Store::GetChannel(Snowflake id) const {
|
const Channel *Store::GetChannel(Snowflake id) const {
|
||||||
auto it = m_channels.find(id);
|
auto it = m_channels.find(id);
|
||||||
if (it == m_channels.end())
|
if (it == m_channels.end())
|
||||||
@@ -38,6 +52,13 @@ const Channel *Store::GetChannel(Snowflake id) const {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Guild *Store::GetGuild(Snowflake id) {
|
||||||
|
auto it = m_guilds.find(id);
|
||||||
|
if (it == m_guilds.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
const Guild *Store::GetGuild(Snowflake id) const {
|
const Guild *Store::GetGuild(Snowflake id) const {
|
||||||
auto it = m_guilds.find(id);
|
auto it = m_guilds.find(id);
|
||||||
if (it == m_guilds.end())
|
if (it == m_guilds.end())
|
||||||
@@ -45,6 +66,13 @@ const Guild *Store::GetGuild(Snowflake id) const {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Role *Store::GetRole(Snowflake id) {
|
||||||
|
auto it = m_roles.find(id);
|
||||||
|
if (it == m_roles.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
const Role *Store::GetRole(Snowflake id) const {
|
const Role *Store::GetRole(Snowflake id) const {
|
||||||
auto it = m_roles.find(id);
|
auto it = m_roles.find(id);
|
||||||
if (it == m_roles.end())
|
if (it == m_roles.end())
|
||||||
@@ -52,6 +80,13 @@ const Role *Store::GetRole(Snowflake id) const {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Message *Store::GetMessage(Snowflake id) {
|
||||||
|
auto it = m_messages.find(id);
|
||||||
|
if (it == m_messages.end())
|
||||||
|
return nullptr;
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
const Message *Store::GetMessage(Snowflake id) const {
|
const Message *Store::GetMessage(Snowflake id) const {
|
||||||
auto it = m_messages.find(id);
|
auto it = m_messages.find(id);
|
||||||
if (it == m_messages.end())
|
if (it == m_messages.end())
|
||||||
@@ -59,6 +94,16 @@ const Message *Store::GetMessage(Snowflake id) const {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) {
|
||||||
|
auto git = m_members.find(guild_id);
|
||||||
|
if (git == m_members.end())
|
||||||
|
return nullptr;
|
||||||
|
auto mit = git->second.find(user_id);
|
||||||
|
if (mit == git->second.end())
|
||||||
|
return nullptr;
|
||||||
|
return &mit->second;
|
||||||
|
}
|
||||||
|
|
||||||
const GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const {
|
const GuildMember *Store::GetGuildMemberData(Snowflake guild_id, Snowflake user_id) const {
|
||||||
auto git = m_members.find(guild_id);
|
auto git = m_members.find(guild_id);
|
||||||
if (git == m_members.end())
|
if (git == m_members.end())
|
||||||
|
@@ -16,6 +16,12 @@ public:
|
|||||||
void SetMessage(Snowflake id, const Message &message);
|
void SetMessage(Snowflake id, const Message &message);
|
||||||
void SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const GuildMember &data);
|
void SetGuildMemberData(Snowflake guild_id, Snowflake user_id, const GuildMember &data);
|
||||||
|
|
||||||
|
User *GetUser(Snowflake id);
|
||||||
|
Channel *GetChannel(Snowflake id);
|
||||||
|
Guild *GetGuild(Snowflake id);
|
||||||
|
Role *GetRole(Snowflake id);
|
||||||
|
Message *GetMessage(Snowflake id);
|
||||||
|
GuildMember *GetGuildMemberData(Snowflake guild_id, Snowflake user_id);
|
||||||
const User *GetUser(Snowflake id) const;
|
const User *GetUser(Snowflake id) const;
|
||||||
const Channel *GetChannel(Snowflake id) const;
|
const Channel *GetChannel(Snowflake id) const;
|
||||||
const Guild *GetGuild(Snowflake id) const;
|
const Guild *GetGuild(Snowflake id) const;
|
||||||
|
Reference in New Issue
Block a user