Provide usable API to send RS mails

Return trackid to sendmail caller
Post RsEvents when sent mail change status
Deprecate old MessageSend
This commit is contained in:
Gioacchino Mazzurco 2019-09-16 18:40:07 +02:00
parent 584918388c
commit 04d3325fbd
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
6 changed files with 368 additions and 90 deletions

View File

@ -66,6 +66,9 @@ enum class RsEventType : uint32_t
/// Emitted when a peer state changes, @see RsPeers /// Emitted when a peer state changes, @see RsPeers
PEER_STATE_CHANGED = 6, PEER_STATE_CHANGED = 6,
/// @see RsMailStatusEvent
MAIL_STATUS_CHANGE = 7,
MAX /// Used to detect invalid event type passed MAX /// Used to detect invalid event type passed
}; };

View File

@ -19,8 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef RS_MSG_GUI_INTERFACE_H #pragma once
#define RS_MSG_GUI_INTERFACE_H
#include <list> #include <list>
#include <iostream> #include <iostream>
@ -28,8 +27,11 @@
#include <set> #include <set>
#include <assert.h> #include <assert.h>
#include "rstypes.h" #include "retroshare/rstypes.h"
#include "rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include "retroshare/rsevents.h"
#include "util/rsdeprecate.h"
#include "util/rsmemory.h"
/********************** For Messages and Channels *****************/ /********************** For Messages and Channels *****************/
@ -93,9 +95,31 @@ const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000010 ) ; // requi
typedef uint64_t ChatLobbyId ; typedef uint64_t ChatLobbyId ;
typedef uint64_t ChatLobbyMsgId ; typedef uint64_t ChatLobbyMsgId ;
typedef std::string ChatLobbyNickName ; typedef std::string ChatLobbyNickName ;
typedef std::string RsMailMessageId; // should be uint32_t !! typedef std::string RsMailMessageId; // TODO: rebase on t_RsGenericIdType
typedef uint64_t MessageId ;
/**
* Used to return a tracker id so the API user can keep track of sent mail
* status
*/
struct RsMailTrackId : RsSerializable
{
RsMailTrackId(RsMailMessageId mailId, RsGxsId recipientId):
mMailId(mailId), mRecipientId(recipientId) {}
RsMailMessageId mMailId;
RsGxsId mRecipientId;
/// @see RsSerializable
void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx ) override;
bool operator<(const RsMailTrackId& other) const;
bool operator==(const RsMailTrackId& other) const;
RsMailTrackId() = default;
~RsMailTrackId() override = default;
};
namespace Rs namespace Rs
{ {
@ -168,7 +192,6 @@ class MessageInfo_v2
struct MessageInfo : RsSerializable struct MessageInfo : RsSerializable
{ {
MessageInfo(): msgflags(0), size(0), count(0), ts(0) {} MessageInfo(): msgflags(0), size(0), count(0), ts(0) {}
virtual ~MessageInfo() = default;
std::string msgId; std::string msgId;
@ -202,7 +225,10 @@ struct MessageInfo : RsSerializable
int ts; int ts;
// RsSerializable interface // RsSerializable interface
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { void serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx ) override
{
RS_SERIAL_PROCESS(msgId); RS_SERIAL_PROCESS(msgId);
RS_SERIAL_PROCESS(rspeerid_srcId); RS_SERIAL_PROCESS(rspeerid_srcId);
@ -230,12 +256,13 @@ struct MessageInfo : RsSerializable
RS_SERIAL_PROCESS(ts); RS_SERIAL_PROCESS(ts);
} }
~MessageInfo() override;
}; };
struct MsgInfoSummary : RsSerializable struct MsgInfoSummary : RsSerializable
{ {
MsgInfoSummary() : msgflags(0), count(0), ts(0) {} MsgInfoSummary() : msgflags(0), count(0), ts(0) {}
virtual ~MsgInfoSummary() = default;
RsMailMessageId msgId; RsMailMessageId msgId;
RsPeerId srcId; RsPeerId srcId;
@ -260,6 +287,8 @@ struct MsgInfoSummary : RsSerializable
RS_SERIAL_PROCESS(count); RS_SERIAL_PROCESS(count);
RS_SERIAL_PROCESS(ts); RS_SERIAL_PROCESS(ts);
} }
~MsgInfoSummary() override;
}; };
struct MsgTagInfo : RsSerializable struct MsgTagInfo : RsSerializable
@ -291,6 +320,22 @@ struct MsgTagType : RsSerializable
} //namespace Rs } //namespace Rs
} //namespace Msgs } //namespace Msgs
struct RsMailStatusEvent : RsEvent
{
RsMailStatusEvent() : RsEvent(RsEventType::MAIL_STATUS_CHANGE) {}
std::set<RsMailMessageId> mChangedMsgIds;
/// @see RsEvent
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mChangedMsgIds);
}
~RsMailStatusEvent() override;
};
#define RS_CHAT_PUBLIC 0x0001 #define RS_CHAT_PUBLIC 0x0001
#define RS_CHAT_PRIVATE 0x0002 #define RS_CHAT_PRIVATE 0x0002
@ -426,11 +471,10 @@ public:
} }
}; };
class VisibleChatLobbyRecord : RsSerializable struct VisibleChatLobbyRecord : RsSerializable
{ {
public: VisibleChatLobbyRecord():
VisibleChatLobbyRecord(): lobby_id(0), total_number_of_peers(0), last_report_time(0){} lobby_id(0), total_number_of_peers(0), last_report_time(0) {}
virtual ~VisibleChatLobbyRecord() = default;
ChatLobbyId lobby_id ; // unique id of the lobby ChatLobbyId lobby_id ; // unique id of the lobby
std::string lobby_name ; // name to use for this lobby std::string lobby_name ; // name to use for this lobby
@ -441,9 +485,11 @@ public:
rstime_t last_report_time ; // last time the lobby was reported. rstime_t last_report_time ; // last time the lobby was reported.
ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE ChatLobbyFlags lobby_flags ; // see RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC / RS_CHAT_LOBBY_PRIVACY_LEVEL_PRIVATE
// RsSerializable interface /// @see RsSerializable
public: void serial_process(
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) { RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext &ctx) override
{
RS_SERIAL_PROCESS(lobby_id); RS_SERIAL_PROCESS(lobby_id);
RS_SERIAL_PROCESS(lobby_name); RS_SERIAL_PROCESS(lobby_name);
RS_SERIAL_PROCESS(lobby_topic); RS_SERIAL_PROCESS(lobby_topic);
@ -453,6 +499,8 @@ public:
RS_SERIAL_PROCESS(last_report_time); RS_SERIAL_PROCESS(last_report_time);
RS_SERIAL_PROCESS(lobby_flags); RS_SERIAL_PROCESS(lobby_flags);
} }
~VisibleChatLobbyRecord() override;
}; };
class ChatLobbyInfo : RsSerializable class ChatLobbyInfo : RsSerializable
@ -499,13 +547,6 @@ class RsMsgs
{ {
public: public:
RsMsgs() {}
virtual ~RsMsgs() = default;
/****************************************/
/* Message Items */
/****************************************/
/** /**
* @brief getMessageSummaries * @brief getMessageSummaries
* @jsonapi{development} * @jsonapi{development}
@ -523,6 +564,33 @@ public:
*/ */
virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0; virtual bool getMessage(const std::string &msgId, Rs::Msgs::MessageInfo &msg) = 0;
/**
* @brief sendMail
* @jsonapi{development}
* @param[in] from GXS id of the author
* @param[in] subject Mail subject
* @param[in] mailBody Mail body
* @param[in] to list of To: recipients
* @param[in] cc list of CC: recipients
* @param[in] bcc list of BCC: recipients
* @param[in] attachments list of suggested files
* @param[out] trackingIds storage for tracking ids for each sent mail
* @param[out] errorMsg error message if errors occurred, empty otherwise
* @return number of successfully sent mails
*/
virtual uint32_t sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& mailBody,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailTrackId>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailTrackId>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
/** /**
* @brief getMessageCount * @brief getMessageCount
* @jsonapi{development} * @jsonapi{development}
@ -535,14 +603,6 @@ public:
*/ */
virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0; virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox) = 0;
/**
* @brief MessageSend
* @jsonapi{development}
* @param[in] info
* @return always true
*/
virtual bool MessageSend(Rs::Msgs::MessageInfo &info) = 0;
/** /**
* @brief SystemMessage * @brief SystemMessage
* @jsonapi{development} * @jsonapi{development}
@ -916,7 +976,14 @@ virtual bool initiateDistantChatConnexion(
virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0; virtual bool getDistantChatStatus(const DistantChatPeerId& pid,DistantChatPeerInfo& info)=0;
virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0; virtual bool closeDistantChatConnexion(const DistantChatPeerId& pid)=0;
/**
* @brief MessageSend
* @jsonapi{development}
* @param[in] info
* @return always true
*/
RS_DEPRECATED_FOR(sendMail)
virtual bool MessageSend(Rs::Msgs::MessageInfo &info) = 0;
virtual ~RsMsgs();
}; };
#endif

