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);
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});
commentDialog->commentLoad(post.mMeta.mGroupId, msg_versions, post.mMeta.mMsgId);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -30,13 +30,13 @@
#include <QDateTime>
/** 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)
{
/* Invoke the Qt Designer generated QObject setup routine */
ui->setupUi(this);
setTokenService(token_service,comment_service);
setTokenService(comment_service);
init(default_author);
}
@ -67,9 +67,9 @@ void GxsCommentDialog::init(const RsGxsId& default_author)
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)

View File

@ -33,10 +33,10 @@ class GxsCommentDialog: public QWidget
public:
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();
void setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service);
void setTokenService(RsGxsCommentService *comment_service);
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 commentClear();

View File

@ -249,7 +249,7 @@ void GxsCommentTreeWidget::mouseMoveEvent(QMouseEvent *e)
}
GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
:QTreeWidget(parent), mTokenQueue(NULL), mRsTokenService(NULL), mCommentService(NULL)
:QTreeWidget(parent), mCommentService(NULL)
{
setVerticalScrollMode(ScrollPerPixel);
setContextMenuPolicy(Qt::CustomContextMenu);
@ -299,9 +299,6 @@ void GxsCommentTreeWidget::updateContent()
}
GxsCommentTreeWidget::~GxsCommentTreeWidget()
{
if (mTokenQueue) {
delete(mTokenQueue);
}
}
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));
});
});
// uint32_t token;
// mCommentService->createNewVote(token, vote);
// mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK);
}
@ -478,12 +471,10 @@ void GxsCommentTreeWidget::copyComment()
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;
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*)));
return;
@ -743,36 +734,6 @@ int GxsCommentTreeWidget::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent)
}
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)
{
@ -796,32 +757,6 @@ void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& c
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)
{
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.
for(auto cid:new_comments)
{
uint32_t token=0;
mCommentService->setCommentAsRead(token,mGroupId,cid);
}
mCommentService->setCommentReadStatus(RsGxsGrpMsgIdPair(mGroupId,cid),true);
}
QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent)
@ -923,50 +855,3 @@ QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMess
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 <QMutex>
#include "util/TokenQueue.h"
#include <retroshare/rsgxscommon.h>
#include <retroshare/rsidentity.h>
class RSTreeWidgetItemCompareRole;
class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse
class GxsCommentTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
GxsCommentTreeWidget(QWidget *parent = 0);
~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 getCurrentMsgId(RsGxsMessageId& parentId);
void applyRankings(std::map<RsGxsMessageId, uint32_t>& positions);
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void setVoteId(const RsGxsId &voterId);
void setUseCache(bool b) { mUseCache = b ;}
@ -63,11 +61,6 @@ protected:
void clearItems();
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 addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item);
@ -114,8 +107,6 @@ protected:
RSTreeWidgetItemCompareRole *commentsRole;
TokenQueue *mTokenQueue;
RsTokenService *mRsTokenService;
RsGxsCommentService *mCommentService;
bool mUseCache;

View File

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

View File

@ -798,7 +798,7 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status)
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.
{
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;
});
}
@ -816,7 +816,7 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
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

View File

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