Merge pull request #2623 from csoler/v0.6-TokenSystem

V0.6 token system
This commit is contained in:
csoler 2022-07-12 15:19:33 +02:00 committed by GitHub
commit c280d030aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 454 additions and 660 deletions

@ -1 +1 @@
Subproject commit 6abbec95073f3c1eb5059cbf8441111ef4a317a7
Subproject commit 659423769541169457c41f71c8a038e2d64ba079

@ -1 +1 @@
Subproject commit 72f8b7e8e240923731a141c6f2a0438588f04f59
Subproject commit 86745109f35dddbf9de9ff84537a1c97fa1d30b3

View File

@ -25,6 +25,7 @@
#include "gui/Circles/CirclesDialog.h"
#include "gui/Circles/CreateCircleDialog.h"
#include "gui/common/UIStateHelper.h"
#include "util/qtthreadsutils.h"
#include <retroshare/rsgxscircles.h>
#include <retroshare/rspeers.h>
@ -72,9 +73,6 @@ CirclesDialog::CirclesDialog(QWidget *parent)
connect(ui.treeWidget_membership, SIGNAL(itemSelectionChanged()), this, SLOT(circle_selected()));
/* Setup TokenQueue */
mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
/* Set header resize modes and initial section sizes */
QHeaderView * membership_header = ui.treeWidget_membership->header () ;
membership_header->resizeSection ( CIRCLEGROUP_CIRCLE_COL_GROUPNAME, 200 );
@ -82,7 +80,6 @@ CirclesDialog::CirclesDialog(QWidget *parent)
CirclesDialog::~CirclesDialog()
{
delete mCircleQueue;
}
void CirclesDialog::todo()
@ -564,38 +561,36 @@ void CirclesDialog::requestGroupMeta()
{
mStateHelper->setLoading(CIRCLESDIALOG_GROUPMETA, true);
std::cerr << "CirclesDialog::requestGroupMeta()";
std::cerr << std::endl;
RsThread::async([this]()
{
std::list<RsGroupMetaData> circles;
mCircleQueue->cancelActiveRequestTokens(CIRCLESDIALOG_GROUPMETA);
if(!rsGxsCircles->getCirclesSummaries(circles))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to get circles summaries " << std::endl;
return;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
RsQThreadUtils::postToObject( [this,circles]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete, note that
* Qt::QueuedConnection is important!
*/
uint32_t token;
mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, CIRCLESDIALOG_GROUPMETA);
loadGroupMeta(circles);
}, this );
});
}
void CirclesDialog::loadGroupMeta(const uint32_t &token)
void CirclesDialog::loadGroupMeta(const std::list<RsGroupMetaData>& groupInfo)
{
mStateHelper->setLoading(CIRCLESDIALOG_GROUPMETA, false);
std::cerr << "CirclesDialog::loadGroupMeta()";
std::cerr << std::endl;
ui.treeWidget_membership->clear();
std::list<RsGroupMetaData> groupInfo;
std::list<RsGroupMetaData>::iterator vit;
if (!rsGxsCircles->getGroupSummary(token,groupInfo))
{
std::cerr << "CirclesDialog::loadGroupMeta() Error getting GroupMeta";
std::cerr << std::endl;
mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, false);
return;
}
mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, true);
/* add the top level item */
@ -615,7 +610,7 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token)
externalOtherCirclesItem->setText(0, tr("External Circles (Other)"));
ui.treeWidget_membership->addTopLevelItem(externalOtherCirclesItem);
for(vit = groupInfo.begin(); vit != groupInfo.end(); ++vit)
for(auto vit = groupInfo.begin(); vit != groupInfo.end(); ++vit)
{
/* Add Widget, and request Pages */
std::cerr << "CirclesDialog::loadGroupMeta() GroupId: " << vit->mGroupId;
@ -647,25 +642,3 @@ void CirclesDialog::loadGroupMeta(const uint32_t &token)
}
}
}
void CirclesDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
std::cerr << "CirclesDialog::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
if (queue == mCircleQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case CIRCLESDIALOG_GROUPMETA:
loadGroupMeta(req.mToken);
break;
default:
std::cerr << "CirclesDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
}
}
}

View File

