aboutsummaryrefslogtreecommitdiff
path: root/src/Window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Window.cpp')
-rw-r--r--src/Window.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Window.cpp b/src/Window.cpp
index 38c187e..72a3d9d 100644
--- a/src/Window.cpp
+++ b/src/Window.cpp
@@ -2,6 +2,7 @@
#include "../include/Cache.hpp"
#include "../include/ChannelDataType.hpp"
#include "../include/WindowNotification.hpp"
+#include <sibs/SafeDeserializer.hpp>
namespace dchat
{
@@ -11,6 +12,7 @@ namespace dchat
Gtk::Overlay *overlay = Gtk::manage(new Gtk::Overlay());
WindowNotification *windowNotification = Gtk::manage(new WindowNotification());
overlay->add_overlay(*windowNotification);
+ overlay->set_overlay_pass_through(*windowNotification);
overlay->add(stack);
add(*overlay);
@@ -54,6 +56,7 @@ namespace dchat
{
std::lock_guard<std::mutex> lock(databaseCallbackMutex);
chatWindow.addChannel(*request.nodeHash);
+ chatWindow.addUser(*request.creatorPublicKey);
};
callbackFuncs.addNodeCallbackFunc = [this](const odhtdb::DatabaseAddNodeRequest &request)
@@ -63,22 +66,44 @@ namespace dchat
return;
ChannelDataType channelDataType = (ChannelDataType)static_cast<const char*>(request.decryptedData.data)[0];
- switch(channelDataType)
+ try
{
- case ChannelDataType::ADD_MESSAGE:
+ switch(channelDataType)
{
- Glib::ustring msg((const char*)request.decryptedData.data + 1, request.decryptedData.size - 1);
- chatWindow.addLocalMessage(*request.nodeHash, std::move(msg));
- break;
+ case ChannelDataType::ADD_MESSAGE:
+ {
+ Glib::ustring msg((const char*)request.decryptedData.data + 1, request.decryptedData.size - 1);
+ uint32_t timestampSeconds = ntp::NtpTimestamp::fromCombined(request.timestamp).seconds;
+ chatWindow.addLocalMessage(*request.nodeHash, *request.creatorPublicKey, timestampSeconds, std::move(msg));
+ break;
+ }
+ case ChannelDataType::NICKNAME_CHANGE:
+ {
+ sibs::SafeDeserializer deserializer((const u8*)request.decryptedData.data + 1, request.decryptedData.size - 1);
+ u8 nameLength = deserializer.extract<u8>();
+ if(nameLength > 0)
+ {
+ std::string nickname;
+ nickname.resize(nameLength);
+ deserializer.extract((u8*)&nickname[0], nameLength);
+ chatWindow.setUserNickname(*request.creatorPublicKey, nickname);
+ }
+ break;
+ }
+ default:
+ break;
}
- default:
- break;
+ }
+ catch(std::exception &e)
+ {
+ fprintf(stderr, "Failed to process add node request, reason: %s\n", e.what());
}
};
callbackFuncs.addUserCallbackFunc = [this](const odhtdb::DatabaseAddUserRequest &request)
{
std::lock_guard<std::mutex> lock(databaseCallbackMutex);
+ chatWindow.addUser(*request.userToAddPublicKey);
};
fprintf(stderr, "Connecting...\n");