From e6331c04af99d7deeb9b15be02dd30665c3c41ce Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 16 May 2018 10:24:22 +0200 Subject: Rewrite code to work with new backend Redesigned join channel system, read README.md for more information --- include/Channel.hpp | 4 ++-- include/User.hpp | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/Channel.hpp b/include/Channel.hpp index 93f3725..6e944c3 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -51,8 +51,8 @@ namespace dchat void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser); void addUserLocally(User *user); - bool addUser(const odhtdb::Signature::PublicKey &userId, const std::string &groupId); - void replaceLocalUser(User *newLocalUser); + bool addUser(const odhtdb::Signature::PublicKey &userId, const odhtdb::DataView &groupId); + void replaceLocalUser(OnlineLocalUser *newOnlineLocalUser); void changeNick(const std::string &newNick); void processEvent(const sf::Event &event); diff --git a/include/User.hpp b/include/User.hpp index a83b9dc..85418dc 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -1,11 +1,7 @@ #pragma once #include - -namespace odhtdb -{ - class User; -} +#include namespace dchat { @@ -14,7 +10,8 @@ namespace dchat public: enum class Type { - ONLINE, + ONLINE_REMOTE_USER, + ONLINE_LOCAL_USER, OFFLINE, SYSTEM }; @@ -22,6 +19,7 @@ namespace dchat User(Type type); virtual ~User(){} virtual const std::string& getName() const = 0; + virtual bool isOnlineUser() const { return false; } const Type type; std::string avatarUrl; @@ -30,11 +28,33 @@ namespace dchat class OnlineUser : public User { public: - OnlineUser(const odhtdb::User *databaseUser); + OnlineUser(const std::string &name, Type type); + virtual ~OnlineUser(){} + virtual const std::string& getName() const override; + virtual const odhtdb::Signature::PublicKey& getPublicKey() const = 0; + + bool isOnlineUser() const override { return true; } std::string name; - const odhtdb::User *databaseUser; + }; + + class OnlineRemoteUser : public OnlineUser + { + public: + OnlineRemoteUser(const std::string &name, const odhtdb::Signature::PublicKey &publicKey); + virtual const odhtdb::Signature::PublicKey& getPublicKey() const override; + + const odhtdb::Signature::PublicKey publicKey; + }; + + class OnlineLocalUser : public OnlineUser + { + public: + OnlineLocalUser(const std::string &name, const odhtdb::Signature::KeyPair &keyPair); + virtual const odhtdb::Signature::PublicKey& getPublicKey() const override; + + const odhtdb::Signature::KeyPair keyPair; }; class OfflineUser : public User -- cgit v1.2.3