From 8089e8e88fb145b4b954c310a0eda2ec647259cd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 27 Oct 2018 01:47:08 +0200 Subject: Add users, nickname change, messages now have author --- src/Window.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/Window.cpp') 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 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 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(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(); + 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 lock(databaseCallbackMutex); + chatWindow.addUser(*request.userToAddPublicKey); }; fprintf(stderr, "Connecting...\n"); -- cgit v1.2.3