merged with upstream/master

This commit is contained in:
csoler 2017-01-20 00:00:47 +01:00
commit d1af2e09dc
10 changed files with 120 additions and 27 deletions

View File

@ -1559,15 +1559,88 @@ void RsGenExchange::notifyChangedGroupStats(const RsGxsGroupId &grpId)
mNotifications.push_back(gc); mNotifications.push_back(gc);
} }
bool RsGenExchange::checkGroupMetaConsistency(const RsGroupMetaData& meta)
{
std::cerr << "Checking group consistency:" << std::endl;
if(meta.mGroupName.empty())
{
std::cerr << "(EE) cannot create a group with no name." << std::endl;
return false;
}
if(meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PUBLIC && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_RESTRICTED && meta.mGroupFlags != GXS_SERV::FLAG_PRIVACY_PRIVATE)
{
std::cerr << "(EE) mGroupFlags has incorrect value " << std::hex << meta.mGroupFlags << std::dec << ". A value among GXS_SERV::FLAG_PRIVACY_{PUBLIC,RESTRICTED,PRIVATE} is expected." << std::endl;
return false ;
}
if(meta.mCircleType < GXS_CIRCLE_TYPE_PUBLIC || meta.mCircleType > GXS_CIRCLE_TYPE_YOUR_EYES_ONLY)
{
std::cerr << "(EE) mCircleType has incorrect value " << std::hex << meta.mCircleType << std::dec << ". A single value among GXS_CIRCLE_TYPE_{PUBLIC,EXTERNAL,YOUR_FRIENDS_ONLY,LOCAL,EXT_SELF,YOUR_EYES_ONLY} is expected." << std::endl;
return false ;
}
if(meta.mCircleType == GXS_CIRCLE_TYPE_EXTERNAL)
{
if(!meta.mInternalCircle.isNull())
{
std::cerr << "(EE) Group circle type is EXTERNAL, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl;
return false ;
}
if(meta.mCircleId.isNull())
{
std::cerr << "(EE) Group circle type is EXTERNAL, but no external circle ID was supplied. meta.mCircleId is indeed empty. This is an error." << std::endl;
return false ;
}
}
if(meta.mCircleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
{
if(!meta.mCircleId.isNull())
{
std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl;
return false ;
}
if(meta.mInternalCircle.isNull())
{
std::cerr << "(EE) Group circle type is YOUR_FRIENDS_ONLY, but no internal circle ID was supplied. meta.mInternalCircle is indeed empty. This is an error." << std::endl;
return false ;
}
}
if(meta.mCircleType == GXS_CIRCLE_TYPE_EXT_SELF)
{
if(!meta.mCircleId.isNull())
{
std::cerr << "(EE) Group circle type is EXT_SELF, but an external circle ID " << meta.mCircleId << " was supplied. This is an error." << std::endl;
return false ;
}
if(!meta.mInternalCircle.isNull())
{
std::cerr << "(EE) Group circle type is EXT_SELF, but an internal circle ID " << meta.mInternalCircle << " was supplied. This is an error." << std::endl;
return false ;
}
}
std::cerr << "Group is clean." << std::endl;
return true ;
}
void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem) void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
{ {
if(!checkGroupMetaConsistency(grpItem->meta))
{
std::cerr << "(EE) Cannot publish group. Some information was not supplied." << std::endl;
return ;
}
RS_STACK_MUTEX(mGenMtx) ; RS_STACK_MUTEX(mGenMtx) ;
token = mDataAccess->generatePublicToken(); token = mDataAccess->generatePublicToken();
GxsGrpPendingSign ggps(grpItem, token); GxsGrpPendingSign ggps(grpItem, token);
mGrpsToPublish.push_back(ggps); mGrpsToPublish.push_back(ggps);
#ifdef GEN_EXCH_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::publishGroup() token: " << token; std::cerr << "RsGenExchange::publishGroup() token: " << token;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
@ -1577,6 +1650,12 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem) void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
{ {
if(!checkGroupMetaConsistency(grpItem->meta))
{
std::cerr << "(EE) Cannot update group. Some information was not supplied." << std::endl;
return ;
}
RS_STACK_MUTEX(mGenMtx) ; RS_STACK_MUTEX(mGenMtx) ;
token = mDataAccess->generatePublicToken(); token = mDataAccess->generatePublicToken();
mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token)); mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token));

