add unpin to menu, refactor a bit

This commit is contained in:
ouwou 2021-06-17 01:08:09 -04:00
parent 51fdcddaea
commit 78f3164063
9 changed files with 36 additions and 25 deletions

View File

@ -106,7 +106,6 @@ int Abaddon::StartGTK() {
m_main_window->GetChannelList()->signal_action_guild_leave().connect(sigc::mem_fun(*this, &Abaddon::ActionLeaveGuild));
m_main_window->GetChannelList()->signal_action_guild_settings().connect(sigc::mem_fun(*this, &Abaddon::ActionGuildSettings));
m_main_window->GetChatWindow()->signal_action_message_delete().connect(sigc::mem_fun(*this, &Abaddon::ActionChatDeleteMessage));
m_main_window->GetChatWindow()->signal_action_message_edit().connect(sigc::mem_fun(*this, &Abaddon::ActionChatEditMessage));
m_main_window->GetChatWindow()->signal_action_chat_submit().connect(sigc::mem_fun(*this, &Abaddon::ActionChatInputSubmit));
m_main_window->GetChatWindow()->signal_action_chat_load_history().connect(sigc::mem_fun(*this, &Abaddon::ActionChatLoadHistory));
@ -538,10 +537,6 @@ void Abaddon::ActionChatInputSubmit(std::string msg, Snowflake channel, Snowflak
m_discord.SendChatMessage(msg, channel);
}
void Abaddon::ActionChatDeleteMessage(Snowflake channel_id, Snowflake id) {
m_discord.DeleteMessage(channel_id, id);
}
void Abaddon::ActionChatEditMessage(Snowflake channel_id, Snowflake id) {
const auto msg = m_discord.GetMessage(id);
if (!msg.has_value()) return;

View File

@ -36,7 +36,6 @@ public:
void ActionChannelOpened(Snowflake id);
void ActionChatInputSubmit(std::string msg, Snowflake channel, Snowflake referenced_message);
void ActionChatLoadHistory(Snowflake id);
void ActionChatDeleteMessage(Snowflake channel_id, Snowflake id);
void ActionChatEditMessage(Snowflake channel_id, Snowflake id);
void ActionInsertMention(Snowflake id);
void ActionLeaveGuild(Snowflake id);

View File

@ -34,18 +34,21 @@ ChatList::ChatList() {
m_menu_copy_id->signal_activate().connect([this] {
Gtk::Clipboard::get()->set_text(std::to_string(m_menu_selected_message));
});
m_menu_copy_id->show();
m_menu.append(*m_menu_copy_id);
m_menu_delete_message = Gtk::manage(new Gtk::MenuItem("Delete Message"));
m_menu_delete_message->signal_activate().connect([this] {
m_signal_action_message_delete.emit(m_active_channel, m_menu_selected_message);
Abaddon::Get().GetDiscordClient().DeleteMessage(m_active_channel, m_menu_selected_message);
});
m_menu_delete_message->show();
m_menu.append(*m_menu_delete_message);
m_menu_edit_message = Gtk::manage(new Gtk::MenuItem("Edit Message"));
m_menu_edit_message->signal_activate().connect([this] {
m_signal_action_message_edit.emit(m_active_channel, m_menu_selected_message);
});
m_menu_edit_message->show();
m_menu.append(*m_menu_edit_message);
m_menu_copy_content = Gtk::manage(new Gtk::MenuItem("Copy Content"));
@ -54,15 +57,23 @@ ChatList::ChatList() {
if (msg.has_value())
Gtk::Clipboard::get()->set_text(msg->Content);
});
m_menu_copy_content->show();
m_menu.append(*m_menu_copy_content);
m_menu_reply_to = Gtk::manage(new Gtk::MenuItem("Reply To"));
m_menu_reply_to->signal_activate().connect([this] {
m_signal_action_reply_to.emit(m_menu_selected_message);
});
m_menu_reply_to->show();
m_menu.append(*m_menu_reply_to);
m_menu.show_all();
m_menu_unpin = Gtk::manage(new Gtk::MenuItem("Unpin"));
m_menu_unpin->signal_activate().connect([this] {
Abaddon::Get().GetDiscordClient().Unpin(m_active_channel, m_menu_selected_message, [](...) {});
});
m_menu.append(*m_menu_unpin);
m_menu.show();
}
void ChatList::Clear() {
@ -148,6 +159,10 @@ void ChatList::ProcessNewMessage(const Message &data, bool prepend) {
if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) {
m_menu_selected_message = id;
m_menu_edit_message->set_visible(!m_use_pinned_menu);
m_menu_reply_to->set_visible(!m_use_pinned_menu);
m_menu_unpin->set_visible(m_use_pinned_menu);
const auto &client = Abaddon::Get().GetDiscordClient();
const auto data = client.GetMessage(id);
if (data->IsDeleted()) {
@ -261,6 +276,10 @@ void ChatList::SetSeparateAll(bool separate) {
m_separate_all = true;
}
void ChatList::SetUsePinnedMenu() {
m_use_pinned_menu = true;
}
void ChatList::OnScrollEdgeOvershot(Gtk::PositionType pos) {
if (pos == Gtk::POS_TOP)
m_signal_action_chat_load_history.emit(m_active_channel);
@ -286,10 +305,6 @@ void ChatList::RemoveMessageAndHeader(Gtk::Widget *widget) {
m_num_messages--;
}
ChatList::type_signal_action_message_delete ChatList::signal_action_message_delete() {
return m_signal_action_message_delete;
}
ChatList::type_signal_action_message_edit ChatList::signal_action_message_edit() {
return m_signal_action_message_edit;
}

View File

@ -21,18 +21,22 @@ public:
void SetFailedByNonce(const std::string &nonce);
std::vector<Snowflake> GetRecentAuthors();
void SetSeparateAll(bool separate);
void SetUsePinnedMenu(); // i think i need a better way to do menus
private:
void OnScrollEdgeOvershot(Gtk::PositionType pos);
void ScrollToBottom();
void RemoveMessageAndHeader(Gtk::Widget *widget);
bool m_use_pinned_menu = false;
Gtk::Menu m_menu;
Gtk::MenuItem *m_menu_copy_id;
Gtk::MenuItem *m_menu_copy_content;
Gtk::MenuItem *m_menu_delete_message;
Gtk::MenuItem *m_menu_edit_message;
Gtk::MenuItem *m_menu_reply_to;
Gtk::MenuItem *m_menu_unpin;
Snowflake m_menu_selected_message;
Snowflake m_active_channel;
@ -48,7 +52,6 @@ private:
public:
// these are all forwarded by the parent
using type_signal_action_message_delete = sigc::signal<void, Snowflake, Snowflake>;
using type_signal_action_message_edit = sigc::signal<void, Snowflake, Snowflake>;
using type_signal_action_chat_submit = sigc::signal<void, std::string, Snowflake, Snowflake>;
using type_signal_action_chat_load_history = sigc::signal<void, Snowflake>;
@ -59,7 +62,6 @@ public:
using type_signal_action_reaction_remove = sigc::signal<void, Snowflake, Glib::ustring>;
using type_signal_action_reply_to = sigc::signal<void, Snowflake>;
type_signal_action_message_delete signal_action_message_delete();
type_signal_action_message_edit signal_action_message_edit();
type_signal_action_chat_submit signal_action_chat_submit();
type_signal_action_chat_load_history signal_action_chat_load_history();
@ -71,7 +73,6 @@ public:
type_signal_action_reply_to signal_action_reply_to();
private:
type_signal_action_message_delete m_signal_action_message_delete;
type_signal_action_message_edit m_signal_action_message_edit;
type_signal_action_chat_submit m_signal_action_chat_submit;
type_signal_action_chat_load_history m_signal_action_chat_load_history;

View File

@ -63,9 +63,6 @@ ChatWindow::ChatWindow() {
// lowkey gross
m_signal_action_insert_mention.emit(id);
});
m_chat->signal_action_message_delete().connect([this](Snowflake channel_id, Snowflake message_id) {
m_signal_action_message_delete.emit(channel_id, message_id);
});
m_chat->signal_action_message_edit().connect([this](Snowflake channel_id, Snowflake message_id) {
m_signal_action_message_edit.emit(channel_id, message_id);
});
@ -202,10 +199,6 @@ void ChatWindow::OnMessageSendFail(const std::string &nonce, float retry_after)
m_chat->SetFailedByNonce(nonce);
}
ChatWindow::type_signal_action_message_delete ChatWindow::signal_action_message_delete() {
return m_signal_action_message_delete;
}
ChatWindow::type_signal_action_message_edit ChatWindow::signal_action_message_edit() {
return m_signal_action_message_edit;
}

View File

@ -59,7 +59,6 @@ protected:
Gtk::Box *m_meta;
public:
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_action_message_delete;
typedef sigc::signal<void, Snowflake, Snowflake> type_signal_action_message_edit;
typedef sigc::signal<void, std::string, Snowflake, Snowflake> type_signal_action_chat_submit;
typedef sigc::signal<void, Snowflake> type_signal_action_chat_load_history;
@ -68,7 +67,6 @@ public:
typedef sigc::signal<void, Snowflake, Glib::ustring> type_signal_action_reaction_add;
typedef sigc::signal<void, Snowflake, Glib::ustring> type_signal_action_reaction_remove;
type_signal_action_message_delete signal_action_message_delete();
type_signal_action_message_edit signal_action_message_edit();
type_signal_action_chat_submit signal_action_chat_submit();
type_signal_action_chat_load_history signal_action_chat_load_history();
@ -78,7 +76,6 @@ public:
type_signal_action_reaction_remove signal_action_reaction_remove();
private:
type_signal_action_message_delete m_signal_action_message_delete;
type_signal_action_message_edit m_signal_action_message_edit;
type_signal_action_chat_submit m_signal_action_chat_submit;
type_signal_action_chat_load_history m_signal_action_chat_load_history;

View File

@ -710,6 +710,15 @@ void DiscordClient::PutRelationship(Snowflake id, sigc::slot<void(bool success,
});
}
void DiscordClient::Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback) {
m_http.MakeDELETE("/channels/" + std::to_string(channel_id) + "/pins/" + std::to_string(message_id), [this, callback](const http::response_type &response) {
if (CheckCode(response, 204))
callback(DiscordError::NONE);
else
callback(GetCodeFromResponse(response));
});
}
void DiscordClient::FetchPinned(Snowflake id, sigc::slot<void(std::vector<Message>, DiscordError code)> callback) {
m_http.MakeGET("/channels/" + std::to_string(id) + "/pins", [this, callback](const http::response_type &response) {
if (!CheckCode(response)) {

View File

@ -138,6 +138,7 @@ public:
void RemoveRelationship(Snowflake id, sigc::slot<void(bool success)> callback);
void SendFriendRequest(const Glib::ustring &username, int discriminator, sigc::slot<void(bool success, DiscordError code)> callback);
void PutRelationship(Snowflake id, sigc::slot<void(bool success, DiscordError code)> callback); // send fr by id, accept incoming
void Unpin(Snowflake channel_id, Snowflake message_id, sigc::slot<void(DiscordError code)> callback);
bool CanModifyRole(Snowflake guild_id, Snowflake role_id) const;
bool CanModifyRole(Snowflake guild_id, Snowflake role_id, Snowflake user_id) const;

View File

@ -19,6 +19,7 @@ PinnedWindow::PinnedWindow(const ChannelData &data)
m_chat.SetSeparateAll(true);
m_chat.SetActiveChannel(ChannelID);
m_chat.SetUsePinnedMenu();
FetchPinned();
}