aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-30 14:54:40 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-30 14:54:44 +0200
commitc633d67f627c23510681842f03522425db91fb91 (patch)
tree14c777b52dfcd60e30b5e4470da9eb8a7f24e88d /src/main.cpp
parent551fa4d1e90d8f197bfd2ef6f06f933592dd2450 (diff)
Do not get notification if loading messages from cache, or if message is not latest
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bc46240..ef4c20f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -107,7 +107,7 @@ static void channelChangeChannelName(Channel *channel, const StringView data, co
// We dont care if there is more data to read (malicious packet), we already got all the data we need
}
-static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp)
+static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &requestHash, const odhtdb::Signature::PublicKey &creatorPublicKey, const StringView decryptedObject, u64 timestamp, bool loadedFromCache)
{
User *user = channel->getUserByPublicKey(creatorPublicKey);
if(!user)
@@ -125,8 +125,10 @@ static void channelAddStoredMessage(Channel *channel, const odhtdb::Hash &reques
case ChannelDataType::ADD_MESSAGE:
{
string msg(decryptedData.data, decryptedData.size);
- channel->addLocalMessage(msg, user, ntp::NtpTimestamp::fromCombined(timestamp).seconds, requestHash);
- if(!windowFocused && channel->getLocalUser()->isOnlineUser())
+ Message *latestMessage = channel->getLatestMessage();
+ auto timestampSeconds = ntp::NtpTimestamp::fromCombined(timestamp).seconds;
+ channel->addLocalMessage(msg, user, timestampSeconds, requestHash);
+ if(!loadedFromCache && !windowFocused && channel->getLocalUser()->isOnlineUser() && (!latestMessage || (latestMessage && timestampSeconds >= latestMessage->timestampSeconds)))
{
auto onlineLocalUser = static_cast<OnlineLocalUser*>(channel->getLocalUser());
if(creatorPublicKey != onlineLocalUser->getPublicKey())
@@ -284,7 +286,7 @@ int main(int argc, char **argv)
{
if(*request.nodeHash == *channel->getNodeInfo().getRequestHash())
{
- channelAddStoredMessage(channel, *request.requestHash, *request.creatorPublicKey, StringView((const char*)request.decryptedData.data, request.decryptedData.size), request.timestamp);
+ channelAddStoredMessage(channel, *request.requestHash, *request.creatorPublicKey, StringView((const char*)request.decryptedData.data, request.decryptedData.size), request.timestamp, request.loadedFromCache);
if(channel == Channel::getCurrent())
lastFocusedTimer.restart();
return;