View File

@ -690,6 +690,8 @@ private:
void publishMsgs(); void publishMsgs();
bool checkGroupMetaConsistency(const RsGroupMetaData& meta);
/*! /*!
* processes msg local meta changes * processes msg local meta changes
*/ */

View File

@ -3892,16 +3892,14 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
#endif #endif
return false; return false;
} }
else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type.
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " PUBLIC_CIRCLE, can send"<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " PUBLIC_CIRCLE, can send"<< std::endl;
#endif #endif
return true; return true;
} }
else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, will be sent encrypted."<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " EXTERNAL_CIRCLE, will be sent encrypted."<< std::endl;
@ -3909,8 +3907,7 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
should_encrypt = true ; should_encrypt = true ;
return true ; return true ;
} }
else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
@ -3924,8 +3921,11 @@ bool RsGxsNetService::canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpM
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId)<< " YOUREYESONLY, checking further"<< std::endl;
#endif #endif
} }
else
return true; {
std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl;
return false;
}
} }
bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, RsGxsCircleId& should_encrypt_id) bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& grpMeta, RsGxsCircleId& should_encrypt_id)
@ -4288,19 +4288,16 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
#endif #endif
return false; return false;
} }
else if(circleType == GXS_CIRCLE_TYPE_PUBLIC || circleType == GXS_CIRCLE_TYPE_UNKNOWN) // this complies with the fact that p3IdService does not initialise the circle type.
if(circleType == GXS_CIRCLE_TYPE_PUBLIC)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl;
#endif #endif
return true; return true;
} }
else if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
const RsGxsCircleId& circleId = grpMeta.mCircleId;
if(circleType == GXS_CIRCLE_TYPE_EXTERNAL)
{ {
const RsGxsCircleId& circleId = grpMeta.mCircleId;
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
#endif #endif
@ -4345,8 +4342,7 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
return true ; return true ;
} }
else if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
if(circleType == GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY)
{ {
#ifdef NXS_NET_DEBUG_4 #ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl; GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " YOUREYESONLY, checking further" << std::endl;
@ -4357,8 +4353,11 @@ bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, co
#endif #endif
return res ; return res ;
} }
else
return false; {
std::cerr << "(EE) unknown value found in circle type for group " << grpMeta.mGroupId << ": " << (int)circleType << ": this is probably a bug in the design of the group creation." << std::endl;
return false;
}
} }
/** inherited methods **/ /** inherited methods **/

View File

@ -52,6 +52,7 @@ typedef RsPgpId RsPgpId;
// The meaning of the different circle types is: // The meaning of the different circle types is:
// //
// //
static const uint32_t GXS_CIRCLE_TYPE_UNKNOWN = 0x0000 ; // not known. Is treated as public.
static const uint32_t GXS_CIRCLE_TYPE_PUBLIC = 0x0001 ; // not restricted to a circle static const uint32_t GXS_CIRCLE_TYPE_PUBLIC = 0x0001 ; // not restricted to a circle
static const uint32_t GXS_CIRCLE_TYPE_EXTERNAL = 0x0002 ; // restricted to an external circle, made of RsGxsId static const uint32_t GXS_CIRCLE_TYPE_EXTERNAL = 0x0002 ; // restricted to an external circle, made of RsGxsId
static const uint32_t GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY = 0x0003 ; // restricted to a subset of friend nodes of a given RS node given by a RsPgpId list static const uint32_t GXS_CIRCLE_TYPE_YOUR_FRIENDS_ONLY = 0x0003 ; // restricted to a subset of friend nodes of a given RS node given by a RsPgpId list

View File

