One step toward sending/receiving messages from both RsPeerId and GXSids

Backend side:
- MessageInfo now has lists of CC,TO and BCC for both RsPeerId and RsGxsId
- p3msgservice handles each type of destination accordingly, possibly encrypting/signing the message
- added new type RsTlvGxsIdSet
- removed virtual peers from p3msgservice (not needed anymore), and removed tunneling as well
Gui side:
- added GXS ids to message RetroShareLink
- messagecomposer now handles Group, RsPeerId and RsGxsIds.

Work in  progress. Does not fully work yet.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7184 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-03-16 22:19:26 +00:00
parent 8b096e0e15
commit 2c471b68ac
17 changed files with 532 additions and 552 deletions

View file

@ -93,16 +93,26 @@ typedef GRouterKeyIdType DistantMsgPeerId ;
class MessageInfo
{
public:
public:
MessageInfo() {}
std::string msgId;
RsPeerId srcId;
RsPeerId rspeerid_srcId;
RsGxsId rsgxsid_srcId;
unsigned int msgflags;
std::list<RsPeerId> msgto;
std::list<RsPeerId> msgcc;
std::list<RsPeerId> msgbcc;
// friend destinations
//
std::list<RsPeerId> rspeerid_msgto; // RsPeerId is used here for various purposes:
std::list<RsPeerId> rspeerid_msgcc; // - real peer ids which are actual friend locations
std::list<RsPeerId> rspeerid_msgbcc; // -
// distant peers
//
std::list<RsGxsId> rsgxsid_msgto; // RsPeerId is used here for various purposes:
std::list<RsGxsId> rsgxsid_msgcc; // - real peer ids which are actual friend locations
std::list<RsGxsId> rsgxsid_msgbcc; // -
std::string title;
std::string msg;
@ -110,7 +120,7 @@ class MessageInfo
std::string attach_title;
std::string attach_comment;
std::list<FileInfo> files;
std::map<std::string,std::string> encryption_keys ; // for concerned ids only the public pgp key id to encrypt the message with.
int size; /* total of files */
int count; /* file count */

View file

@ -1380,9 +1380,13 @@ void RsMsgItem::clear()
subject.clear();
message.clear();
msgto.TlvClear();
msgcc.TlvClear();
msgbcc.TlvClear();
rspeerid_msgto.TlvClear();
rspeerid_msgcc.TlvClear();
rspeerid_msgbcc.TlvClear();
rsgxsid_msgto.TlvClear();
rsgxsid_msgcc.TlvClear();
rsgxsid_msgbcc.TlvClear();
attachment.TlvClear();
}
@ -1403,15 +1407,18 @@ std::ostream &RsMsgItem::print(std::ostream &out, uint16_t indent)
printIndent(out, int_Indent);
out << "Message To: " << std::endl;
msgto.print(out, int_Indent);
rspeerid_msgto.print(out, int_Indent);
rsgxsid_msgto.print(out, int_Indent);
printIndent(out, int_Indent);
out << "Message CC: " << std::endl;
msgcc.print(out, int_Indent);
rspeerid_msgcc.print(out, int_Indent);
rsgxsid_msgcc.print(out, int_Indent);
printIndent(out, int_Indent);
out << "Message BCC: " << std::endl;
msgbcc.print(out, int_Indent);
rspeerid_msgbcc.print(out, int_Indent);
rsgxsid_msgbcc.print(out, int_Indent);
printIndent(out, int_Indent);
std::string cnv_subject(subject.begin(), subject.end());
@ -1514,9 +1521,14 @@ uint32_t RsMsgItem::serial_size(bool m_bConfiguration)
s += GetTlvStringSize(subject);
s += GetTlvStringSize(message);
s += msgto.TlvSize();
s += msgcc.TlvSize();
s += msgbcc.TlvSize();
s += rspeerid_msgto.TlvSize();
s += rspeerid_msgcc.TlvSize();
s += rspeerid_msgbcc.TlvSize();
s += rsgxsid_msgto.TlvSize();
s += rsgxsid_msgcc.TlvSize();
s += rsgxsid_msgbcc.TlvSize();
s += attachment.TlvSize();
if (m_bConfiguration) {
@ -1558,9 +1570,13 @@ bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config)
ok &= SetTlvString(data,tlvsize,&offset,TLV_TYPE_STR_SUBJECT,subject);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message);
ok &= msgto.SetTlv(data, tlvsize, &offset);
ok &= msgcc.SetTlv(data, tlvsize, &offset);
ok &= msgbcc.SetTlv(data, tlvsize, &offset);
ok &= rspeerid_msgto.SetTlv(data, tlvsize, &offset);
ok &= rspeerid_msgcc.SetTlv(data, tlvsize, &offset);
ok &= rspeerid_msgbcc.SetTlv(data, tlvsize, &offset);
ok &= rsgxsid_msgto.SetTlv(data, tlvsize, &offset);
ok &= rsgxsid_msgcc.SetTlv(data, tlvsize, &offset);
ok &= rsgxsid_msgbcc.SetTlv(data, tlvsize, &offset);
ok &= attachment.SetTlv(data, tlvsize, &offset);
@ -1614,9 +1630,14 @@ RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize)
ok &= GetTlvString(data,rssize,&offset,TLV_TYPE_STR_SUBJECT,item->subject);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message);
ok &= item->msgto.GetTlv(data, rssize, &offset);
ok &= item->msgcc.GetTlv(data, rssize, &offset);
ok &= item->msgbcc.GetTlv(data, rssize, &offset);
ok &= item->rspeerid_msgto.GetTlv(data, rssize, &offset);
ok &= item->rspeerid_msgcc.GetTlv(data, rssize, &offset);
ok &= item->rspeerid_msgbcc.GetTlv(data, rssize, &offset);
ok &= item->rsgxsid_msgto.GetTlv(data, rssize, &offset);
ok &= item->rsgxsid_msgcc.GetTlv(data, rssize, &offset);
ok &= item->rsgxsid_msgbcc.GetTlv(data, rssize, &offset);
ok &= item->attachment.GetTlv(data, rssize, &offset);
if (m_bConfiguration) {

View file

@ -458,11 +458,6 @@ class RsMsgItem: public RsMessageItem
public:
RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
// RsMsgItem(uint16_t type)
// :RsItem(RS_PKT_VERSION_SERVICE, type,
// RS_PKT_SUBTYPE_DEFAULT)
// { setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
virtual ~RsMsgItem() {}
virtual void clear();
@ -482,9 +477,13 @@ class RsMsgItem: public RsMessageItem
std::string subject;
std::string message;
RsTlvPeerIdSet msgto;
RsTlvPeerIdSet msgcc;
RsTlvPeerIdSet msgbcc;
RsTlvPeerIdSet rspeerid_msgto;
RsTlvPeerIdSet rspeerid_msgcc;
RsTlvPeerIdSet rspeerid_msgbcc;
RsTlvGxsIdSet rsgxsid_msgto;
RsTlvGxsIdSet rsgxsid_msgcc;
RsTlvGxsIdSet rsgxsid_msgbcc;
RsTlvFileSet attachment;
};

View file

@ -212,6 +212,7 @@ const uint16_t TLV_TYPE_HASHSET = 0x1022;
const uint16_t TLV_TYPE_PGPIDSET = 0x1023;
const uint16_t TLV_TYPE_RECOGNSET = 0x1024;
const uint16_t TLV_TYPE_GXSIDSET = 0x1025;
const uint16_t TLV_TYPE_SERVICESET = 0x1030;

View file