@ -24,14 +24,13 @@
#define MRK_CIRCLE_DIALOG_H
#include "gui/gxs/RsGxsUpdateBroadcastPage.h"
#include "util/TokenQueue.h"
#include "ui_CirclesDialog.h"
#define IMAGE_CIRCLES ":/icons/png/circles.png"
class UIStateHelper;
class CirclesDialog : public MainPage, public TokenResponse
class CirclesDialog : public MainPage
{
Q_OBJECT
@ -43,8 +42,6 @@ public:
virtual QString pageName() const { return tr("Circles") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected:
virtual void updateDisplay(bool complete);
@ -62,9 +59,8 @@ private:
void reloadAll();
void requestGroupMeta();
void loadGroupMeta(const uint32_t &token);
void loadGroupMeta(const std::list<RsGroupMetaData>& groupInfo);
TokenQueue *mCircleQueue;
UIStateHelper *mStateHelper;
/* UI - from Designer */

View File

@ -422,7 +422,7 @@ void CreateCircleDialog::createCircle()
close() ;
return ;
}
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle()";
std::cerr << std::endl;
@ -431,10 +431,10 @@ void CreateCircleDialog::createCircle()
QString name = ui.circleName->text();
if(name.isEmpty()) {
/* error message */
QMessageBox::warning(this, tr("RetroShare"),tr("Please set a name for your Circle"), QMessageBox::Ok, QMessageBox::Ok);
/* error message */
QMessageBox::warning(this, tr("RetroShare"),tr("Please set a name for your Circle"), QMessageBox::Ok, QMessageBox::Ok);
return; //Don't add a empty Subject!!
return; //Don't add a empty Subject!!
}
RsGxsCircleGroup circle = mCircleGroup; // init with loaded group
@ -448,23 +448,23 @@ void CreateCircleDialog::createCircle()
{
case GxsIdChooser::KnowId:
case GxsIdChooser::UnKnowId:
circle.mMeta.mAuthorId = authorId;
circle.mMeta.mAuthorId = authorId;
circle.mMeta.mAuthenFlags = GXS_SERV::GRP_OPTION_AUTHEN_AUTHOR_SIGN;
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() AuthorId: " << authorId;
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() AuthorId: " << authorId;
std::cerr << std::endl;
#endif
break;
break;
case GxsIdChooser::NoId:
case GxsIdChooser::None:
circle.mMeta.mAuthorId.clear();
circle.mMeta.mAuthenFlags = 0;
default: ;
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() No AuthorId Chosen!";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() No AuthorId Chosen!";
std::cerr << std::endl;
#endif
}
@ -472,144 +472,163 @@ void CreateCircleDialog::createCircle()
/* copy Ids from GUI */
QTreeWidget *tree = ui.treeWidget_membership;
int count = tree->topLevelItemCount();
for(int i = 0; i < count; ++i)
for(int i = 0; i < count; ++i)
{
QTreeWidgetItem *item = tree->topLevelItem(i);
QString keyId = item->text(RSCIRCLEID_COL_KEYID);
QTreeWidgetItem *item = tree->topLevelItem(i);
QString keyId = item->text(RSCIRCLEID_COL_KEYID);
/* insert into circle */
if (mIsExternalCircle)
{
RsGxsId key_id_gxs(keyId.toStdString()) ;
/* insert into circle */
if (mIsExternalCircle)
{
RsGxsId key_id_gxs(keyId.toStdString()) ;
if(key_id_gxs.isNull())
{
std::cerr << "Error: Not a proper keyID: " << keyId.toStdString() << std::endl;
continue ;
}
if(key_id_gxs.isNull())
{
std::cerr << "Error: Not a proper keyID: " << keyId.toStdString() << std::endl;
continue ;
}
circle.mInvitedMembers.insert(key_id_gxs) ;
circle.mInvitedMembers.insert(key_id_gxs) ;
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() Inserting Member: " << keyId.toStdString();
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Inserting Member: " << keyId.toStdString();
std::cerr << std::endl;
#endif
}
else
{
RsPgpId key_id_pgp(keyId.toStdString()) ;
}
else
{
RsPgpId key_id_pgp(keyId.toStdString()) ;
if(key_id_pgp.isNull())
{
std::cerr << "Error: Not a proper PGP keyID: " << keyId.toStdString() << std::endl;
continue ;
}
if(key_id_pgp.isNull())
{
std::cerr << "Error: Not a proper PGP keyID: " << keyId.toStdString() << std::endl;
continue ;
}
circle.mLocalFriends.insert(key_id_pgp) ;
circle.mLocalFriends.insert(key_id_pgp) ;
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() Inserting Friend: " << keyId.toStdString();
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Inserting Friend: " << keyId.toStdString();
std::cerr << std::endl;
#endif
}
}
}
if (mIsExternalCircle)
if (mIsExternalCircle)
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() External Circle";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() External Circle";
std::cerr << std::endl;
#endif
// set distribution from GUI.
circle.mMeta.mCircleId.clear() ;
// set distribution from GUI.
circle.mMeta.mCircleId.clear() ;
circle.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC;
if (ui.radioButton_Public->isChecked()) {
if (ui.radioButton_Public->isChecked()) {
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() Public Circle";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Public Circle";
std::cerr << std::endl;
#endif
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
} else if (ui.radioButton_Self->isChecked()) {
} else if (ui.radioButton_Self->isChecked()) {
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() ExtSelfRef Circle";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() ExtSelfRef Circle";
std::cerr << std::endl;
#endif
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXT_SELF;
} else if (ui.radioButton_Restricted->isChecked()) {
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXT_SELF;
} else if (ui.radioButton_Restricted->isChecked()) {
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() External (Other) Circle";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() External (Other) Circle";
std::cerr << std::endl;
#endif
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_EXTERNAL;
/* grab circle ID from chooser */
RsGxsCircleId chosenId;
if (ui.circleComboBox->getChosenCircle(chosenId)) {
/* grab circle ID from chooser */
RsGxsCircleId chosenId;
if (ui.circleComboBox->getChosenCircle(chosenId)) {
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() ChosenId: " << chosenId;
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() ChosenId: " << chosenId;
std::cerr << std::endl;
#endif
circle.mMeta.mCircleId = chosenId;
} else {//if (ui.circleComboBox->getChosenCircle(chosenId))
circle.mMeta.mCircleId = chosenId;
} else {//if (ui.circleComboBox->getChosenCircle(chosenId))
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() Error no Id Chosen";
std::cerr << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Error no Id Chosen";
std::cerr << std::endl;
#endif
QMessageBox::warning(this, tr("RetroShare"),tr("No Restriction Circle Selected"), QMessageBox::Ok, QMessageBox::Ok);
return;
}//else (ui.circleComboBox->getChosenCircle(chosenId))
}
else
{
QMessageBox::warning(this, tr("RetroShare"),tr("No Circle Limitations Selected"), QMessageBox::Ok, QMessageBox::Ok);
return;
}
}
else
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() Personal Circle";
std::cerr << std::endl;
#endif
// set personal distribution
circle.mMeta.mCircleId.clear() ;
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_LOCAL;
}
uint32_t token;
if(mIsExistingCircle)
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::updateCircle() : mCircleType: " << circle.mMeta.mCircleType << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() : mCircleId: " << circle.mMeta.mCircleId << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() : mGroupId: " << circle.mMeta.mGroupId << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() Checks and Balances Okay - calling service proper.."<< std::endl;
#endif
rsGxsCircles->updateGroup(token, circle);
QMessageBox::warning(this, tr("RetroShare"),tr("No Restriction Circle Selected"), QMessageBox::Ok, QMessageBox::Ok);
return;
}//else (ui.circleComboBox->getChosenCircle(chosenId))
}
else
{
QMessageBox::warning(this, tr("RetroShare"),tr("No Circle Limitations Selected"), QMessageBox::Ok, QMessageBox::Ok);
return;
}
}
else
{
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() : mCircleType: " << circle.mMeta.mCircleType << std::endl;
std::cerr << "CreateCircleDialog::createCircle() : mCircleId: " << circle.mMeta.mCircleId << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Checks and Balances Okay - calling service proper.."<< std::endl;
std::cerr << "CreateCircleDialog::createCircle() Personal Circle";
std::cerr << std::endl;
#endif
rsGxsCircles->createGroup(token, circle);
// set personal distribution
circle.mMeta.mCircleId.clear() ;
circle.mMeta.mCircleType = GXS_CIRCLE_TYPE_LOCAL;
}
RsThread::async([&circle,this]()
{
RsGxsCircleId circleId;
if(mIsExistingCircle)
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::updateCircle() : mCircleType: " << circle.mMeta.mCircleType << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() : mCircleId: " << circle.mMeta.mCircleId << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() : mGroupId: " << circle.mMeta.mGroupId << std::endl;
std::cerr << "CreateCircleDialog::updateCircle() Checks and Balances Okay - calling service proper.."<< std::endl;
#endif
rsGxsCircles->editCircle(circle);
circleId = RsGxsCircleId(circle.mMeta.mGroupId);
}
else
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::createCircle() : mCircleType: " << circle.mMeta.mCircleType << std::endl;
std::cerr << "CreateCircleDialog::createCircle() : mCircleId: " << circle.mMeta.mCircleId << std::endl;
std::cerr << "CreateCircleDialog::createCircle() Checks and Balances Okay - calling service proper.."<< std::endl;
#endif
rsGxsCircles->createCircle(circle.mMeta.mGroupName,
static_cast<RsGxsCircleType>(circle.mMeta.mCircleType),
circleId,
circle.mMeta.mCircleId,
circle.mMeta.mAuthorId,
circle.mInvitedMembers,
circle.mLocalFriends);
}
RsQThreadUtils::postToObject( [this,circle,circleId]()
{
if(!mIsExistingCircle)
QMessageBox::information(nullptr,tr("Circle created"),
tr("Your new circle has been created:\n Name: %1\n Id: %2.")
.arg(QString::fromUtf8(circle.mMeta.mGroupName.c_str()))
.arg(QString::fromStdString(circleId.toStdString())));
});
});
close();
}
@ -810,11 +829,6 @@ void CreateCircleDialog::loadIdentities()
void CreateCircleDialog::fillIdentitiesList(const std::vector<RsGxsIdGroup>& id_groups)
{
#ifdef DEBUG_CREATE_CIRCLE_DIALOG
std::cerr << "CreateCircleDialog::loadIdentities(" << token << ")";
std::cerr << std::endl;
#endif
QTreeWidget *tree = ui.treeWidget_IdList;
tree->clear();

View File

@ -23,7 +23,6 @@
#include <QDialog>
#include "util/TokenQueue.h"
#include <retroshare/rsidentity.h>
namespace Ui {

View File

@ -23,7 +23,6 @@
#include <inttypes.h>
#include "util/TokenQueue.h"
#include <retroshare/rsidentity.h>
#include <retroshare/rsgxsifacetypes.h>
#include <QDialog>
@ -71,7 +70,6 @@ private:
void updateIdType(bool pseudo);
void loadExistingId(const RsGxsIdGroup& id_group);
void setAvatar(const QPixmap &avatar);
void idCreated(uint32_t token);
void loadRecognTags();
// extract details.

View File

@ -28,6 +28,7 @@
#include "ui_PostedCreatePostDialog.h"
#include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "util/RichTextEdit.h"
#include "gui/feeds/SubFileItem.h"
#include "util/rsdir.h"
@ -178,10 +179,20 @@ void PostedCreatePostDialog::createPost()
return;
}
uint32_t token;
mPosted->createPost(token, post);
RsThread::async([this,post]()
{
RsGxsMessageId post_id;
accept();
bool res = rsPosted->createPost(post,post_id);
RsQThreadUtils::postToObject( [res,this]()
{
if(!res)
QMessageBox::information(nullptr,tr("Error while creating post"),tr("An error occurred while creating the post."));
accept();
}, this );
});
}
void PostedCreatePostDialog::fileHashingFinished(QList<HashedFile> hashedFiles)

