Receiving a shared key:

- Added notify of the group id and the refresh of the gui
- Added system message (create of message disabled)
- Added possibility to show a news feed item

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7926 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-02-08 01:01:48 +00:00
parent 961641c186
commit 8351510841
16 changed files with 251 additions and 42 deletions

View File

@ -1007,7 +1007,7 @@ void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
}
else
{
#warning cyril: very weird code. Why delete an element without removing it from the array??
#warning cyril: very weird code. Why delete an element without removing it from the array
delete n;
}
}
@ -1508,6 +1508,14 @@ void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
}
void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId)
{
RS_STACK_MUTEX(mGenMtx);
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PUBLISHKEY, false);
gc->mGrpIdList.push_back(grpId);
mNotifications.push_back(gc);
}
void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
{

View File

@ -144,12 +144,17 @@ public:
/*!
* @param messages messages are deleted after function returns
*/
void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
virtual void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
/*!
* @param messages messages are deleted after function returns
* @param groups groups are deleted after function returns
*/
void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
virtual void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
/*!
* @param grpId group id
*/
virtual void notifyReceivePublishKey(const RsGxsGroupId &grpId);
/** E: Observer implementation **/

View File

@ -3428,11 +3428,15 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
it->second = item->key ;
bool ret = mDataStore->updateGroupKeys(item->grpId,grpMeta->keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ;
if(!ret)
std::cerr << "(EE) could not update database. Something went wrong." << std::endl;
if(ret)
{
#ifdef NXS_NET_DEBUG
else
std::cerr << " updated database with new publish keys." << std::endl;
std::cerr << " updated database with new publish keys." << std::endl;
#endif
mObserver->notifyReceivePublishKey(item->grpId);
}
else
{
std::cerr << "(EE) could not update database. Something went wrong." << std::endl;
}
}

View File

@ -45,12 +45,14 @@ public:
virtual void notifyNewMessages(std::vector<RsNxsMsg*>& messages) = 0;
/*!
* @param messages messages are deleted after function returns
* @param groups groups are deleted after function returns
*/
virtual void notifyNewGroups(std::vector<RsNxsGrp*>& groups) = 0;
/*!
* @param grpId group id
*/
virtual void notifyReceivePublishKey(const RsGxsGroupId &grpId) = 0;
};
#endif // RSNXSOBSERVER_H

View File

