worked on display of posts and selection in new forum model

This commit is contained in:
csoler 2018-11-22 22:07:58 +01:00
parent 3edd1dd0dd
commit 20b8bca801
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 166 additions and 53 deletions

View File

@ -150,6 +150,19 @@ public:
const std::list<RsGxsGroupId>& forumIds, const std::list<RsGxsGroupId>& forumIds,
std::vector<RsGxsForumMsg>& messages ) = 0; std::vector<RsGxsForumMsg>& messages ) = 0;
/**
* @brief Get specific list of messages from a single forums. Blocking API
* @jsonapi{development}
* @param[in] forumId id of the forum of which the content is requested
* @param[in] msgs_to_request list of message ids to request
* @param[out] msgs storage for the forum messages
* @return false if something failed, true otherwhise
*/
virtual bool getForumsContent(
const RsGxsGroupId& forumId,
std::set<RsGxsMessageId>& msgs_to_request,
std::vector<RsGxsForumMsg>& msgs) =0;
/** /**
* @brief Toggle message read status. Blocking API. * @brief Toggle message read status. Blocking API.
* @jsonapi{development} * @jsonapi{development}

View File

@ -456,6 +456,20 @@ bool p3GxsForums::getForumsInfo(
return getGroupData(token, forumsInfo); return getGroupData(token, forumsInfo);
} }
bool p3GxsForums::getForumsContent( const RsGxsGroupId& forumId, std::set<RsGxsMessageId>& msgs_to_request,std::vector<RsGxsForumMsg>& msgs)
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
GxsMsgReq msgIds;
msgIds[forumId] = msgs_to_request;
if( !requestMsgInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE ) return false;
return getMsgData(token, msgs) ;
}
bool p3GxsForums::getForumsContent( bool p3GxsForums::getForumsContent(
const std::list<RsGxsGroupId>& forumIds, const std::list<RsGxsGroupId>& forumIds,
std::vector<RsGxsForumMsg>& messages ) std::vector<RsGxsForumMsg>& messages )

View File

@ -77,6 +77,9 @@ public:
const std::list<RsGxsGroupId>& forumIds, const std::list<RsGxsGroupId>& forumIds,
std::vector<RsGxsForumMsg>& messages ); std::vector<RsGxsForumMsg>& messages );
/// @see RsGxsForums::getForumsContent
virtual bool getForumsContent( const RsGxsGroupId& forumId, std::set<RsGxsMessageId>& msgs_to_request,std::vector<RsGxsForumMsg>& msgs) ;
/// @see RsGxsForums::markRead /// @see RsGxsForums::markRead
virtual bool markRead(const RsGxsGrpMsgIdPair& messageId, bool read); virtual bool markRead(const RsGxsGrpMsgIdPair& messageId, bool read);

View File

@ -223,32 +223,6 @@ int RsGxsForumModel::getChildrenCount(void *ref) const
return mPosts[entry].mChildren.size(); return mPosts[entry].mChildren.size();
} }
//bool RsGxsForumModel::hasIndex(int row,int column,const QModelIndex& parent) const
//{
// if(row < 0 || column < 0 || column >= COLUMN_COUNT)
// return false;
//
// if(!parent.isValid())
// return false;
//
// ForumModelIndex entry;
//
// convertRefPointerToTabEntry(parent.internalPointer(),entry);
//
// if(entry >= mPosts.size())
// return false;
//
// if(row >= mPosts[entry].children.size())
// return false;
//
// if(mPosts[entry].children[row] >= mPosts.size())
// return false;
//
// return true;
//}
QVariant RsGxsForumModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant RsGxsForumModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if(role != Qt::DisplayRole) if(role != Qt::DisplayRole)

View File

@ -24,6 +24,7 @@
#include <QScrollBar> #include <QScrollBar>
#include <QPainter> #include <QPainter>
#include "util/qtthreadsutils.h"
#include "GxsForumThreadWidget.h" #include "GxsForumThreadWidget.h"
#include "ui_GxsForumThreadWidget.h" #include "ui_GxsForumThreadWidget.h"
#include "GxsForumsFillThread.h" #include "GxsForumsFillThread.h"
@ -475,7 +476,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
{ {
if (complete) { if (complete) {
/* Fill complete */ /* Fill complete */
requestGroupData(); updateGroupData();
//insertThreads(); //insertThreads();
insertMessage(); insertMessage();
@ -511,7 +512,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
} }
if (updateGroup) { if (updateGroup) {
requestGroupData(); updateGroupData();
} }
} }
@ -777,25 +778,25 @@ void GxsForumThreadWidget::changedVersion()
void GxsForumThreadWidget::changedThread() void GxsForumThreadWidget::changedThread()
{ {
#ifdef TODO
/* just grab the ids of the current item */ /* just grab the ids of the current item */
QTreeWidgetItem *item = ui->threadTreeWidget->currentItem(); QModelIndexList selected_indexes = ui->threadTreeWidget->selectionModel()->selectedIndexes();
if (!item || !item->isSelected()) { if(selected_indexes.size() != 1)
{
mThreadId.clear(); mThreadId.clear();
mOrigThreadId.clear(); mOrigThreadId.clear();
} else {
mThreadId = mOrigThreadId = RsGxsMessageId(item->data(COLUMN_THREAD_MSGID, Qt::DisplayRole).toString().toStdString());
}
if (mFillThread) {
return; return;
} }
ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages()) ;
QModelIndex index = *selected_indexes.begin();
mThreadId = mOrigThreadId = RsGxsMessageId(index.sibling(index.row(),COLUMN_THREAD_MSGID).data(Qt::DisplayRole).toString().toStdString());
std::cerr << "Switched to new thread ID " << mThreadId << std::endl;
//ui->postText->resetImagesStatus(Settings->getForumLoadEmbeddedImages()) ;
insertMessage(); insertMessage();
#endif
} }
void GxsForumThreadWidget::clickedThread(QTreeWidgetItem *item, int column) void GxsForumThreadWidget::clickedThread(QTreeWidgetItem *item, int column)
@ -1679,7 +1680,6 @@ void GxsForumThreadWidget::fillChildren(QTreeWidgetItem *parentItem, QTreeWidget
void GxsForumThreadWidget::insertMessage() void GxsForumThreadWidget::insertMessage()
{ {
#ifdef TODO
if (groupId().isNull()) if (groupId().isNull())
{ {
mStateHelper->setActive(mTokenTypeMessageData, false); mStateHelper->setActive(mTokenTypeMessageData, false);
@ -1689,7 +1689,6 @@ void GxsForumThreadWidget::insertMessage()
ui->time_label->show(); ui->time_label->show();
ui->postText->clear(); ui->postText->clear();
//ui->threadTitle->clear();
return; return;
} }
@ -1701,14 +1700,15 @@ void GxsForumThreadWidget::insertMessage()
ui->versions_CB->hide(); ui->versions_CB->hide();
ui->time_label->show(); ui->time_label->show();
//ui->threadTitle->setText(tr("Forum Description"));
ui->postText->setText(mForumDescription); ui->postText->setText(mForumDescription);
return; return;
} }
mStateHelper->setActive(mTokenTypeMessageData, true); mStateHelper->setActive(mTokenTypeMessageData, true);
#ifdef TODO
QTreeWidgetItem *item = ui->threadTreeWidget->currentItem(); QTreeWidgetItem *item = ui->threadTreeWidget->currentItem();
if (item) { if (item) {
QTreeWidgetItem *parentItem = item->parent(); QTreeWidgetItem *parentItem = item->parent();
int index = parentItem ? parentItem->indexOfChild(item) : ui->threadTreeWidget->indexOfTopLevelItem(item); int index = parentItem ? parentItem->indexOfChild(item) : ui->threadTreeWidget->indexOfTopLevelItem(item);
@ -1723,6 +1723,7 @@ void GxsForumThreadWidget::insertMessage()
ui->time_label->show(); ui->time_label->show();
return; return;
} }
#endif
mStateHelper->setWidgetEnabled(ui->newmessageButton, (IS_GROUP_SUBSCRIBED(mSubscribeFlags) && mThreadId.isNull() == false)); mStateHelper->setWidgetEnabled(ui->newmessageButton, (IS_GROUP_SUBSCRIBED(mSubscribeFlags) && mThreadId.isNull() == false));
@ -1738,7 +1739,7 @@ void GxsForumThreadWidget::insertMessage()
// add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox. // add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox.
std::cerr << "Looking into existing versions for post " << mThreadId << ", thread history: " << mPostVersions.size() << std::endl; std::cerr << "Looking into existing versions for post " << mThreadId << ", thread history: " << mPostVersions.size() << std::endl;
#ifdef TODO
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::const_iterator it = mPostVersions.find(mOrigThreadId) ; QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::const_iterator it = mPostVersions.find(mOrigThreadId) ;
ui->versions_CB->blockSignals(true) ; ui->versions_CB->blockSignals(true) ;
@ -1773,13 +1774,13 @@ void GxsForumThreadWidget::insertMessage()
ui->versions_CB->hide(); ui->versions_CB->hide();
ui->time_label->show(); ui->time_label->show();
} }
#endif
ui->versions_CB->blockSignals(false) ; ui->versions_CB->blockSignals(false) ;
/* request Post */ /* request Post */
RsGxsGrpMsgIdPair msgId = std::make_pair(groupId(), mThreadId); //RsGxsGrpMsgIdPair msgId = std::make_pair(groupId(), mThreadId);
requestMessageData(msgId); updateMessageData(mThreadId);
#endif
} }
void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
@ -2542,6 +2543,111 @@ bool GxsForumThreadWidget::filterItem(QTreeWidgetItem *item, const QString &text
/** Request / Response of Data ********************************/ /** Request / Response of Data ********************************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
void GxsForumThreadWidget::updateGroupData()
{
mSubscribeFlags = 0;
mSignFlags = 0;
mForumDescription.clear();
emit groupChanged(this);
RsThread::async([this]()
{
// 1 - get message data from p3GxsForums
std::list<RsGxsGroupId> forumIds;
std::vector<RsGxsForumGroup> groups;
forumIds.push_back(groupId());
if(!rsGxsForums->getForumsInfo(forumIds,groups))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << groupId() << std::endl;
return;
}
if(groups.size() != 1)
{
mStateHelper->setActive(mTokenTypeGroupData, false);
mStateHelper->clear(mTokenTypeGroupData);
return;
}
// 2 - sort the messages into a proper hierarchy
RsGxsForumGroup group = groups[0];
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [group,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, note that
* Qt::QueuedConnection is important!
*/
mForumGroup = group;
insertGroupData();
ui->threadTreeWidget->setColumnHidden(COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mSubscribeFlags)) ;
}, this );
});
}
void GxsForumThreadWidget::updateMessageData(const RsGxsMessageId& msgId)
{
RsThread::async([msgId,this]()
{
// 1 - get message data from p3GxsForums
std::set<RsGxsMessageId> msgs_to_request ;
std::vector<RsGxsForumMsg> msgs;
msgs_to_request.insert(msgId);
if(!rsGxsForums->getForumsContent(groupId(),msgs_to_request,msgs))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum group info for forum " << groupId() << std::endl;
return;
}
if(msgs.size() != 1)
{
mStateHelper->setActive(mTokenTypeGroupData, false);
mStateHelper->clear(mTokenTypeGroupData);
return;
}
// 2 - sort the messages into a proper hierarchy
RsGxsForumMsg msg = msgs[0];
// 3 - update the model in the UI thread.
RsQThreadUtils::postToObject( [msg,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, note that
* Qt::QueuedConnection is important!
*/
insertMessageData(msg);
ui->threadTreeWidget->setColumnHidden(COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));
ui->subscribeToolButton->setHidden(IS_GROUP_SUBSCRIBED(mSubscribeFlags)) ;
}, this );
});
}
#ifdef TO_REMOVE
void GxsForumThreadWidget::requestGroupData() void GxsForumThreadWidget::requestGroupData()
{ {
mSubscribeFlags = 0; mSubscribeFlags = 0;
@ -2549,19 +2655,17 @@ void GxsForumThreadWidget::requestGroupData()
mForumDescription.clear(); mForumDescription.clear();
mTokenQueue->cancelActiveRequestTokens(mTokenTypeGroupData); mTokenQueue->cancelActiveRequestTokens(mTokenTypeGroupData);
emit groupChanged(this);
if (groupId().isNull()) { if (groupId().isNull()) {
mStateHelper->setActive(mTokenTypeGroupData, false); mStateHelper->setActive(mTokenTypeGroupData, false);
mStateHelper->setLoading(mTokenTypeGroupData, false); mStateHelper->setLoading(mTokenTypeGroupData, false);
mStateHelper->clear(mTokenTypeGroupData); mStateHelper->clear(mTokenTypeGroupData);
emit groupChanged(this);
return; return;
} }
mStateHelper->setLoading(mTokenTypeGroupData, true); mStateHelper->setLoading(mTokenTypeGroupData, true);
emit groupChanged(this);
RsTokReqOptions opts; RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
@ -2666,6 +2770,7 @@ void GxsForumThreadWidget::loadMessageData(const uint32_t &token)
mStateHelper->clear(mTokenTypeMessageData); mStateHelper->clear(mTokenTypeMessageData);
} }
} }
#endif
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
@ -2897,6 +3002,7 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
if (queue == mTokenQueue) if (queue == mTokenQueue)
{ {
#ifdef TO_REMOVE
/* now switch on req */ /* now switch on req */
if (req.mUserType == mTokenTypeGroupData) { if (req.mUserType == mTokenTypeGroupData) {
loadGroupData(req.mToken); loadGroupData(req.mToken);
@ -2907,6 +3013,7 @@ void GxsForumThreadWidget::loadRequest(const TokenQueue *queue, const TokenReque
loadMessageData(req.mToken); loadMessageData(req.mToken);
return; return;
} }
#endif
if (req.mUserType == mTokenTypeReplyMessage) { if (req.mUserType == mTokenTypeReplyMessage) {
loadMsgData_ReplyMessage(req.mToken); loadMsgData_ReplyMessage(req.mToken);

View File

@ -151,6 +151,7 @@ private:
void insertMessageData(const RsGxsForumMsg &msg); void insertMessageData(const RsGxsForumMsg &msg);
void insertMessage(); void insertMessage();
void insertGroupData();
//void insertThreads(); //void insertThreads();
//void fillThreads(QList<QTreeWidgetItem *> &threadList, bool expandNewMessages, QList<QTreeWidgetItem*> &itemToExpand); //void fillThreads(QList<QTreeWidgetItem *> &threadList, bool expandNewMessages, QList<QTreeWidgetItem*> &itemToExpand);
@ -169,18 +170,19 @@ private:
void processSettings(bool bLoad); void processSettings(bool bLoad);
void requestGroupData(); void updateGroupData();
void loadGroupData(const uint32_t &token);
void insertGroupData();
static void loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/); static void loadAuthorIdCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/);
void requestMessageData(const RsGxsGrpMsgIdPair &msgId); void updateMessageData(const RsGxsMessageId& msgId);
void requestMsgData_ReplyWithPrivateMessage(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ReplyWithPrivateMessage(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ShowAuthorInPeople(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_ReplyForumMessage(const RsGxsGrpMsgIdPair &msgId);
void requestMsgData_EditForumMessage(const RsGxsGrpMsgIdPair &msgId); void requestMsgData_EditForumMessage(const RsGxsGrpMsgIdPair &msgId);
#ifdef TO_REMOVE
void loadMessageData(const uint32_t &token); void loadMessageData(const uint32_t &token);
#endif
void loadMsgData_ReplyMessage(const uint32_t &token); void loadMsgData_ReplyMessage(const uint32_t &token);
void loadMsgData_ReplyForumMessage(const uint32_t &token); void loadMsgData_ReplyForumMessage(const uint32_t &token);
void loadMsgData_EditForumMessage(const uint32_t &token); void loadMsgData_EditForumMessage(const uint32_t &token);