aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp25
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: