From 347b3ac9aa444b036548c3f253a332f456533480 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 11 Aug 2020 22:10:22 +0200 Subject: [PATCH] added mechanism for voting. Not working yet --- libretroshare/src/retroshare/rsposted.h | 2 ++ libretroshare/src/services/p3posted.cc | 6 ++++++ libretroshare/src/services/p3posted.h | 4 +++- .../gui/Posted/PostedListWidgetWithModel.cpp | 18 +++++++++++++++++- .../src/gui/Posted/PostedListWidgetWithModel.h | 1 + 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 4cd6e8cf4..71350a826 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -172,6 +172,8 @@ public: virtual bool getBoardsServiceStatistics(GxsServiceStatistic& stat) =0; + virtual bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) =0; + enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType }; RS_DEPRECATED_FOR(getBoardsInfo) diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 88ff25808..39b350243 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -442,6 +442,12 @@ bool p3Posted::createBoard(RsPostedGroup& board) return true; } +bool p3Posted::voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) +{ + std::cerr << "(EE) " << __PRETTY_FUNCTION__ << ": Not implemented yet"<< std::endl; + return true; +} + bool p3Posted::editBoard(RsPostedGroup& board) { uint32_t token; diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index bc213ac0d..2bd3c3a0b 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -84,7 +84,9 @@ virtual void receiveHelperChanges(std::vector& changes) bool createBoard(RsPostedGroup& board) override; - virtual bool getGroupData(const uint32_t &token, std::vector &groups) override; + bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) override; + + virtual bool getGroupData(const uint32_t &token, std::vector &groups) override; virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts, std::vector &vots) override; virtual bool getPostData(const uint32_t &token, std::vector &posts, std::vector &cmts) override; virtual bool getPostData(const uint32_t &token, std::vector &posts) override; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 6373fa43a..f949a33f1 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -145,6 +145,8 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie { QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent); + QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),this,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool))); + w->adjustSize(); w->setFixedSize(option.rect.size()); @@ -176,6 +178,8 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI ui->postsTree->sortByColumn(0, Qt::AscendingOrder); ui->postsTree->setAutoSelect(true); + ui->idChooser->setFlags(IDCHOOSER_ID_REQUIRED); + connect(ui->sortStrategy_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(updateSorting(int))); connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts())); connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts())); @@ -630,7 +634,7 @@ void PostedListWidgetWithModel::insertBoardDetails(const RsPostedGroup& group) ui->logoLabel->setPixmap(chanImage); ui->logoLabel->setFixedSize(QSize(ui->logoLabel->height()*chanImage.width()/(float)chanImage.height(),ui->logoLabel->height())); // make the logo have the same aspect ratio than the original image - ui->submitPostButton->setEnabled(bool(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)); + //ui->submitPostButton->setEnabled(bool(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)); ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags)); ui->subscribeToolButton->setEnabled(true); @@ -917,6 +921,18 @@ void PostedListWidgetWithModel::subscribeGroup(bool subscribe) } ); } +void PostedListWidgetWithModel::voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down) +{ + RsGxsId voter_id ; + if(ui->idChooser->getChosenId(voter_id) != GxsIdChooser::KnowId) + { + std::cerr << "(EE) No id returned by GxsIdChooser. Somthing's wrong?" << std::endl; + return; + } + + rsPosted->voteForPost(up_or_down,msg.first,msg.second,voter_id); +} + #ifdef TODO class PostedPostsReadData { diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index eef377233..f0218d942 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -135,6 +135,7 @@ private slots: public slots: void handlePostsTreeSizeChange(QSize size); + void voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down); private: void processSettings(bool load);