@ -41,7 +41,7 @@
#include <serialiser/rstlvtypes.h>
#include <serialiser/rstlvbase.h>
#include <serialiser/rsbaseserial.h>
#include <retroshare/rsgxsifacetypes.h>
//! A base class for all tlv items
/*! This class is provided to allow the serialisation and deserialization of compund
@ -192,6 +192,7 @@ template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
typedef t_RsTlvIdSet<RsPgpId,TLV_TYPE_PGPIDSET> RsTlvPgpIdSet ;
typedef t_RsTlvIdSet<Sha1CheckSum,TLV_TYPE_HASHSET> RsTlvHashSet ;
typedef t_RsTlvIdSet<RsGxsId,TLV_TYPE_GXSIDSET> RsTlvGxsIdSet ;
class RsTlvServiceIdSet: public RsTlvItem
{

View file

@ -324,9 +324,8 @@ int p3MsgService::checkOutgoingMessages()
std::map<uint32_t, RsMsgItem *>::iterator mit;
for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++)
{
if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH) {
if (mit->second->msgFlags & RS_MSG_FLAGS_TRASH)
continue;
}
/* find the certificate */
RsPeerId pid = mit->second->PeerId();
@ -1034,48 +1033,35 @@ bool p3MsgService::MessageSend(MessageInfo &info)
{
std::list<RsPeerId>::const_iterator pit;
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
for(pit = info.rspeerid_msgto.begin(); pit != info.rspeerid_msgto.end(); pit++)
{
RsMsgItem *msg = initMIRsMsg(info, *pit);
if (msg)
{
sendMessage(msg);
}
}
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
for(pit = info.rspeerid_msgcc.begin(); pit != info.rspeerid_msgcc.end(); pit++)
{
RsMsgItem *msg = initMIRsMsg(info, *pit);
if (msg)
{
sendMessage(msg);
}
}
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
for(pit = info.rspeerid_msgbcc.begin(); pit != info.rspeerid_msgbcc.end(); pit++)
{
RsMsgItem *msg = initMIRsMsg(info, *pit);
if (msg)
{
sendMessage(msg);
}
}
/* send to ourselves as well */
RsMsgItem *msg = initMIRsMsg(info, mLinkMgr->getOwnId());
if (msg)
{
std::list<RsPgpId>::iterator it ;
// Update destination ids in place of distant message hash, since this Outgoing message is for display
//
// for(it = msg->msgbcc.ids.begin(); it != msg->msgbcc.ids.end(); it++)
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
// for(it = msg->msgcc.ids.begin(); it != msg->msgcc.ids.end(); it++)
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
// for(it = msg->msgto.ids.begin(); it != msg->msgto.ids.end(); it++)
// if(info.encryption_keys.find(*it) != info.encryption_keys.end()) *it = info.encryption_keys[*it] ;
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED)
msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message
@ -1118,7 +1104,7 @@ bool p3MsgService::SystemMessage(const std::string &title, const std::string &me
msg->subject = title;
msg->message = message;
msg->msgto.ids.push_back(ownId);
msg->rspeerid_msgto.ids.push_back(ownId);
processMsg(msg, true);
@ -1492,96 +1478,35 @@ 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() == mLinkMgr->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;
}
if (msg->msgFlags & RS_MSG_FLAGS_DRAFT)
{
mi.msgflags |= RS_MSG_DRAFT;
}
if (msg->msgFlags & RS_MSG_FLAGS_NEW)
{
mi.msgflags |= RS_MSG_NEW;
}
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED)
mi.msgflags |= RS_MSG_SIGNED ;
if (msg->msgFlags & RS_MSG_FLAGS_OUTGOING) mi.msgflags |= RS_MSG_OUTGOING;
if (msg->msgFlags & RS_MSG_FLAGS_PENDING) mi.msgflags |= RS_MSG_PENDING; /* if it has a pending flag, then its in the outbox */
if (msg->msgFlags & RS_MSG_FLAGS_DRAFT) mi.msgflags |= RS_MSG_DRAFT;
if (msg->msgFlags & RS_MSG_FLAGS_NEW) mi.msgflags |= RS_MSG_NEW;
if (msg->msgFlags & RS_MSG_FLAGS_SIGNATURE_CHECKS)
mi.msgflags |= RS_MSG_SIGNATURE_CHECKS ;
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED)
mi.msgflags |= RS_MSG_ENCRYPTED ;
if (msg->msgFlags & RS_MSG_FLAGS_DECRYPTED)
mi.msgflags |= RS_MSG_DECRYPTED ;
if (msg->msgFlags & RS_MSG_FLAGS_TRASH)
{
mi.msgflags |= RS_MSG_TRASH;
}
if (msg->msgFlags & RS_MSG_FLAGS_UNREAD_BY_USER)
{
mi.msgflags |= RS_MSG_UNREAD_BY_USER;
}
if (msg->msgFlags & RS_MSG_FLAGS_REPLIED)
{
mi.msgflags |= RS_MSG_REPLIED;
}
if (msg->msgFlags & RS_MSG_FLAGS_FORWARDED)
{
mi.msgflags |= RS_MSG_FORWARDED;
}
if (msg->msgFlags & RS_MSG_FLAGS_STAR)
{
mi.msgflags |= RS_MSG_STAR;
}
if (msg->msgFlags & RS_MSG_FLAGS_USER_REQUEST)
{
mi.msgflags |= RS_MSG_USER_REQUEST;
}
if (msg->msgFlags & RS_MSG_FLAGS_FRIEND_RECOMMENDATION)
{
mi.msgflags |= RS_MSG_FRIEND_RECOMMENDATION;
}
if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES)
{
mi.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES;
}
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED) mi.msgflags |= RS_MSG_SIGNED ;
if (msg->msgFlags & RS_MSG_FLAGS_SIGNATURE_CHECKS) mi.msgflags |= RS_MSG_SIGNATURE_CHECKS ;
if (msg->msgFlags & RS_MSG_FLAGS_ENCRYPTED) mi.msgflags |= RS_MSG_ENCRYPTED ;
if (msg->msgFlags & RS_MSG_FLAGS_DECRYPTED) mi.msgflags |= RS_MSG_DECRYPTED ;
if (msg->msgFlags & RS_MSG_FLAGS_TRASH) mi.msgflags |= RS_MSG_TRASH;
if (msg->msgFlags & RS_MSG_FLAGS_UNREAD_BY_USER) mi.msgflags |= RS_MSG_UNREAD_BY_USER;
if (msg->msgFlags & RS_MSG_FLAGS_REPLIED) mi.msgflags |= RS_MSG_REPLIED;
if (msg->msgFlags & RS_MSG_FLAGS_FORWARDED) mi.msgflags |= RS_MSG_FORWARDED;
if (msg->msgFlags & RS_MSG_FLAGS_STAR) mi.msgflags |= RS_MSG_STAR;
if (msg->msgFlags & RS_MSG_FLAGS_USER_REQUEST) mi.msgflags |= RS_MSG_USER_REQUEST;
if (msg->msgFlags & RS_MSG_FLAGS_FRIEND_RECOMMENDATION) mi.msgflags |= RS_MSG_FRIEND_RECOMMENDATION;
if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES) mi.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES;
mi.ts = msg->sendTime;
mi.srcId = msg->PeerId();
{
//msg->msgId;
rs_sprintf(mi.msgId, "%lu", msg->msgId);
}
mi.rspeerid_srcId = msg->PeerId();
std::list<RsPeerId>::iterator pit;
mi.rspeerid_msgto = msg->rspeerid_msgto.ids ;
mi.rspeerid_msgcc = msg->rspeerid_msgcc.ids ;
mi.rspeerid_msgbcc = msg->rspeerid_msgbcc.ids ;
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.rsgxsid_msgto = msg->rsgxsid_msgto.ids ;
mi.rsgxsid_msgcc = msg->rsgxsid_msgcc.ids ;
mi.rsgxsid_msgbcc = msg->rsgxsid_msgbcc.ids ;
mi.title = msg->subject;
mi.msg = msg->message;
@ -1592,9 +1517,7 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
mi.count = 0;
mi.size = 0;
std::list<RsTlvFileItem>::iterator it;
for(it = msg->attachment.items.begin();
it != msg->attachment.items.end(); it++)
for(std::list<RsTlvFileItem>::iterator it = msg->attachment.items.begin(); it != msg->attachment.items.end(); it++)
{
FileInfo fi;
fi.fname = RsDirUtil::getTopDir(it->name);
@ -1605,7 +1528,6 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
mi.count++;
mi.size += fi.size;
}
}
void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
@ -1687,50 +1609,33 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
mis.ts = msg->sendTime;
}
RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const RsPeerId &to)
void p3MsgService::initMIRsMsg(RsMsgItem *msg,const MessageInfo& info)
{
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<RsPeerId>::iterator pit;
for(pit = info.msgto.begin(); pit != info.msgto.end(); pit++)
{
msg -> msgto.ids.push_back(*pit);
}
msg->rspeerid_msgto.ids = info.rspeerid_msgto ;
msg->rspeerid_msgcc.ids = info.rspeerid_msgcc ;
for(pit = info.msgcc.begin(); pit != info.msgcc.end(); pit++)
{
msg -> msgcc.ids.push_back(*pit);
}
msg->rsgxsid_msgto.ids = info.rsgxsid_msgto ;
msg->rsgxsid_msgcc.ids = info.rsgxsid_msgcc ;
/* We don't fill in bcc (unless to ourselves) */
if (to == mLinkMgr->getOwnId())
if (msg->PeerId() == mLinkMgr->getOwnId())
{
for(pit = info.msgbcc.begin(); pit != info.msgbcc.end(); pit++)
{
msg -> msgbcc.ids.push_back(*pit);
}
msg->rsgxsid_msgbcc.ids = info.rsgxsid_msgbcc ;
msg->rspeerid_msgbcc.ids = info.rspeerid_msgbcc ;
}
msg -> attachment.title = info.attach_title;
msg -> attachment.comment = info.attach_comment;
RsPeerDetails details ;
if(!rsPeers->getPeerDetails(to,details))
msg->msgFlags |= RS_MSG_FLAGS_DISTANT;
std::list<FileInfo>::iterator it;
for(it = info.files.begin(); it != info.files.end(); it++)
for(std::list<FileInfo>::const_iterator it = info.files.begin(); it != info.files.end(); it++)
{
RsTlvFileItem mfi;
mfi.hash = it -> hash;
@ -1738,32 +1643,45 @@ RsMsgItem *p3MsgService::initMIRsMsg(MessageInfo &info, const RsPeerId &to)
mfi.filesize = it -> size;
msg -> attachment.items.push_back(mfi);
}
/* translate flags from outside */
if (info.msgflags & RS_MSG_USER_REQUEST)
msg->msgFlags |= RS_MSG_FLAGS_USER_REQUEST;
if (info.msgflags & RS_MSG_FRIEND_RECOMMENDATION)
msg->msgFlags |= RS_MSG_FLAGS_FRIEND_RECOMMENDATION;
}
RsMsgItem *p3MsgService::initMIRsMsg(const MessageInfo& info, const RsGxsId& to)
{
RsMsgItem *msg = new RsMsgItem();
initMIRsMsg(msg,info) ;
msg->PeerId(RsPeerId(to));
msg->msgFlags |= RS_MSG_FLAGS_DISTANT;
if (info.msgflags & RS_MSG_SIGNED)
msg->msgFlags |= RS_MSG_FLAGS_SIGNED;
/* load embedded images from own messages */
msg->msgFlags |= RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES;
// See if we need to encrypt this message. If so, we replace the msg text
// by the whole message serialized and binary encrypted, so as to obfuscate
// all its content.
//
createDistantMessage(to,info.rsgxsid_srcId,msg) ;
if(!info.encryption_keys.empty())
std::cerr << "(WW) Cannot encrypt message. Code needs to be improved." << std::endl;
// if(info.encryption_keys.find(to) != info.encryption_keys.end())
// encryptMessage(info.encryption_keys[to],msg) ;
return msg ;
}
RsMsgItem *p3MsgService::initMIRsMsg(const MessageInfo &info, const RsPeerId& to)
{
RsMsgItem *msg = new RsMsgItem();
initMIRsMsg(msg,info) ;
msg->PeerId(to) ;
/* load embedded images from own messages */
msg->msgFlags |= RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES;
//std::cerr << "p3MsgService::initMIRsMsg()" << std::endl;
//msg->print(std::cerr);
return msg;
}
@ -1892,9 +1810,12 @@ bool p3MsgService::createDistantMessage(const RsGxsId& destination_gxs_id,const
item->message = armoured_data ;
item->subject = "" ;
item->msgcc.ids.clear() ;
item->msgbcc.ids.clear() ;
item->msgto.ids.clear() ;
item->rspeerid_msgcc.ids.clear() ;
item->rspeerid_msgbcc.ids.clear() ;
item->rspeerid_msgto.ids.clear() ;
item->rsgxsid_msgcc.ids.clear() ;
item->rsgxsid_msgbcc.ids.clear() ;
item->rsgxsid_msgto.ids.clear() ;
item->msgFlags |= RS_MSG_FLAGS_ENCRYPTED ;
item->attachment.TlvClear() ;

View file

@ -163,19 +163,22 @@ int checkOutgoingMessages();
p3GRouter *mGRouter ;
#endif
uint32_t getNewUniqueMsgId();
int sendMessage(RsMsgItem *item);
void checkSizeAndSendMessage(RsMsgItem *msg);
uint32_t getNewUniqueMsgId();
int sendMessage(RsMsgItem *item);
void checkSizeAndSendMessage(RsMsgItem *msg);
int incomingMsgs();
void processMsg(RsMsgItem *mi, bool incoming);
bool checkAndRebuildPartialMessage(RsMsgItem*) ;
int incomingMsgs();
void processMsg(RsMsgItem *mi, bool incoming);
bool checkAndRebuildPartialMessage(RsMsgItem*) ;
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
RsMsgItem *initMIRsMsg(MessageInfo &info, const RsPeerId &to);
void initRsMI(RsMsgItem *msg, MessageInfo &mi);
void initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis);
void initStandardTagTypes();
RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsPeerId& to);
RsMsgItem *initMIRsMsg(const MessageInfo &info, const RsGxsId& to);
void initMIRsMsg(RsMsgItem *item,const MessageInfo &info) ;
void initStandardTagTypes();
p3LinkMgr *mLinkMgr;