View File

@ -20,6 +20,7 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <iostream> #include <iostream>
#include <tuple>
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
@ -300,6 +301,22 @@ bool p3Msgs::MessageSend(MessageInfo &info)
return mMsgSrv->MessageSend(info); return mMsgSrv->MessageSend(info);
} }
uint32_t p3Msgs::sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to,
const std::set<RsGxsId>& cc,
const std::set<RsGxsId>& bcc,
const std::vector<FileInfo>& attachments,
std::set<RsMailTrackId>& trackingIds,
std::string& errorMsg )
{
return mMsgSrv->sendMail(
from, subject, body, to, cc, bcc, attachments,
trackingIds, errorMsg );
}
bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) bool p3Msgs::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
{ {
return mMsgSrv->SystemMessage(title, message, systemFlag); return mMsgSrv->SystemMessage(title, message, systemFlag);
@ -541,3 +558,28 @@ uint32_t p3Msgs::getDistantChatPermissionFlags()
return mChatSrv->getDistantChatPermissionFlags() ; return mChatSrv->getDistantChatPermissionFlags() ;
} }
RsMsgs::~RsMsgs() = default;
RsMailStatusEvent::~RsMailStatusEvent() = default;
Rs::Msgs::MessageInfo::~MessageInfo() = default;
MsgInfoSummary::~MsgInfoSummary() = default;
VisibleChatLobbyRecord::~VisibleChatLobbyRecord() = default;
void RsMailTrackId::serial_process(
RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mMailId);
RS_SERIAL_PROCESS(mRecipientId);
}
bool RsMailTrackId::operator<(const RsMailTrackId& o) const
{
return std::tie( mMailId, mRecipientId) <
std::tie(o.mMailId, o.mRecipientId);
}
bool RsMailTrackId::operator==(const RsMailTrackId& o) const
{
return std::tie( mMailId, mRecipientId) ==
std::tie(o.mMailId, o.mRecipientId);
}