View File

@ -217,34 +217,6 @@ QWidget *PostedDialog::createCommentHeaderWidget(const RsGxsGroupId &grpId, cons
return new PostedItem(NULL, 0, grpId, msgId, true, false);
}
#ifdef TO_REMOVE
void PostedDialog::loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata *&userdata)
{
std::vector<RsPostedGroup> groups;
rsPosted->getGroupData(token, groups);
/* Save groups to fill description */
PostedGroupInfoData *postedData = new PostedGroupInfoData;
userdata = postedData;
std::vector<RsPostedGroup>::iterator groupIt;
for (groupIt = groups.begin(); groupIt != groups.end(); ++groupIt) {
RsPostedGroup &group = *groupIt;
groupInfo.push_back(group.mMeta);
if (group.mGroupImage.mData != NULL) {
QPixmap image;
GxsIdDetails::loadPixmapFromData(group.mGroupImage.mData, group.mGroupImage.mSize, image,GxsIdDetails::ORIGINAL);
postedData->mIcon[group.mMeta.mGroupId] = image;
}
if (!group.mDescription.empty()) {
postedData->mDescription[group.mMeta.mGroupId] = QString::fromUtf8(group.mDescription.c_str());
}
}
}
#endif
void PostedDialog::groupInfoToGroupItemInfo(const RsGxsGenericGroupData *groupData, GroupItemInfo &groupItemInfo)
{
GxsGroupFrameDialog::groupInfoToGroupItemInfo(groupData, groupItemInfo);

View File

@ -279,16 +279,20 @@ void BasePostedItem::loadComments()
}
void BasePostedItem::readToggled(bool checked)
{
if (mInFill) {
return;
}
if (mInFill) {
return;
}
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
RsThread::async([this,checked]()
{
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
rsPosted->setPostReadStatus(msgPair, !checked);
uint32_t token;
rsPosted->setMessageReadStatus(token, msgPair, !checked);
setReadStatus(false, checked);
RsQThreadUtils::postToObject( [checked,this]()
{
setReadStatus(false, checked);
}, this );
});
}
void BasePostedItem::readAndClearItem()

