aboutsummaryrefslogtreecommitdiff
path: root/src/User.cpp
blob: 510f88415fe84462e191350be9ace29249146db5 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "../include/User.hpp"
#include <cassert>

namespace dchat
{
    const static std::string SYSTEM_USER_NAME = "System";
    const i64 USER_TIMEOUT_SEC = 25;
    
    User::User(Type _type) : 
        type(_type)
    {
        
    }
    
    OnlineUser::OnlineUser(const std::string &_name, Type type) : 
        User(type),
        name(_name),
        pingTimestampSec(0)
    {
        
    }

    const std::string& OnlineUser::getName() const
    {
        return name;
    }

    bool OnlineUser::isConnected(i64 timestampUtcSec) const
    {
        i64 pingTimeDiffSec = timestampUtcSec - (i64)pingTimestampSec;
        return pingTimeDiffSec <= USER_TIMEOUT_SEC;
    }

    OnlineRemoteUser::OnlineRemoteUser(const std::string &name, const odhtdb::Signature::PublicKey &_publicKey) : 
        OnlineUser(name, Type::ONLINE_REMOTE_USER),
        publicKey(_publicKey)
    {
        
    }
    
    const odhtdb::Signature::PublicKey& OnlineRemoteUser::getPublicKey() const
    {
        return publicKey;
    }

    OnlineLocalUser::OnlineLocalUser(const std::string &name, const odhtdb::Signature::KeyPair &_keyPair) : 
        OnlineUser(name, Type::ONLINE_LOCAL_USER),
        keyPair(_keyPair)
    {
        
    }

    const odhtdb::Signature::PublicKey& OnlineLocalUser::getPublicKey() const
    {
        return keyPair.getPublicKey();
    }

    OnlineDiscordUser::OnlineDiscordUser(const std::string &discordUserName, u64 _discordUserId, User *_bridgeOwner) : 
        OnlineUser(discordUserName, Type::ONLINE_DISCORD_USER),
        discordUserId(_discordUserId),
        bridgeOwner(_bridgeOwner)
    {
        assert(bridgeOwner);
    }
    
    const odhtdb::Signature::PublicKey& OnlineDiscordUser::getPublicKey() const
    {
        return odhtdb::Signature::PublicKey::ZERO;
    }
    
    OfflineUser::OfflineUser(const std::string &_name) : 
        User(Type::OFFLINE),
        name(_name)
    {
        
    }
    
    const std::string& OfflineUser::getName() const
    {
        return name;
    }
    
    SystemUser::SystemUser() : 
        User(Type::SYSTEM)
    {
        
    }
    
    const std::string& SystemUser::getName() const
    {
        return SYSTEM_USER_NAME;
    }
}