removed token system from GxsCommentDialog

This commit is contained in:
csoler 2022-07-09 22:33:42 +02:00
parent 1089d1470e
commit ac4b9b2971
13 changed files with 42 additions and 159 deletions

View file

@ -795,7 +795,7 @@ void PostedListWidgetWithModel::openComments(const RsGxsMessageId& msgId)
ui->idChooser->getChosenId(current_author); ui->idChooser->getChosenId(current_author);
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ; RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
auto *commentDialog = new GxsCommentDialog(this,current_author,rsPosted->getTokenService(),rsPosted); auto *commentDialog = new GxsCommentDialog(this,current_author,rsPosted);
std::set<RsGxsMessageId> msg_versions({post.mMeta.mMsgId}); std::set<RsGxsMessageId> msg_versions({post.mMeta.mMsgId});
commentDialog->commentLoad(post.mMeta.mGroupId, msg_versions, post.mMeta.mMsgId); commentDialog->commentLoad(post.mMeta.mGroupId, msg_versions, post.mMeta.mMsgId);

View file

@ -28,6 +28,7 @@
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "util/qtthreadsutils.h"
#include "util/DateTime.h" #include "util/DateTime.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/stringutil.h" #include "util/stringutil.h"
@ -286,12 +287,15 @@ void BaseBoardsCommentsItem::readToggled(bool checked)
return; return;
} }
RsThread::async( [this,checked]() {
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
uint32_t token; rsPosted->setCommentReadStatus(msgPair, !checked);
rsPosted->setMessageReadStatus(token, msgPair, !checked);
RsQThreadUtils::postToObject( [this,checked]() {
setReadStatus(false, checked); setReadStatus(false, checked);
} );
});
} }
void BaseBoardsCommentsItem::readAndClearItem() void BaseBoardsCommentsItem::readAndClearItem()

View file

@ -617,7 +617,7 @@ void ChannelsCommentsItem::readToggled(bool /*checked*/)
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
rsGxsChannels->markRead(msgPair, isUnread()); rsGxsChannels->setCommentReadStatus(msgPair, isUnread());
//setReadStatus(false, checked); // Updated by events //setReadStatus(false, checked); // Updated by events
} }

View file

@ -850,7 +850,7 @@ void GxsChannelPostItem::readToggled(bool /*checked*/)
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
rsGxsChannels->markRead(msgPair, isUnread()); rsGxsChannels->setMessageReadStatus(msgPair, isUnread());
//setReadStatus(false, checked); // Updated by events //setReadStatus(false, checked); // Updated by events
} }

View file

@ -481,12 +481,15 @@ void GxsForumMsgItem::setAsRead()
mCloseOnRead = false; mCloseOnRead = false;
RsThread::async( [this]() {
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
uint32_t token; rsGxsForums->markRead(msgPair, true);
rsGxsForums->setMessageReadStatus(token, msgPair, true);
setReadStatus(false, false); RsQThreadUtils::postToObject( [this]() {
setReadStatus(false, true);
} );
});
} }
void GxsForumMsgItem::on_linkActivated(QString link) void GxsForumMsgItem::on_linkActivated(QString link)

View file

@ -60,7 +60,7 @@ void GxsCommentContainer::commentLoad(const RsGxsGroupId &grpId, const std::set<
comments += "..."; comments += "...";
} }
GxsCommentDialog *commentDialog = new GxsCommentDialog(this, RsGxsId(),getTokenService(), getCommentService()); GxsCommentDialog *commentDialog = new GxsCommentDialog(this, RsGxsId(),getCommentService());
QWidget *commentHeader = createHeaderWidget(grpId, msgId); QWidget *commentHeader = createHeaderWidget(grpId, msgId);
commentDialog->setCommentHeader(commentHeader); commentDialog->setCommentHeader(commentHeader);

View file

