mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-04 11:33:27 +03:00
update pins window on pin/unpin
This commit is contained in:
@@ -280,6 +280,12 @@ void ChatList::SetUsePinnedMenu() {
|
||||
m_use_pinned_menu = true;
|
||||
}
|
||||
|
||||
void ChatList::ActuallyRemoveMessage(Snowflake id) {
|
||||
auto it = m_id_to_widget.find(id);
|
||||
if (it != m_id_to_widget.end())
|
||||
RemoveMessageAndHeader(it->second);
|
||||
}
|
||||
|
||||
void ChatList::OnScrollEdgeOvershot(Gtk::PositionType pos) {
|
||||
if (pos == Gtk::POS_TOP)
|
||||
m_signal_action_chat_load_history.emit(m_active_channel);
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
std::vector<Snowflake> GetRecentAuthors();
|
||||
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
|
||||
|
||||
private:
|
||||
void OnScrollEdgeOvershot(Gtk::PositionType pos);
|
||||
|
||||
@@ -1632,15 +1632,39 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
}
|
||||
|
||||
bool IsCompleteMessageObject(const nlohmann::json &j) {
|
||||
const auto required = { "id", "channel_id", "author", "content", "timestamp", "edited_timestamp", "tts", "mention_everyone", "mention_roles", "attachments", "embeds", "pinned", "type" };
|
||||
for (const auto &str : required) {
|
||||
if (!j.contains(str)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||
Snowflake id = msg.Data.at("id");
|
||||
|
||||
auto current = m_store.GetMessage(id);
|
||||
if (!current.has_value())
|
||||
return;
|
||||
if (!current.has_value()) {
|
||||
// im not sure how the client determines if a MESSAGE_UPDATE is suitable to be stored as a full message but i guess its something like this
|
||||
if (IsCompleteMessageObject(msg.Data)) {
|
||||
current = msg.Data;
|
||||
m_store.SetMessage(id, *current);
|
||||
// this doesnt mean a message is newly pinned when called here
|
||||
// it just means theres an (old) message that the client is now aware of that is also pinned
|
||||
m_signal_message_pinned.emit(*current);
|
||||
} else
|
||||
return;
|
||||
} else {
|
||||
const bool old_pinned = current->IsPinned;
|
||||
|
||||
current->from_json_edited(msg.Data);
|
||||
m_store.SetMessage(id, *current);
|
||||
current->from_json_edited(msg.Data);
|
||||
m_store.SetMessage(id, *current);
|
||||
|
||||
if (old_pinned && !current->IsPinned)
|
||||
m_signal_message_unpinned.emit(*current);
|
||||
else if (!old_pinned && current->IsPinned)
|
||||
m_signal_message_pinned.emit(*current);
|
||||
}
|
||||
|
||||
m_signal_message_update.emit(id, current->ChannelID);
|
||||
}
|
||||
@@ -2035,6 +2059,14 @@ DiscordClient::type_signal_relationship_add DiscordClient::signal_relationship_a
|
||||
return m_signal_relationship_add;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_unpinned DiscordClient::signal_message_unpinned() {
|
||||
return m_signal_message_unpinned;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_pinned DiscordClient::signal_message_pinned() {
|
||||
return m_signal_message_pinned;
|
||||
}
|
||||
|
||||
DiscordClient::type_signal_message_sent DiscordClient::signal_message_sent() {
|
||||
return m_signal_message_sent;
|
||||
}
|
||||
|
||||
@@ -326,6 +326,8 @@ public:
|
||||
typedef sigc::signal<void, GuildJoinRequestDeleteData> type_signal_guild_join_request_delete;
|
||||
typedef sigc::signal<void, Snowflake, RelationshipType> type_signal_relationship_remove;
|
||||
typedef sigc::signal<void, RelationshipAddData> type_signal_relationship_add;
|
||||
typedef sigc::signal<void, Message> type_signal_message_unpinned; // not a real event
|
||||
typedef sigc::signal<void, Message> type_signal_message_pinned; // not a real event either
|
||||
typedef sigc::signal<void, Message> type_signal_message_sent;
|
||||
typedef sigc::signal<void, std::string /* nonce */, float /* retry_after */> type_signal_message_send_fail; // retry after param will be 0 if it failed for a reason that isnt slowmode
|
||||
typedef sigc::signal<void, bool, GatewayCloseCode> type_signal_disconnected; // bool true if reconnecting
|
||||
@@ -361,6 +363,8 @@ public:
|
||||
type_signal_guild_join_request_delete signal_guild_join_request_delete();
|
||||
type_signal_relationship_remove signal_relationship_remove();
|
||||
type_signal_relationship_add signal_relationship_add();
|
||||
type_signal_message_unpinned signal_message_unpinned();
|
||||
type_signal_message_pinned signal_message_pinned();
|
||||
type_signal_message_sent signal_message_sent();
|
||||
type_signal_message_send_fail signal_message_send_fail();
|
||||
type_signal_disconnected signal_disconnected();
|
||||
@@ -397,6 +401,8 @@ protected:
|
||||
type_signal_guild_join_request_delete m_signal_guild_join_request_delete;
|
||||
type_signal_relationship_remove m_signal_relationship_remove;
|
||||
type_signal_relationship_add m_signal_relationship_add;
|
||||
type_signal_message_unpinned m_signal_message_unpinned;
|
||||
type_signal_message_pinned m_signal_message_pinned;
|
||||
type_signal_message_sent m_signal_message_sent;
|
||||
type_signal_message_send_fail m_signal_message_send_fail;
|
||||
type_signal_disconnected m_signal_disconnected;
|
||||
|
||||
@@ -21,9 +21,19 @@ PinnedWindow::PinnedWindow(const ChannelData &data)
|
||||
m_chat.SetActiveChannel(ChannelID);
|
||||
m_chat.SetUsePinnedMenu();
|
||||
|
||||
Abaddon::Get().GetDiscordClient().signal_message_pinned().connect(sigc::mem_fun(*this, &PinnedWindow::OnMessagePinned));
|
||||
Abaddon::Get().GetDiscordClient().signal_message_unpinned().connect(sigc::mem_fun(*this, &PinnedWindow::OnMessageUnpinned));
|
||||
FetchPinned();
|
||||
}
|
||||
|
||||
void PinnedWindow::OnMessagePinned(const Message &msg) {
|
||||
FetchPinned();
|
||||
}
|
||||
|
||||
void PinnedWindow::OnMessageUnpinned(const Message &msg) {
|
||||
m_chat.ActuallyRemoveMessage(msg.ID);
|
||||
}
|
||||
|
||||
void PinnedWindow::FetchPinned() {
|
||||
Abaddon::Get().GetDiscordClient().FetchPinned(ChannelID, sigc::mem_fun(*this, &PinnedWindow::OnFetchedPinned));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ public:
|
||||
Snowflake ChannelID;
|
||||
|
||||
private:
|
||||
void OnMessagePinned(const Message &msg);
|
||||
void OnMessageUnpinned(const Message &msg);
|
||||
void FetchPinned();
|
||||
void OnFetchedPinned(const std::vector<Message> &msgs, DiscordError code);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user