diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-27 01:47:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-10-27 01:47:11 +0200 |
commit | 8089e8e88fb145b4b954c310a0eda2ec647259cd (patch) | |
tree | 2858973c86754099de4fa206001588eea0f5b5e1 /src/Window.cpp | |
parent | 206a58f9996a36693b1e73460191b08db1db0327 (diff) |
Add users, nickname change, messages now have author
Diffstat (limited to 'src/Window.cpp')
-rw-r--r-- | src/Window.cpp | 39 |
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"); |