@ -30,13 +30,13 @@
#include <QDateTime> #include <QDateTime>
/** Constructor */ /** Constructor */
GxsCommentDialog::GxsCommentDialog(QWidget *parent, const RsGxsId &default_author, RsTokenService *token_service, RsGxsCommentService *comment_service) GxsCommentDialog::GxsCommentDialog(QWidget *parent, const RsGxsId &default_author, RsGxsCommentService *comment_service)
: QWidget(parent), ui(new Ui::GxsCommentDialog) : QWidget(parent), ui(new Ui::GxsCommentDialog)
{ {
/* Invoke the Qt Designer generated QObject setup routine */ /* Invoke the Qt Designer generated QObject setup routine */
ui->setupUi(this); ui->setupUi(this);
setTokenService(token_service,comment_service); setTokenService(comment_service);
init(default_author); init(default_author);
} }
@ -67,9 +67,9 @@ void GxsCommentDialog::init(const RsGxsId& default_author)
ui->sortBox->setIconSize(QSize(S*1.5,S*1.5)); ui->sortBox->setIconSize(QSize(S*1.5,S*1.5));
} }
void GxsCommentDialog::setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service) void GxsCommentDialog::setTokenService(RsGxsCommentService *comment_service)
{ {
ui->treeWidget->setup(token_service, comment_service); ui->treeWidget->setup(comment_service);
} }
GxsCommentDialog::GxsCommentDialog(QWidget *parent,const RsGxsId &default_author) GxsCommentDialog::GxsCommentDialog(QWidget *parent,const RsGxsId &default_author)

View file

@ -33,10 +33,10 @@ class GxsCommentDialog: public QWidget
public: public:
GxsCommentDialog(QWidget *parent=nullptr,const RsGxsId& default_author=RsGxsId()); GxsCommentDialog(QWidget *parent=nullptr,const RsGxsId& default_author=RsGxsId());
GxsCommentDialog(QWidget *parent,const RsGxsId& default_author, RsTokenService *token_service, RsGxsCommentService *comment_service); GxsCommentDialog(QWidget *parent, const RsGxsId& default_author, RsGxsCommentService *comment_service);
virtual ~GxsCommentDialog(); virtual ~GxsCommentDialog();
void setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service); void setTokenService(RsGxsCommentService *comment_service);
void setCommentHeader(QWidget *header); void setCommentHeader(QWidget *header);
void commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId> &msg_versions, const RsGxsMessageId &most_recent_msgId, bool use_cache=false); void commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId> &msg_versions, const RsGxsMessageId &most_recent_msgId, bool use_cache=false);
void commentClear(); void commentClear();

View file