View File

@ -19,8 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * * along with this program. If not, see <https://www.gnu.org/licenses/>. *
* * * *
*******************************************************************************/ *******************************************************************************/
#ifndef RS_P3MSG_INTERFACE_H #pragma once
#define RS_P3MSG_INTERFACE_H
#include "retroshare/rsmsgs.h" #include "retroshare/rsmsgs.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
@ -38,11 +37,25 @@ class RsChatMsgItem;
*/ */
class p3Msgs: public RsMsgs class p3Msgs: public RsMsgs
{ {
public: public:
p3Msgs(p3MsgService *p3m, p3ChatService *p3c) p3Msgs(p3MsgService *p3m, p3ChatService *p3c) :
:mMsgSrv(p3m), mChatSrv(p3c) { return; } mMsgSrv(p3m), mChatSrv(p3c) {}
virtual ~p3Msgs() { return; } ~p3Msgs() override = default;
/// @see RsMsgs
uint32_t sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailTrackId>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailTrackId>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) ) override;
/****************************************/ /****************************************/
/* Message Items */ /* Message Items */
@ -54,6 +67,7 @@ class p3Msgs: public RsMsgs
virtual bool getMessage(const std::string &mId, Rs::Msgs::MessageInfo &msg); virtual bool getMessage(const std::string &mId, Rs::Msgs::MessageInfo &msg);
virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox); virtual void getMessageCount(uint32_t &nInbox, uint32_t &nInboxNew, uint32_t &nOutbox, uint32_t &nDraftbox, uint32_t &nSentbox, uint32_t &nTrashbox);
RS_DEPRECATED_FOR(sendMail)
virtual bool MessageSend(Rs::Msgs::MessageInfo &info); virtual bool MessageSend(Rs::Msgs::MessageInfo &info);
virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); virtual bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId); virtual bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId);
@ -172,6 +186,3 @@ class p3Msgs: public RsMsgs
p3MsgService *mMsgSrv; p3MsgService *mMsgSrv;
p3ChatService *mChatSrv; p3ChatService *mChatSrv;
}; };
#endif

