From 8089e8e88fb145b4b954c310a0eda2ec647259cd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 27 Oct 2018 01:47:08 +0200 Subject: Add users, nickname change, messages now have author --- include/ChatMessage.hpp | 6 +++++- include/ChatWindow.hpp | 19 ++++++++++++++++--- include/User.hpp | 13 +++++++++++++ include/Window.hpp | 2 +- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 include/User.hpp (limited to 'include') diff --git a/include/ChatMessage.hpp b/include/ChatMessage.hpp index 0547557..271aa5f 100644 --- a/include/ChatMessage.hpp +++ b/include/ChatMessage.hpp @@ -1,16 +1,20 @@ #pragma once +#include "types.hpp" #include #include namespace dchat { + class User; class ChatMessage : public Gtk::Grid { public: - ChatMessage(const Glib::ustring &username, const Glib::ustring &text); + ChatMessage(const Glib::ustring &username, const Glib::ustring &text, uint32_t timestampSeconds, const User *user); Gtk::Label username; Gtk::Label text; + uint32_t timestampSeconds; + const User *user; }; } \ No newline at end of file diff --git a/include/ChatWindow.hpp b/include/ChatWindow.hpp index b13046e..b10af2b 100644 --- a/include/ChatWindow.hpp +++ b/include/ChatWindow.hpp @@ -1,7 +1,8 @@ #pragma once +#include "User.hpp" #include -#include +#include #include #include #include @@ -9,15 +10,23 @@ #include #include #include +#include namespace dchat { + class ChatMessage; + class ChatWindow : public Gtk::Grid { public: ChatWindow(); void addChannel(const odhtdb::Hash &nodeHash); - void addLocalMessage(const odhtdb::Hash &channelId, Glib::ustring msg); + void addLocalMessage(const odhtdb::Hash &channelId, const odhtdb::Signature::PublicKey &userPublicKey, uint32_t timestampSeconds, Glib::ustring msg); + void addUser(const odhtdb::Signature::PublicKey &userPublicKey); + void setUserNickname(const odhtdb::Signature::PublicKey &userPublicKey, const Glib::ustring &name); + + // Returns nullptr if user with @publicKey is not found + User* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey) const; private: void setupTopBar(); void setupLeftPanel(Gtk::Paned *sidePanels); @@ -27,6 +36,7 @@ namespace dchat Gtk::Grid topbar; Gtk::Entry topbarSearchBar; Gtk::Grid leftPanelChannels; + Gtk::Grid leftPanelUsers; Gtk::Label currentChannelTitle; Gtk::ScrolledWindow chatArea; Gtk::Grid chatAreaLayout; @@ -34,11 +44,14 @@ namespace dchat struct ChannelData { - Gtk::Button *button; + Gtk::ToggleButton *button; int messageCount; }; odhtdb::MapHash channelDataById; int channelCount; + std::vector users; + + ChatMessage *lastMessage; }; } \ No newline at end of file diff --git a/include/User.hpp b/include/User.hpp new file mode 100644 index 0000000..471a5cc --- /dev/null +++ b/include/User.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include + +namespace dchat +{ + struct User + { + const odhtdb::Signature::PublicKey publicKey; + Glib::ustring name; + }; +} \ No newline at end of file diff --git a/include/Window.hpp b/include/Window.hpp index 96197c6..29ec285 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -14,7 +14,7 @@ namespace dchat public: Window(); virtual ~Window(); - protected: + private: std::unique_ptr database; std::mutex databaseCallbackMutex; Gtk::Stack stack; -- cgit v1.2.3