View file

@ -1114,19 +1114,28 @@ void MessagesDialog::insertMessages()
text.clear();
std::list<RsPeerId>::const_iterator pit;
for (pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++)
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgto.begin(); pit != msgInfo.rspeerid_msgto.end(); pit++)
{
if (text.isEmpty() == false) {
if (!text.isEmpty())
text += ", ";
}
std::string peerName = rsPeers->getPeerName(*pit);
if (peerName.empty()) {
if (peerName.empty())
text += PeerDefs::rsid("", *pit);
} else {
else
text += QString::fromUtf8(peerName.c_str());
}
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgto.begin(); pit != msgInfo.rsgxsid_msgto.end(); pit++)
{
if (!text.isEmpty())
text += ", ";
// We should improve this by showing the real names of each GXS id.
std::string peerName = "GXS_id("+(*pit).toStdString() + ")" ;
if (peerName.empty())
text += PeerDefs::rsid("", *pit);
else
text += QString::fromUtf8(peerName.c_str());
}
} else {
std::cerr << "MessagesDialog::insertMsgTxtAndFiles() Couldn't find Msg" << std::endl;

View file

@ -565,7 +565,23 @@ bool RetroShareLink::createMessage(const RsPeerId& peerId, const QString& subjec
return valid();
}
bool RetroShareLink::createMessage(const RsGxsId& peerId, const QString& subject)
{
clear();
_hash = QString::fromStdString(peerId.toStdString());
//PeerDefs::rsidFromId(peerId, &_name);
_name = QString::fromStdString("GXS_id("+peerId.toStdString()+")") ;
// do something better here!!
_subject = subject;
_type = TYPE_MESSAGE;
check();
return valid();
}
void RetroShareLink::clear()
{
_valid = false;
@ -1507,7 +1523,7 @@ static void processList(const QStringList &list, const QString &textSingular, co
{
if (detail.accept_connection || RsPeerId(detail.id) == rsPeers->getOwnId() || RsPgpId(detail.gpg_id) == rsPeers->getGPGOwnId()) {
MessageComposer *msg = MessageComposer::newMsg();
msg->addRecipient(MessageComposer::TO, detail.id, false);
msg->addRecipient(MessageComposer::TO, detail.id);
if (link.subject().isEmpty() == false) {
msg->setTitleText(link.subject());
}

View file

@ -35,6 +35,7 @@
#include <stdint.h>
#include <retroshare/rstypes.h>
#include <retroshare/rsgxsifacetypes.h>
#include <QString>
#include <QVector>
@ -79,7 +80,8 @@ class RetroShareLink
bool createForum(const std::string& id, const std::string& msgId);
bool createChannel(const std::string& id, const std::string& msgId);
bool createSearch(const QString& keywords);
bool createMessage(const RsPeerId& peerId, const QString& subject);
bool createMessage(const RsPeerId &peerId, const QString& subject);
bool createMessage(const RsGxsId &peerId, const QString& subject);
bool createCertificate(const RsPeerId &ssl_id) ;
bool createPrivateChatInvite(time_t time_stamp,const QString& gpg_id,const QString& encrypted_chat_info) ;
bool createPublicMsgInvite(time_t time_stamp,const QString& pgp_id,const QString& hash) ;

View file

@ -1312,7 +1312,7 @@ void FriendList::msgfriend()
std::string id = getRsId(peer);
MessageComposer::msgFriend(RsPeerId(id), (peer->type() == TYPE_GROUP));
MessageComposer::msgFriend(RsPeerId(id)) ;
}
void FriendList::recommendfriend()

View file

@ -197,7 +197,7 @@ void ChatMsgItem::sendMsg()
return;
}
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId);
nMsgDialog->show();
nMsgDialog->activateWindow();
@ -245,7 +245,7 @@ void ChatMsgItem::sendMessage()
mi.title = tr("Quick Message").toUtf8().constData();
mi.msg = quickmsgText->toHtml().toUtf8().constData();
mi.msgto.push_back(mPeerId);
mi.rspeerid_msgto.push_back(mPeerId);
rsMsgs->MessageSend(mi);

View file

@ -81,16 +81,16 @@ void MsgItem::updateItemStatic()
return;
/* get peer Id */
mPeerId = mi.srcId;
mPeerId = mi.rspeerid_srcId;
avatar->setId(mPeerId);
QString title;
QString srcName;
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.srcId == rsPeers->getOwnId()) {
if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId()) {
srcName = "RetroShare";
} else {
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.srcId).c_str());
srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
}
timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));
@ -138,7 +138,7 @@ void MsgItem::updateItemStatic()
for(it = mi.files.begin(); it != mi.files.end(); it++)
{
/* add file */
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size, SFI_STATE_REMOTE, mi.srcId);
SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size, SFI_STATE_REMOTE, mi.rspeerid_srcId);
mFileItems.push_back(fi);
QLayout *layout = expandFrame->layout();

