2020-08-26 05:46:43 +00:00
|
|
|
#pragma once
|
|
|
|
#include <gtkmm.h>
|
|
|
|
#include "../discord/discord.hpp"
|
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
class ChatMessageItemContainer : public Gtk::Box {
|
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
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
ChatMessageItemContainer();
|
|
|
|
static ChatMessageItemContainer *FromMessage(Snowflake id);
|
2020-08-30 06:00:56 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
// attributes = edited, deleted
|
|
|
|
void UpdateAttributes();
|
|
|
|
void UpdateContent();
|
2020-10-03 22:49:22 +00:00
|
|
|
void UpdateImage(std::string url, Glib::RefPtr<Gdk::Pixbuf> buf);
|
2020-09-20 05:12:54 +00:00
|
|
|
|
2020-08-30 06:00:56 +00:00
|
|
|
protected:
|
2020-09-30 19:12:52 +00:00
|
|
|
bool EmitImageLoad(std::string url);
|
|
|
|
|
2020-09-30 04:12:38 +00:00
|
|
|
void AddClickHandler(Gtk::Widget *widget, std::string);
|
2020-10-11 03:38:58 +00:00
|
|
|
Gtk::TextView *CreateTextComponent(const Message *data); // Message.Content
|
2020-10-05 06:09:15 +00:00
|
|
|
void UpdateTextComponent(Gtk::TextView *tv);
|
2020-11-06 07:36:08 +00:00
|
|
|
Gtk::Widget *CreateEmbedComponent(const Message *data); // Message.Embeds[0]
|
|
|
|
Gtk::Widget *CreateImageComponent(const AttachmentData &data);
|
|
|
|
Gtk::Widget *CreateAttachmentComponent(const AttachmentData &data); // non-image attachments
|
|
|
|
Gtk::Widget *CreateStickerComponent(const Sticker &data);
|
2020-09-30 04:12:38 +00:00
|
|
|
void HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url);
|
|
|
|
|
2020-12-11 05:12:43 +00:00
|
|
|
void OnEmbedImageLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
|
|
|
|
2020-10-30 19:54:28 +00:00
|
|
|
static Glib::ustring GetText(const Glib::RefPtr<Gtk::TextBuffer> &buf);
|
2020-10-24 23:42:06 +00:00
|
|
|
|
2020-10-13 00:20:37 +00:00
|
|
|
void HandleUserMentions(Gtk::TextView *tv);
|
2020-10-24 23:42:06 +00:00
|
|
|
void HandleStockEmojis(Gtk::TextView *tv);
|
|
|
|
void HandleCustomEmojis(Gtk::TextView *tv);
|
|
|
|
void HandleEmojis(Gtk::TextView *tv);
|
2020-10-05 06:09:15 +00:00
|
|
|
|
2020-10-11 03:38:58 +00:00
|
|
|
void HandleChannelMentions(Gtk::TextView *tv);
|
|
|
|
bool OnClickChannel(GdkEventButton *ev);
|
|
|
|
|
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;
|
|
|
|
|
2020-10-11 03:42:53 +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
|
|
|
|
2020-09-30 04:12:38 +00:00
|
|
|
std::unordered_map<std::string, std::pair<Gtk::Image *, AttachmentData>> m_img_loadmap;
|
|
|
|
|
2020-10-11 04:32:14 +00:00
|
|
|
void AttachGuildMenuHandler(Gtk::Widget *widget);
|
2020-09-26 03:02:13 +00:00
|
|
|
void ShowMenu(GdkEvent *event);
|
2020-08-30 06:00:56 +00:00
|
|
|
|
|
|
|
Gtk::Menu m_menu;
|
|
|
|
Gtk::MenuItem *m_menu_copy_id;
|
2020-10-13 03:55:52 +00:00
|
|
|
Gtk::MenuItem *m_menu_copy_content;
|
2020-08-30 06:00:56 +00:00
|
|
|
Gtk::MenuItem *m_menu_delete_message;
|
2020-08-31 02:55:36 +00:00
|
|
|
Gtk::MenuItem *m_menu_edit_message;
|
2020-09-07 06:45:46 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
void on_menu_copy_id();
|
|
|
|
void on_menu_delete_message();
|
|
|
|
void on_menu_edit_message();
|
2020-10-13 03:55:52 +00:00
|
|
|
void on_menu_copy_content();
|
2020-08-31 00:24:02 +00:00
|
|
|
|
2020-11-06 07:36:08 +00:00
|
|
|
Gtk::EventBox *m_ev;
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::Box *m_main;
|
|
|
|
Gtk::Label *m_attrib_label = nullptr;
|
2020-09-30 04:12:38 +00:00
|
|
|
Gtk::Image *m_embed_img = nullptr; // yes this is hacky no i dont care (for now)
|
|
|
|
std::string m_embed_imgurl;
|
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-09-03 05:54:40 +00:00
|
|
|
|
|
|
|
public:
|
2020-09-30 04:12:38 +00:00
|
|
|
typedef sigc::signal<void, std::string> type_signal_image_load;
|
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
typedef sigc::signal<void> type_signal_action_delete;
|
|
|
|
typedef sigc::signal<void> type_signal_action_edit;
|
2020-10-11 03:38:58 +00:00
|
|
|
typedef sigc::signal<void, Snowflake> type_signal_channel_click;
|
2020-09-03 05:54:40 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
type_signal_action_delete signal_action_delete();
|
|
|
|
type_signal_action_edit signal_action_edit();
|
2020-10-11 03:38:58 +00:00
|
|
|
type_signal_channel_click signal_action_channel_click();
|
2020-09-03 05:54:40 +00:00
|
|
|
|
2020-09-30 04:12:38 +00:00
|
|
|
type_signal_image_load signal_image_load();
|
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
private:
|
|
|
|
type_signal_action_delete m_signal_action_delete;
|
|
|
|
type_signal_action_edit m_signal_action_edit;
|
2020-10-11 03:38:58 +00:00
|
|
|
type_signal_channel_click m_signal_action_channel_click;
|
2020-09-30 04:12:38 +00:00
|
|
|
|
|
|
|
type_signal_image_load m_signal_image_load;
|
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;
|
2020-09-22 01:01:32 +00:00
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
ChatMessageHeader(const Message *data);
|
|
|
|
void AddContent(Gtk::Widget *widget, bool prepend);
|
|
|
|
void UpdateNameColor();
|
2020-09-22 01:01:32 +00:00
|
|
|
|
|
|
|
protected:
|
2020-11-18 21:25:10 +00:00
|
|
|
void OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
|
|
|
|
|
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);
|
|
|
|
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::Box *m_main_box;
|
|
|
|
Gtk::Box *m_content_box;
|
|
|
|
Gtk::Box *m_meta_box;
|
2020-11-08 05:44:26 +00:00
|
|
|
Gtk::EventBox *m_meta_ev;
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::Label *m_author;
|
|
|
|
Gtk::Label *m_timestamp;
|
2020-10-06 02:46:44 +00:00
|
|
|
Gtk::Label *m_extra = nullptr;
|
2020-09-26 03:02:13 +00:00
|
|
|
Gtk::Image *m_avatar;
|
2020-11-08 05:44:26 +00:00
|
|
|
Gtk::EventBox *m_avatar_ev;
|
|
|
|
|
|
|
|
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
|
|
|
};
|