From 0469c43a45310b6b92eb704773e3a34beb57f288 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 1 Nov 2018 07:17:49 +0100 Subject: Move room code to dchat_core, add ability to send messages --- include/ChannelDataType.hpp | 16 ---------------- include/ChatMessage.hpp | 3 +-- include/ChatWindow.hpp | 26 +++++++++++--------------- include/LoginWindow.hpp | 2 +- include/User.hpp | 13 ------------- include/Window.hpp | 4 ++-- 6 files changed, 15 insertions(+), 49 deletions(-) delete mode 100644 include/ChannelDataType.hpp delete mode 100644 include/User.hpp (limited to 'include') diff --git a/include/ChannelDataType.hpp b/include/ChannelDataType.hpp deleted file mode 100644 index 21e828d..0000000 --- a/include/ChannelDataType.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include - -namespace dchat -{ - enum class ChannelDataType : u8 - { - ADD_MESSAGE, - EDIT_MESSAGE, - DELETE_MESSAGE, - NICKNAME_CHANGE, - CHANGE_AVATAR, - CHANGE_CHANNEL_NAME, - }; -} \ No newline at end of file diff --git a/include/ChatMessage.hpp b/include/ChatMessage.hpp index c13db9d..c1ef459 100644 --- a/include/ChatMessage.hpp +++ b/include/ChatMessage.hpp @@ -10,13 +10,12 @@ namespace dchat class ChatMessage : public Gtk::Grid { public: - ChatMessage(const Glib::ustring &username, const Glib::ustring &text, uint32_t timestampSeconds, const User *user); + ChatMessage(const Glib::ustring &username, const Glib::ustring &text, uint32_t timestampSeconds); Gtk::Grid avatar; Gtk::Label username; Gtk::Label text; uint32_t timestampSeconds; - const User *user; private: bool updateContent(const Cairo::RefPtr &cairo); }; diff --git a/include/ChatWindow.hpp b/include/ChatWindow.hpp index 0b58506..988b225 100644 --- a/include/ChatWindow.hpp +++ b/include/ChatWindow.hpp @@ -1,6 +1,6 @@ #pragma once -#include "User.hpp" +#include #include #include #include @@ -20,13 +20,11 @@ namespace dchat { public: ChatWindow(); - void addChannel(const odhtdb::Hash &nodeHash); - 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; + void addRoom(std::shared_ptr room); + void addMessage(const RoomAddMessageRequest &request); + void addUser(std::shared_ptr room, std::shared_ptr user); + void setUserNickname(const UserChangeNicknameRequest &request); + void scrollToBottom(); private: void setupTopBar(); void setupLeftPanel(Gtk::Paned *sidePanels); @@ -42,17 +40,15 @@ namespace dchat Gtk::Grid messageAreaLayout; Gtk::TextView chatInput; - struct ChannelData + struct RoomData { Gtk::ToggleButton *button; - int messageCount; }; - odhtdb::MapHash channelDataById; - int channelCount; - std::vector users; - - ChatMessage *lastMessage; + odhtdb::MapHash roomDataById; + odhtdb::MapHash messageById; int chatPrevNumLines; + int roomCount; + std::shared_ptr currentRoom; }; } \ No newline at end of file diff --git a/include/LoginWindow.hpp b/include/LoginWindow.hpp index ea9b905..d5585a5 100644 --- a/include/LoginWindow.hpp +++ b/include/LoginWindow.hpp @@ -22,7 +22,7 @@ namespace dchat private: void setupLogin(); void setupRegister(); - private: + public: Gtk::Grid loginLayout; Gtk::Entry loginUsernameInput; Gtk::Entry loginPasswordInput; diff --git a/include/User.hpp b/include/User.hpp deleted file mode 100644 index 471a5cc..0000000 --- a/include/User.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#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 4c67a68..a29ec62 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -26,7 +26,7 @@ namespace dchat void draw(const Cairo::RefPtr &cairo) { Gtk::Overlay::draw(cairo); } }; - std::unique_ptr database; + std::shared_ptr rooms; std::mutex databaseCallbackMutex; OverlayDrawable overlay; Gtk::Stack stack; -- cgit v1.2.3