added auto-resend of unsent messages. Fixed display of From field in outbox

This commit is contained in:
csoler 2016-01-08 20:48:47 -05:00
parent 0c591f08ae
commit 75edb46c99
2 changed files with 108 additions and 77 deletions

View File

@ -327,96 +327,118 @@ void p3MsgService::checkSizeAndSendMessage(RsMsgItem *msg)
int p3MsgService::checkOutgoingMessages() int p3MsgService::checkOutgoingMessages()
{ {
/* iterate through the outgoing queue /* iterate through the outgoing queue
* *
* if online, send * if online, send
*/ */
bool changed = false ; static const uint32_t OLD_MESSAGE_FLUSHING_DELAY = 86400*7 ; // re-send old messages every week. This mainly ensures that
std::list<RsMsgItem*> output_queue ; // messages that where never sent get sent at some point.
{ time_t now = time(NULL);
const RsPeerId& ownId = mServiceCtrl->getOwnId(); bool changed = false ;
std::list<RsMsgItem*> output_queue ;
std::list<uint32_t>::iterator it; {
std::list<uint32_t> toErase; RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
std::map<uint32_t, RsMsgItem *>::iterator mit; const RsPeerId& ownId = mServiceCtrl->getOwnId();
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); ++mit)
{
if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH)
continue;
/* find the certificate */ std::list<uint32_t>::iterator it;
RsPeerId pid = mit->second->PeerId(); std::list<uint32_t> toErase;
if( pid == ownId std::map<uint32_t, RsMsgItem *>::iterator mit;
|| ( (mit->second->msgFlags & RS_MSG_FLAGS_DISTANT) && (!(mit->second->msgFlags & RS_MSG_FLAGS_ROUTED))) for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); ++mit)
|| mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid) ) /* FEEDBACK Msg to Ourselves */ {
{ if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH)
/* send msg */ continue;
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::checkOutGoingMessages() Sending out message");
/* remove the pending flag */
output_queue.push_back(mit->second) ; /* find the certificate */
RsPeerId pid = mit->second->PeerId();
bool should_send = false ;
// When the message is a distant msg, dont remove it yet from the list. Only mark it as being sent, so that we don't send it again. if( pid == ownId)
// should_send = true ;
if(!(mit->second->msgFlags & RS_MSG_FLAGS_DISTANT))
{ if( mServiceCtrl->isPeerConnected(getServiceInfo().mServiceType, pid) ) /* FEEDBACK Msg to Ourselves */
(mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING; should_send = true ;
toErase.push_back(mit->first);
changed = true ; if (mit->second->msgFlags & RS_MSG_FLAGS_DISTANT)
} {
else if(!(mit->second->msgFlags & RS_MSG_FLAGS_ROUTED))
should_send = true ;
if(mit->second->sendTime + OLD_MESSAGE_FLUSHING_DELAY < now)
{ {
should_send = true ;
mit->second->sendTime = now;
}
}
if(should_send)
{
/* send msg */
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::checkOutGoingMessages() Sending out message");
/* remove the pending flag */
output_queue.push_back(mit->second) ;
// When the message is a distant msg, dont remove it yet from the list. Only mark it as being sent, so that we don't send it again.
//
if(!(mit->second->msgFlags & RS_MSG_FLAGS_DISTANT))
{
(mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING;
toErase.push_back(mit->first);
changed = true ;
}
else
{
#ifdef DEBUG_DISTANT_MSG #ifdef DEBUG_DISTANT_MSG
std::cerr << "Message id " << mit->first << " is distant: kept in outgoing, and marked as ROUTED" << std::endl; std::cerr << "Message id " << mit->first << " is distant: kept in outgoing, and marked as ROUTED" << std::endl;
#endif #endif
mit->second->msgFlags |= RS_MSG_FLAGS_ROUTED ; mit->second->msgFlags |= RS_MSG_FLAGS_ROUTED ;
} }
} }
else else
{ {
pqioutput(PQL_DEBUG_BASIC, msgservicezone, pqioutput(PQL_DEBUG_BASIC, msgservicezone,
"p3MsgService::checkOutGoingMessages() Delaying until available..."); "p3MsgService::checkOutGoingMessages() Delaying until available...");
} }
} }
/* clean up */ /* clean up */
for(it = toErase.begin(); it != toErase.end(); ++it) for(it = toErase.begin(); it != toErase.end(); ++it)
{ {
mit = msgOutgoing.find(*it); mit = msgOutgoing.find(*it);
if (mit != msgOutgoing.end()) if (mit != msgOutgoing.end())
{ {
msgOutgoing.erase(mit); msgOutgoing.erase(mit);
} }
std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(*it); std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(*it);
if (srcIt != mSrcIds.end()) { if (srcIt != mSrcIds.end()) {
delete (srcIt->second); delete (srcIt->second);
mSrcIds.erase(srcIt); mSrcIds.erase(srcIt);
} }
} }
if (toErase.size() > 0) if (toErase.size() > 0)
{ {
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
} }
} }
for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it) for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it)
if((*it)->msgFlags & RS_MSG_FLAGS_DISTANT) // don't split distant messages. The global router takes care of it. if((*it)->msgFlags & RS_MSG_FLAGS_DISTANT) // don't split distant messages. The global router takes care of it.
sendDistantMsgItem(*it) ; sendDistantMsgItem(*it) ;
else else
checkSizeAndSendMessage(*it) ; checkSizeAndSendMessage(*it) ;
if(changed) if(changed)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
return 0; return 0;
} }
bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList) bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)

View File

@ -1098,25 +1098,34 @@ void MessagesDialog::insertMessages()
// From .... // From ....
{ {
bool setText = true; bool setText = true;
if (msgbox == RS_MSG_INBOX || msgbox == RS_MSG_OUTBOX) { if (msgbox == RS_MSG_INBOX || msgbox == RS_MSG_OUTBOX)
{
if ((it->msgflags & RS_MSG_SYSTEM) && it->srcId == ownId) { if ((it->msgflags & RS_MSG_SYSTEM) && it->srcId == ownId) {
text = "RetroShare"; text = "RetroShare";
} else { }
else
{
if (it->msgflags & RS_MSG_DISTANT) if (it->msgflags & RS_MSG_DISTANT)
{ {
// distant message // distant message
setText = false; setText = false;
if (gotInfo || rsMail->getMessage(it->msgId, msgInfo)) { if (gotInfo || rsMail->getMessage(it->msgId, msgInfo)) {
gotInfo = true; gotInfo = true;
item->setId(RsGxsId(msgInfo.rsgxsid_srcId), COLUMN_FROM, false);
} else { if(msgbox != RS_MSG_INBOX && !msgInfo.rsgxsid_msgto.empty())
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl; item->setId(RsGxsId(*msgInfo.rsgxsid_msgto.begin()), COLUMN_FROM, false);
else
item->setId(RsGxsId(msgInfo.rsgxsid_srcId), COLUMN_FROM, false);
} }
} else { else
text = QString::fromUtf8(rsPeers->getPeerName(it->srcId).c_str()); std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl;
} }
else
text = QString::fromUtf8(rsPeers->getPeerName(it->srcId).c_str());
} }
} else { }
else
{
if (gotInfo || rsMail->getMessage(it->msgId, msgInfo)) { if (gotInfo || rsMail->getMessage(it->msgId, msgInfo)) {
gotInfo = true; gotInfo = true;