View File

@ -773,7 +773,7 @@ QIcon PostedListWidgetWithModel::groupIcon()
return QIcon(postedImage);
}
void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &/*token*/)
void PostedListWidgetWithModel::setAllMessagesReadDo(bool read)
{
if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags))
return;
@ -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);
@ -1190,8 +1190,7 @@ void PostedListWidgetWithModel::subscribeGroup(bool subscribe)
RsThread::async([=]()
{
uint32_t token;
rsPosted->subscribeToGroup(token,grpId, subscribe);
rsPosted->subscribeToBoard(grpId, subscribe);
} );
}
@ -1204,7 +1203,14 @@ void PostedListWidgetWithModel::voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down)
return;
}
rsPosted->voteForPost(up_or_down,msg.first,msg.second,voter_id);
RsGxsVoteType tvote = up_or_down?(RsGxsVoteType::UP):(RsGxsVoteType::DOWN);
std::string error_str;
RsGxsMessageId vote_id;
if(!rsPosted->voteForPost(msg.first,msg.second,voter_id,tvote,vote_id,error_str))
QMessageBox::critical(nullptr,tr("Could not vote"), tr("Error occured while voting: ")+QString::fromStdString(error_str));
else
updateDisplay(true);
}
#ifdef TODO

View File

@ -130,7 +130,7 @@ protected:
#endif
/* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
virtual void setAllMessagesReadDo(bool read) override;
private slots:
#ifdef TO_REMOVE

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);
setGxsService(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::setGxsService(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 setGxsService(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

@ -25,12 +25,14 @@
#include "gui/common/RSTreeWidgetItem.h"
#include "gui/gxs/GxsCreateCommentDialog.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h"
#include "util/qtthreadsutils.h"
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QTextEdit>
#include <QHeaderView>
#include <QClipboard>
#include <QMessageBox>
#include <QDateTime>
#include <QMenu>
#include <QMimeData>
@ -247,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);
@ -297,9 +299,6 @@ void GxsCommentTreeWidget::updateContent()
}
GxsCommentTreeWidget::~GxsCommentTreeWidget()
{
if (mTokenQueue) {
delete(mTokenQueue);
}
}
void GxsCommentTreeWidget::setCurrentCommentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous)
@ -401,35 +400,23 @@ void GxsCommentTreeWidget::setVoteId(const RsGxsId &voterId)
void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId,
const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up)
{
RsGxsVote vote;
RsThread::async([this,groupId,threadId,parentId,authorId,up]()
{
std::string error_string;
RsGxsMessageId vote_id;
RsGxsVoteType tvote = up?(RsGxsVoteType::UP):(RsGxsVoteType::DOWN);
vote.mMeta.mGroupId = groupId;
vote.mMeta.mThreadId = threadId;
vote.mMeta.mParentId = parentId;
vote.mMeta.mAuthorId = authorId;
bool res = mCommentService->voteForComment(groupId, threadId, parentId, authorId,tvote,vote_id, error_string);
if (up)
{
vote.mVoteType = GXS_VOTE_UP;
}
else
{
vote.mVoteType = GXS_VOTE_DOWN;
}
RsQThreadUtils::postToObject( [this,res,error_string]()
{
#ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std::cerr << "GxsCommentTreeWidget::vote()";
std::cerr << std::endl;
std::cerr << "GroupId : " << vote.mMeta.mGroupId << std::endl;
std::cerr << "ThreadId : " << vote.mMeta.mThreadId << std::endl;
std::cerr << "ParentId : " << vote.mMeta.mParentId << std::endl;
std::cerr << "AuthorId : " << vote.mMeta.mAuthorId << std::endl;
#endif
uint32_t token;
mCommentService->createNewVote(token, vote);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK);
if(res)
service_requestComments(mGroupId,mMsgVersions);
else
QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string));
});
});
}
@ -484,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;
@ -529,25 +514,80 @@ void GxsCommentTreeWidget::service_requestComments(const RsGxsGroupId& group_id,
std::cerr << "GxsCommentTreeWidget::service_requestComments for group " << group_id << std::endl;
#endif
std::vector<RsGxsGrpMsgIdPair> ids_to_ask;
for(std::set<RsGxsMessageId>::const_iterator it(msgIds.begin());it!=msgIds.end();++it)
RsThread::async([this,group_id,msgIds]()
{
#ifdef DEBUG_GXSCOMMENT_TREEWIDGET
std::cerr << " asking for msg " << *it << std::endl;
#endif
std::vector<RsGxsComment> comments;
ids_to_ask.push_back(std::make_pair(group_id,*it));
}
if(!mCommentService->getRelatedComments(group_id,msgIds,comments))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to get comments" << std::endl;
return;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST;
RsQThreadUtils::postToObject( [this,comments]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete, note that
* Qt::QueuedConnection is important!
*/
uint32_t token;
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids_to_ask, GXSCOMMENTS_LOADTHREAD);
clearItems();
service_loadThread(comments);
completeItems();
emit commentsLoaded(treeCount(this));
}, this );
});
}
#ifdef TODO
void GxsCommentTreeWidget::async_msg_action(const CmtMethod &action)
{
RsThread::async([this,action]()
{
// 1 - get message data from p3GxsForums
std::set<RsGxsMessageId> msgs_to_request ;
std::vector<RsGxsForumMsg> msgs;
msgs_to_request.insert(mThreadId);
if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << groupId() << " and thread " << mThreadId << std::endl;
return;
}
if(msgs.size() != 1)
{
std::cerr << __PRETTY_FUNCTION__ << " more than 1 or no msgs selected in forum " << groupId() << std::endl;
return;
}
// 2 - sort the messages into a proper hierarchy
RsGxsForumMsg msg = msgs[0];
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [msg,action,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
(this->*action)(msg);
}, this );
});
}
#endif
/* Generic Handling */
void GxsCommentTreeWidget::clearItems()
@ -673,7 +713,7 @@ void GxsCommentTreeWidget::addItem(RsGxsMessageId itemId, RsGxsMessageId parentI
}
}
int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0)
int GxsCommentTreeWidget::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent)
{
int count = 0;
if (parent == 0)
@ -694,45 +734,11 @@ int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0)
}
return count;
}
void GxsCommentTreeWidget::loadThread(const uint32_t &token)
void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& comments)
{
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 uint32_t &token)
{
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
std::cerr << std::endl;
std::vector<RsGxsComment> comments;
mCommentService->getRelatedComments(token, comments);
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
std::cerr << std::endl;
// 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.
@ -821,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)
@ -852,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 ;}
@ -56,20 +54,17 @@ protected:
/* to be overloaded */
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 std::vector<RsGxsComment>& comments);
virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent);
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);
static int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0);
public slots:
void customPopUpMenu(const QPoint& point);
void setCurrentCommentMsgId(QTreeWidgetItem* current, QTreeWidgetItem* previous);
@ -112,8 +107,6 @@ protected:
RSTreeWidgetItemCompareRole *commentsRole;
TokenQueue *mTokenQueue;
RsTokenService *mRsTokenService;
RsGxsCommentService *mCommentService;
bool mUseCache;