View file

@ -275,7 +275,7 @@ void PeerItem::sendMsg()
return;
}
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId, false);
nMsgDialog->addRecipient(MessageComposer::TO, mPeerId);
nMsgDialog->show();
nMsgDialog->activateWindow();
@ -314,7 +314,7 @@ void PeerItem::sendMessage()
mi.title = tr("Quick Message").toUtf8().constData();
mi.msg = quickmsgText->toHtml().toUtf8().constData();
mi.msgto.push_back(mPeerId);
mi.rspeerid_msgto.push_back(mPeerId);
rsMsgs->MessageSend(mi);

View file

@ -74,9 +74,6 @@
#define COLOR_CONNECT Qt::blue
#define TYPE_GROUP 0
#define TYPE_SSL 1
#define COLUMN_RECIPIENT_TYPE 0
#define COLUMN_RECIPIENT_ICON 1
#define COLUMN_RECIPIENT_NAME 2
@ -84,7 +81,7 @@
#define COLUMN_RECIPIENT_DATA COLUMN_RECIPIENT_ICON // the column with a QTableWidgetItem
#define ROLE_RECIPIENT_ID Qt::UserRole
#define ROLE_RECIPIENT_GROUP Qt::UserRole + 1
#define ROLE_RECIPIENT_TYPE Qt::UserRole + 1
#define COLUMN_FILE_CHECKED 0
#define COLUMN_FILE_NAME 0
@ -373,18 +370,15 @@ void MessageComposer::processSettings(bool bLoad)
if (pMsgDialog == NULL)
return;
DistantMsgPeerId pid ;
rsMsgs->getDistantMessagePeerId(id,pid) ;
pMsgDialog->addRecipient(TO, RsPeerId(pid), false);
pMsgDialog->addRecipient(TO, id);
pMsgDialog->show();
/* window will destroy itself! */
}
/*static*/ void MessageComposer::msgFriend(const RsPeerId &id, bool group)
/*static*/ void MessageComposer::msgFriend(const RsPeerId &id)
{
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
// std::cerr << "MessageComposer::msgfriend()" << std::endl;
/* create a message */
@ -393,25 +387,10 @@ void MessageComposer::processSettings(bool bLoad)
return;
}
if (group) {
pMsgDialog->addRecipient(TO, id, true);
} else {
RsPeerDetails detail;
if (rsPeers->getPeerDetails(id, detail) && detail.accept_connection)
{
// if (detail.isOnlyGPGdetail) {
// //put all sslChilds in message list
// std::list<RsPeerId> sslIds;
// rsPeers->getAssociatedSSLIds(id, sslIds);
//
// std::list<RsPeerId>::const_iterator it;
// for (it = sslIds.begin(); it != sslIds.end(); it++) {
// pMsgDialog->addRecipient(TO, *it, false);
// }
// } else {
pMsgDialog->addRecipient(TO, detail.id, false);
// }
}
pMsgDialog->addRecipient(TO, id);
}
pMsgDialog->show();
@ -463,7 +442,7 @@ void MessageComposer::recommendFriend(const std::list <RsPeerId> &sslIds, const
composer->msgFlags |= RS_MSG_FRIEND_RECOMMENDATION;
if (!to.isNull()) {
composer->addRecipient(TO, to, false);
composer->addRecipient(TO, to);
}
RsPgpId ownPgpId = rsPeers->getGPGOwnId();
RetroShareLink link;
@ -482,7 +461,7 @@ void MessageComposer::recommendFriend(const std::list <RsPeerId> &sslIds, const
if (*peerIt == to) {
continue;
}
composer->addRecipient(CC, *peerIt, false);
composer->addRecipient(CC, *peerIt);
}
if (autoSend) {
@ -686,18 +665,19 @@ void MessageComposer::peerStatusChanged(const QString& peer_id, int status)
for (row = 0; row < rowCount; row++) {
enumType type;
destinationType dtype ;
std::string id;
bool group;
if (getRecipientFromRow(row, type, id, group) && !id.empty() ) {
if (group == false && QString::fromStdString(id) == peer_id) {
if (getRecipientFromRow(row, type,dtype, id) && !id.empty() ) {
if (dtype == PEER_TYPE_SSL && QString::fromStdString(id) == peer_id)
{
QTableWidgetItem *item = ui.recipientWidget->item(row, COLUMN_RECIPIENT_ICON);
if (item) {
if (item)
item->setIcon(QIcon(StatusDefs::imageUser(status)));
}
}
}
}
}
void MessageComposer::setFileList(const std::list<DirDetails>& dir_info)
@ -895,38 +875,34 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/)
std::list<std::string> groupIds;
std::list<std::string>::iterator groupIt;
std::list<RsPeerId>::iterator it;
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgto, groupIds);
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
// msgComposer->addRecipient(MessageComposer::TO, *groupIt, true) ;
// }
for (it = msgInfo.msgto.begin(); it != msgInfo.msgto.end(); it++ ) {
msgComposer->addRecipient(MessageComposer::TO, *it, false) ;
}
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgcc, groupIds);
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
// msgComposer->addRecipient(MessageComposer::CC, *groupIt, true) ;
// }
for (it = msgInfo.msgcc.begin(); it != msgInfo.msgcc.end(); it++ ) {
msgComposer->addRecipient(MessageComposer::CC, *it, false) ;
}
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgbcc, groupIds);
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
// msgComposer->addRecipient(MessageComposer::BCC, *groupIt, true) ;
// }
for (it = msgInfo.msgbcc.begin(); it != msgInfo.msgbcc.end(); it++ ) {
msgComposer->addRecipient(MessageComposer::BCC, *it, false) ;
}
// calculateGroupsOfSslIds(groupInfoList, msgInfo.msgbcc, groupIds);
// for (groupIt = groupIds.begin(); groupIt != groupIds.end(); groupIt++ ) {
// msgComposer->addRecipient(MessageComposer::BCC, *groupIt, true) ;
// }
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgto.begin(); it != msgInfo.rspeerid_msgto.end(); it++ ) msgComposer->addRecipient(MessageComposer::TO, *it) ;
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgcc.begin(); it != msgInfo.rspeerid_msgcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::CC, *it) ;
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgbcc.begin(); it != msgInfo.rspeerid_msgbcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::BCC, *it) ;
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgto.begin(); it != msgInfo.rsgxsid_msgto.end(); it++ ) msgComposer->addRecipient(MessageComposer::TO, *it) ;
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgcc.begin(); it != msgInfo.rsgxsid_msgcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::CC, *it) ;
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgbcc.begin(); it != msgInfo.rsgxsid_msgbcc.end(); it++ ) msgComposer->addRecipient(MessageComposer::BCC, *it) ;
MsgTagInfo tagInfo;
rsMsgs->getMessageTag(msgId, tagInfo);
msgComposer->m_tagIds = tagInfo.tagIds;
msgComposer->showTagLabels();
msgComposer->ui.msgText->document()->setModified(false);
}
@ -938,29 +914,44 @@ MessageComposer *MessageComposer::newMsg(const std::string &msgId /* = ""*/)
QString MessageComposer::buildReplyHeader(const MessageInfo &msgInfo)
{
RetroShareLink link;
link.createMessage(msgInfo.srcId, "");
link.createMessage(msgInfo.rspeerid_srcId, "");
QString from = link.toHtml();
QString to;
std::list<RsPeerId>::const_iterator it;
for (it = msgInfo.msgto.begin(); it != msgInfo.msgto.end(); it++) {
if (link.createMessage(*it, "")) {
if (!to.isEmpty()) {
for ( std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgto.begin(); it != msgInfo.rspeerid_msgto.end(); it++)
if (link.createMessage(*it, ""))
{
if (!to.isEmpty())
to += ", ";
}
to += link.toHtml();
}
for ( std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgto.begin(); it != msgInfo.rsgxsid_msgto.end(); it++)
if (link.createMessage(*it, ""))
{
if (!to.isEmpty())
to += ", ";
to += link.toHtml();
}
QString cc;
for (it = msgInfo.msgcc.begin(); it != msgInfo.msgcc.end(); it++) {
for (std::list<RsPeerId>::const_iterator it = msgInfo.rspeerid_msgcc.begin(); it != msgInfo.rspeerid_msgcc.end(); it++)
if (link.createMessage(*it, "")) {
if (!cc.isEmpty()) {
cc += ", ";
}
cc += link.toHtml();
}
for (std::list<RsGxsId>::const_iterator it = msgInfo.rsgxsid_msgcc.begin(); it != msgInfo.rsgxsid_msgcc.end(); it++)
if (link.createMessage(*it, "")) {
if (!cc.isEmpty()) {
cc += ", ";
}
cc += link.toHtml();
}
QString header = QString("<span>-----%1-----").arg(tr("Original Message"));
header += QString("<br><font size='3'><strong>%1: </strong>%2</font><br>").arg(tr("From"), from);
@ -1033,22 +1024,28 @@ MessageComposer *MessageComposer::replyMsg(const std::string &msgId, bool all)
msgComposer->setTitleText(QString::fromUtf8(msgInfo.title.c_str()), REPLY);
msgComposer->setQuotedMsg(QString::fromUtf8(msgInfo.msg.c_str()), buildReplyHeader(msgInfo));
msgComposer->addRecipient(MessageComposer::TO, msgInfo.srcId, false);
if(!msgInfo.rspeerid_srcId.isNull()) msgComposer->addRecipient(MessageComposer::TO, msgInfo.rspeerid_srcId);
if(!msgInfo.rsgxsid_srcId.isNull()) msgComposer->addRecipient(MessageComposer::TO, msgInfo.rsgxsid_srcId);
if (all) {
if (all)
{
RsPeerId ownId = rsPeers->getOwnId();
for (std::list<RsPeerId>::iterator tli = msgInfo.msgto.begin(); tli != msgInfo.msgto.end(); tli++) {
if (ownId != *tli) {
msgComposer->addRecipient(MessageComposer::TO, *tli, false) ;
}
}
for (std::list<RsPeerId>::iterator tli = msgInfo.rspeerid_msgto.begin(); tli != msgInfo.rspeerid_msgto.end(); tli++)
if (ownId != *tli)
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
for (std::list<RsPeerId>::iterator tli = msgInfo.msgcc.begin(); tli != msgInfo.msgcc.end(); tli++) {
if (ownId != *tli) {
msgComposer->addRecipient(MessageComposer::TO, *tli, false) ;
}
}
for (std::list<RsPeerId>::iterator tli = msgInfo.rspeerid_msgcc.begin(); tli != msgInfo.rspeerid_msgcc.end(); tli++)
if (ownId != *tli)
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
for (std::list<RsGxsId>::iterator tli = msgInfo.rsgxsid_msgto.begin(); tli != msgInfo.rsgxsid_msgto.end(); tli++)
//if (ownId != *tli)
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
for (std::list<RsGxsId>::iterator tli = msgInfo.rsgxsid_msgcc.begin(); tli != msgInfo.rsgxsid_msgcc.end(); tli++)
//if (ownId != *tli)
msgComposer->addRecipient(MessageComposer::TO, *tli) ;
}
// needed to send system flags with reply
@ -1142,9 +1139,10 @@ void MessageComposer::sendMessage()
}
}
template<class T> void addUnique(std::list<T>& lst,const T& t) { if(std::find(lst.begin(),lst.end(),t) == lst.end()) lst.push_back(t) ; }
bool MessageComposer::sendMessage_internal(bool bDraftbox)
{
#ifdef SUSPENDED
/* construct a message */
MessageInfo mi;
@ -1168,7 +1166,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
for (int i = 0; i < filesCount; i++) {
QTreeWidgetItem *item = ui.msgFileList->topLevelItem(i);
if (item->checkState(COLUMN_FILE_CHECKED)) {
std::string hash = item->text(COLUMN_FILE_HASH).toStdString();
RsFileHash hash ( item->text(COLUMN_FILE_HASH).toStdString() );
for(std::list<FileInfo>::iterator it = _recList.begin(); it != _recList.end(); it++) {
if (it->hash == hash) {
mi.files.push_back(*it);
@ -1188,21 +1186,26 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
int rowCount = ui.recipientWidget->rowCount();
int row;
for (row = 0; row < rowCount; row++) {
for (row = 0; row < rowCount; row++)
{
enumType type;
destinationType dtype ;
std::string id;
bool group;
if (getRecipientFromRow(row, type, id, group) && !id.empty())
if (!getRecipientFromRow(row, type,dtype, id) || id.empty())
continue ;
switch(dtype)
{
if (group) {
case PEER_TYPE_GROUP: {
RsGroupInfo groupInfo;
if (rsPeers->getGroupInfo(id, groupInfo) == false) {
// group not found
continue;
}
std::list<std::string>::const_iterator groupIt;
std::list<RsPgpId>::const_iterator groupIt;
for (groupIt = groupInfo.peerIds.begin(); groupIt != groupInfo.peerIds.end(); groupIt++) {
std::list<RsPeerId> sslIds;
rsPeers->getAssociatedSSLIds(*groupIt, sslIds);
@ -1214,53 +1217,52 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
continue;
}
switch (type) {
case TO:
if (std::find(mi.msgto.begin(), mi.msgto.end(), *sslIt) == mi.msgto.end()) {
mi.msgto.push_back(*sslIt);
}
switch (type)
{
case TO: addUnique(mi.rspeerid_msgto,*sslIt);
break;
case CC:
if (std::find(mi.msgcc.begin(), mi.msgcc.end(), *sslIt) == mi.msgcc.end()) {
mi.msgcc.push_back(*sslIt);
}
case CC: addUnique(mi.rspeerid_msgcc,*sslIt);
break;
case BCC:
if (std::find(mi.msgbcc.begin(), mi.msgbcc.end(), *sslIt) == mi.msgbcc.end()) {
mi.msgbcc.push_back(*sslIt);
}
case BCC:addUnique(mi.rspeerid_msgbcc,*sslIt);
break;
}
}
}
} else {
if (_distant_peers.find(id)==_distant_peers.end() && std::find(peers.begin(), peers.end(), id) == peers.end()) {
// no friend
continue;
}
break ;
case PEER_TYPE_SSL:
{
RsPeerId pid(id) ;
switch (type) {
case TO:
if (std::find(mi.msgto.begin(), mi.msgto.end(), id) == mi.msgto.end()) {
mi.msgto.push_back(id);
}
break;
case CC:
if (std::find(mi.msgcc.begin(), mi.msgcc.end(), id) == mi.msgcc.end()) {
mi.msgcc.push_back(id);
}
break;
case BCC:
if (std::find(mi.msgbcc.begin(), mi.msgbcc.end(), id) == mi.msgbcc.end()) {
mi.msgbcc.push_back(id);
}
break;
switch (type)
{
case TO: addUnique(mi.rspeerid_msgto,pid);
case CC: addUnique(mi.rspeerid_msgcc,pid);
case BCC:addUnique(mi.rspeerid_msgbcc,pid);
}
}
break ;
case PEER_TYPE_GXS:
{
RsGxsId gid(id) ;
switch (type)
{
case TO: addUnique(mi.rsgxsid_msgto,gid) ;
case CC: addUnique(mi.rsgxsid_msgcc,gid) ;
case BCC:addUnique(mi.rsgxsid_msgbcc,gid) ;
}
}
break ;
default:
std::cerr << __PRETTY_FUNCTION__ << ": Unhandled desitnation type " << dtype << std::endl;
break ;
}
}
if (bDraftbox) {
if (bDraftbox)
{
mi.msgId = m_sDraftMsgId;
rsMsgs->MessageToDraft(mi, m_msgParentId);
@ -1278,14 +1280,16 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
rsMsgs->MessageForwarded(m_sDraftMsgId, true);
break;
}
} else {
}
else
{
/* check for the recipient */
if (mi.msgto.empty()) {
if (mi.rspeerid_msgto.empty() && mi.rspeerid_msgcc.empty() && mi.rspeerid_msgbcc.empty()
&& mi.rsgxsid_msgto.empty() && mi.rsgxsid_msgcc.empty() && mi.rsgxsid_msgbcc.empty())
{
QMessageBox::warning(this, tr("RetroShare"), tr("Please insert at least one recipient."), QMessageBox::Ok);
return false; // Don't send with no recipient
}
mi.encryption_keys = _distant_peers ;
if(ui.signMessage_CB->isChecked())
mi.msgflags |= RS_MSG_SIGNED ;
@ -1327,7 +1331,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
}
}
ui.msgText->document()->setModified(false);
#endif
return true;
}
@ -1353,10 +1357,10 @@ void MessageComposer::addEmptyRecipient()
}
}
setRecipientToRow(lastRow, TO,"", false);
setRecipientToRow(lastRow, TO,PEER_TYPE_SSL,"");
}
bool MessageComposer::getRecipientFromRow(int row, enumType &type, std::string &id, bool &group)
bool MessageComposer::getRecipientFromRow(int row, enumType &type, destinationType& dest_type,std::string &id)
{
if (row >= ui.recipientWidget->rowCount()) {
return false;
@ -1369,12 +1373,12 @@ bool MessageComposer::getRecipientFromRow(int row, enumType &type, std::string &
type = (enumType) cb->itemData(cb->currentIndex(), Qt::UserRole).toInt();
id = ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_ID).toString().toStdString();
group = ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_GROUP).toBool();
dest_type = (destinationType)ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->data(ROLE_RECIPIENT_TYPE).toInt();
return true;
}
void MessageComposer::setRecipientToRow(int row, enumType type, const std::string& id, bool group)
void MessageComposer::setRecipientToRow(int row, enumType type, destinationType dest_type, const std::string &id)
{
if (row + 1 > ui.recipientWidget->rowCount()) {
ui.recipientWidget->setRowCount(row + 1);
@ -1411,8 +1415,9 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
QString name;
if (!id.empty())
{
if (group)
switch(dest_type)
{
case PEER_TYPE_GROUP: {
icon = QIcon(IMAGE_GROUP16);
RsGroupInfo groupInfo;
@ -1422,25 +1427,32 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
name = tr("Unknown");
}
}
else
{
RsPeerDetails details;
break ;
case PEER_TYPE_GXS: {
if(_distant_peers.find(DistantMsgPeerId(id)) != _distant_peers.end())
{
RsIdentityDetails detail;
RsGxsId gid(id) ;
if(!rsIdentity->getIdDetails(_distant_peers[DistantMsgPeerId(id)], detail))
if(!rsIdentity->getIdDetails(gid, detail))
{
std::cerr << "Can't get peer details from " << _distant_peers[DistantMsgPeerId(id)] << std::endl;
std::cerr << "Can't get peer details from " << gid << std::endl;
return ;
}
name = tr("Distant peer (name: %2, PGP key: %1)").arg(QString::fromStdString(_distant_peers[DistantMsgPeerId(id)].toStdString())).arg(QString::fromStdString(detail.mNickname)) ;
name = tr("Distant peer (name: %2, PGP key: %1)").arg(QString::fromStdString(gid.toStdString())).arg(QString::fromStdString(detail.mNickname)) ;
icon = QIcon(StatusDefs::imageUser(RS_STATUS_ONLINE));
}
else if(rsPeers->getPeerDetails(RsPeerId(id), details) && (!details.isOnlyGPGdetail))
break ;
case PEER_TYPE_SSL: {
RsPeerDetails details ;
if(!rsPeers->getPeerDetails(RsPeerId(id), details))
{
std::cerr << "Can't get peer details from " << id << std::endl;
return ;
}
name = PeerDefs::nameWithLocation(details);
StatusInfo peerStatusInfo;
@ -1449,28 +1461,25 @@ void MessageComposer::setRecipientToRow(int row, enumType type, const std::strin
icon = QIcon(StatusDefs::imageUser(peerStatusInfo.status));
}
else
{
icon = QIcon(StatusDefs::imageUser(RS_STATUS_OFFLINE));
name = tr("Unknown friend");
}
default:
std::cerr << __PRETTY_FUNCTION__ << ": Unhandled type " << dest_type << std::endl;
return ;
}
}
comboBox->setCurrentIndex(comboBox->findData(type, Qt::UserRole));
lineEdit->setText(name);
if (id.empty()) {
if (id.empty())
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
} else {
else
lineEdit->setStyleSheet(QString(STYLE_NORMAL).arg(lineEdit->objectName()));
}
QTableWidgetItem *item = new QTableWidgetItem(icon, "", 0);
item->setFlags(Qt::NoItemFlags);
ui.recipientWidget->setItem(row, COLUMN_RECIPIENT_ICON, item);
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_ID, QString::fromStdString(id));
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_GROUP, group);
ui.recipientWidget->item(row, COLUMN_RECIPIENT_DATA)->setData(ROLE_RECIPIENT_TYPE, dest_type);
addEmptyRecipient();
}
@ -1537,13 +1546,14 @@ void MessageComposer::editingRecipientFinished()
enumType type;
std::string id; // dummy
bool group; // dummy
getRecipientFromRow(row, type, id, group);
destinationType dtype ;
getRecipientFromRow(row, type, dtype, id);
QString text = lineEdit->text();
if (text.isEmpty()) {
setRecipientToRow(row, type, "", false);
setRecipientToRow(row, type,PEER_TYPE_SSL, "");
return;
}
@ -1561,7 +1571,7 @@ void MessageComposer::editingRecipientFinished()
QString name = PeerDefs::nameWithLocation(details);
if (text.compare(name, Qt::CaseSensitive) == 0) {
// found it
setRecipientToRow(row, type, details.id.toStdString(), false);
setRecipientToRow(row, type, PEER_TYPE_SSL, details.id.toStdString());
return;
}
}
@ -1575,19 +1585,42 @@ void MessageComposer::editingRecipientFinished()
QString groupName = GroupDefs::name(*groupIt);
if (text.compare(groupName, Qt::CaseSensitive) == 0) {
// found it
setRecipientToRow(row, type, groupIt->id, true);
setRecipientToRow(row, type, PEER_TYPE_GROUP, groupIt->id);
return;
}
}
setRecipientToRow(row, type, "", false);
setRecipientToRow(row, type, PEER_TYPE_SSL, "");
lineEdit->setStyleSheet(QString(STYLE_FAIL).arg(lineEdit->objectName()));
lineEdit->setText(text);
}
void MessageComposer::addRecipient(enumType type, const DistantMsgPeerId& pid,const RsGxsId& gxs_id)
void MessageComposer::addRecipient(enumType type, const RsPeerId& pid)
{
_distant_peers[pid] = gxs_id ;
int rowCount = ui.recipientWidget->rowCount();
int row;
for (row = 0; row < rowCount; row++)
{
enumType rowType;
std::string rowId;
destinationType dtype ;
if (getRecipientFromRow(row, rowType, dtype, rowId))
{
if (rowId.empty()) // use row
break;
if (RsPeerId(rowId) == pid && rowType == type) // existing row
break;
}
else // use row
break;
}
setRecipientToRow(row, type, PEER_TYPE_SSL,pid.toStdString());
}
void MessageComposer::addRecipient(enumType type, const RsGxsId& gxs_id)
{
_distant_peers.insert(gxs_id) ;
int rowCount = ui.recipientWidget->rowCount();
int row;
@ -1595,69 +1628,41 @@ void MessageComposer::addRecipient(enumType type, const DistantMsgPeerId& pid,co
{
enumType rowType;
std::string rowId;
bool rowGroup;
destinationType dtype ;
if (getRecipientFromRow(row, rowType, rowId, rowGroup) == true)
if (getRecipientFromRow(row, rowType, dtype, rowId))
{
if (rowId.empty()) // use row
break;
if (rowId == pid.toStdString() && rowType == type) // existing row
if (RsGxsId(rowId) == gxs_id && rowType == type) // existing row
break;
}
else // use row
break;
}
setRecipientToRow(row, type, pid.toStdString(), false);
setRecipientToRow(row, type, PEER_TYPE_GXS,gxs_id.toStdString());
}
void MessageComposer::addRecipient(enumType type, const RsPeerId &id, bool group)
void MessageComposer::addRecipient(enumType type, const std::string& id)
{
std::list<RsPeerId> sslIds;
if (group) {
sslIds.push_back(id);
} else {
// check for gpg id or ssl id
RsPeerDetails detail;
if (!rsPeers->getPeerDetails(id, detail)) {
return;
}
// if (detail.isOnlyGPGdetail)
// {
// if( (!rsPeers->getAssociatedSSLIds(id, sslIds)) || sslIds.empty())
// {
// std::string hash ;
// if(rsMsgs->getDistantMessageHash(id,hash))
// addRecipient(type, hash, id);
// else
// {
// QMessageBox::warning(this,tr("PGP key unknown"),tr("You dont have the PGP key of the message sender. So you cannot respond!"),QMessageBox::Ok) ;
// return;
// }
// }
// }
// else {
sslIds.push_back(id);
// }
}
std::list<RsPeerId>::const_iterator sslIt;
for (sslIt = sslIds.begin(); sslIt != sslIds.end(); sslIt++) {
// search existing or empty row
int rowCount = ui.recipientWidget->rowCount();
int row;
for (row = 0; row < rowCount; row++) {
enumType rowType;
std::string rowId;
destinationType dtype ;
bool rowGroup;
if (getRecipientFromRow(row, rowType, rowId, rowGroup) == true) {
if (getRecipientFromRow(row, rowType, dtype,rowId))
{
if (rowId.empty()) {
// use row
break;
}
if (rowId == (*sslIt).toStdString() && rowType == type && group == rowGroup) {
if (rowId == id && rowType == type && dtype == PEER_TYPE_GROUP) {
// existing row
break;
}
@ -1667,8 +1672,7 @@ void MessageComposer::addRecipient(enumType type, const RsPeerId &id, bool group
}
}
setRecipientToRow(row, type, (*sslIt).toStdString(), group);
}
setRecipientToRow(row, type, PEER_TYPE_GROUP, id);
}
void MessageComposer::setupFileActions()
@ -2315,18 +2319,13 @@ void MessageComposer::addContact(enumType type)
std::list<RsPeerId> ids ;
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(ids, true);
for (std::list<RsPeerId>::const_iterator idIt = ids.begin(); idIt != ids.end(); idIt++) {
addRecipient(type, *idIt, false);
addRecipient(type, *idIt);
}
std::list<RsGxsId> id2 ;
ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(id2, true);
for (std::list<RsGxsId>::const_iterator idIt = id2.begin(); idIt != id2.end(); idIt++)
{
DistantMsgPeerId pid ;
if(rsMsgs->getDistantMessagePeerId(*idIt,pid))
addRecipient(type, pid, *idIt);
}
addRecipient(type, *idIt);
}
void MessageComposer::toggleShowNonFriend(bool bValue)
@ -2358,14 +2357,16 @@ void MessageComposer::addRecommend()
std::list<RsPeerId> sslIds;
ui.friendSelectionWidget->selectedIds<RsPeerId,FriendSelectionWidget::IDTYPE_SSL>(sslIds, false);
if (sslIds.empty()) {
return;
}
std::list<RsGxsId> gxsIds ;
ui.friendSelectionWidget->selectedIds<RsGxsId,FriendSelectionWidget::IDTYPE_GXS>(gxsIds, true);
std::list <RsPeerId>::iterator it;
for (it = sslIds.begin(); it != sslIds.end(); it++) {
addRecipient(CC, *it, false);
}
if (sslIds.empty() && gxsIds.empty())
return;
for(std::list <RsPeerId>::iterator it = sslIds.begin(); it != sslIds.end(); it++)
addRecipient(CC, *it);
for (std::list<RsGxsId>::const_iterator it = gxsIds.begin(); it != gxsIds.end(); it++)
addRecipient(TO, *it);
QString text = buildRecommendHtml(sslIds);
ui.msgText->textCursor().insertHtml(text);

View file

@ -42,6 +42,7 @@ class MessageComposer : public QMainWindow
public:
enum enumType { TO, CC, BCC };
enum enumMessageType { NORMAL, REPLY, FORWARD };
enum destinationType { PEER_TYPE_SSL, PEER_TYPE_GROUP, PEER_TYPE_GXS };
public:
/** Default Constructor */
@ -49,9 +50,9 @@ public:
MessageComposer(QWidget *parent = 0, Qt::WindowFlags flags = 0);
~MessageComposer();
static void msgFriend(const RsPeerId &id, bool group);
//static void msgDistantPeer(const std::string& hash,const std::string& pgp_id) ;
static void msgFriend(const RsPeerId &id);
static void msgGxsIdentity(const RsGxsId& gxs_id) ;
static void msgGroup(const std::string& group_id) ;
static QString recommendMessage();
static void recommendFriend(const std::list <RsPeerId> &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false);
@ -68,8 +69,9 @@ public:
void setTitleText(const QString &title, enumMessageType type = NORMAL);
void setQuotedMsg(const QString &msg, const QString &header);
void setMsgText(const QString &msg, bool asHtml = false);
void addRecipient(enumType type, const RsPeerId &id, bool group);
void addRecipient(enumType type, const DistantMsgPeerId &pid, const RsGxsId &gxs_id) ;
void addRecipient(enumType type, const RsPeerId &id);
void addRecipient(enumType type, const RsGxsId &gxs_id) ;
void addRecipient(enumType type, const std::string& group_id) ;
public slots:
/* actions to take.... */
@ -174,8 +176,8 @@ private:
void calculateTitle();
void addEmptyRecipient();
bool getRecipientFromRow(int row, enumType &type, std::string &id, bool &group);
void setRecipientToRow(int row, enumType type, const std::string &id, bool group);
bool getRecipientFromRow(int row, enumType &type, destinationType& dest_type, std::string &id);
void setRecipientToRow(int row, enumType type, destinationType dest_type,const std::string &id);
void clearTagLabels();
void showTagLabels();
@ -221,7 +223,7 @@ private:
Ui::MessageComposer ui;
std::list<FileInfo> _recList ;
std::map<DistantMsgPeerId,RsGxsId> _distant_peers ; // pairs (hash,gxs_id)
std::set<RsGxsId> _distant_peers ; // we keep a list of them, in order to know which peer is a GXS id.
};
#endif

View file

@ -304,7 +304,7 @@ void MessageWidget::getcurrentrecommended()
}
std::list<RsPeerId> srcIds;
srcIds.push_back(msgInfo.srcId);
srcIds.push_back(msgInfo.rspeerid_srcId);
QModelIndexList list = ui.msgList->selectionModel()->selectedIndexes();
@ -353,7 +353,7 @@ void MessageWidget::getallrecommended()
for(it = recList.begin(); it != recList.end(); it++) {
std::cerr << "MessageWidget::getallrecommended() Calling File Request" << std::endl;
std::list<RsPeerId> srcIds;
srcIds.push_back(msgInfo.srcId);
srcIds.push_back(msgInfo.rspeerid_srcId);
rsFiles->FileRequest(it->fname, it->hash, it->size, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds);
}
}
@ -497,28 +497,23 @@ void MessageWidget::fill(const std::string &msgId)
ui.msgList->insertTopLevelItems(0, items);
/* iterate through the sources */
std::list<RsPeerId>::const_iterator pit;
RetroShareLink link;
QString text;
for(pit = msgInfo.msgto.begin(); pit != msgInfo.msgto.end(); pit++) {
if (link.createMessage(*pit, "")) {
text += link.toHtml() + " ";
}
}
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgto.begin(); pit != msgInfo.rspeerid_msgto.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
for(std::list<RsGxsId >::const_iterator pit = msgInfo.rsgxsid_msgto.begin(); pit != msgInfo.rsgxsid_msgto.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
ui.toText->setText(text);
if (msgInfo.msgcc.size() > 0) {
if (!msgInfo.rspeerid_msgcc.empty() || !msgInfo.rsgxsid_msgcc.empty())
{
ui.cclabel->setVisible(true);
ui.ccText->setVisible(true);
text.clear();
for(pit = msgInfo.msgcc.begin(); pit != msgInfo.msgcc.end(); pit++) {
if (link.createMessage(*pit, "")) {
text += link.toHtml() + " ";
}
}
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgcc.begin(); pit != msgInfo.rspeerid_msgcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgcc.begin(); pit != msgInfo.rsgxsid_msgcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
ui.ccText->setText(text);
} else {
ui.cclabel->setVisible(false);
@ -526,16 +521,15 @@ void MessageWidget::fill(const std::string &msgId)
ui.ccText->clear();
}
if (msgInfo.msgbcc.size() > 0) {
if (!msgInfo.rspeerid_msgbcc.empty() || !msgInfo.rsgxsid_msgbcc.empty())
{
ui.bcclabel->setVisible(true);
ui.bccText->setVisible(true);
text.clear();
for(pit = msgInfo.msgbcc.begin(); pit != msgInfo.msgbcc.end(); pit++) {
if (link.createMessage(*pit, "")) {
text += link.toHtml() + " ";
}
}
for(std::list<RsPeerId>::const_iterator pit = msgInfo.rspeerid_msgbcc.begin(); pit != msgInfo.rspeerid_msgbcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
for(std::list<RsGxsId>::const_iterator pit = msgInfo.rsgxsid_msgbcc.begin(); pit != msgInfo.rsgxsid_msgbcc.end(); pit++) if (link.createMessage(*pit, "")) text += link.toHtml() + " ";
ui.bccText->setText(text);
} else {
ui.bcclabel->setVisible(false);
@ -552,11 +546,11 @@ void MessageWidget::fill(const std::string &msgId)
// outgoing message are from me
srcId = ownId;
} else {
srcId = msgInfo.srcId;
srcId = msgInfo.rspeerid_srcId;
}
link.createMessage(srcId, "");
if ((msgInfo.msgflags & RS_MSG_SYSTEM) && msgInfo.srcId == ownId) {
if ((msgInfo.msgflags & RS_MSG_SYSTEM) && msgInfo.rspeerid_srcId == ownId) {
ui.fromText->setText("RetroShare");
} else {
ui.fromText->setText(link.toHtml());