From 907b9c14a9794ea1020b7fa6a524ec1f77210566 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 May 2018 20:46:34 +0200 Subject: Implement notification when you get a message using notify-send --- src/main.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 541efae..b5ec81e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include using namespace std; @@ -26,7 +27,7 @@ using namespace dchat; static bool focused = true; -void channelChangeUserNickname(Channel *channel, const StringView data, const odhtdb::Signature::PublicKey &userPublicKey) +static void channelChangeUserNickname(Channel *channel, const StringView data, const odhtdb::Signature::PublicKey &userPublicKey) { auto user = channel->getUserByPublicKey(userPublicKey); if(!user) @@ -45,7 +46,17 @@ void channelChangeUserNickname(Channel *channel, const StringView data, const od // We dont care if there is more data to read (malicious packet), we already got all the data we need } -void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp) +static void stringReplaceChar(string &str, const string &from, const string &to) +{ + size_t pos = 0; + while((pos = str.find(from, pos)) != string::npos) + { + str.replace(pos, from.size(), to); + pos += to.size(); + } +} + +static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp) { User *user = channel->getUserByPublicKey(creatorPublicKey); if(!user) @@ -64,6 +75,16 @@ void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, { string msg(decryptedData.data, decryptedData.size); channel->addLocalMessage(msg, user, ntp::NtpTimestamp::fromCombined(timestamp).seconds, requestHash); + if(!focused) + { + stringReplaceChar(msg, "'", ""); + stringReplaceChar(msg, "\"", ""); + stringReplaceChar(msg, "\\", ""); + string cmd = "notify-send dchat '"; + cmd += msg; + cmd += "'"; + TinyProcessLib::Process notifySend(cmd, ""); + } break; } case ChannelDataType::DELETE_MESSAGE: -- cgit v1.2.3