View File

@ -25,7 +25,6 @@
#include <retroshare/rsidentity.h>
#include "retroshare/rsgxscommon.h"
#include "util/TokenQueue.h"
namespace Ui {
class GxsCreateCommentDialog;

View File

@ -52,11 +52,6 @@ protected:
//virtual bool isLoading();
//virtual void fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool complete);
#ifdef TO_REMOVE
/* TokenResponse */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
#endif
protected slots:
void comments(const QString &title);
void copyMessageLink();

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

@ -28,7 +28,6 @@ GxsMessageFrameWidget::GxsMessageFrameWidget(RsGxsIfaceHelper *ifaceImpl, QWidge
{
mNextTokenType = 0;
mTokenQueue = new TokenQueue(ifaceImpl->getTokenService(), this);
mStateHelper = new UIStateHelper(this);
/* Set read status */
@ -46,8 +45,6 @@ GxsMessageFrameWidget::~GxsMessageFrameWidget()
emit waitingChanged(this);
}
delete(mTokenQueue);
}
const RsGxsGroupId &GxsMessageFrameWidget::groupId()
@ -95,34 +92,6 @@ void GxsMessageFrameWidget::setGroupId(const RsGxsGroupId &groupId)
void GxsMessageFrameWidget::setAllMessagesRead(bool read)
{
uint32_t token = 0;
setAllMessagesReadDo(read, token);
if (token) {
/* Wait for acknowlegde of the token */
mAcknowledgeReadStatusToken = token;
mTokenQueue->queueRequest(mAcknowledgeReadStatusToken, 0, 0, mTokenTypeAcknowledgeReadStatus);
mStateHelper->setLoading(mTokenTypeAcknowledgeReadStatus, true);
emit waitingChanged(this);
}
setAllMessagesReadDo(read);
}
void GxsMessageFrameWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
if (queue == mTokenQueue)
{
if (req.mUserType == mTokenTypeAcknowledgeReadStatus) {
if (mAcknowledgeReadStatusToken == req.mToken) {
/* Set read status is finished */
mStateHelper->setLoading(mTokenTypeAcknowledgeReadStatus, false);
emit waitingChanged(this);
}
return;
}
}
std::cerr << "GxsMessageFrameWidget::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
}

