diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-28 15:31:27 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-28 15:31:33 +0200 |
commit | 9d84d5d8e7f61a02c01eef021ea5e8b2f49dcf8f (patch) | |
tree | c680f1d77e09d8333299d4098b0093240e138f91 /include | |
parent | 3b03f87070d91f63f0dc3c7152723727781dcccf (diff) |
Connect channels to database, currently only locally
Diffstat (limited to 'include')
-rw-r--r-- | include/Channel.hpp | 30 | ||||
-rw-r--r-- | include/ChannelSidePanel.hpp | 2 | ||||
-rw-r--r-- | include/MessageBoard.hpp | 9 | ||||
-rw-r--r-- | include/User.hpp | 35 | ||||
-rw-r--r-- | include/UsersSidePanel.hpp | 7 |
5 files changed, 71 insertions, 12 deletions
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 <vector> +#include <odhtdb/DatabaseNode.hpp> +#include <odhtdb/Signature.hpp> + +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<User*> 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<User*> users; + odhtdb::Signature::MapPublicKey<OnlineUser*> 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,18 +10,21 @@ 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; bool selectingText; 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 <string> +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 <SFML/Graphics/RenderWindow.hpp> 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(); }; |