Merge pull request #2220 from csoler/v0.6-BugFixing_5

Bug fixing for 0.6.6
This commit is contained in:
csoler 2021-01-14 13:45:18 +01:00 committed by GitHub
commit 8bfdbe6af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 8 deletions

View File

@ -71,14 +71,15 @@ struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData
struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
{ {
RsGxsChannelPost() : mAttachmentCount(0), mCommentCount(0), mSize(0) {} RsGxsChannelPost() : mAttachmentCount(0), mCommentCount(0), mUnreadCommentCount(0), mSize(0) {}
std::set<RsGxsMessageId> mOlderVersions; std::set<RsGxsMessageId> mOlderVersions;
std::string mMsg; // UTF8 encoded. std::string mMsg; // UTF8 encoded.
std::list<RsGxsFile> mFiles; std::list<RsGxsFile> mFiles;
uint32_t mAttachmentCount; // auto calced. 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. uint64_t mSize; // auto calced.
RsGxsImage mThumbnail; RsGxsImage mThumbnail;
@ -95,6 +96,7 @@ struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
RS_SERIAL_PROCESS(mFiles); RS_SERIAL_PROCESS(mFiles);
RS_SERIAL_PROCESS(mAttachmentCount); RS_SERIAL_PROCESS(mAttachmentCount);
RS_SERIAL_PROCESS(mCommentCount); RS_SERIAL_PROCESS(mCommentCount);
RS_SERIAL_PROCESS(mUnreadCommentCount);
RS_SERIAL_PROCESS(mSize); RS_SERIAL_PROCESS(mSize);
RS_SERIAL_PROCESS(mThumbnail); RS_SERIAL_PROCESS(mThumbnail);
} }

View File

@ -176,6 +176,8 @@ struct RsGxsCommentService
virtual bool acknowledgeVote( virtual bool acknowledgeVote(
uint32_t token, uint32_t token,
std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0; std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) = 0;
virtual bool setCommentAsRead(uint32_t& token,const RsGxsGroupId& gid,const RsGxsMessageId& comment_msg_id) = 0;
}; };
/// @deprecated use RsGxsVoteType::NONE instead @see RsGxsVoteType /// @deprecated use RsGxsVoteType::NONE instead @see RsGxsVoteType

View File

@ -202,7 +202,9 @@ public:
virtual bool getPostData( virtual bool getPostData(
const uint32_t& token, std::vector<RsPostedPost>& posts) = 0; const uint32_t& token, std::vector<RsPostedPost>& 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<RsPostedPost> &posts) = 0; //virtual bool getRelatedPosts(const uint32_t &token, std::vector<RsPostedPost> &posts) = 0;
/* From RsGxsCommentService */ /* From RsGxsCommentService */

View File

@ -151,6 +151,12 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
return mCommentService->createGxsComment(token, msg); 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 virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override
{ {
return mCommentService->createGxsVote(token, msg); return mCommentService->createGxsVote(token, msg);

View File

@ -110,6 +110,13 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
return p3PostBase::setMessageReadStatus(token, msgId, read); 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 - /** Comment service - Provide RsGxsCommentService -
* redirect to p3GxsCommentService */ * redirect to p3GxsCommentService */

View File

@ -659,8 +659,10 @@ void GenCertDialog::genPerson()
RsInit::LoadPassword(sslPasswd); RsInit::LoadPassword(sslPasswd);
if (Rshare::loadCertificate(sslId, false)) { if (Rshare::loadCertificate(sslId, false)) {
// Now clear the cached passphrase // Normally we should clear the cached passphrase as soon as possible. However,some other GUI components may still need it at start.
rsNotify->clearPgpPassphrase(); // (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(); accept();
} }

View File

@ -753,9 +753,15 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments) void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments)
{ {
std::list<RsGxsMessageId> new_comments;
for(auto vit = comments.begin(); vit != comments.end(); ++vit) for(auto vit = comments.begin(); vit != comments.end(); ++vit)
{ {
const RsGxsComment &comment = *vit; const RsGxsComment &comment = *vit;
if(IS_MSG_NEW(comment.mMeta.mMsgStatus))
new_comments.push_back(comment.mMeta.mMsgId);
/* convert to a QTreeWidgetItem */ /* convert to a QTreeWidgetItem */
std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId; std::cerr << "GxsCommentTreeWidget::service_loadThread() Got Comment: " << comment.mMeta.mMsgId;
std::cerr << std::endl; std::cerr << std::endl;
@ -811,6 +817,14 @@ void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comme
addItem(comment.mMeta.mMsgId, comment.mMeta.mParentId, item); 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) QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent)

View File

@ -57,6 +57,7 @@ protected:
/* to be overloaded */ /* to be overloaded */
virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set<RsGxsMessageId> &msgIds); virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set<RsGxsMessageId> &msgIds);
virtual void service_loadThread(const uint32_t &token); virtual void service_loadThread(const uint32_t &token);
virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent); virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent);
void clearItems(); void clearItems();

View File

@ -82,6 +82,7 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
{ {
post_indices[posts[i].mMeta.mMsgId] = i; post_indices[posts[i].mMeta.mMsgId] = i;
posts[i].mCommentCount = 0; // should be 0 already, but we secure that value. posts[i].mCommentCount = 0; // should be 0 already, but we secure that value.
posts[i].mUnreadCommentCount = 0;
} }
// now look into comments and increase the count // now look into comments and increase the count
@ -100,6 +101,9 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
continue; continue;
++posts[it->second].mCommentCount; ++posts[it->second].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<const RsEve
RsThread::async([this, E]() RsThread::async([this, E]()
{ {
// 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject() // 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject()
// At this point we dont know what kind of msg id we have. It can be a vote, a comment or an actual message.
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments; std::vector<RsGxsComment> comments;
std::vector<RsGxsVote> votes; std::vector<RsGxsVote> votes;
std::set<RsGxsMessageId> msg_ids{ E.mChannelMsgId };
if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,std::set<RsGxsMessageId>{ 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; std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl;
return; 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. // 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. // 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<RsGxsMessageId>{ 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; std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl;
return; return;

View File

@ -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)); 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); QPainter p(&pixmap);
QFontMetricsF fm(option.font); QFontMetricsF fm(option.font);