2020-08-26 05:46:43 +00:00
|
|
|
#pragma once
|
2024-01-19 01:30:54 +00:00
|
|
|
#include <gdkmm/pixbufanimation.h>
|
|
|
|
#include <gtkmm/box.h>
|
|
|
|
#include <gtkmm/eventbox.h>
|
|
|
|
#include <gtkmm/image.h>
|
|
|
|
#include <gtkmm/listboxrow.h>
|
|
|
|
#include <gtkmm/textview.h>
|
2021-11-21 03:29:03 +00:00
|
|
|
#include "discord/discord.hpp"
|
2020-08-26 05:46:43 +00:00
|
|
|
|
2022-08-12 00:53:02 +00:00
|
|
|
class ChatMessageItemContainer : public Gtk::EventBox {
|
2020-08-26 05:46:43 +00:00
|
|
|
public:
|
|
|
|
Snowflake ID;
|
2020-09-26 03:02:13 +00:00
|
|
|
Snowflake ChannelID;
|
2020-08-29 05:14:07 +00:00
|
|
|
|
2021-04-03 06:40:37 +00:00
|
|
|
std::string Nonce;
|
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
ChatMessageItemContainer();
|
2021-06-10 19:27:32 +00:00
|
|
|
static ChatMessageItemContainer *FromMessage(const Message &data);
|
2020-08-30 06:00:56 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
// attributes = edited, deleted
|
|
|
|
void UpdateAttributes();
|
|
|
|
void UpdateContent();
|
2020-12-15 06:51:49 +00:00
|
|
|
void UpdateReactions();
|
2021-04-03 06:40:37 +00:00
|
|
|
void SetFailed();
|
2020-09-20 05:12:54 +00:00
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
protected:
|
2022-04-06 02:01:53 +00:00
|
|
|
static void AddClickHandler(Gtk::Widget *widget, const std::string &);
|
2021-06-10 19:27:32 +00:00
|
|
|
Gtk::TextView *CreateTextComponent(const Message &data); // Message.Content
|
2020-10-05 06:09:15 +00:00
|
|
|
void UpdateTextComponent(Gtk::TextView *tv);
|
2022-02-20 06:20:19 +00:00
|
|
|
Gtk::Widget *CreateEmbedsComponent(const std::vector<EmbedData> &embeds);
|
2022-04-06 02:01:53 +00:00
|
|
|
static Gtk::Widget *CreateEmbedComponent(const EmbedData &data); // Message.Embeds[0]
|
2020-12-26 08:57:08 +00:00
|
|
|
Gtk::Widget *CreateImageComponent(const std::string &proxy_url, const std::string &url, int inw, int inh);
|
2020-11-06 07:36:08 +00:00
|
|
|
Gtk::Widget *CreateAttachmentComponent(const AttachmentData &data); // non-image attachments
|
2021-07-01 06:03:41 +00:00
|
|
|
Gtk::Widget *CreateStickersComponent(const std::vector<StickerItem> &data);
|
2021-01-01 07:47:03 +00:00
|
|
|
Gtk::Widget *CreateReactionsComponent(const Message &data);
|
|
|
|
Gtk::Widget *CreateReplyComponent(const Message &data);
|
2020-12-11 05:12:43 +00:00
|
|
|
|
2020-12-26 08:57:08 +00:00
|
|
|
static bool IsEmbedImageOnly(const EmbedData &data);
|
|
|
|
|
2022-04-06 02:01:53 +00:00
|
|
|
void HandleChannelMentions(const Glib::RefPtr<Gtk::TextBuffer> &buf);
|
2020-10-11 03:38:58 +00:00
|
|
|
void HandleChannelMentions(Gtk::TextView *tv);
|
|
|
|
bool OnClickChannel(GdkEventButton *ev);
|
2022-08-12 00:53:02 +00:00
|
|
|
bool OnTextViewButtonPress(GdkEventButton *ev);
|
2020-10-11 03:38:58 +00:00
|
|
|
|
2020-11-06 07:36:08 +00:00
|
|
|
// reused for images and links
|
2020-11-06 05:20:31 +00:00
|
|
|
Gtk::Menu m_link_menu;
|
|
|
|
Gtk::MenuItem *m_link_menu_copy;
|
|
|
|
|
|
|
|
void on_link_menu_copy();
|
|
|
|
Glib::ustring m_selected_link;
|
|
|
|
|
2021-01-01 07:47:03 +00:00
|
|
|
void HandleLinks(Gtk::TextView &tv);
|
2020-10-10 03:14:57 +00:00
|
|
|
bool OnLinkClick(GdkEventButton *ev);
|
2020-10-11 03:38:58 +00:00
|
|
|
std::map<Glib::RefPtr<Gtk::TextTag>, std::string> m_link_tagmap;
|
|
|
|
std::map<Glib::RefPtr<Gtk::TextTag>, Snowflake> m_channel_tagmap;
|
2020-10-10 03:14:57 +00:00
|
|
|
|
2021-07-05 05:57:55 +00:00
|
|
|
Gtk::EventBox *_ev;
|
|
|
|
Gtk::Box m_main;
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::Label *m_attrib_label = nullptr;
|
2020-08-31 00:24:02 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::TextView *m_text_component = nullptr;
|
2020-11-06 07:36:08 +00:00
|
|
|
Gtk::Widget *m_embed_component = nullptr;
|
2020-12-15 06:51:49 +00:00
|
|
|
Gtk::Widget *m_reactions_component = nullptr;
|
2020-09-03 05:54:40 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-11 03:38:58 +00:00
|
|
|
typedef sigc::signal<void, Snowflake> type_signal_channel_click;
|
2020-12-15 06:51:49 +00:00
|
|
|
typedef sigc::signal<void, Glib::ustring> type_signal_action_reaction_add;
|
|
|
|
typedef sigc::signal<void, Glib::ustring> type_signal_action_reaction_remove;
|
2020-09-03 05:54:40 +00:00
|
|
|
|
2020-10-11 03:38:58 +00:00
|
|
|
type_signal_channel_click signal_action_channel_click();
|
2020-12-15 06:51:49 +00:00
|
|
|
type_signal_action_reaction_add signal_action_reaction_add();
|
|
|
|
type_signal_action_reaction_remove signal_action_reaction_remove();
|
2021-03-14 22:59:52 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
private:
|
2020-10-11 03:38:58 +00:00
|
|
|
type_signal_channel_click m_signal_action_channel_click;
|
2020-12-15 06:51:49 +00:00
|
|
|
type_signal_action_reaction_add m_signal_action_reaction_add;
|
|
|
|
type_signal_action_reaction_remove m_signal_action_reaction_remove;
|
2020-09-03 05:54:40 +00:00
|
|
|
};
|
2020-09-22 01:01:32 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
class ChatMessageHeader : public Gtk::ListBoxRow {
|
2020-09-22 01:01:32 +00:00
|
|
|
public:
|
2020-09-26 03:02:13 +00:00
|
|
|
Snowflake UserID;
|
|
|
|
Snowflake ChannelID;
|
2021-04-12 06:21:26 +00:00
|
|
|
Snowflake NewestID = 0;
|
2020-09-22 01:01:32 +00:00
|
|
|
|
2021-06-10 19:27:32 +00:00
|
|
|
ChatMessageHeader(const Message &data);
|
2020-09-26 03:02:13 +00:00
|
|
|
void AddContent(Gtk::Widget *widget, bool prepend);
|
2022-03-26 06:51:56 +00:00
|
|
|
void UpdateName();
|
2021-07-01 06:03:41 +00:00
|
|
|
std::vector<Gtk::Widget *> GetChildContent();
|
2020-09-22 01:01:32 +00:00
|
|
|
|
|
|
|
protected:
|
2020-11-08 05:44:26 +00:00
|
|
|
void AttachUserMenuHandler(Gtk::Widget &widget);
|
|
|
|
|
2020-10-11 05:56:30 +00:00
|
|
|
bool on_author_button_press(GdkEventButton *ev);
|
|
|
|
|
2021-07-01 06:03:41 +00:00
|
|
|
std::vector<Gtk::Widget *> m_content_widgets;
|
2021-03-31 02:31:13 +00:00
|
|
|
|
2021-07-05 05:57:55 +00:00
|
|
|
Gtk::Box m_main_box;
|
|
|
|
Gtk::Box m_content_box;
|
|
|
|
Gtk::EventBox m_content_box_ev;
|
|
|
|
Gtk::Box m_meta_box;
|
|
|
|
Gtk::EventBox m_meta_ev;
|
|
|
|
Gtk::Label m_author;
|
|
|
|
Gtk::Label m_timestamp;
|
2020-10-06 02:46:44 +00:00
|
|
|
Gtk::Label *m_extra = nullptr;
|
2021-07-05 05:57:55 +00:00
|
|
|
Gtk::Image m_avatar;
|
|
|
|
Gtk::EventBox m_avatar_ev;
|
2020-11-08 05:44:26 +00:00
|
|
|
|
2020-12-22 07:24:09 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> m_static_avatar;
|
|
|
|
Glib::RefPtr<Gdk::PixbufAnimation> m_anim_avatar;
|
|
|
|
|
2020-11-08 05:44:26 +00:00
|
|
|
typedef sigc::signal<void> type_signal_action_insert_mention;
|
|
|
|
typedef sigc::signal<void, const GdkEvent *> type_signal_action_open_user_menu;
|
2020-10-11 05:56:30 +00:00
|
|
|
|
|
|
|
type_signal_action_insert_mention m_signal_action_insert_mention;
|
2020-11-08 05:44:26 +00:00
|
|
|
type_signal_action_open_user_menu m_signal_action_open_user_menu;
|
2020-10-11 05:56:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
type_signal_action_insert_mention signal_action_insert_mention();
|
2020-11-08 05:44:26 +00:00
|
|
|
type_signal_action_open_user_menu signal_action_open_user_menu();
|
2020-09-22 01:01:32 +00:00
|
|
|
};
|