@ -249,7 +249,7 @@ void GxsCommentTreeWidget::mouseMoveEvent(QMouseEvent *e)
} }
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent) GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
:QTreeWidget(parent), mTokenQueue(NULL), mRsTokenService(NULL), mCommentService(NULL) :QTreeWidget(parent), mCommentService(NULL)
{ {
setVerticalScrollMode(ScrollPerPixel); setVerticalScrollMode(ScrollPerPixel);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
@ -299,9 +299,6 @@ void GxsCommentTreeWidget::updateContent()
} }
GxsCommentTreeWidget::~GxsCommentTreeWidget() GxsCommentTreeWidget::~GxsCommentTreeWidget()
{ {
if (mTokenQueue) {
delete(mTokenQueue);
}
} }
void GxsCommentTreeWidget::setCurrentCommentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous) void GxsCommentTreeWidget::setCurrentCommentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
@ -420,10 +417,6 @@ void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageI
QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string)); QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string));
}); });
}); });
// uint32_t token;
// mCommentService->createNewVote(token, vote);
// mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK);
} }
@ -478,11 +471,9 @@ void GxsCommentTreeWidget::copyComment()
clipboard->setMimeData(mimeData, QClipboard::Clipboard); clipboard->setMimeData(mimeData, QClipboard::Clipboard);
} }
void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service) void GxsCommentTreeWidget::setup(RsGxsCommentService *comment_service)
{ {
mRsTokenService = token_service;
mCommentService = comment_service; mCommentService = comment_service;
mTokenQueue = new TokenQueue(token_service, this);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint)));
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentCommentMsgId(QTreeWidgetItem*, QTreeWidgetItem*))); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentCommentMsgId(QTreeWidgetItem*, QTreeWidgetItem*)));
@ -743,36 +734,6 @@ int GxsCommentTreeWidget::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent)
} }
return count; return count;
} }
// void GxsCommentTreeWidget::loadThread(const uint32_t &token)
// {
// clearItems();
//
// service_loadThread(token);
//
// completeItems();
//
// emit commentsLoaded(treeCount(this));
// }
void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token)
{
RsGxsGrpMsgIdPair msgId;
mCommentService->acknowledgeComment(token, msgId);
// simply reload data
service_requestComments(mGroupId,mMsgVersions);
}
void GxsCommentTreeWidget::acknowledgeVote(const uint32_t &token)
{
RsGxsGrpMsgIdPair msgId;
if (mCommentService->acknowledgeVote(token, msgId))
{
// reload data if vote was added.
service_requestComments(mGroupId,mMsgVersions);
}
}
void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& comments) void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& comments)
{ {
@ -796,32 +757,6 @@ void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& c
insertComments(comments); insertComments(comments);
} }
// void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
// {
// std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
// std::cerr << std::endl;
//
// std::vector<RsGxsComment> comments;
// mCommentService->getRelatedComments(token, comments);
//
// // This is inconsistent since we cannot know here that all comments are for the same thread. However they are only
// // requested in requestComments() where a single MsgId is used.
//
// if(mUseCache)
// {
// QMutexLocker lock(&mCacheMutex);
//
// if(!comments.empty())
// {
// std::cerr << "Updating cache with " << comments.size() << " for thread " << comments[0].mMeta.mThreadId << std::endl;
// mCommentsCache[comments[0].mMeta.mThreadId] = comments;
// }
// }
//
// insertComments(comments);
// }
void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments) void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments)
{ {
std::list<RsGxsMessageId> new_comments; std::list<RsGxsMessageId> new_comments;
@ -892,10 +827,7 @@ void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comme
// now set all loaded comments as not new, since they have been loaded. // now set all loaded comments as not new, since they have been loaded.
for(auto cid:new_comments) for(auto cid:new_comments)
{ mCommentService->setCommentReadStatus(RsGxsGrpMsgIdPair(mGroupId,cid),true);
uint32_t token=0;
mCommentService->setCommentAsRead(token,mGroupId,cid);
}
} }
QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent) QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent)
@ -923,50 +855,3 @@ QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMess
return item; return item;
} }
void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std::cerr << "GxsCommentTreeWidget::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
#endif
if (queue != mTokenQueue)
{
std::cerr << "GxsCommentTreeWidget::loadRequest() Queue ERROR";
std::cerr << std::endl;
return;
}
/* now switch on req */
switch(req.mType)
{
case TOKENREQ_MSGINFO:
{
switch(req.mAnsType)
{
case RS_TOKREQ_ANSTYPE_ACK:
if (req.mUserType == COMMENT_VOTE_ACK)
{
acknowledgeVote(req.mToken);
}
else
{
acknowledgeComment(req.mToken);
}
break;
// case RS_TOKREQ_ANSTYPE_DATA:
// loadThread(req.mToken);
// break;
}
}
break;
default:
std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType ";
std::cerr << std::endl;
break;
}
}

View file

