aboutsummaryrefslogtreecommitdiff
path: root/include/Channel.hpp
blob: be6e7c7015fd94b95e1697b7ca98f212666290b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include "MessageBoard.hpp"
#include "Chatbar.hpp"
#include "User.hpp"
#include "Channel.hpp"
#include <vector>
#include <odhtdb/DatabaseNode.hpp>
#include <odhtdb/Signature.hpp>
#include <odhtdb/Group.hpp>

namespace odhtdb
{
    class Database;
}

namespace dchat
{
    class Channel
    {
    public:
        Channel(const std::string &name, const odhtdb::DatabaseNode &databaseNodeInfo = odhtdb::DatabaseNode(), User *localUser = nullptr, odhtdb::Database *database = nullptr);
        virtual ~Channel();
        Channel(const Channel& other) = delete;
        Channel& operator = (const Channel &other) = delete;
        
        User* getLocalUser();
        SystemUser* getSystemUser();
        MessageBoard& getMessageBoard();
        
        const std::string& getName() const;
        const std::vector<User*> getUsers() const;
        User* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey);
        std::shared_ptr<odhtdb::Hash> getId();
        
        // If timestamp is 0, then timestamp is not used
        void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds = 0);
        void addMessage(const std::string &msg);
        void addUserLocally(User *user);
        bool addUser(const odhtdb::Signature::PublicKey &userId, const std::string &groupId);
        void replaceLocalUser(User *newLocalUser);
        
        void processEvent(const sf::Event &event);
        void draw(sf::RenderWindow &window, Cache &cache);
        
        static void setCurrent(Channel *channel);
        static Channel* getCurrent();
    protected:
        odhtdb::Database *database;
        odhtdb::DatabaseNode databaseNodeInfo;
        std::string name;
        MessageBoard messageBoard;
        Chatbar chatbar;
        User *localUser;
        SystemUser systemUser;
        std::vector<User*> users;
        odhtdb::Signature::MapPublicKey<OnlineUser*> publicKeyOnlineUsersMap;
    };
}