View File

@ -356,6 +356,9 @@ int p3MsgService::checkOutgoingMessages()
bool changed = false; bool changed = false;
std::list<RsMsgItem*> output_queue; std::list<RsMsgItem*> output_queue;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
{ {
RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/ RS_STACK_MUTEX(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -391,7 +394,8 @@ int p3MsgService::checkOutgoingMessages()
"p3MsgService::checkOutGoingMessages() Sending out message"); "p3MsgService::checkOutGoingMessages() Sending out message");
/* remove the pending flag */ /* remove the pending flag */
output_queue.push_back(mit->second) ; output_queue.push_back(mit->second);
pEvent->mChangedMsgIds.insert(std::to_string(mit->first));
/* When the message is a distant msg, dont remove it yet from /* 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 * the list. Only mark it as being sent, so that we don't send
@ -446,6 +450,9 @@ int p3MsgService::checkOutgoingMessages()
if(changed) if(changed)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return 0; return 0;
} }
@ -911,6 +918,8 @@ bool p3MsgService::removeMsgId(const std::string &mid)
} }
bool changed = false; bool changed = false;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
{ {
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
@ -922,6 +931,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsMsgItem *mi = mit->second; RsMsgItem *mi = mit->second;
imsg.erase(mit); imsg.erase(mit);
delete mi; delete mi;
pEvent->mChangedMsgIds.insert(mid);
} }
mit = msgOutgoing.find(msgId); mit = msgOutgoing.find(msgId);
@ -931,6 +941,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsMsgItem *mi = mit->second; RsMsgItem *mi = mit->second;
msgOutgoing.erase(mit); msgOutgoing.erase(mit);
delete mi; delete mi;
pEvent->mChangedMsgIds.insert(mid);
} }
std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(msgId); std::map<uint32_t, RsMsgSrcId*>::iterator srcIt = mSrcIds.find(msgId);
@ -938,6 +949,7 @@ bool p3MsgService::removeMsgId(const std::string &mid)
changed = true; changed = true;
delete (srcIt->second); delete (srcIt->second);
mSrcIds.erase(srcIt); mSrcIds.erase(srcIt);
pEvent->mChangedMsgIds.insert(mid);
} }
} }
@ -950,6 +962,9 @@ bool p3MsgService::removeMsgId(const std::string &mid)
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
} }
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return changed; return changed;
} }
@ -1131,7 +1146,12 @@ uint32_t p3MsgService::sendMessage(RsMsgItem *item) // no from field because
uint32_t p3MsgService::sendDistantMessage(RsMsgItem *item, const RsGxsId& from) uint32_t p3MsgService::sendDistantMessage(RsMsgItem *item, const RsGxsId& from)
{ {
if(!item) return 0; if(!item)
{
RsErr() << __PRETTY_FUNCTION__ << " item can't be null" << std::endl;
print_stacktrace();
return 0;
}
item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */ item->msgId = getNewUniqueMsgId(); /* grabs Mtx as well */
item->msgFlags |= ( RS_MSG_FLAGS_DISTANT | RS_MSG_FLAGS_OUTGOING | item->msgFlags |= ( RS_MSG_FLAGS_DISTANT | RS_MSG_FLAGS_OUTGOING |
@ -1178,8 +1198,6 @@ bool p3MsgService::MessageSend(MessageInfo &info)
if (msg) if (msg)
{ {
std::list<RsPgpId>::iterator it ;
if (msg->msgFlags & RS_MSG_FLAGS_SIGNED) if (msg->msgFlags & RS_MSG_FLAGS_SIGNED)
msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message msg->msgFlags |= RS_MSG_FLAGS_SIGNATURE_CHECKS; // this is always true, since we are sending the message
@ -1192,14 +1210,106 @@ bool p3MsgService::MessageSend(MessageInfo &info)
imsg[msg->msgId] = msg; imsg[msg->msgId] = msg;
RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_ADD);
//
// // return new message id
// rs_sprintf(info.msgId, "%lu", msg->msgId);
} }
return true; return true;
} }
uint32_t p3MsgService::sendMail(
const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to,
const std::set<RsGxsId>& cc,
const std::set<RsGxsId>& bcc,
const std::vector<FileInfo>& attachments,
std::set<RsMailTrackId>& trackingIds,
std::string& errorMsg )
{
errorMsg.clear();
const std::string fname = __PRETTY_FUNCTION__;
auto pCheck = [&](bool test, const std::string& errMsg)
{
if(!test)
{
errorMsg = errMsg;
RsErr() << fname << " " << errMsg << std::endl;
}
return test;
};
if(!pCheck(!from.isNull(), "from can't be null")) return false;
if(!pCheck(!(to.empty() && cc.empty() && bcc.empty()),
"You must specify at least one recipient" )) return false;
auto dstCheck =
[&](const std::set<RsGxsId>& dstSet)
{
for(const RsGxsId& dst: dstSet) if(dst.isNull()) return false;
return true;
};
if(!pCheck(dstCheck(to), "to contains a null recipient" )) return false;
if(!pCheck(dstCheck(cc), "cc contains a null recipient" )) return false;
if(!pCheck(dstCheck(bcc), "bcc contains a null recipient")) return false;
MessageInfo msgInfo;
msgInfo.rsgxsid_srcId = from;
msgInfo.title = subject;
msgInfo.msg = body;
msgInfo.rsgxsid_msgto = to;
msgInfo.rsgxsid_msgcc = cc;
msgInfo.rsgxsid_msgbcc = bcc;
std::copy( attachments.begin(), attachments.end(),
std::back_inserter(msgInfo.files) );
uint32_t ret = 0;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
auto pSend = [&](const std::set<RsGxsId>& sDest)
{
for(const RsGxsId& dst : sDest)
{
RsMsgItem* msgItem = initMIRsMsg(msgInfo, dst);
if(!msgItem)
{
errorMsg += " initMIRsMsg from: " + from.toStdString()
+ " dst: " + dst.toStdString() + " subject: " + subject
+ " returned nullptr!\n";
RsErr() << fname << errorMsg;
continue;
}
uint32_t msgId = sendDistantMessage(msgItem, from);
// ensure we don't use that ptr again without noticing
msgItem = nullptr;
if(!msgId)
{
errorMsg += " sendDistantMessage from: " + from.toStdString()
+ " dst: " + dst.toStdString() + " subject: " + subject
+ " returned 0!\n";
RsErr() << fname << errorMsg;
continue;
}
const RsMailMessageId mailId = std::to_string(msgId);
pEvent->mChangedMsgIds.insert(mailId);
trackingIds.insert(RsMailTrackId(mailId, dst));
++ret;
}
};
pSend(to);
pSend(cc);
pSend(bcc);
if(rsEvents) rsEvents->postEvent(pEvent);
return ret;
}
bool p3MsgService::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag) bool p3MsgService::SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag)
{ {
if ((systemFlag & RS_MSG_SYSTEM) == 0) { if ((systemFlag & RS_MSG_SYSTEM) == 0) {
@ -1890,20 +2000,21 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
{ {
RS_STACK_MUTEX(mMsgMtx); RS_STACK_MUTEX(mMsgMtx);
std::cerr << "(WW) p3MsgService::notifyDataStatus: Global router tells "
<< "us that item ID " << id
<< " could not be delivered on time.";
auto it = _ongoing_messages.find(id); auto it = _ongoing_messages.find(id);
if(it == _ongoing_messages.end()) if(it == _ongoing_messages.end())
{ {
std::cerr << " (EE) cannot find pending message to acknowledge. " RsErr() << __PRETTY_FUNCTION__
<< "Weird. grouter id = " << id << std::endl; << " cannot find pending message to acknowledge. "
<< "Weird. grouter id: " << id << std::endl;
return; return;
} }
uint32_t msg_id = it->second; uint32_t msg_id = it->second;
std::cerr << " message id = " << msg_id << std::endl;
RsWarn() << __PRETTY_FUNCTION__ << " Global router tells "
<< "us that item ID " << id
<< " could not be delivered on time. Message id: "
<< msg_id << std::endl;
/* this is needed because it's not saved in config, but we should /* this is needed because it's not saved in config, but we should
* probably include it in _ongoing_messages */ * probably include it in _ongoing_messages */
@ -1912,10 +2023,10 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
std::map<uint32_t,RsMsgItem*>::iterator mit = msgOutgoing.find(msg_id); std::map<uint32_t,RsMsgItem*>::iterator mit = msgOutgoing.find(msg_id);
if(mit == msgOutgoing.end()) if(mit == msgOutgoing.end())
{ {
std::cerr << " (II) message has been notified as not delivered, " RsInfo() << __PRETTY_FUNCTION__
<< "but it's not in outgoing list. Probably it has been " << " message has been notified as not delivered, "
<< "delivered successfully by other means." << "but it's not in outgoing list. Probably it has been "
<< std::endl; << "delivered successfully by other means." << std::endl;
} }
else else
{ {
@ -1925,6 +2036,7 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
// clear the routed flag so that the message is requested again // clear the routed flag so that the message is requested again
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED; mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED;
} }
return; return;
} }
@ -1954,17 +2066,31 @@ void p3MsgService::notifyDataStatus( const GRouterMsgPropagationId& id,
return; return;
} }
#if 0
delete it2->second; delete it2->second;
msgOutgoing.erase(it2); msgOutgoing.erase(it2);
#else
// Do not delete it move to sent folder instead!
it2->second->msgFlags &= ~RS_MSG_FLAGS_PENDING;
imsg[msg_id] = it2->second;
msgOutgoing.erase(it2);
#endif
RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST, RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST,
NOTIFY_TYPE_ADD ); NOTIFY_TYPE_ADD );
IndicateConfigChanged(); IndicateConfigChanged();
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
if(rsEvents) rsEvents->postEvent(pEvent);
return; return;
} }
std::cerr << "p3MsgService: unhandled data status info from global router"
<< " for msg ID " << id << ": this is a bug." << std::endl; RsErr() << __PRETTY_FUNCTION__
<< " unhandled data status info from global router"
<< " for msg ID " << id << ": this is a bug." << std::endl;
} }
bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id) bool p3MsgService::acceptDataFromPeer(const RsGxsId& to_gxs_id)
@ -2049,8 +2175,11 @@ bool p3MsgService::receiveGxsTransMail( const RsGxsId& authorId,
bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId, bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
GxsTransSendStatus status ) GxsTransSendStatus status )
{ {
std::cout << __PRETTY_FUNCTION__ << " " << mailId << ", " Dbg2() << __PRETTY_FUNCTION__ << " " << mailId << ", "
<< static_cast<uint>(status) << std::endl; << static_cast<uint>(status) << std::endl;
using Evt_t = RsMailStatusEvent;
std::shared_ptr<Evt_t> pEvent(new Evt_t());
if( status == GxsTransSendStatus::RECEIPT_RECEIVED ) if( status == GxsTransSendStatus::RECEIPT_RECEIVED )
{ {
@ -2062,11 +2191,10 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
auto it = gxsOngoingMessages.find(mailId); auto it = gxsOngoingMessages.find(mailId);
if(it == gxsOngoingMessages.end()) if(it == gxsOngoingMessages.end())
{ {
std::cerr << __PRETTY_FUNCTION__<< " " RsErr() << __PRETTY_FUNCTION__<< " " << mailId << ", "
<< mailId << static_cast<uint>(status)
<< ", " << static_cast<uint>(status) << " cannot find pending message to acknowledge!"
<< " (EE) cannot find pending message to acknowledge!" << std::endl;
<< std::endl;
return false; return false;
} }
@ -2081,26 +2209,32 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
auto it2 = msgOutgoing.find(msg_id); auto it2 = msgOutgoing.find(msg_id);
if(it2 == msgOutgoing.end()) if(it2 == msgOutgoing.end())
{ {
std::cerr << __PRETTY_FUNCTION__ << " " << mailId RsInfo() << __PRETTY_FUNCTION__ << " " << mailId
<< ", " << static_cast<uint>(status) << " (II) " << ", " << static_cast<uint>(status)
<< "received receipt for message that is not in " << " received receipt for message that is not in "
<< "outgoing list, probably it has been acknoweldged " << "outgoing list, probably it has been acknoweldged "
<< "before by other means." << std::endl; << "before by other means." << std::endl;
return true; }
else
{
#if 0
delete it2->second;
msgOutgoing.erase(it2);
#else
// Do not delete it move to sent folder instead!
it2->second->msgFlags &= ~RS_MSG_FLAGS_PENDING;
imsg[msg_id] = it2->second;
msgOutgoing.erase(it2);
#endif
pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
} }
delete it2->second;
msgOutgoing.erase(it2);
} }
RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST, RsServer::notify()->notifyListChange( NOTIFY_LIST_MESSAGELIST,
NOTIFY_TYPE_ADD ); NOTIFY_TYPE_ADD );
IndicateConfigChanged(); IndicateConfigChanged();
return true;
} }
else if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
if( status >= GxsTransSendStatus::FAILED_RECEIPT_SIGNATURE )
{ {
uint32_t msg_id; uint32_t msg_id;
@ -2132,17 +2266,22 @@ bool p3MsgService::notifyGxsTransSendStatus( RsGxsTransId mailId,
std::cerr << " message has been notified as not delivered, " std::cerr << " message has been notified as not delivered, "
<< "but it not on outgoing list." << "but it not on outgoing list."
<< std::endl; << std::endl;
return true;
} }
std::cerr << " reseting the ROUTED flag so that the message is " else
<< "requested again" << std::endl; {
std::cerr << " reseting the ROUTED flag so that the message is "
<< "requested again" << std::endl;
// clear the routed flag so that the message is requested again
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED;
// clear the routed flag so that the message is requested again pEvent->mChangedMsgIds.insert(std::to_string(msg_id));
mit->second->msgFlags &= ~RS_MSG_FLAGS_ROUTED; }
return true;
} }
} }
if(rsEvents && !pEvent->mChangedMsgIds.empty())
rsEvents->postEvent(pEvent);
return true; return true;
} }