@ -24,26 +24,24 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QMutex> #include <QMutex>
#include "util/TokenQueue.h"
#include <retroshare/rsgxscommon.h> #include <retroshare/rsgxscommon.h>
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
class RSTreeWidgetItemCompareRole; class RSTreeWidgetItemCompareRole;
class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse class GxsCommentTreeWidget : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GxsCommentTreeWidget(QWidget *parent = 0); GxsCommentTreeWidget(QWidget *parent = 0);
~GxsCommentTreeWidget(); ~GxsCommentTreeWidget();
void setup(RsTokenService *token_service, RsGxsCommentService *comment_service); void setup(RsGxsCommentService *comment_service);
void requestComments(const RsGxsGroupId& group, const std::set<RsGxsMessageId> &message_versions, const RsGxsMessageId &most_recent_message); void requestComments(const RsGxsGroupId& group, const std::set<RsGxsMessageId> &message_versions, const RsGxsMessageId &most_recent_message);
void getCurrentMsgId(RsGxsMessageId& parentId); void getCurrentMsgId(RsGxsMessageId& parentId);
void applyRankings(std::map<RsGxsMessageId, uint32_t>& positions); void applyRankings(std::map<RsGxsMessageId, uint32_t>& positions);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void setVoteId(const RsGxsId &voterId); void setVoteId(const RsGxsId &voterId);
void setUseCache(bool b) { mUseCache = b ;} void setUseCache(bool b) { mUseCache = b ;}
@ -63,11 +61,6 @@ protected:
void clearItems(); void clearItems();
void completeItems(); void completeItems();
void acknowledgeComment(const uint32_t& token);
void acknowledgeVote(const uint32_t &token);
//void loadThread(const uint32_t &token);
void insertComments(const std::vector<RsGxsComment>& comments); void insertComments(const std::vector<RsGxsComment>& comments);
void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item); void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item);
@ -114,8 +107,6 @@ protected:
RSTreeWidgetItemCompareRole *commentsRole; RSTreeWidgetItemCompareRole *commentsRole;
TokenQueue *mTokenQueue;
RsTokenService *mRsTokenService;
RsGxsCommentService *mCommentService; RsGxsCommentService *mCommentService;
bool mUseCache; bool mUseCache;

View file

@ -724,7 +724,7 @@ void GxsGroupFrameDialog::loadComment(const RsGxsGroupId &grpId, const QVector<R
comments += ""; comments += "";
} }
commentDialog = new GxsCommentDialog(this,RsGxsId(), mInterface->getTokenService(), commentService); commentDialog = new GxsCommentDialog(this,RsGxsId(), commentService);
QWidget *commentHeader = createCommentHeaderWidget(grpId, most_recent_msgId); QWidget *commentHeader = createCommentHeaderWidget(grpId, most_recent_msgId);
if (commentHeader) { if (commentHeader) {

View file

@ -798,7 +798,7 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status)
for(uint32_t i=0;i<pairs.size();++i) for(uint32_t i=0;i<pairs.size();++i)
RsThread::async([p=pairs[i], read_status]() // use async because each markRead() waits for the token to complete in order to properly acknowledge it. RsThread::async([p=pairs[i], read_status]() // use async because each markRead() waits for the token to complete in order to properly acknowledge it.
{ {
if(!rsGxsChannels->markRead(p,read_status)) if(!rsGxsChannels->setMessageReadStatus(p,read_status))
RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl; RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl;
}); });
} }
@ -816,7 +816,7 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size()) if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
return ; return ;
rsGxsChannels->markRead(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status); rsGxsChannels->setMessageReadStatus(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status);
} }
QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const

View file

@ -487,7 +487,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
setAutoDownload(false); setAutoDownload(false);
#endif #endif
ui->commentsDialog->setTokenService(rsGxsChannels->getTokenService(),rsGxsChannels); ui->commentsDialog->setTokenService(rsGxsChannels);
/* Initialize GUI */ /* Initialize GUI */
settingsChanged(); settingsChanged();
@ -852,7 +852,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
postId.second = post.mMeta.mMsgId; postId.second = post.mMeta.mMsgId;
postId.first = post.mMeta.mGroupId; postId.first = post.mMeta.mGroupId;
RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } ); RsThread::async([postId]() { rsGxsChannels->setMessageReadStatus(postId, true) ; } );
} }
updateDAll_PB(); updateDAll_PB();