mirror of
https://github.com/celisej567/abaddon.git
synced 2025-12-31 17:48:26 +03:00
check if message is editable
This commit is contained in:
@@ -133,10 +133,9 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) {
|
||||
m_menu_delete_message->set_sensitive(false);
|
||||
m_menu_edit_message->set_sensitive(false);
|
||||
} else {
|
||||
const bool can_edit = client.GetUserData().ID == data->Author.ID;
|
||||
const bool can_delete = can_edit || has_manage;
|
||||
const bool can_delete = (client.GetUserData().ID == data->Author.ID) || has_manage;
|
||||
m_menu_delete_message->set_sensitive(can_delete);
|
||||
m_menu_edit_message->set_sensitive(can_edit);
|
||||
m_menu_edit_message->set_sensitive(data->IsEditable());
|
||||
}
|
||||
|
||||
m_menu.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev));
|
||||
@@ -253,18 +252,20 @@ void ChatList::ActuallyRemoveMessage(Snowflake id) {
|
||||
RemoveMessageAndHeader(it->second);
|
||||
}
|
||||
|
||||
std::optional<Snowflake> ChatList::GetLastSentMessage() {
|
||||
std::optional<Snowflake> ChatList::GetLastSentEditableMessage() {
|
||||
const auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
const auto self_id = discord.GetUserData().ID;
|
||||
|
||||
std::map<Snowflake, Gtk::Widget *> ordered(m_id_to_widget.begin(), m_id_to_widget.end());
|
||||
|
||||
for (auto it = ordered.crbegin(); it != ordered.crend(); it++) {
|
||||
const auto *widget = dynamic_cast<ChatMessageItemContainer*>(it->second);
|
||||
const auto *widget = dynamic_cast<ChatMessageItemContainer *>(it->second);
|
||||
if (widget == nullptr) continue;
|
||||
const auto msg = discord.GetMessage(widget->ID);
|
||||
if (!msg.has_value()) continue;
|
||||
if (msg->Author.ID == self_id) return msg->ID;
|
||||
if (msg->Author.ID != self_id) continue;
|
||||
if (!msg->IsEditable()) continue;
|
||||
return msg->ID;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
void SetSeparateAll(bool separate);
|
||||
void SetUsePinnedMenu(); // i think i need a better way to do menus
|
||||
void ActuallyRemoveMessage(Snowflake id); // perhaps not the best method name
|
||||
std::optional<Snowflake> GetLastSentMessage();
|
||||
std::optional<Snowflake> GetLastSentEditableMessage();
|
||||
|
||||
private:
|
||||
void SetupMenu();
|
||||
|
||||
@@ -288,7 +288,7 @@ bool ChatWindow::OnInputSubmit(ChatSubmitParams data) {
|
||||
bool ChatWindow::ProcessKeyEvent(GdkEventKey *e) {
|
||||
if (e->type != GDK_KEY_PRESS) return false;
|
||||
if (e->keyval == GDK_KEY_Up && !(e->state & GDK_SHIFT_MASK) && m_input->IsEmpty()) {
|
||||
const auto edit_id = m_chat->GetLastSentMessage();
|
||||
const auto edit_id = m_chat->GetLastSentEditableMessage();
|
||||
if (edit_id.has_value()) {
|
||||
StartEditing(*edit_id);
|
||||
}
|
||||
|
||||
@@ -265,6 +265,10 @@ bool Message::IsEdited() const {
|
||||
return m_edited;
|
||||
}
|
||||
|
||||
bool Message::IsEditable() const noexcept {
|
||||
return (Abaddon::Get().GetDiscordClient().GetUserData().ID == Author.ID) && !IsDeleted() && !IsPending && (Type == MessageType::DEFAULT || Type == MessageType::INLINE_REPLY);
|
||||
}
|
||||
|
||||
bool Message::DoesMentionEveryoneOrUser(Snowflake id) const noexcept {
|
||||
if (DoesMentionEveryone) return true;
|
||||
return std::any_of(Mentions.begin(), Mentions.end(), [id](const UserData &user) {
|
||||
|
||||
@@ -219,11 +219,13 @@ struct Message {
|
||||
|
||||
void SetDeleted();
|
||||
void SetEdited();
|
||||
[[nodiscard]] bool IsDeleted() const;
|
||||
[[nodiscard]] bool IsEdited() const;
|
||||
bool IsDeleted() const;
|
||||
bool IsEdited() const;
|
||||
|
||||
[[nodiscard]] bool DoesMentionEveryoneOrUser(Snowflake id) const noexcept;
|
||||
[[nodiscard]] bool DoesMention(Snowflake id) const noexcept;
|
||||
bool IsEditable() const noexcept;
|
||||
|
||||
bool DoesMentionEveryoneOrUser(Snowflake id) const noexcept;
|
||||
bool DoesMention(Snowflake id) const noexcept;
|
||||
|
||||
private:
|
||||
bool m_deleted = false;
|
||||
|
||||
Reference in New Issue
Block a user