From af696639cc72a0691ef5dd29235bee49ab129d51 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 12 Jan 2021 22:31:59 +0100 Subject: [PATCH 1/2] fixed channel UI so that comment label is only shown when a new comment is here --- libretroshare/src/retroshare/rsgxschannels.h | 6 ++-- libretroshare/src/retroshare/rsgxscommon.h | 2 ++ libretroshare/src/retroshare/rsposted.h | 4 ++- libretroshare/src/services/p3gxschannels.h | 6 ++++ libretroshare/src/services/p3posted.h | 7 +++++ .../src/gui/gxs/GxsCommentTreeWidget.cpp | 14 +++++++++ .../src/gui/gxs/GxsCommentTreeWidget.h | 1 + .../gui/gxschannels/GxsChannelPostsModel.cpp | 29 +++++++++++++++++-- .../GxsChannelPostsWidgetWithModel.cpp | 2 +- 9 files changed, 65 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 933826789..421417bdc 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -71,14 +71,15 @@ struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData { - RsGxsChannelPost() : mAttachmentCount(0), mCommentCount(0), mSize(0) {} + RsGxsChannelPost() : mAttachmentCount(0), mCommentCount(0), mUnreadCommentCount(0), mSize(0) {} std::set mOlderVersions; std::string mMsg; // UTF8 encoded. std::list mFiles; uint32_t mAttachmentCount; // auto calced. - uint32_t mCommentCount; // auto calced. WARNING: not computed yet. In the future we need a background process to update this and store in the service string. + uint32_t mCommentCount; // auto calced. + uint32_t mUnreadCommentCount; // auto calced. uint64_t mSize; // auto calced. RsGxsImage mThumbnail; @@ -95,6 +96,7 @@ struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData RS_SERIAL_PROCESS(mFiles); RS_SERIAL_PROCESS(mAttachmentCount); RS_SERIAL_PROCESS(mCommentCount); + RS_SERIAL_PROCESS(mUnreadCommentCount); RS_SERIAL_PROCESS(mSize); RS_SERIAL_PROCESS(mThumbnail); } diff --git a/libretroshare/src/retroshare/rsgxscommon.h b/libretroshare/src/retroshare/rsgxscommon.h index cf71e0b95..c820e1999 100644 --- a/libretroshare/src/retroshare/rsgxscommon.h +++ b/libretroshare/src/retroshare/rsgxscommon.h @@ -176,6 +176,8 @@ struct RsGxsCommentService virtual bool acknowledgeVote( uint32_t token, std::pair& msgId ) = 0; + + virtual bool setCommentAsRead(uint32_t& token,const RsGxsGroupId& gid,const RsGxsMessageId& comment_msg_id) = 0; }; /// @deprecated use RsGxsVoteType::NONE instead @see RsGxsVoteType diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index e56c3cef0..bdcaa3798 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -202,7 +202,9 @@ public: virtual bool getPostData( const uint32_t& token, std::vector& posts) = 0; - //Not currently used + virtual bool setCommentAsRead(uint32_t& token,const RsGxsGroupId& gid,const RsGxsMessageId& comment_msg_id) =0; + + //Not currently used //virtual bool getRelatedPosts(const uint32_t &token, std::vector &posts) = 0; /* From RsGxsCommentService */ diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index e353881e2..95d531448 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -151,6 +151,12 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin return mCommentService->createGxsComment(token, msg); } + virtual bool setCommentAsRead(uint32_t& token,const RsGxsGroupId& gid,const RsGxsMessageId& comment_msg_id) override + { + setMessageReadStatus(token,RsGxsGrpMsgIdPair(gid,comment_msg_id),true); + return true; + } + virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override { return mCommentService->createGxsVote(token, msg); diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 08eb0b2d7..0965ec1d1 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -110,6 +110,13 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI return p3PostBase::setMessageReadStatus(token, msgId, read); } + virtual bool setCommentAsRead(uint32_t& token,const RsGxsGroupId& gid,const RsGxsMessageId& comment_msg_id) override + { + p3PostBase::setMessageReadStatus(token,RsGxsGrpMsgIdPair(gid,comment_msg_id),true); + return true; + } + + /** Comment service - Provide RsGxsCommentService - * redirect to p3GxsCommentService */ diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 56a2cf1b6..343f88c91 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -753,9 +753,15 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) void GxsCommentTreeWidget::insertComments(const std::vector& comments) { + std::list new_comments; + for(auto vit = comments.begin(); vit != comments.end(); ++vit) { const RsGxsComment &comment = *vit; + + if(IS_MSG_NEW(comment.mMeta.mMsgStatus)) + new_comments.push_back(comment.mMeta.mMsgId); + /* convert to a QTreeWidgetItem */ std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId; std::cerr << std::endl; @@ -811,6 +817,14 @@ void GxsCommentTreeWidget::insertComments(const std::vector& comme addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item); } + + // now set all loaded comments as not new, since they have been loaded. + + for(auto cid:new_comments) + { + uint32_t token=0; + mCommentService->setCommentAsRead(token,mGroupId,cid); + } } QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent) diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h index 00ddb7cb1..c4840eb46 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h @@ -57,6 +57,7 @@ protected: /* to be overloaded */ virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set &msgIds); virtual void service_loadThread(const uint32_t &token); + virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent); void clearItems(); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 4ac243420..cb68d841a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -82,6 +82,7 @@ void updateCommentCounts( std::vector& posts, std::vector& posts, std::vectorsecond].mCommentCount; + + if(IS_MSG_NEW(comments[i].mMeta.mMsgStatus)) + ++posts[it->second].mUnreadCommentCount; } } @@ -129,21 +133,42 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr posts; std::vector comments; std::vector votes; + std::set msg_ids{ E.mChannelMsgId }; - if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,std::set{ E.mChannelMsgId }, posts,comments,votes)) + if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids, posts,comments,votes)) { std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; return; } + // Check if what we have actually is a comment or a vote. If so we need to update the actual message they refer to + + if(posts.empty()) // means we have a comment or a vote + { + msg_ids.clear(); + + for(auto c:comments) msg_ids.insert(c.mMeta.mThreadId); + for(auto v:votes ) msg_ids.insert(v.mMeta.mThreadId); + + comments.clear(); + votes.clear(); + + if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids,posts,comments,votes)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; + return; + } + } + // Need to call this in order to get the actuall comment count. The previous call only retrieves the message, since we supplied the message ID. // another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent. - if(!rsGxsChannels->getChannelComments(E.mChannelGroupId,std::set{ E.mChannelMsgId },comments)) + if(!rsGxsChannels->getChannelComments(E.mChannelGroupId,msg_ids,comments)) { std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl; return; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index f1aa38f68..02a603284 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -183,7 +183,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); } - if(post.mCommentCount) + if(post.mUnreadCommentCount) { QPainter p(&pixmap); QFontMetricsF fm(option.font); From 1bbde46c4a17bfbfadbe480bdddba4b8a162b925 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 13 Jan 2021 23:13:37 +0100 Subject: [PATCH 2/2] giving 30 secs of time to create identity before clearing PGP passphrase cache --- retroshare-gui/src/gui/GenCertDialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index 4b5f09e21..e106146fb 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -659,8 +659,10 @@ void GenCertDialog::genPerson() RsInit::LoadPassword(sslPasswd); if (Rshare::loadCertificate(sslId, false)) { - // Now clear the cached passphrase - rsNotify->clearPgpPassphrase(); + // Normally we should clear the cached passphrase as soon as possible. However,some other GUI components may still need it at start. + // (csoler) This is really bad: we have to guess that 30 secs will be enough. I have no better way to do this. + + QTimer::singleShot(30000, []() { rsNotify->clearPgpPassphrase(); } ); accept(); }