View File

@ -37,7 +37,7 @@
#include "services/p3service.h" #include "services/p3service.h"
#include "rsitems/rsmsgitems.h" #include "rsitems/rsmsgitems.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "util/rsdebug.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include "grouter/p3grouter.h" #include "grouter/p3grouter.h"
@ -59,6 +59,19 @@ public:
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
/// @see RsMsgs::sendMail
uint32_t sendMail(const RsGxsId from,
const std::string& subject,
const std::string& body,
const std::set<RsGxsId>& to = std::set<RsGxsId>(),
const std::set<RsGxsId>& cc = std::set<RsGxsId>(),
const std::set<RsGxsId>& bcc = std::set<RsGxsId>(),
const std::vector<FileInfo>& attachments = std::vector<FileInfo>(),
std::set<RsMailTrackId>& trackingIds =
RS_DEFAULT_STORAGE_PARAM(std::set<RsMailTrackId>),
std::string& errorMsg =
RS_DEFAULT_STORAGE_PARAM(std::string) );
/* External Interface */ /* External Interface */
bool getMessageSummaries(std::list<Rs::Msgs::MsgInfoSummary> &msgList); bool getMessageSummaries(std::list<Rs::Msgs::MsgInfoSummary> &msgList);
bool getMessage(const std::string &mid, Rs::Msgs::MessageInfo &msg); bool getMessage(const std::string &mid, Rs::Msgs::MessageInfo &msg);
@ -72,6 +85,7 @@ public:
// msgParentId == 0 --> remove // msgParentId == 0 --> remove
bool setMsgParentId(uint32_t msgId, uint32_t msgParentId); bool setMsgParentId(uint32_t msgId, uint32_t msgParentId);
RS_DEPRECATED_FOR(sendMail)
bool MessageSend(Rs::Msgs::MessageInfo &info); bool MessageSend(Rs::Msgs::MessageInfo &info);
bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag); bool SystemMessage(const std::string &title, const std::string &message, uint32_t systemFlag);
bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId); bool MessageToDraft(Rs::Msgs::MessageInfo &info, const std::string &msgParentId);
@ -227,6 +241,8 @@ private:
bool mShouldEnableDistantMessaging ; bool mShouldEnableDistantMessaging ;
p3GxsTrans& mGxsTransServ; p3GxsTrans& mGxsTransServ;
RS_SET_CONTEXT_DEBUG_LEVEL(3)
}; };
#endif // MESSAGE_SERVICE_HEADER #endif // MESSAGE_SERVICE_HEADER