View File

@ -22,12 +22,11 @@
#define GXSMESSAGEFRAMEWIDGET_H
#include "gui/gxs/RsGxsUpdateBroadcastWidget.h"
#include "util/TokenQueue.h"
struct RsGxsIfaceHelper;
class UIStateHelper;
class GxsMessageFrameWidget : public QWidget, public TokenResponse
class GxsMessageFrameWidget : public QWidget
{
Q_OBJECT
@ -49,7 +48,6 @@ public:
/* GXS functions */
uint32_t nextTokenType() { return ++mNextTokenType; }
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
signals:
void groupChanged(QWidget *widget);
@ -58,10 +56,9 @@ signals:
void groupDataLoaded();
protected:
virtual void setAllMessagesReadDo(bool read, uint32_t &token) = 0;
virtual void setAllMessagesReadDo(bool read) = 0;
protected:
TokenQueue *mTokenQueue;
UIStateHelper *mStateHelper;
/* Set read status */

View File

@ -24,9 +24,8 @@
#include <QObject>
#include "gui/common/UserNotify.h"
#include "gui/gxs/GxsGroupFrameDialog.h"
#include "util/TokenQueue.h"
struct RsGxsIfaceHelper;
class RsGxsIfaceHelper;
class RsGxsUpdateBroadcastBase;
class GxsUserNotify : public UserNotify

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->setGxsService(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();
@ -1432,7 +1432,7 @@ public:
uint32_t mLastToken;
};
void GxsChannelPostsWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t& /*token*/)
void GxsChannelPostsWidgetWithModel::setAllMessagesReadDo(bool read)
{
if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags))
return;

View File