@ -22,7 +22,7 @@ class RsGxsNotify
{
public:
enum NotifyType { TYPE_PUBLISH, TYPE_RECEIVE, TYPE_PROCESSED };
enum NotifyType { TYPE_PUBLISH, TYPE_RECEIVE, TYPE_PROCESSED, TYPE_PUBLISHKEY };
virtual ~RsGxsNotify() {return; }
virtual NotifyType getType() = 0;

View File

@ -59,12 +59,14 @@
// system message
#define RS_MSG_USER_REQUEST 0x000400 /* user request */
#define RS_MSG_FRIEND_RECOMMENDATION 0x000800 /* friend recommendation */
#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION)
#define RS_MSG_ENCRYPTED 0x001000 /* message is encrypted */
#define RS_MSG_SIGNATURE_CHECKS 0x002000 /* message was signed, and signature checked */
#define RS_MSG_SIGNED 0x004000 /* message was signed and signature didn't check */
#define RS_MSG_LOAD_EMBEDDED_IMAGES 0x008000 /* load embedded images */
#define RS_MSG_DECRYPTED 0x010000 /* message was previously encrypted, and is now decrypted */
#define RS_MSG_PUBLISH_KEY 0x020000 /* publish key */
#define RS_MSG_SYSTEM (RS_MSG_USER_REQUEST | RS_MSG_FRIEND_RECOMMENDATION | RS_MSG_PUBLISH_KEY)
#define RS_CHAT_LOBBY_EVENT_PEER_LEFT 0x01
#define RS_CHAT_LOBBY_EVENT_PEER_STATUS 0x02

View File

@ -92,10 +92,12 @@ const uint32_t RS_FEED_ITEM_SEC_MISSING_CERTIFICATE = RS_FEED_TYPE_SECURITY | 0
const uint32_t RS_FEED_ITEM_CHANNEL_NEW = RS_FEED_TYPE_CHANNEL | 0x0001;
//const uint32_t RS_FEED_ITEM_CHANNEL_UPDATE = RS_FEED_TYPE_CHANNEL | 0x0002;
const uint32_t RS_FEED_ITEM_CHANNEL_MSG = RS_FEED_TYPE_CHANNEL | 0x0003;
const uint32_t RS_FEED_ITEM_CHANNEL_PUBLISHKEY = RS_FEED_TYPE_CHANNEL | 0x0004;
const uint32_t RS_FEED_ITEM_FORUM_NEW = RS_FEED_TYPE_FORUM | 0x0001;
//const uint32_t RS_FEED_ITEM_FORUM_UPDATE = RS_FEED_TYPE_FORUM | 0x0002;
const uint32_t RS_FEED_ITEM_FORUM_MSG = RS_FEED_TYPE_FORUM | 0x0003;
const uint32_t RS_FEED_ITEM_FORUM_PUBLISHKEY = RS_FEED_TYPE_FORUM | 0x0004;
//const uint32_t RS_FEED_ITEM_BLOG_NEW = RS_FEED_TYPE_BLOG | 0x0001;
//const uint32_t RS_FEED_ITEM_BLOG_UPDATE = RS_FEED_TYPE_BLOG | 0x0002;

View File

@ -65,7 +65,6 @@ const uint32_t RS_MSG_FLAGS_STAR = 0x00000200;
const uint32_t RS_MSG_FLAGS_PARTIAL = 0x00000400;
const uint32_t RS_MSG_FLAGS_USER_REQUEST = 0x00000800;
const uint32_t RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x00001000;
const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION;
const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x00002000;
const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x00004000;
const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000;
@ -74,6 +73,9 @@ const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000;
const uint32_t RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES = 0x00040000;
const uint32_t RS_MSG_FLAGS_DECRYPTED = 0x00080000;
const uint32_t RS_MSG_FLAGS_ROUTED = 0x00100000;
const uint32_t RS_MSG_FLAGS_PUBLISH_KEY = 0x00200000;
const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION | RS_MSG_FLAGS_PUBLISH_KEY;
class RsMessageItem: public RsItem
{

View File

@ -197,17 +197,38 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
else
{
if (notify && (*it)->getType() == RsGxsNotify::TYPE_RECEIVE)
if (notify)
{
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange*>(*it);
if (grpChange)
{
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
switch (grpChange->getType())
{
notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_NEW, git->toStdString());
case RsGxsNotify::TYPE_PROCESSED:
case RsGxsNotify::TYPE_PUBLISH:
break;
case RsGxsNotify::TYPE_RECEIVE:
{
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
{
notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_NEW, git->toStdString());
}
}
case RsGxsNotify::TYPE_PUBLISHKEY:
{
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
{
notify->AddFeedItem(RS_FEED_ITEM_CHANNEL_PUBLISHKEY, git->toStdString());
}
}
}
}
}

View File

@ -110,35 +110,59 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
for(it = changes.begin(); it != changes.end(); ++it)
{
RsGxsNotify *c = *it;
if (c->getType() == RsGxsNotify::TYPE_RECEIVE)
switch (c->getType())
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange*>(c);
if (msgChange)
case RsGxsNotify::TYPE_PROCESSED:
case RsGxsNotify::TYPE_PUBLISH:
break;
case RsGxsNotify::TYPE_RECEIVE:
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for (mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange*>(c);
if (msgChange)
{
std::vector<RsGxsMessageId>::iterator mit1;
for (mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgChangeMap = msgChange->msgChangeMap;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit;
for (mit = msgChangeMap.begin(); mit != msgChangeMap.end(); ++mit)
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, mit->first.toStdString(), mit1->toStdString());
std::vector<RsGxsMessageId>::iterator mit1;
for (mit1 = mit->second.begin(); mit1 != mit->second.end(); ++mit1)
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, mit->first.toStdString(), mit1->toStdString());
}
}
continue;
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
if (grpChange)
{
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_NEW, git->toStdString());
}
continue;
}
continue;
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
if (grpChange)
case RsGxsNotify::TYPE_PUBLISHKEY:
{
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
if (grpChange)
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_NEW, git->toStdString());
/* group received */
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_PUBLISHKEY, git->toStdString());
}
continue;
}
continue;
}
}
}

View File

