aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Channel.hpp21
-rw-r--r--include/Chatbar.hpp2
-rw-r--r--include/MessageBoard.hpp3
-rw-r--r--include/Rpc.hpp21
-rw-r--r--include/Suggestions.hpp19
-rw-r--r--include/User.hpp15
6 files changed, 78 insertions, 3 deletions
diff --git a/include/Channel.hpp b/include/Channel.hpp
index af6cbf2..663b163 100644
--- a/include/Channel.hpp
+++ b/include/Channel.hpp
@@ -5,7 +5,10 @@
#include "User.hpp"
#include "Channel.hpp"
#include "types.hpp"
+#include "Suggestions.hpp"
+#include "../bridge/DiscordService.hpp"
#include <vector>
+#include <unordered_map>
#include <SFML/System/Clock.hpp>
#include <odhtdb/DatabaseNode.hpp>
#include <odhtdb/Signature.hpp>
@@ -28,7 +31,9 @@ namespace dchat
DELETE_MESSAGE,
NICKNAME_CHANGE,
CHANGE_AVATAR,
- CHANGE_CHANNEL_NAME
+ CHANGE_CHANNEL_NAME,
+
+ ADD_DISCORD_MESSAGE
};
class Channel
@@ -44,7 +49,7 @@ namespace dchat
MessageBoard& getMessageBoard();
const std::string& getName() const;
- const std::vector<User*> getUsers() const;
+ const std::vector<User*>& getUsers() const;
OnlineUser* getUserByPublicKey(const odhtdb::Signature::PublicKey &publicKey);
const odhtdb::DatabaseNode& getNodeInfo() const;
Message* getLatestMessage();
@@ -52,8 +57,10 @@ namespace dchat
// If timestamp is 0, then current time is used
void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds = 0);
void addLocalMessage(const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
+ void addLocalDiscordMessage(const std::string &discordUserName, u64 discordUserId, const std::string &msg, User *owner, u64 timestampSeconds, const odhtdb::Hash &id);
void addSystemMessage(const std::string &msg, bool plainText = true);
void addMessage(const std::string &msg);
+ void addDiscordMessage(const std::string &discordUserName, u64 discordUserId, const std::string &msg);
void deleteLocalMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
@@ -64,6 +71,9 @@ namespace dchat
void setAvatar(const std::string &newAvatarUrl);
void setNameLocally(const std::string &name);
void setName(const std::string &name);
+
+ // Returns -1 on failure
+ int getUserLowestPermissionLevel(OnlineUser *user) const;
void processEvent(const sf::Event &event, Cache &cache);
void draw(sf::RenderWindow &window, Cache &cache);
@@ -71,6 +81,9 @@ namespace dchat
void update();
// Returns 0 if we are offline
u32 getSyncedTimestampUtcInSec();
+
+ const std::vector<BridgeService*>& getBridgeServices() const;
+ DiscordService* getDiscordService();
static void setCurrent(Channel *channel);
static Channel* getCurrent();
@@ -82,12 +95,16 @@ namespace dchat
std::string name;
MessageBoard messageBoard;
Chatbar chatbar;
+ Suggestions suggestions;
User *localUser;
SystemUser systemUser;
std::vector<User*> users;
+ std::unordered_map<u64, OnlineDiscordUser*> discordUserById;
odhtdb::Signature::MapPublicKey<OnlineUser*> publicKeyOnlineUsersMap;
dht::InfoHash pingKey;
std::future<size_t> pingListener;
sf::Clock pingTimer;
+
+ std::vector<BridgeService*> bridgeServices;
};
}
diff --git a/include/Chatbar.hpp b/include/Chatbar.hpp
index df492ac..10bbebd 100644
--- a/include/Chatbar.hpp
+++ b/include/Chatbar.hpp
@@ -24,6 +24,8 @@ namespace dchat
void processEvent(const sf::Event &event, Cache &cache, Channel *channel);
void draw(sf::RenderWindow &window, Cache &cache);
+ static sf::Vector2f getInputPosition(sf::RenderWindow &window);
+ static sf::Vector2f getInputSize(sf::RenderWindow &window);
static float getHeight();
static bool addBind(const std::string &key, const std::string &value, bool updateFile = true);
diff --git a/include/MessageBoard.hpp b/include/MessageBoard.hpp
index fdde8c7..1d1f523 100644
--- a/include/MessageBoard.hpp
+++ b/include/MessageBoard.hpp
@@ -27,11 +27,12 @@ namespace dchat
void draw(sf::RenderWindow &window, Cache &cache);
Message* getLatestMessage();
+ const std::vector<Message*>& getMessages() const;
private:
usize findPositionToInsertMessageByTimestamp(Message *message);
void updateStaticContentTexture(const sf::Vector2u &newSize);
- void addMessage(Message *message, const odhtdb::Hash &id);
+ bool addMessage(Message *message, const odhtdb::Hash &id);
void deleteMessage(const odhtdb::Hash &id, const odhtdb::Signature::PublicKey &requestedByUser);
void drawDefault(sf::RenderWindow &window, Cache &cache);
diff --git a/include/Rpc.hpp b/include/Rpc.hpp
new file mode 100644
index 0000000..c8b47e0
--- /dev/null
+++ b/include/Rpc.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <zmq.hpp>
+#include "types.hpp"
+#include <functional>
+
+namespace dchat
+{
+ using RpcRecvCallbackFunc = std::function<void(zmq::message_t*)>;
+
+ class Rpc
+ {
+ public:
+ Rpc(u16 port);
+ void recv(RpcRecvCallbackFunc recvCallbackFunc);
+ bool send(const void *data, const usize size);
+ private:
+ zmq::context_t context;
+ zmq::socket_t socket;
+ };
+} \ No newline at end of file
diff --git a/include/Suggestions.hpp b/include/Suggestions.hpp
new file mode 100644
index 0000000..56f3afa
--- /dev/null
+++ b/include/Suggestions.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Text.hpp"
+#include "Cache.hpp"
+#include <vector>
+#include <string>
+#include <SFML/Graphics/RenderWindow.hpp>
+
+namespace dchat
+{
+ class Suggestions
+ {
+ public:
+ void show(const std::vector<std::string> &texts);
+ void draw(sf::RenderWindow &window, Cache &cache);
+ private:
+ std::vector<std::unique_ptr<Text>> texts;
+ };
+} \ No newline at end of file
diff --git a/include/User.hpp b/include/User.hpp
index c2874c2..7e99c60 100644
--- a/include/User.hpp
+++ b/include/User.hpp
@@ -11,8 +11,10 @@ namespace dchat
public:
enum class Type
{
+ OTHER,
ONLINE_REMOTE_USER,
ONLINE_LOCAL_USER,
+ ONLINE_DISCORD_USER,
OFFLINE,
SYSTEM
};
@@ -21,6 +23,8 @@ namespace dchat
virtual ~User(){}
virtual const std::string& getName() const = 0;
virtual bool isOnlineUser() const { return false; }
+
+ virtual bool isConnected(i64 timestampUtcSec) const { return true; }
const Type type;
std::string avatarUrl;
@@ -35,6 +39,7 @@ namespace dchat
virtual const std::string& getName() const override;
virtual const odhtdb::Signature::PublicKey& getPublicKey() const = 0;
+ bool isConnected(i64 timestampUtcSec) const override;
bool isOnlineUser() const override { return true; }
std::string name;
@@ -58,6 +63,16 @@ namespace dchat
const odhtdb::Signature::KeyPair keyPair;
};
+
+ class OnlineDiscordUser : public OnlineUser
+ {
+ public:
+ OnlineDiscordUser(const std::string &discordUserName, u64 discordUserId, User *bridgeOwner);
+ virtual const odhtdb::Signature::PublicKey& getPublicKey() const override;
+
+ u64 discordUserId;
+ User *bridgeOwner;
+ };
class OfflineUser : public User
{