@ -137,7 +137,7 @@ protected:
#endif
/* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
virtual void setAllMessagesReadDo(bool read) override;
private slots:
void showPostDetails();

View File

@ -39,6 +39,7 @@
#include "util/HandleRichText.h"
#include "util/misc.h"
#include "util/qtthreadsutils.h"
#include <sys/stat.h>
#include <iostream>
@ -60,10 +61,6 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
setAttribute(Qt::WA_DeleteOnClose, true);
/* Setup Queue */
mForumQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
mCirclesQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
mStateHelper->addWidget(CREATEGXSFORUMMSG_FORUMINFO, ui.postButton);
@ -133,8 +130,6 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
CreateGxsForumMsg::~CreateGxsForumMsg()
{
processSettings(false);
delete(mForumQueue);
delete(mCirclesQueue);
}
void CreateGxsForumMsg::processSettings(bool load)
@ -194,59 +189,109 @@ void CreateGxsForumMsg::newMsg()
return;
}
{/* request Data */
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
RsThread::async( [this]()
{
// We only need group Meta information, but forums do not provide it currently
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mForumId);
std::vector<RsGxsForumGroup> forums_info;
rsGxsForums->getForumsInfo(std::list<RsGxsGroupId>{ mForumId },forums_info);
//std::cerr << "ForumsV2Dialog::newMsg() Requesting Group Summary(" << mForumId << ")"<< std::endl;
uint32_t token;
mForumQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, groupIds, CREATEGXSFORUMMSG_FORUMINFO);
}/* request Data */
RsQThreadUtils::postToObject( [this,forums_info]()
{
if(forums_info.size() != 1)
{
RsErr() << "Cannot retrieve group information for forum " << mForumId ;
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
return;
}
auto fg(forums_info.front());
if (mParentId.isNull()) {
const RsGroupMetaData& fi(fg.mMeta);
mForumMetaLoaded = true;
mForumMeta = fi;
if(!fi.mCircleId.isNull())
loadCircleInfo(RsGxsGroupId(fi.mCircleId));
loadFormInformation();
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
},this);
});
if (mParentId.isNull())
{
mStateHelper->setActive(CREATEGXSFORUMMSG_PARENTMSG, true);
mParentMsgLoaded = true;
} else {
}
else
{
mStateHelper->setLoading(CREATEGXSFORUMMSG_PARENTMSG, true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
RsThread::async( [this]() {
GxsMsgReq msgIds;
std::set<RsGxsMessageId> &vect = msgIds[mForumId];
vect.insert(mParentId);
std::vector<RsGxsForumMsg> parent_msgs;
rsGxsForums->getForumContent(mForumId,std::set<RsGxsMessageId>{ mParentId },parent_msgs);
//std::cerr << "ForumsV2Dialog::newMsg() Requesting Parent Summary(" << mParentId << ")";
//std::cerr << std::endl;
RsQThreadUtils::postToObject( [this,parent_msgs]() {
if(parent_msgs.size() != 1)
{
RsErr() << "Cannot get parent message from forum." ;
uint32_t token;
mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, CREATEGXSFORUMMSG_PARENTMSG);
}
mStateHelper->setActive(CREATEGXSFORUMMSG_PARENTMSG, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_PARENTMSG, false);
if (mOrigMsgId.isNull()) {
return ;
}
mParentMsg = parent_msgs.front();
mParentMsgLoaded = true;
loadFormInformation();
},this);
});
}
if (mOrigMsgId.isNull())
{
mStateHelper->setActive(CREATEGXSFORUMMSG_ORIGMSG, true);
mOrigMsgLoaded = true;
} else {
mStateHelper->setLoading(CREATEGXSFORUMMSG_ORIGMSG, true);
}
else
{
mStateHelper->setLoading(CREATEGXSFORUMMSG_ORIGMSG , true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
RsThread::async( [this]() {
GxsMsgReq msgIds;
std::set<RsGxsMessageId> &vect = msgIds[mForumId];
vect.insert(mOrigMsgId);
std::vector<RsGxsForumMsg> orig_msgs;
rsGxsForums->getForumContent(mForumId,std::set<RsGxsMessageId>{ mOrigMsgId },orig_msgs);
//std::cerr << "ForumsV2Dialog::newMsg() Requesting Parent Summary(" << mParentId << ")";
//std::cerr << std::endl;
RsQThreadUtils::postToObject( [this,orig_msgs]() {
if(orig_msgs.size() != 1)
{
RsErr() << "Cannot get parent message from forum." ;
mStateHelper->setActive(CREATEGXSFORUMMSG_ORIGMSG, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_ORIGMSG, false);
return ;
}
mOrigMsg = orig_msgs.front();
mOrigMsgLoaded = true;
loadFormInformation();
},this);
});
uint32_t token;
mForumQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, CREATEGXSFORUMMSG_ORIGMSG);
}
}
@ -330,7 +375,7 @@ void CreateGxsForumMsg::loadFormInformation()
else if (!mParentId.isNull())
{
QString title = QString::fromUtf8(mParentMsg.mMeta.mMsgName.c_str());
name += " " + tr("In Reply to") + ": ";
name += " - " + tr("In Reply to") + ": ";
name += title;
QString text = title;
@ -583,181 +628,52 @@ void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
ui.hashGroupBox->hide();
}
void CreateGxsForumMsg::loadForumInfo(const uint32_t &token)
{
//std::cerr << "CreateGxsForumMsg::loadForumInfo()";
//std::cerr << std::endl;
std::list<RsGroupMetaData> groupInfo;
rsGxsForums->getGroupSummary(token, groupInfo);
if (groupInfo.size() == 1)
{
RsGroupMetaData fi = groupInfo.front();
mForumMeta = fi;
mForumMetaLoaded = true;
if(!fi.mCircleId.isNull())
{
//std::cerr << "Circle ID is not null: " << fi.mCircleId << ": loading circle info to add constraint to the GXS ID chooser." << std::endl;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(RsGxsGroupId(fi.mCircleId));
uint32_t _token;
mCirclesQueue->requestGroupInfo(_token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, CREATEGXSFORUMMSG_CIRCLENFO);
}
loadFormInformation();
}
else
{
std::cerr << "CreateGxsForumMsg::loadForumInfo() ERROR INVALID Number of Forums";
std::cerr << std::endl;
mStateHelper->setActive(CREATEGXSFORUMMSG_FORUMINFO, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_FORUMINFO, false);
}
}
void CreateGxsForumMsg::loadForumCircleInfo(const uint32_t& token)
void CreateGxsForumMsg::loadCircleInfo(const RsGxsGroupId& circle_id)
{
//std::cerr << "Loading forum circle info" << std::endl;
std::vector<RsGxsCircleGroup> circle_grp_v ;
rsGxsCircles->getGroupData(token, circle_grp_v);
if (circle_grp_v.empty())
RsThread::async( [circle_id,this]()
{
std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl;
return ;
}
if (circle_grp_v.size() != 1)
{
std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl;
return ;
}
RsGxsCircleGroup cg = circle_grp_v.front();
std::vector<RsGxsCircleGroup> circle_grp_v ;
rsGxsCircles->getCirclesInfo(std::list<RsGxsGroupId>{ circle_id }, circle_grp_v);
mForumCircleData = cg;
mForumCircleLoaded = true;
//std::cerr << "Loaded content of circle " << cg.mMeta.mGroupId << std::endl;
//for(std::set<RsGxsId>::const_iterator it(cg.mInvitedMembers.begin());it!=cg.mInvitedMembers.end();++it)
// std::cerr << " added constraint to circle element " << *it << std::endl;
ui.idChooser->setIdConstraintSet(cg.mInvitedMembers) ;
ui.idChooser->setFlags(IDCHOOSER_NO_CREATE | ui.idChooser->flags()) ; // since there's a circle involved, no ID creation can be needed
RsGxsId tmpid ;
if(ui.idChooser->countEnabledEntries() == 0)
{
QMessageBox::information(NULL,tr("No compatible ID for this forum"),tr("None of your identities is allowed to post in this forum. This could be due to the forum being limited to a circle that contains none of your identities, or forum flags requiring a PGP-signed identity.")) ;
close() ;
}
}
void CreateGxsForumMsg::loadOrigMsg(const uint32_t &token)
{
//std::cerr << "CreateGxsForumMsg::loadParentMsg()";
//std::cerr << std::endl;
// Only grab one.... ignore more (shouldn't be any).
std::vector<RsGxsForumMsg> msgs;
if (rsGxsForums->getMsgData(token, msgs))
{
if (msgs.size() != 1)
{
/* error */
std::cerr << "CreateGxsForumMsg::loadOrigMsg() ERROR wrong number of msgs";
std::cerr << std::endl;
mStateHelper->setActive(CREATEGXSFORUMMSG_ORIGMSG, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_ORIGMSG, false);
return;
}
mOrigMsg = msgs[0];
mOrigMsgLoaded = true;
loadFormInformation();
}
}
void CreateGxsForumMsg::loadParentMsg(const uint32_t &token)
{
//std::cerr << "CreateGxsForumMsg::loadParentMsg()";
//std::cerr << std::endl;
// Only grab one.... ignore more (shouldn't be any).
std::vector<RsGxsForumMsg> msgs;
if (rsGxsForums->getMsgData(token, msgs))
{
if (msgs.size() != 1)
{
/* error */
std::cerr << "CreateGxsForumMsg::loadParentMsg() ERROR wrong number of msgs";
std::cerr << std::endl;
mStateHelper->setActive(CREATEGXSFORUMMSG_PARENTMSG, false);
mStateHelper->setLoading(CREATEGXSFORUMMSG_PARENTMSG, false);
return;
}
mParentMsg = msgs[0];
mParentMsgLoaded = true;
loadFormInformation();
}
}
void CreateGxsForumMsg::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
//std::cerr << "CreateGxsForum::loadRequest() UserType: " << req.mUserType;
//std::cerr << std::endl;
if (queue == mForumQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case CREATEGXSFORUMMSG_FORUMINFO:
loadForumInfo(req.mToken);
break;
case CREATEGXSFORUMMSG_ORIGMSG:
loadOrigMsg(req.mToken);
break;
case CREATEGXSFORUMMSG_PARENTMSG:
loadParentMsg(req.mToken);
break;
default:
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mForumQueue";
std::cerr << std::endl;
}
}
if(queue == mCirclesQueue)
if (circle_grp_v.empty())
{
switch(req.mUserType)
{
case CREATEGXSFORUMMSG_CIRCLENFO:
loadForumCircleInfo(req.mToken) ;
break ;
default:
std::cerr << "CreateGxsForumMsg::loadRequest() UNKNOWN UserType " << req.mUserType << " for token request in mCirclesQueue";
std::cerr << std::endl;
}
std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl;
return ;
}
if (circle_grp_v.size() != 1)
{
std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl;
return ;
}
RsGxsCircleGroup cg = circle_grp_v.front();
RsQThreadUtils::postToObject( [cg,this]()
{
mForumCircleData = cg;
mForumCircleLoaded = true;
//std::cerr << "Loaded content of circle " << cg.mMeta.mGroupId << std::endl;
//for(std::set<RsGxsId>::const_iterator it(cg.mInvitedMembers.begin());it!=cg.mInvitedMembers.end();++it)
// std::cerr << " added constraint to circle element " << *it << std::endl;
ui.idChooser->setIdConstraintSet(cg.mInvitedMembers) ;
ui.idChooser->setFlags(IDCHOOSER_NO_CREATE | ui.idChooser->flags()) ; // since there's a circle involved, no ID creation can be needed
RsGxsId tmpid ;
if(ui.idChooser->countEnabledEntries() == 0)
{
QMessageBox::information(NULL,tr("No compatible ID for this forum"),tr("None of your identities is allowed to post in this forum. This could be due to the forum being limited to a circle that contains none of your identities, or forum flags requiring a PGP-signed identity.")) ;
close() ;
}
}, this);
});
}
void CreateGxsForumMsg::setSubject(const QString& msg)
{
ui.forumSubject->setText(msg);

View File

@ -23,14 +23,12 @@
#include "ui_CreateGxsForumMsg.h"
#include "util/TokenQueue.h"
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
class UIStateHelper;
class CreateGxsForumMsg : public QDialog, public TokenResponse
class CreateGxsForumMsg : public QDialog
{
Q_OBJECT
@ -39,7 +37,6 @@ public:
~CreateGxsForumMsg();
void newMsg(); /* cleanup */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void insertPastedText(const QString& msg) ;
void setSubject(const QString& msg);
@ -58,15 +55,11 @@ private slots:
protected:
void closeEvent (QCloseEvent * event);
void loadCircleInfo(const RsGxsGroupId& circle_id);
private:
void processSettings(bool load);
void loadFormInformation();
void loadForumInfo(const uint32_t &token);
void loadParentMsg(const uint32_t &token);
void loadOrigMsg(const uint32_t &token);
void loadForumCircleInfo(const uint32_t &token);
RsGxsGroupId mForumId;
RsGxsCircleId mCircleId ;
RsGxsMessageId mParentId;
@ -84,9 +77,6 @@ private:
RsGroupMetaData mForumMeta;
RsGxsCircleGroup mForumCircleData ;
TokenQueue *mForumQueue;
TokenQueue *mCirclesQueue;
UIStateHelper *mStateHelper;
/** Qt Designer generated object */

View File

@ -1503,7 +1503,7 @@ void GxsForumThreadWidget::markMsgAsUnreadChildren()
markMsgAsReadUnread(false, true, false);
}
void GxsForumThreadWidget::setAllMessagesReadDo(bool read, uint32_t &/*token*/)
void GxsForumThreadWidget::setAllMessagesReadDo(bool read)
{
markMsgAsReadUnread(read, true, true);
}

View File

@ -102,7 +102,7 @@ protected:
virtual void updateDisplay(bool complete);
/* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token);
virtual void setAllMessagesReadDo(bool read);
void setMessageLoadingError(const QString& error);
private slots: