aboutsummaryrefslogtreecommitdiff
path: root/bridge/DiscordService.cpp
blob: a4546a8154790e08a08d817ef48a865117f85e90 (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
#include "DiscordService.hpp"

namespace dchat
{
    DiscordServiceUser::DiscordServiceUser(const std::string &name, const u64 _id, bool _connected) : 
        BridgeServiceUser(Type::DISCORD, name),
        id(_id),
        connected(_connected)
    {

    }

    bool DiscordServiceUser::equals(BridgeServiceUser *other) const
    {
        return other && type == other->type && id == static_cast<DiscordServiceUser*>(other)->id;
    }

    bool DiscordService::removeUser(u64 discordUserId)
    {
        for(auto it = users.begin(), end = users.end(); it != end; ++it)
        {
            BridgeServiceUser *serviceUser = static_cast<BridgeServiceUser*>(*it);
            if(serviceUser->type == BridgeServiceUser::Type::DISCORD && static_cast<DiscordServiceUser*>(serviceUser)->id == discordUserId)
            {
                delete serviceUser;
                users.erase(it);
                return true;
            }
        }
        return false;
    }

    DiscordServiceUser* DiscordService::getUserById(u64 discordUserId)
    {
        for(User *user : users)
        {
            BridgeServiceUser *serviceUser = static_cast<BridgeServiceUser*>(user);
            if(serviceUser->type == BridgeServiceUser::Type::DISCORD && static_cast<DiscordServiceUser*>(serviceUser)->id == discordUserId)
                return static_cast<DiscordServiceUser*>(serviceUser);
        }
        return nullptr;
    }
}