diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-17 20:46:34 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-05-17 21:24:46 +0200 |
commit | 907b9c14a9794ea1020b7fa6a524ec1f77210566 (patch) | |
tree | e22acee5c7bb0a449210379be158430adcb04420 /src | |
parent | 9e3b1440c74249fbb1f19e6c321db0d11dc2f345 (diff) |
Implement notification when you get a message using notify-send
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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 <odhtdb/hex2bin.hpp> #include <ntp/NtpClient.hpp> #include <sibs/SafeSerializer.hpp> +#include <process.hpp> #include <X11/Xlib.h> 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: |