From 9d84d5d8e7f61a02c01eef021ea5e8b2f49dcf8f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 28 Apr 2018 15:31:27 +0200 Subject: Connect channels to database, currently only locally --- include/Channel.hpp | 30 +++++++++++++++++++++++++----- include/ChannelSidePanel.hpp | 2 ++ include/MessageBoard.hpp | 9 ++++++--- include/User.hpp | 35 +++++++++++++++++++++++++++++++++-- include/UsersSidePanel.hpp | 7 +++++-- 5 files changed, 71 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/Channel.hpp b/include/Channel.hpp index 4bdb4b5..6f5495f 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -4,25 +4,45 @@ #include "Chatbar.hpp" #include "User.hpp" #include "Channel.hpp" +#include +#include +#include + +namespace odhtdb +{ + class Database; +} namespace dchat { class Channel { public: - Channel(const std::string &name); - ~Channel(); + Channel(const std::string &name, const odhtdb::DatabaseNode &databaseNodeInfo = odhtdb::DatabaseNode(), User *localUser = nullptr, odhtdb::Database *database = nullptr); + virtual ~Channel(); User* getLocalUser(); MessageBoard& getMessageBoard(); + const std::string& getName() const; + const std::vector getUsers() const; + User* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey); + + void addLocalMessage(const std::string &msg, User *owner); + void addMessage(const std::string &msg); + void addUser(User *user); void processEvent(const sf::Event &event); void draw(sf::RenderWindow &window, Cache &cache); - private: + protected: + odhtdb::Database *database; + odhtdb::DatabaseNode databaseNodeInfo; + std::string name; MessageBoard messageBoard; Chatbar chatbar; - OfflineUser localOfflineUser; - std::string name; + User *localUser; + SystemUser systemUser; + std::vector users; + odhtdb::Signature::MapPublicKey publicKeyOnlineUsersMap; }; } diff --git a/include/ChannelSidePanel.hpp b/include/ChannelSidePanel.hpp index c1ed5d6..9cee907 100644 --- a/include/ChannelSidePanel.hpp +++ b/include/ChannelSidePanel.hpp @@ -10,6 +10,8 @@ namespace dchat { public: static void addChannel(Channel *channel); + static void removeAllChannels(); + static void draw(sf::RenderWindow &window); static float getWidth(); }; diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp index ca1405f..b431af8 100644 --- a/include/MessageBoard.hpp +++ b/include/MessageBoard.hpp @@ -10,17 +10,20 @@ namespace dchat { + class Channel; + class MessageBoard { + friend class Channel; public: MessageBoard(const sf::Vector2u &size); ~MessageBoard(); - void updateStaticContentTexture(const sf::Vector2u &newSize); - void addMessage(Message *message); - void processEvent(const sf::Event &event); void draw(sf::RenderWindow &window, Cache &cache); + private: + void updateStaticContentTexture(const sf::Vector2u &newSize); + void addMessage(Message *message); private: sf::RenderTexture staticContentTexture; bool dirty; diff --git a/include/User.hpp b/include/User.hpp index 2a8f46b..e9e334a 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -2,13 +2,37 @@ #include +namespace odhtdb +{ + class User; +} + namespace dchat { class User { public: + enum class Type + { + ONLINE, + OFFLINE, + SYSTEM + }; + + User(Type type); virtual ~User(){} virtual const std::string& getName() const = 0; + + const Type type; + }; + + class OnlineUser : public User + { + public: + OnlineUser(const odhtdb::User *databaseUser); + virtual const std::string& getName() const override; + + const odhtdb::User *databaseUser; }; class OfflineUser : public User @@ -16,7 +40,14 @@ namespace dchat public: OfflineUser(const std::string &name); virtual const std::string& getName() const override; - - std::string name; + + const std::string name; + }; + + class SystemUser : public User + { + public: + SystemUser(); + virtual const std::string& getName() const override; }; } diff --git a/include/UsersSidePanel.hpp b/include/UsersSidePanel.hpp index aebdb34..b2855bb 100644 --- a/include/UsersSidePanel.hpp +++ b/include/UsersSidePanel.hpp @@ -1,14 +1,17 @@ #pragma once -#include "User.hpp" #include namespace dchat { + class Channel; + class UsersSidePanel { public: - static void addUser(User *user); + static void setCurrentChannel(Channel *channel); + static Channel* getCurrentChannel(); + static void draw(sf::RenderWindow &window); static float getWidth(); }; -- cgit v1.2.3