@ -33,11 +33,13 @@ typedef std::map<RsGxsGroupId, std::vector<RsMsgMetaData> > MsgMetaResult;
class RsGxsGrpMetaData; class RsGxsGrpMetaData;
class RsGxsMsgMetaData; class RsGxsMsgMetaData;
struct RsGroupMetaData struct RsGroupMetaData
{ {
// (csoler) The correct default value to be used in mCircleType is GXS_CIRCLE_TYPE_PUBLIC, which is defined in rsgxscircles.h,
// but because of a loop in the includes, I cannot include it here. So I replaced with its current value 0x0001.
RsGroupMetaData() : mGroupFlags(0), mSignFlags(0), mPublishTs(0), RsGroupMetaData() : mGroupFlags(0), mSignFlags(0), mPublishTs(0),
mCircleType(0), mAuthenFlags(0), mSubscribeFlags(0), mPop(0), mCircleType(0x0001), mAuthenFlags(0), mSubscribeFlags(0), mPop(0),
mVisibleMsgCount(0), mLastPost(0), mGroupStatus(0) {} mVisibleMsgCount(0), mLastPost(0), mGroupStatus(0) {}
void operator =(const RsGxsGrpMetaData& rGxsMeta); void operator =(const RsGxsGrpMetaData& rGxsMeta);

View File

@ -43,6 +43,7 @@ extern RsIdentity *rsIdentity;
// GroupFlags: Only one so far: // GroupFlags: Only one so far:
#warning THIS FLAG OVERLAPS THE FLAGS FOR mGroupFlags. This is an error that should be fixed.
#define RSGXSID_GROUPFLAG_REALID 0x0001 #define RSGXSID_GROUPFLAG_REALID 0x0001
// THESE ARE FLAGS FOR INTERFACE. // THESE ARE FLAGS FOR INTERFACE.

View File

@ -690,6 +690,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
RsGxsIdGroup id; RsGxsIdGroup id;
id.mMeta.mGroupName = params.nickname; id.mMeta.mGroupName = params.nickname;
id.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ;
id.mImage = params.mImage; id.mImage = params.mImage;
if (params.isPgpLinked) if (params.isPgpLinked)
@ -712,6 +713,7 @@ bool p3IdService::updateIdentity(uint32_t& token, RsGxsIdGroup &group)
std::cerr << "p3IdService::updateIdentity()"; std::cerr << "p3IdService::updateIdentity()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
group.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ;
updateGroup(token, group); updateGroup(token, group);

View File

@ -199,7 +199,9 @@ QString GxsChannelPostItem::getTitleLabel()
QString GxsChannelPostItem::getMsgLabel() QString GxsChannelPostItem::getMsgLabel()
{ {
return RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS); //return RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
// Disabled, because emoticon replacement kills performance.
return QString::fromUtf8(mPost.mMsg.c_str());
} }
QString GxsChannelPostItem::groupName() QString GxsChannelPostItem::groupName()
@ -359,9 +361,10 @@ void GxsChannelPostItem::fill()
/* subject */ /* subject */
ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str())); ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));
// fill first 4 lines of message // fill first 4 lines of message. (csoler) Disabled the replacement of smileys and links, because the cost is too crazy
ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); //ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->subjectLabel->setText(RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4)) ;
//QString score = QString::number(post.mTopScore); //QString score = QString::number(post.mTopScore);
// scoreLabel->setText(score); // scoreLabel->setText(score);

View File

@ -36,7 +36,9 @@ ChatLobbyToaster::ChatLobbyToaster(const ChatLobbyId &lobby_id, const RsGxsId &s
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide())); connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
/* set informations */ /* set informations */
ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE)); //ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
// Disabled, because emoticon replacement kills performance
ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_CLEANSTYLE));
ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME); ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME);
ui.avatarWidget->setDefaultAvatar(":images/chat_64.png"); ui.avatarWidget->setDefaultAvatar(":images/chat_64.png");

View File

@ -34,7 +34,9 @@ ChatToaster::ChatToaster(const RsPeerId &peer_id, const QString &message) : QWid
connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide())); connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide()));
/* set informations */ /* set informations */
ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE)); //ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE));
// emoticons disabled because they kill performance.
ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_CLEANSTYLE));
ui.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(mPeerId).c_str())); ui.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(mPeerId).c_str()));
ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME);
ui.avatarWidget->setId(ChatId(mPeerId)); ui.avatarWidget->setId(ChatId(mPeerId));