@ -1087,6 +1087,9 @@ bool p3MsgService::SystemMessage(const std::string &title, const std::string &me
if (systemFlag & RS_MSG_FRIEND_RECOMMENDATION) {
msg->msgFlags |= RS_MSG_FLAGS_FRIEND_RECOMMENDATION;
}
if (systemFlag & RS_MSG_PUBLISH_KEY) {
msg->msgFlags |= RS_MSG_FLAGS_PUBLISH_KEY;
}
msg->msgId = 0;
msg->sendTime = time(NULL);
@ -1486,6 +1489,7 @@ void p3MsgService::initRsMI(RsMsgItem *msg, MessageInfo &mi)
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_PUBLISH_KEY) mi.msgflags |= RS_MSG_PUBLISH_KEY;
if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES) mi.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES;
mi.ts = msg->sendTime;
@ -1584,6 +1588,10 @@ void p3MsgService::initRsMIS(RsMsgItem *msg, MsgInfoSummary &mis)
{
mis.msgflags |= RS_MSG_FRIEND_RECOMMENDATION;
}
if (msg->msgFlags & RS_MSG_FLAGS_PUBLISH_KEY)
{
mis.msgflags |= RS_MSG_PUBLISH_KEY;
}
if (msg->msgFlags & RS_MSG_FLAGS_LOAD_EMBEDDED_IMAGES)
{
mis.msgflags |= RS_MSG_LOAD_EMBEDDED_IMAGES;

View File

@ -783,6 +783,8 @@ static void InitIconAndFont(QTreeWidgetItem *item)
item->setIcon(COLUMN_SUBJECT, QIcon(":/images/user/user_request16.png"));
} else if (msgFlags & RS_MSG_FRIEND_RECOMMENDATION) {
item->setIcon(COLUMN_SUBJECT, QIcon(":/images/user/friend_suggestion16.png"));
} else if (msgFlags & RS_MSG_PUBLISH_KEY) {
item->setIcon(COLUMN_SUBJECT, QIcon(":/images/share-icon-16.png"));
} else if (msgFlags & RS_MSG_UNREAD_BY_USER) {
if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) {
item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-replied.png"));

View File

@ -79,8 +79,9 @@ const uint32_t NEWSFEED_POSTEDMSGLIST = 0x000c;
#define ROLE_RECEIVED FEED_TREEWIDGET_SORTROLE
#define TOKEN_TYPE_GROUP 1
#define TOKEN_TYPE_MESSAGE 2
#define TOKEN_TYPE_GROUP 1
#define TOKEN_TYPE_MESSAGE 2
#define TOKEN_TYPE_PUBLISHKEY 3
/*****
* #define NEWS_DEBUG 1
@ -255,6 +256,27 @@ void NewsFeed::updateDisplay()
if (flags & RS_FEED_TYPE_CHANNEL)
addFeedItemChannelMsg(fi);
break;
case RS_FEED_ITEM_CHANNEL_PUBLISHKEY:
{
if (!mTokenQueueChannel) {
mTokenQueueChannel = new TokenQueue(rsGxsChannels->getTokenService(), instance);
}
RsGxsGroupId grpId(fi.mId1);
if (!grpId.isNull()) {
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> grpIds;
grpIds.push_back(grpId);
uint32_t token;
mTokenQueueChannel->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_PUBLISHKEY);
}
}
// if (flags & RS_FEED_TYPE_CHANNEL)
// addFeedItemChannelPublishKey(fi);
break;
case RS_FEED_ITEM_FORUM_NEW:
if (flags & RS_FEED_TYPE_FORUM)
@ -268,6 +290,27 @@ void NewsFeed::updateDisplay()
if (flags & RS_FEED_TYPE_FORUM)
addFeedItemForumMsg(fi);
break;
case RS_FEED_ITEM_FORUM_PUBLISHKEY:
{
if (!mTokenQueueForum) {
mTokenQueueForum = new TokenQueue(rsGxsForums->getTokenService(), instance);
}
RsGxsGroupId grpId(fi.mId1);
if (!grpId.isNull()) {
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> grpIds;
grpIds.push_back(grpId);
uint32_t token;
mTokenQueueForum->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_PUBLISHKEY);
}
}
// if (flags & RS_FEED_TYPE_FORUM)
// addFeedItemForumPublishKey(fi);
break;
case RS_FEED_ITEM_POSTED_NEW:
if (flags & RS_FEED_TYPE_POSTED)
@ -537,6 +580,25 @@ void NewsFeed::loadChannelPost(const uint32_t &token)
}
}
void NewsFeed::loadChannelPublishKey(const uint32_t &token)
{
std::vector<RsGxsChannelGroup> groups;
if (!rsGxsChannels->getGroupData(token, groups)) {
std::cerr << "NewsFeed::loadChannelPublishKey() ERROR getting data";
std::cerr << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "NewsFeed::loadChannelPublishKey() Wrong number of Items";
std::cerr << std::endl;
return;
}
MessageComposer::sendChannelPublishKey(groups[0]);
}
void NewsFeed::loadForumGroup(const uint32_t &token)
{
std::vector<RsGxsForumGroup> forums;
@ -611,6 +673,25 @@ void NewsFeed::loadForumMessage(const uint32_t &token)
}
}
void NewsFeed::loadForumPublishKey(const uint32_t &token)
{
std::vector<RsGxsForumGroup> groups;
if (!rsGxsForums->getGroupData(token, groups)) {
std::cerr << "NewsFeed::loadForumPublishKey() ERROR getting data";
std::cerr << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "NewsFeed::loadForumPublishKey() Wrong number of Items";
std::cerr << std::endl;
return;
}
MessageComposer::sendForumPublishKey(groups[0]);
}
void NewsFeed::loadPostedGroup(const uint32_t &token)
{
std::vector<RsPostedGroup> posted;
@ -697,6 +778,10 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req)
loadChannelPost(req.mToken);
break;
case TOKEN_TYPE_PUBLISHKEY:
loadChannelPublishKey(req.mToken);
break;
default:
std::cerr << "NewsFeed::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
@ -714,6 +799,10 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req)
loadForumMessage(req.mToken);
break;
case TOKEN_TYPE_PUBLISHKEY:
loadForumPublishKey(req.mToken);
break;
default:
std::cerr << "NewsFeed::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;

View File

@ -118,9 +118,11 @@ private:
virtual void loadChannelGroup(const uint32_t &token);
virtual void loadChannelPost(const uint32_t &token);
virtual void loadChannelPublishKey(const uint32_t &token);
virtual void loadForumGroup(const uint32_t &token);
virtual void loadForumMessage(const uint32_t &token);
virtual void loadForumPublishKey(const uint32_t &token);
virtual void loadPostedGroup(const uint32_t &token);
virtual void loadPostedMessage(const uint32_t &token);

View File

@ -45,6 +45,8 @@
#include <retroshare/rsstatus.h>
#include <retroshare/rsfiles.h>
#include <retroshare/rsidentity.h>
#include <retroshare/rsgxschannels.h>
#include <retroshare/rsgxsforums.h>
#include "gui/notifyqt.h"
#include "gui/common/RSTreeWidgetItem.h"
@ -533,6 +535,38 @@ void MessageComposer::sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId
rsMsgs->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_USER_REQUEST);
}
void MessageComposer::sendChannelPublishKey(RsGxsChannelGroup &group)
{
// QString channelName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, group.mMeta.mGroupId, channelName)) {
// return;
// }
// QString title = tr("Publish key for channel %1").arg(channelName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(channelName, link.toHtml());
// rsMsgs->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
}
void MessageComposer::sendForumPublishKey(RsGxsForumGroup &group)
{
// QString forumName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
// RetroShareLink link;
// if (!link.createGxsGroupLink(RetroShareLink::TYPE_FORUM, group.mMeta.mGroupId, forumName)) {
// return;
// }
// QString title = tr("Publish key for forum %1").arg(forumName);
// /* create a message */
// QString msgText = tr("... %1 ...<br>%2").arg(forumName, link.toHtml());
// rsMsgs->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
}
void MessageComposer::closeEvent (QCloseEvent * event)
{
bool bClose = true;

View File

@ -34,6 +34,8 @@ class QTextEdit;
class QTextCharFormat;
class RSTreeWidgetItemCompareRole;
struct MessageInfo;
class RsGxsChannelGroup;
class RsGxsForumGroup;
class MessageComposer : public QMainWindow
{
@ -57,6 +59,8 @@ public:
static QString recommendMessage();
static void recommendFriend(const std::list <RsPeerId> &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false);
static void sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &sslName);
static void sendChannelPublishKey(RsGxsChannelGroup &group);
static void sendForumPublishKey(RsGxsForumGroup &group);
static MessageComposer *newMsg(const std::string &msgId = "");
static MessageComposer *replyMsg(const std::string &msgId, bool all);