2007-12-11 20:43:17 -05:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services msgservice.cc
|
|
|
|
*
|
|
|
|
* Services for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2008 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "pqi/pqibin.h"
|
|
|
|
#include "pqi/pqiarchive.h"
|
2008-01-25 02:49:28 -05:00
|
|
|
#include "pqi/p3connmgr.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
#include "services/p3msgservice.h"
|
2008-03-31 10:06:59 -04:00
|
|
|
#include "pqi/pqinotify.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
#include "util/rsdir.h"
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
const int msgservicezone = 54319;
|
|
|
|
|
|
|
|
/* Another little hack ..... unique message Ids
|
|
|
|
* will be handled in this class.....
|
|
|
|
* These are unique within this run of the server,
|
|
|
|
* and are not stored long term....
|
|
|
|
*
|
|
|
|
* Only 3 entry points:
|
|
|
|
* (1) from network....
|
|
|
|
* (2) from local send
|
|
|
|
* (3) from storage...
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
p3MsgService::p3MsgService(p3ConnectMgr *cm)
|
2008-02-07 11:18:34 -05:00
|
|
|
:p3Service(RS_SERVICE_TYPE_MSG), pqiConfig(CONFIG_TYPE_MSGS),
|
|
|
|
mConnMgr(cm), msgChanged(1), mMsgUniqueId(1)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-04 12:55:13 -05:00
|
|
|
addSerialType(new RsMsgSerialiser());
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
uint32_t p3MsgService::getNewUniqueMsgId()
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
return mMsgUniqueId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****** Mods/Notifications ****/
|
|
|
|
|
|
|
|
bool p3MsgService::MsgsChanged()
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
bool m1 = msgChanged.Changed();
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
return (m1);
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
bool p3MsgService::MsgNotifications()
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
return (msgNotifications.size() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3MsgService::getMessageNotifications(std::list<MsgInfoSummary> ¬eList)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
noteList = msgNotifications;
|
|
|
|
msgNotifications.clear();
|
|
|
|
|
|
|
|
return (noteList.size() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
int p3MsgService::tick()
|
|
|
|
{
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::tick()");
|
|
|
|
|
|
|
|
/* don't worry about increasing tick rate!
|
|
|
|
* (handled by p3service)
|
|
|
|
*/
|
|
|
|
|
|
|
|
incomingMsgs();
|
2008-02-07 11:18:34 -05:00
|
|
|
//checkOutgoingMessages();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int p3MsgService::status()
|
|
|
|
{
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::status()");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int p3MsgService::incomingMsgs()
|
|
|
|
{
|
|
|
|
RsMsgItem *mi;
|
|
|
|
int i = 0;
|
2009-02-22 12:36:39 -05:00
|
|
|
bool changed = false ;
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
while((mi = (RsMsgItem *) recvItem()) != NULL)
|
|
|
|
{
|
2009-02-22 12:36:39 -05:00
|
|
|
changed = true ;
|
2007-12-11 20:43:17 -05:00
|
|
|
++i;
|
|
|
|
mi -> recvTime = time(NULL);
|
2008-02-04 16:40:34 -05:00
|
|
|
mi -> msgFlags = RS_MSG_FLAGS_NEW;
|
|
|
|
mi -> msgId = getNewUniqueMsgId();
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
std::string mesg;
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /*** STACK LOCKED MTX ***/
|
|
|
|
|
2008-01-25 02:49:28 -05:00
|
|
|
if (mi -> PeerId() == mConnMgr->getOwnId())
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
/* from the loopback device */
|
2008-02-04 16:40:34 -05:00
|
|
|
mi -> msgFlags |= RS_MSG_FLAGS_OUTGOING;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* from a peer */
|
2008-02-04 16:40:34 -05:00
|
|
|
MsgInfoSummary mis;
|
|
|
|
initRsMIS(mi, mis);
|
2008-03-05 11:32:18 -05:00
|
|
|
|
|
|
|
// msgNotifications.push_back(mis);
|
2008-03-31 10:06:59 -04:00
|
|
|
pqiNotify *notify = getPqiNotify();
|
|
|
|
if (notify)
|
2008-03-05 11:32:18 -05:00
|
|
|
{
|
2010-06-13 06:17:50 -04:00
|
|
|
std::string message , title;
|
|
|
|
notify->AddPopupMessage(RS_POPUP_MSG, mi->PeerId(),
|
|
|
|
title.assign(mi->subject.begin(), mi->subject.end()),
|
|
|
|
message.assign(mi->message.begin(),mi->message.end()));
|
2008-07-04 10:27:10 -04:00
|
|
|
|
|
|
|
std::ostringstream out;
|
|
|
|
out << mi->msgId;
|
|
|
|
notify->AddFeedItem(RS_FEED_ITEM_MESSAGE, out.str(), "", "");
|
2008-03-05 11:32:18 -05:00
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
imsg[mi->msgId] = mi;
|
2007-12-11 20:43:17 -05:00
|
|
|
msgChanged.IndicateChanged();
|
2008-02-07 11:18:34 -05:00
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
2008-02-04 16:40:34 -05:00
|
|
|
|
|
|
|
/**** STACK UNLOCKED ***/
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2009-02-22 12:36:39 -05:00
|
|
|
if(changed)
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
void p3MsgService::statusChange(const std::list<pqipeer> &plist)
|
|
|
|
{
|
|
|
|
/* should do it properly! */
|
|
|
|
checkOutgoingMessages();
|
|
|
|
}
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
int p3MsgService::checkOutgoingMessages()
|
|
|
|
{
|
|
|
|
/* iterate through the outgoing queue
|
|
|
|
*
|
|
|
|
* if online, send
|
|
|
|
*/
|
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
bool changed = false ;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2010-05-07 18:23:38 -04:00
|
|
|
const std::string ownId = mConnMgr->getOwnId();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
std::list<uint32_t>::iterator it;
|
|
|
|
std::list<uint32_t> toErase;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
2008-01-25 02:49:28 -05:00
|
|
|
{
|
2010-05-28 10:42:54 -04:00
|
|
|
if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-07 18:23:38 -04:00
|
|
|
|
|
|
|
/* find the certificate */
|
|
|
|
std::string pid = mit->second->PeerId();
|
|
|
|
peerConnectState pstate;
|
|
|
|
bool toSend = false;
|
|
|
|
|
|
|
|
if (mConnMgr->getFriendNetStatus(pid, pstate))
|
|
|
|
{
|
|
|
|
if (pstate.state & RS_PEER_S_CONNECTED)
|
|
|
|
{
|
|
|
|
toSend = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pid == ownId) /* FEEDBACK Msg to Ourselves */
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
|
|
|
toSend = true;
|
|
|
|
}
|
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
if (toSend)
|
|
|
|
{
|
|
|
|
/* send msg */
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::checkOutGoingMessages() Sending out message");
|
|
|
|
/* remove the pending flag */
|
|
|
|
(mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING;
|
|
|
|
|
|
|
|
sendItem(mit->second);
|
|
|
|
toErase.push_back(mit->first);
|
|
|
|
|
|
|
|
changed = true ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::checkOutGoingMessages() Delaying until available...");
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2010-05-07 18:23:38 -04:00
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
for(it = toErase.begin(); it != toErase.end(); it++)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2010-05-07 18:23:38 -04:00
|
|
|
mit = msgOutgoing.find(*it);
|
|
|
|
if (mit != msgOutgoing.end())
|
|
|
|
{
|
|
|
|
msgOutgoing.erase(mit);
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
if (toErase.size() > 0)
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
2010-05-07 18:23:38 -04:00
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-07 18:23:38 -04:00
|
|
|
if(changed)
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
bool p3MsgService::saveConfiguration()
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::save_config()");
|
|
|
|
|
|
|
|
/* now we create a pqiarchive, and stream all the msgs into it
|
|
|
|
*/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
std::string msgfile = Filename();
|
2009-03-20 19:37:06 -04:00
|
|
|
std::string msgfiletmp = Filename()+".tmp";
|
2008-02-04 16:40:34 -05:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
if (RsDirUtil::createBackup (msgfile) == false) {
|
|
|
|
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File backup error", "Error while backing up file " + msgfile);
|
|
|
|
// no error ?
|
|
|
|
}
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
RsSerialiser *rss = new RsSerialiser();
|
2010-06-04 19:39:33 -04:00
|
|
|
rss->addSerialType(new RsMsgSerialiser(true)); // create serialiser for configuration
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2009-03-20 19:37:06 -04:00
|
|
|
BinFileInterface *out = new BinFileInterface(msgfiletmp.c_str(), BIN_FLAGS_WRITEABLE | BIN_FLAGS_HASH_DATA);
|
|
|
|
pqiarchive *pa_out = new pqiarchive(rss, out, BIN_FLAGS_WRITEABLE | BIN_FLAGS_NO_DELETE);
|
|
|
|
bool written = true;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
2007-12-11 20:43:17 -05:00
|
|
|
for(mit = imsg.begin(); mit != imsg.end(); mit++)
|
2009-03-20 19:37:06 -04:00
|
|
|
written = written && pa_out -> SendItem(mit->second) ;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
2009-03-20 19:37:06 -04:00
|
|
|
written = written && pa_out -> SendItem(mit->second) ;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
setHash(out->gethash());
|
2007-12-11 20:43:17 -05:00
|
|
|
delete pa_out;
|
2009-03-20 19:37:06 -04:00
|
|
|
|
|
|
|
if(!written)
|
|
|
|
return false ;
|
|
|
|
|
2009-03-29 09:58:28 -04:00
|
|
|
if(!RsDirUtil::renameFile(msgfiletmp,msgfile))
|
|
|
|
{
|
|
|
|
getPqiNotify()->AddSysMessage(0, RS_SYS_WARNING, "File rename error", "Error while renaming file " + msgfile) ;
|
2009-03-20 19:37:06 -04:00
|
|
|
return false ;
|
2009-03-29 09:58:28 -04:00
|
|
|
}
|
2009-03-20 19:37:06 -04:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
return true;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
bool p3MsgService::loadConfiguration(std::string &loadHash)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2008-02-07 11:18:34 -05:00
|
|
|
std::string msgfile = Filename();
|
2007-12-11 20:43:17 -05:00
|
|
|
|
|
|
|
RsSerialiser *rss = new RsSerialiser();
|
2010-06-04 19:39:33 -04:00
|
|
|
rss->addSerialType(new RsMsgSerialiser(true)); // create serialiser for configuration
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
BinFileInterface *in = new BinFileInterface(msgfile.c_str(), BIN_FLAGS_READABLE | BIN_FLAGS_HASH_DATA);
|
2007-12-11 20:43:17 -05:00
|
|
|
pqiarchive *pa_in = new pqiarchive(rss, in, BIN_FLAGS_READABLE);
|
|
|
|
RsItem *item;
|
|
|
|
RsMsgItem *mitem;
|
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
std::list<RsMsgItem*> items;
|
2008-02-04 16:40:34 -05:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
// load items and calculate next unique msgId
|
2007-12-11 20:43:17 -05:00
|
|
|
while((item = pa_in -> GetItem()))
|
|
|
|
{
|
|
|
|
if (NULL != (mitem = dynamic_cast<RsMsgItem *>(item)))
|
|
|
|
{
|
|
|
|
/* STORE MsgID */
|
2010-06-04 19:39:33 -04:00
|
|
|
if (mitem->msgId >= mMsgUniqueId) {
|
|
|
|
mMsgUniqueId = mitem->msgId + 1;
|
|
|
|
}
|
|
|
|
items.push_back(mitem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
}
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
// sort items into lists
|
|
|
|
std::list<RsMsgItem*>::iterator it;
|
|
|
|
for (it = items.begin(); it != items.end(); it++)
|
|
|
|
{
|
|
|
|
mitem = *it;
|
2008-07-09 05:55:09 -04:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
/* STORE MsgID */
|
|
|
|
if (mitem->msgId == 0) {
|
|
|
|
mitem->msgId = getNewUniqueMsgId();
|
|
|
|
}
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
/* switch depending on the PENDING
|
|
|
|
* flags
|
|
|
|
*/
|
|
|
|
if (mitem -> msgFlags & RS_MSG_FLAGS_PENDING)
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
//std::cerr << "MSG_PENDING";
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
//mitem->print(std::cerr);
|
|
|
|
|
|
|
|
msgOutgoing[mitem->msgId] = mitem;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-04 19:39:33 -04:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
imsg[mitem->msgId] = mitem;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
std::string hashin = in->gethash();
|
|
|
|
|
2010-06-04 19:39:33 -04:00
|
|
|
delete pa_in;
|
2008-02-08 07:39:40 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
if (hashin != loadHash)
|
|
|
|
{
|
|
|
|
/* big error message! */
|
2008-02-08 07:39:40 -05:00
|
|
|
std::cerr << "p3MsgService::loadConfiguration() FAILED! Msgs Tampered" << std::endl;
|
|
|
|
std::string msgfileold = msgfile + ".failed";
|
|
|
|
|
|
|
|
rename(msgfile.c_str(), msgfileold.c_str());
|
|
|
|
|
|
|
|
std::cerr << "Moving Old file to: " << msgfileold << std::endl;
|
|
|
|
std::cerr << "removing dodgey msgs" << std::endl;
|
|
|
|
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
for(mit = imsg.begin(); mit != imsg.end(); mit++)
|
|
|
|
{
|
|
|
|
delete (mit->second);
|
|
|
|
}
|
|
|
|
imsg.clear();
|
|
|
|
|
|
|
|
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
|
|
|
{
|
|
|
|
delete (mit->second);
|
|
|
|
}
|
|
|
|
msgOutgoing.clear();
|
|
|
|
setHash("");
|
|
|
|
return false;
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setHash(hashin);
|
|
|
|
|
|
|
|
return true;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void p3MsgService::loadWelcomeMsg()
|
|
|
|
{
|
|
|
|
/* Load Welcome Message */
|
|
|
|
RsMsgItem *msg = new RsMsgItem();
|
|
|
|
|
2010-06-13 06:17:50 -04:00
|
|
|
//msg -> PeerId(mConnMgr->getOwnId());
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2010-06-13 06:17:50 -04:00
|
|
|
msg -> sendTime = time(NULL);
|
|
|
|
msg -> recvTime = time(NULL);
|
|
|
|
msg -> msgFlags = RS_MSG_FLAGS_NEW;
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-26 08:00:57 -05:00
|
|
|
msg -> subject = L"Welcome to Retroshare";
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-26 08:00:57 -05:00
|
|
|
msg -> message = L"Send and receive messages\n";
|
|
|
|
msg -> message += L"with your friends...\n\n";
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-26 08:00:57 -05:00
|
|
|
msg -> message += L"These can hold recommendations\n";
|
|
|
|
msg -> message += L"from your local shared files\n\n";
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-26 08:00:57 -05:00
|
|
|
msg -> message += L"Add recommendations through\n";
|
|
|
|
msg -> message += L"the Local Files Dialog\n\n";
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-01-26 08:00:57 -05:00
|
|
|
msg -> message += L"Enjoy.\n";
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
msg -> msgId = getNewUniqueMsgId();
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
imsg[msg->msgId] = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/***********************************************************************/
|
|
|
|
/***********************************************************************/
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
bool p3MsgService::getMessageSummaries(std::list<MsgInfoSummary> &msgList)
|
|
|
|
{
|
|
|
|
/* do stuff */
|
|
|
|
msgList.clear();
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
for(mit = imsg.begin(); mit != imsg.end(); mit++)
|
|
|
|
{
|
|
|
|
MsgInfoSummary mis;
|
|
|
|
initRsMIS(mit->second, mis);
|
|
|
|
msgList.push_back(mis);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
|
|
|
|
{
|
|
|
|
MsgInfoSummary mis;
|
|
|
|
initRsMIS(mit->second, mis);
|
|
|
|
msgList.push_back(mis);
|
|
|
|
}
|
2010-05-13 15:20:40 -04:00
|
|
|
return true;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
bool p3MsgService::getMessage(std::string mId, MessageInfo &msg)
|
|
|
|
{
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
uint32_t msgId = atoi(mId.c_str());
|
|
|
|
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
mit = imsg.find(msgId);
|
|
|
|
if (mit == imsg.end())
|
|
|
|
{
|
|
|
|
mit = msgOutgoing.find(msgId);
|
|
|
|
if (mit == msgOutgoing.end())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mit valid */
|
|
|
|
initRsMI(mit->second, msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-28 10:42:54 -04:00
|
|
|
void p3MsgService::getMessageCount(unsigned int *pnInbox, unsigned int *pnInboxNew, unsigned int *pnOutbox, unsigned int *pnDraftbox, unsigned int *pnSentbox, unsigned int *pnTrashbox)
|
2010-05-13 15:20:40 -04:00
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
if (pnInbox) *pnInbox = 0;
|
|
|
|
if (pnInboxNew) *pnInboxNew = 0;
|
|
|
|
if (pnOutbox) *pnOutbox = 0;
|
|
|
|
if (pnDraftbox) *pnDraftbox = 0;
|
|
|
|
if (pnSentbox) *pnSentbox = 0;
|
2010-05-28 10:42:54 -04:00
|
|
|
if (pnTrashbox) *pnTrashbox = 0;
|
2010-05-13 15:20:40 -04:00
|
|
|
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
std::map<uint32_t, RsMsgItem *> *apMsg [2] = { &imsg, &msgOutgoing };
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
for (mit = apMsg [i]->begin(); mit != apMsg [i]->end(); mit++) {
|
|
|
|
MsgInfoSummary mis;
|
|
|
|
initRsMIS(mit->second, mis);
|
|
|
|
|
2010-05-28 10:42:54 -04:00
|
|
|
if (mis.msgflags & RS_MSG_TRASH) {
|
|
|
|
if (pnTrashbox) (*pnTrashbox)++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-13 15:20:40 -04:00
|
|
|
switch (mis.msgflags & RS_MSG_BOXMASK) {
|
|
|
|
case RS_MSG_INBOX:
|
|
|
|
if (pnInbox) (*pnInbox)++;
|
|
|
|
if ((mis.msgflags & RS_MSG_NEW) == RS_MSG_NEW) {
|
|
|
|
if (pnInboxNew) (*pnInboxNew)++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RS_MSG_OUTBOX:
|
|
|
|
if (pnOutbox) (*pnOutbox)++;
|
|
|
|
break;
|
|
|
|
case RS_MSG_DRAFTBOX:
|
|
|
|
if (pnDraftbox) (*pnDraftbox)++;
|
|
|
|
break;
|
|
|
|
case RS_MSG_SENTBOX:
|
|
|
|
if (pnSentbox) (*pnSentbox)++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
/* remove based on the unique mid (stored in sid) */
|
|
|
|
bool p3MsgService::removeMsgId(std::string mid)
|
|
|
|
{
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
uint32_t msgId = atoi(mid.c_str());
|
2009-02-22 12:36:39 -05:00
|
|
|
bool changed = false ;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
{
|
2009-02-22 12:36:39 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
mit = imsg.find(msgId);
|
|
|
|
if (mit != imsg.end())
|
|
|
|
{
|
|
|
|
changed = true ;
|
|
|
|
RsMsgItem *mi = mit->second;
|
|
|
|
imsg.erase(mit);
|
|
|
|
delete mi;
|
|
|
|
// msgChanged.IndicateChanged();
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
return true;
|
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
mit = msgOutgoing.find(msgId);
|
|
|
|
if (mit != msgOutgoing.end())
|
|
|
|
{
|
|
|
|
changed = true ;
|
|
|
|
RsMsgItem *mi = mit->second;
|
|
|
|
msgOutgoing.erase(mit);
|
|
|
|
delete mi;
|
|
|
|
// msgChanged.IndicateChanged();
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
|
|
|
|
2009-02-22 12:36:39 -05:00
|
|
|
if(changed)
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3MsgService::markMsgIdRead(std::string mid)
|
|
|
|
{
|
2009-02-22 12:36:39 -05:00
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
2008-02-04 12:55:13 -05:00
|
|
|
uint32_t msgId = atoi(mid.c_str());
|
2009-02-22 12:36:39 -05:00
|
|
|
bool changed = false ;
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
{
|
2009-02-22 12:36:39 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
mit = imsg.find(msgId);
|
|
|
|
if (mit != imsg.end())
|
|
|
|
{
|
|
|
|
changed = true ;
|
|
|
|
RsMsgItem *mi = mit->second;
|
|
|
|
mi -> msgFlags &= ~(RS_MSG_FLAGS_NEW);
|
|
|
|
|
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
2009-02-22 12:36:39 -05:00
|
|
|
|
|
|
|
if(changed) // no need to notify, because the msg is always
|
|
|
|
return true; // marked as read from the gui itself, so the gui
|
|
|
|
else // can mark it as read.
|
|
|
|
return false;
|
2008-02-04 12:55:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
/* Message Items */
|
|
|
|
int p3MsgService::sendMessage(RsMsgItem *item)
|
|
|
|
{
|
|
|
|
pqioutput(PQL_DEBUG_BASIC, msgservicezone,
|
|
|
|
"p3MsgService::sendMessage()");
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
item -> msgId = getNewUniqueMsgId(); /* grabs Mtx as well */
|
|
|
|
|
|
|
|
{
|
2008-02-04 16:40:34 -05:00
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
/* add pending flag */
|
|
|
|
item->msgFlags |=
|
|
|
|
(RS_MSG_FLAGS_OUTGOING |
|
|
|
|
RS_MSG_FLAGS_PENDING);
|
|
|
|
/* STORE MsgID */
|
|
|
|
msgOutgoing[item->msgId] = item;
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
|
|
|
|
|
|
checkOutgoingMessages();
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool p3MsgService::MessageSend(MessageInfo &info)
|
|
|
|
{
|
|
|
|
std::list<std::string>::const_iterator pit;
|
|
|
|
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
|
|
|
|
{
|
|
|
|
RsMsgItem *msg = initMIRsMsg(info, *pit);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
|
|
|
|
{
|
|
|
|
RsMsgItem *msg = initMIRsMsg(info, *pit);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
|
|
|
{
|
|
|
|
RsMsgItem *msg = initMIRsMsg(info, *pit);
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send to ourselves as well */
|
|
|
|
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-25 05:32:14 -04:00
|
|
|
bool p3MsgService::MessageToDraft(MessageInfo &info)
|
|
|
|
{
|
|
|
|
RsMsgItem *msg = initMIRsMsg(info, mConnMgr->getOwnId());
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
uint32_t msgId = 0;
|
|
|
|
if (info.msgId.empty() == false) {
|
2010-05-28 10:42:54 -04:00
|
|
|
msgId = atoi(info.msgId.c_str());
|
2010-05-25 05:32:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (msgId) {
|
|
|
|
msg->msgId = msgId;
|
|
|
|
} else {
|
|
|
|
msg->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
/* add pending flag */
|
|
|
|
msg->msgFlags |= (RS_MSG_OUTGOING | RS_MSG_FLAGS_DRAFT);
|
|
|
|
|
|
|
|
if (msgId) {
|
|
|
|
// remove existing message
|
2010-05-28 10:42:54 -04:00
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
mit = imsg.find(msgId);
|
|
|
|
if (mit != imsg.end()) {
|
|
|
|
RsMsgItem *mi = mit->second;
|
|
|
|
imsg.erase(mit);
|
|
|
|
delete mi;
|
2010-05-25 05:32:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* STORE MsgID */
|
|
|
|
imsg[msg->msgId] = msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
|
|
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-28 10:42:54 -04:00
|
|
|
/* move message to trash based on the unique mid */
|
|
|
|
bool p3MsgService::MessageToTrash(std::string mid, bool bTrash)
|
|
|
|
{
|
|
|
|
std::map<uint32_t, RsMsgItem *>::iterator mit;
|
|
|
|
uint32_t msgId = atoi(mid.c_str());
|
|
|
|
|
|
|
|
bool bChanged = false;
|
|
|
|
bool bFound = false;
|
|
|
|
|
|
|
|
{
|
|
|
|
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
|
|
|
|
|
|
|
|
RsMsgItem *mi = NULL;
|
|
|
|
|
|
|
|
mit = imsg.find(msgId);
|
|
|
|
if (mit != imsg.end()) {
|
|
|
|
mi = mit->second;
|
|
|
|
} else {
|
|
|
|
mit = msgOutgoing.find(msgId);
|
|
|
|
if (mit != msgOutgoing.end()) {
|
|
|
|
mi = mit->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mi) {
|
|
|
|
bFound = true;
|
|
|
|
|
|
|
|
if (bTrash) {
|
|
|
|
if ((mi->msgFlags & RS_MSG_FLAGS_TRASH) == 0) {
|
|
|
|
mi->msgFlags |= RS_MSG_FLAGS_TRASH;
|
|
|
|
bChanged = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mi->msgFlags & RS_MSG_FLAGS_TRASH) {
|
|
|
|
mi->msgFlags &= ~RS_MSG_FLAGS_TRASH;
|
|
|
|
bChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bChanged) {
|
|
|
|
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
|
|
|
|
|
|
|
checkOutgoingMessages();
|
|
|
|
|
|
|
|
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bFound;
|
|
|
|
}
|
|
|
|
|
2008-02-04 12:55:13 -05:00
|
|
|
/****************************************/
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
/**** HELPER FNS For Chat/Msg/Channel Lists ************
|
|
|
|
* These aren't required to be locked, unless
|
|
|
|
* the data used is from internal stores -> then they should be.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
|
|
|
{
|
|
|
|
|
|
|
|
mi.msgflags = 0;
|
|
|
|
|
|
|
|
/* translate flags, if we sent it... outgoing */
|
|
|
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
|
|
|
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
|
|
|
{
|
|
|
|
mi.msgflags |= RS_MSG_OUTGOING;
|
|
|
|
}
|
|
|
|
/* if it has a pending flag, then its in the outbox */
|
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_PENDING)
|
|
|
|
{
|
|
|
|
mi.msgflags |= RS_MSG_PENDING;
|
|
|
|
}
|
2010-05-25 05:32:14 -04:00
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_DRAFT)
|
|
|
|
{
|
|
|
|
mi.msgflags |= RS_MSG_DRAFT;
|
|
|
|
}
|
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_NEW)
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
|
|
|
mi.msgflags |= RS_MSG_NEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi.ts = msg->sendTime;
|
|
|
|
mi.srcId = msg->PeerId();
|
|
|
|
{
|
|
|
|
//msg->msgId;
|
|
|
|
std::ostringstream out;
|
|
|
|
out << msg->msgId;
|
|
|
|
mi.msgId = out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<std::string>::iterator pit;
|
|
|
|
|
|
|
|
for(pit = msg->msgto.ids.begin();
|
|
|
|
pit != msg->msgto.ids.end(); pit++)
|
|
|
|
{
|
|
|
|
mi.msgto.push_back(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pit = msg->msgcc.ids.begin();
|
|
|
|
pit != msg->msgcc.ids.end(); pit++)
|
|
|
|
{
|
|
|
|
mi.msgcc.push_back(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pit = msg->msgbcc.ids.begin();
|
|
|
|
pit != msg->msgbcc.ids.end(); pit++)
|
|
|
|
{
|
|
|
|
mi.msgbcc.push_back(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
mi.title = msg->subject;
|
|
|
|
mi.msg = msg->message;
|
|
|
|
|
|
|
|
mi.attach_title = msg->attachment.title;
|
|
|
|
mi.attach_comment = msg->attachment.comment;
|
|
|
|
|
|
|
|
mi.count = 0;
|
|
|
|
mi.size = 0;
|
|
|
|
|
|
|
|
std::list<RsTlvFileItem>::iterator it;
|
|
|
|
for(it = msg->attachment.items.begin();
|
|
|
|
it != msg->attachment.items.end(); it++)
|
|
|
|
{
|
|
|
|
FileInfo fi;
|
|
|
|
fi.fname = RsDirUtil::getTopDir(it->name);
|
|
|
|
fi.size = it->filesize;
|
|
|
|
fi.hash = it->hash;
|
|
|
|
fi.path = it->path;
|
|
|
|
mi.files.push_back(fi);
|
|
|
|
mi.count++;
|
|
|
|
mi.size += fi.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
|
|
|
|
{
|
|
|
|
mis.msgflags = 0;
|
|
|
|
|
|
|
|
/* translate flags, if we sent it... outgoing */
|
|
|
|
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
|
|
|
|| (msg->PeerId() == mConnMgr->getOwnId()))
|
|
|
|
{
|
|
|
|
mis.msgflags |= RS_MSG_OUTGOING;
|
|
|
|
}
|
|
|
|
/* if it has a pending flag, then its in the outbox */
|
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_PENDING)
|
|
|
|
{
|
|
|
|
mis.msgflags |= RS_MSG_PENDING;
|
|
|
|
}
|
2010-05-25 05:32:14 -04:00
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_DRAFT)
|
|
|
|
{
|
|
|
|
mis.msgflags |= RS_MSG_DRAFT;
|
|
|
|
}
|
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_NEW)
|
2008-02-04 12:55:13 -05:00
|
|
|
{
|
|
|
|
mis.msgflags |= RS_MSG_NEW;
|
|
|
|
}
|
2010-05-28 10:42:54 -04:00
|
|
|
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
|
|
|
|
{
|
|
|
|
mis.msgflags |= RS_MSG_TRASH;
|
|
|
|
}
|
2008-02-04 12:55:13 -05:00
|
|
|
|
|
|
|
mis.srcId = msg->PeerId();
|
|
|
|
{
|
|
|
|
//msg->msgId;
|
|
|
|
std::ostringstream out;
|
|
|
|
out << msg->msgId;
|
|
|
|
mis.msgId = out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
mis.title = msg->subject;
|
|
|
|
mis.count = msg->attachment.items.size();
|
|
|
|
mis.ts = msg->sendTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, std::string to)
|
|
|
|
{
|
|
|
|
RsMsgItem *msg = new RsMsgItem();
|
|
|
|
|
|
|
|
msg -> PeerId(to);
|
|
|
|
|
|
|
|
msg -> msgFlags = 0;
|
|
|
|
msg -> msgId = 0;
|
|
|
|
msg -> sendTime = time(NULL);
|
|
|
|
msg -> recvTime = 0;
|
|
|
|
|
|
|
|
msg -> subject = info.title;
|
|
|
|
msg -> message = info.msg;
|
|
|
|
|
|
|
|
std::list<std::string>::iterator pit;
|
|
|
|
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
|
|
|
|
{
|
|
|
|
msg -> msgto.ids.push_back(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
|
|
|
|
{
|
|
|
|
msg -> msgcc.ids.push_back(*pit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't fill in bcc (unless to ourselves) */
|
|
|
|
if (to == mConnMgr->getOwnId())
|
|
|
|
{
|
|
|
|
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
|
|
|
|
{
|
|
|
|
msg -> msgbcc.ids.push_back(*pit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg -> attachment.title = info.attach_title;
|
|
|
|
msg -> attachment.comment = info.attach_comment;
|
|
|
|
|
|
|
|
std::list<FileInfo>::iterator it;
|
|
|
|
for(it = info.files.begin(); it != info.files.end(); it++)
|
|
|
|
{
|
|
|
|
RsTlvFileItem mfi;
|
|
|
|
mfi.hash = it -> hash;
|
|
|
|
mfi.name = it -> fname;
|
|
|
|
mfi.filesize = it -> size;
|
|
|
|
msg -> attachment.items.push_back(mfi);
|
|
|
|
}
|
|
|
|
|
2008-07-09 05:55:09 -04:00
|
|
|
//std::cerr << "p3MsgService::initMIRsMsg()" << std::endl;
|
|
|
|
//msg->print(std::cerr);
|
2008-02-04 12:55:13 -05:00
|
|
|
return msg;
|
|
|
|
}
|
2007-12-11 20:43:17 -05:00
|
|
|
|