RS mail post event when receiving a mail

+ delete some deadcode
This commit is contained in:
Gioacchino Mazzurco 2019-09-17 17:27:36 +02:00
parent 04d3325fbd
commit f2c90ba3c6
No known key found for this signature in database
GPG key ID: A1FBCA3872E87051
2 changed files with 27 additions and 25 deletions

View file

@ -3,7 +3,8 @@
* * * *
* libretroshare: retroshare core library * * libretroshare: retroshare core library *
* * * *
* Copyright 2004-2008 Robert Fernie <retroshare@lunamutt.com> * * Copyright (C) 2004-2008 Robert Fernie <retroshare@lunamutt.com> *
* Copyright (C) 2016-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* * * *
* This program is free software: you can redistribute it and/or modify * * This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as * * it under the terms of the GNU Lesser General Public License as *
@ -158,7 +159,7 @@ void p3MsgService::cleanListOfReceivedMessageHashes()
{ {
RS_STACK_MUTEX(recentlyReceivedMutex); RS_STACK_MUTEX(recentlyReceivedMutex);
rstime_t now = time(NULL); rstime_t now = time(nullptr);
for( auto it = mRecentlyReceivedMessageHashes.begin(); for( auto it = mRecentlyReceivedMessageHashes.begin();
it != mRecentlyReceivedMessageHashes.end(); ) it != mRecentlyReceivedMessageHashes.end(); )
@ -173,21 +174,13 @@ void p3MsgService::cleanListOfReceivedMessageHashes()
else ++it; else ++it;
} }
int p3MsgService::status()
{
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::status()");
return 1;
}
void p3MsgService::processIncomingMsg(RsMsgItem *mi) void p3MsgService::processIncomingMsg(RsMsgItem *mi)
{ {
mi -> recvTime = time(NULL); mi -> recvTime = static_cast<uint32_t>(time(nullptr));
mi -> msgId = getNewUniqueMsgId(); mi -> msgId = getNewUniqueMsgId();
{ {
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/ RS_STACK_MUTEX(mMsgMtx);
/* from a peer */ /* from a peer */
@ -226,6 +219,13 @@ void p3MsgService::processIncomingMsg(RsMsgItem *mi)
} }
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
if(rsEvents)
{
std::shared_ptr<RsMailStatusEvent> pEvent(new RsMailStatusEvent());
pEvent->mChangedMsgIds.insert(std::to_string(mi->msgId));
rsEvents->postEvent(pEvent);
}
} }
bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci) bool p3MsgService::checkAndRebuildPartialMessage(RsMsgItem *ci)
@ -289,7 +289,8 @@ void p3MsgService::handleIncomingItem(RsMsgItem *mi)
{ {
bool changed = false ; bool changed = false ;
if(checkAndRebuildPartialMessage(mi)) // only returns true when a msg is complete. // only returns true when a msg is complete.
if(checkAndRebuildPartialMessage(mi))
{ {
processIncomingMsg(mi); processIncomingMsg(mi);
changed = true ; changed = true ;
@ -2123,8 +2124,8 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
const RsGxsId& recipientId, const RsGxsId& recipientId,
const uint8_t* data, uint32_t dataSize ) const uint8_t* data, uint32_t dataSize )
{ {
std::cout << __PRETTY_FUNCTION__ << " " << authorId << ", " << recipientId Dbg2() << __PRETTY_FUNCTION__ << " " << authorId << ", " << recipientId
<< ",, " << dataSize << std::endl; << ",, " << dataSize << std::endl;
Sha1CheckSum hash = RsDirUtil::sha1sum(data, dataSize); Sha1CheckSum hash = RsDirUtil::sha1sum(data, dataSize);
@ -2133,29 +2134,31 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
if( mRecentlyReceivedMessageHashes.find(hash) != if( mRecentlyReceivedMessageHashes.find(hash) !=
mRecentlyReceivedMessageHashes.end() ) mRecentlyReceivedMessageHashes.end() )
{ {
std::cerr << __PRETTY_FUNCTION__ << " (II) receiving " RsInfo() << __PRETTY_FUNCTION__ << " (II) receiving "
<< "message of hash " << hash << " more than once. " << "message of hash " << hash << " more than once. "
<< "Probably it has arrived before by other means." << "Probably it has arrived before by other means."
<< std::endl; << std::endl;
return true; return true;
} }
mRecentlyReceivedMessageHashes[hash] = time(NULL); mRecentlyReceivedMessageHashes[hash] =
static_cast<uint32_t>(time(nullptr));
} }
IndicateConfigChanged(); IndicateConfigChanged();
RsItem *item = _serialiser->deserialise(const_cast<uint8_t*>(data), &dataSize); RsItem *item = _serialiser->deserialise(
const_cast<uint8_t*>(data), &dataSize );
RsMsgItem *msg_item = dynamic_cast<RsMsgItem*>(item); RsMsgItem *msg_item = dynamic_cast<RsMsgItem*>(item);
if(msg_item) if(msg_item)
{ {
std::cerr << __PRETTY_FUNCTION__ << " Encrypted item correctly " Dbg3() << __PRETTY_FUNCTION__ << " Encrypted item correctly "
<< "deserialised. Passing on to incoming list." << "deserialised. Passing on to incoming list."
<< std::endl; << std::endl;
msg_item->msgFlags |= RS_MSG_FLAGS_DISTANT; msg_item->msgFlags |= RS_MSG_FLAGS_DISTANT;
/* we expect complete msgs - remove partial flag just in case /* we expect complete msgs - remove partial flag just in case
* someone has funny ideas */ * someone has funny ideas */
msg_item->msgFlags &= ~RS_MSG_FLAGS_PARTIAL; msg_item->msgFlags &= ~RS_MSG_FLAGS_PARTIAL;
// hack to pass on GXS id. // hack to pass on GXS id.
@ -2164,8 +2167,8 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
} }
else else
{ {
std::cerr << __PRETTY_FUNCTION__ << " Item could not be " RsWarn() << __PRETTY_FUNCTION__ << " Item could not be "
<< "deserialised. Format error??" << std::endl; << "deserialised. Format error?" << std::endl;
return false; return false;
} }

View file

@ -108,7 +108,6 @@ public:
//std::list<RsMsgItem *> &getMsgOutList(); //std::list<RsMsgItem *> &getMsgOutList();
int tick(); int tick();
int status();
/*** Overloaded from p3Config ****/ /*** Overloaded from p3Config ****/
virtual RsSerialiser *setupSerialiser(); virtual RsSerialiser *setupSerialiser();