Fix GXS (Forum/Channel/Boards) RSLink

Have to add ID: tag in Board Filter due to range view.
This commit is contained in:
Phenom 2020-11-10 15:32:25 +01:00
parent af27ff5e4f
commit 68e027b227
8 changed files with 138 additions and 106 deletions

View File

@ -162,8 +162,8 @@ bool PostedDialog::getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo)
// request all group infos at once
if(! rsPosted->getBoardsInfo(std::list<RsGxsGroupId>(),groups))
return false;
if(! rsPosted->getBoardsInfo(std::list<RsGxsGroupId>(),groups))
return false;
/* Save groups to fill icons and description */

View File

@ -62,6 +62,8 @@
* #define DEBUG_POSTED
***/
static const int POSTED_TABS_POSTS = 1;
/* View mode */
#define VIEW_MODE_FEEDS 1
#define VIEW_MODE_FILES 2
@ -529,8 +531,8 @@ void PostedListWidgetWithModel::showPostDetails()
if(index.row()==0 && index.column()==0)
std::cerr << "here" << std::endl;
std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl;
mSelectedPost = post.mMeta.mMsgId;
std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl;
mLastSelectedPosts[groupId()] = post.mMeta.mMsgId;
std::list<ChannelPostFileInfo> files;
for(auto& file:post.mFiles)
@ -625,24 +627,30 @@ void PostedListWidgetWithModel::updateGroupData()
void PostedListWidgetWithModel::postPostLoad()
{
std::cerr << "Post channel load..." << std::endl;
std::cerr << "Post channel load..." << std::endl;
whileBlocking(ui->filter_LE)->setText(QString()); //Clear it before navigate, as it will update it.
if(!mSelectedPost.isNull())
{
QModelIndex index = mPostedPostsModel->getIndexOfMessage(mSelectedPost);
if (!mNavigatePendingMsgId.isNull())
navigate(mNavigatePendingMsgId);
std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post "
<< mSelectedPost.toStdString() << std::endl;
#ifdef TO_REMOVE
else if( (mLastSelectedPosts.count(groupId()) > 0)
&& !mLastSelectedPosts[groupId()].isNull())
{
QModelIndex index = mPostedPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]);
std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post "
<< mLastSelectedPosts[groupId()].toStdString() << std::endl;
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded
ui->postsTree->setFocus();
}
else
std::cerr << "No pre-selected channel post." << std::endl;
}
#endif
else
std::cerr << "No pre-selected channel post." << std::endl;
whileBlocking(ui->showLabel)->setText(QString::number(mPostedPostsModel->displayedStartPostIndex()+1)+" - "+QString::number(std::min(mPostedPostsModel->filteredPostsCount(),mPostedPostsModel->displayedStartPostIndex()+POSTS_CHUNK_SIZE+1)));
whileBlocking(ui->filter_LE)->setText(QString());
whileBlocking(ui->showLabel)->setText(QString::number(mPostedPostsModel->displayedStartPostIndex()+1)+" - "+QString::number(std::min(mPostedPostsModel->filteredPostsCount(),mPostedPostsModel->displayedStartPostIndex()+POSTS_CHUNK_SIZE+1)));
}
void PostedListWidgetWithModel::forceRedraw()
@ -721,7 +729,7 @@ QString PostedListWidgetWithModel::groupName(bool)
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
}
void PostedListWidgetWithModel::groupNameChanged(const QString &name)
void PostedListWidgetWithModel::groupNameChanged(const QString &/*name*/)
{
}
@ -737,12 +745,12 @@ QIcon PostedListWidgetWithModel::groupIcon()
return QIcon(postedImage);
}
void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &token)
void PostedListWidgetWithModel::setAllMessagesReadDo(bool read, uint32_t &/*token*/)
{
if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags))
return;
QModelIndex src_index;
//QModelIndex src_index;
mPostedPostsModel->setAllMsgReadStatus(read);
@ -1126,20 +1134,24 @@ void PostedListWidgetWithModel::blank()
bool PostedListWidgetWithModel::navigate(const RsGxsMessageId& msgId)
{
ui->filter_LE->setText("ID:" + QString::fromStdString(msgId.toStdString()));
QModelIndex index = mPostedPostsModel->getIndexOfMessage(msgId);
if(!index.isValid())
{
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in board " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
if(!index.isValid())
{
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in board " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
mSelectedPost = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading.
return true; // we have to return true here, otherwise the caller will intepret the async loading as an error.
}
mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading.
return true; // we have to return true here, otherwise the caller will intepret the async loading as an error.
}
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded
ui->postsTree->setFocus();
ui->tabWidget->setCurrentIndex(POSTED_TABS_POSTS);
mNavigatePendingMsgId.clear();
return true;
}

View File

@ -132,6 +132,9 @@ protected:
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
private slots:
#ifdef TO_REMOVE
void showPostDetails();
#endif
void showAuthorInPeople();
void tabCloseRequested(int index);
void updateSorting(int);
@ -166,7 +169,10 @@ private:
RsPostedPostsModel *mPostedPostsModel;
PostedPostDelegate *mPostedPostsDelegate;
RsGxsMessageId mSelectedPost;
#ifdef TO_REMOVE
std::map<RsGxsGroupId,RsGxsMessageId> mLastSelectedPosts;
#endif
RsGxsMessageId mNavigatePendingMsgId;
/* UI - from Designer */
Ui::PostedListWidgetWithModel *ui;

View File

@ -158,42 +158,47 @@ void RsPostedPostsModel::triggerRedraw()
void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count)
{
preMods();
preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1);
endRemoveRows();
endRemoveRows();
if(strings.empty())
{
mFilteredPosts.clear();
for(int i=0;i<mPosts.size();++i)
mFilteredPosts.push_back(i);
}
{
mFilteredPosts.clear();
for(int i=0;i<(int)(mPosts.size());++i)
mFilteredPosts.push_back(i);
}
else
{
mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
{
mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
for(int i=0;i<mPosts.size();++i)
{
bool passes_strings = true;
for(int i=0;i<static_cast<int>(mPosts.size());++i)
{
bool passes_strings = true;
for(auto& s:strings)
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
{
if (s.startsWith("ID:",Qt::CaseInsensitive))
passes_strings = passes_strings && mPosts[i].mMeta.mMsgId == RsGxsMessageId(s.right(s.length() - 3).toStdString());
else
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
}
if(passes_strings)
mFilteredPosts.push_back(i);
}
}
count = mFilteredPosts.size();
if(passes_strings)
mFilteredPosts.push_back(i);
}
}
count = mFilteredPosts.size();
mDisplayedStartIndex = 0;
mDisplayedStartIndex = 0;
mDisplayedNbPosts = std::min(count,DEFAULT_DISPLAYED_NB_POSTS) ;
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
endInsertRows();
postMods();
}
@ -237,8 +242,8 @@ bool RsPostedPostsModel::getPostData(const QModelIndex& i,RsPostedPost& fmpe) co
bool RsPostedPostsModel::hasChildren(const QModelIndex &parent) const
{
if(!parent.isValid())
return true;
if(!parent.isValid())
return true;
return false; // by default, no post has children
}
@ -292,8 +297,8 @@ QModelIndex RsPostedPostsModel::index(int row, int column, const QModelIndex & p
QModelIndex RsPostedPostsModel::parent(const QModelIndex& index) const
{
if(!index.isValid())
return QModelIndex();
if(!index.isValid())
return QModelIndex();
return QModelIndex(); // there's no hierarchy here. So nothing to do!
}
@ -333,10 +338,10 @@ quintptr RsPostedPostsModel::getParentRow(quintptr ref,int& row) const
int RsPostedPostsModel::getChildrenCount(quintptr ref) const
{
uint32_t entry = 0 ;
//uint32_t entry = 0 ;
if(ref == quintptr(0))
return rowCount()-1;
if(ref == quintptr(0))
return rowCount()-1;
return 0;
}
@ -391,7 +396,7 @@ QVariant RsPostedPostsModel::data(const QModelIndex& index, int role) const
}
}
QVariant RsPostedPostsModel::sizeHintRole(int col) const
QVariant RsPostedPostsModel::sizeHintRole(int /*col*/) const
{
float factor = QFontMetricsF(QApplication::font()).height()/14.0f ;
@ -483,8 +488,8 @@ void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy
void RsPostedPostsModel::setPostsInterval(int start,int nb_posts)
{
if(start >= mFilteredPosts.size())
return;
if(start >= (int)mFilteredPosts.size())
return;
preMods();
@ -538,8 +543,8 @@ void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPost
void RsPostedPostsModel::update_posts(const RsGxsGroupId& group_id)
{
if(group_id.isNull())
return;
if(group_id.isNull())
return;
RsThread::async([this, group_id]()
{
@ -592,7 +597,7 @@ void RsPostedPostsModel::update_posts(const RsGxsGroupId& group_id)
});
}
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
//static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsPostedPostsModel::createPostsArray(std::vector<RsPostedPost>& posts)
{
@ -761,34 +766,35 @@ void RsPostedPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const
{
// Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map.
// Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map.
RsGxsMessageId postId = mid;
RsGxsMessageId postId = mid;
for(uint32_t i=mDisplayedStartIndex;i<mDisplayedStartIndex+mDisplayedNbPosts;++i)
{
for(uint32_t i=mDisplayedStartIndex;i<mDisplayedStartIndex+mDisplayedNbPosts;++i)
{
// First look into msg versions, in case the msg is a version of an existing message
#ifdef TODO
for(auto& msg_id:mPosts[mFilteredPosts[i]].mOlderVersions)
if(msg_id == postId)
{
for(auto& msg_id:mPosts[mFilteredPosts[i]].mOlderVersions)
if(msg_id == postId)
{
quintptr ref ;
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
return createIndex(i,0, ref);
}
}
#endif
if(mPosts[mFilteredPosts[i]].mMeta.mMsgId == postId)
{
quintptr ref ;
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
if( mFilteredPosts.size() > (size_t)(i)
&& mPosts[mFilteredPosts[i]].mMeta.mMsgId == postId )
{
quintptr ref ;
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
return createIndex(i,0, ref);
}
}
}
}
return QModelIndex();
return QModelIndex();
}

View File

@ -98,6 +98,7 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
mStateHelper = new UIStateHelper(this);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_SUMMARY, ui->loadingLabel, UISTATE_LOADING_VISIBLE);
mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true);
connect(ui->groupTreeWidget, SIGNAL(treeCustomContextMenuRequested(QPoint)), this, SLOT(groupTreeCustomPopupMenu(QPoint)));
connect(ui->groupTreeWidget, SIGNAL(treeCurrentItemChanged(QString)), this, SLOT(changedCurrentGroup(QString)));

View File

@ -166,7 +166,7 @@ private:
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &/*grpId*/, const RsGxsMessageId &/*msgId*/) { return NULL; }
virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& /* group_infos */){ return false ;}
virtual void clearDistantSearchResults(TurtleRequestId /* id */) {}
virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& group_id){ return nullptr ;}
virtual RsGxsGenericGroupData *getDistantSearchResultGroupData(const RsGxsGroupId& /*group_id*/){ return nullptr ;}
void initUi();

View File

@ -774,31 +774,31 @@ void GxsChannelPostsWidgetWithModel::showPostDetails()
std::cerr << "showPostDetails: current index is " << index.row() << "," << index.column() << std::endl;
#endif
QTextDocument doc;
doc.setHtml(post.mMsg.c_str());
//QTextDocument doc;
//doc.setHtml(post.mMsg.c_str());
if(post.mMeta.mPublishTs == 0)
{
ui->postDetails_TE->clear();
ui->postLogo_LB->hide();
if(post.mMeta.mPublishTs == 0)
{
ui->postDetails_TE->clear();
ui->postLogo_LB->hide();
ui->postName_LB->hide();
ui->postTime_LB->hide();
mChannelPostFilesModel->clear();
ui->details_TW->setEnabled(false);
mSelectedPost.clear();
mChannelPostFilesModel->clear();
ui->details_TW->setEnabled(false);
//mLastSelectedPosts[groupId()].clear();
return;
}
ui->details_TW->setEnabled(true);
return;
}
ui->details_TW->setEnabled(true);
ui->postLogo_LB->show();
ui->postName_LB->show();
ui->postTime_LB->show();
#ifdef DEBUG_CHANNEL_POSTS_WIDGET
std::cerr << "showPostDetails: setting mSelectedPost to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mSelectedPost << std::endl;
std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl;
#endif
mSelectedPost = post.mMeta.mMsgId;
mLastSelectedPosts[groupId()] = post.mMeta.mMsgId;
std::list<ChannelPostFileInfo> files;
for(auto& file:post.mFiles)
@ -886,7 +886,7 @@ void GxsChannelPostsWidgetWithModel::updateGroupData()
RsQThreadUtils::postToObject( [this,group]()
{
if(mGroup.mMeta.mGroupId != group.mMeta.mGroupId) // this prevents any attempt to display the wrong index. Navigate() if needed will use mSelectedPost
if(mGroup.mMeta.mGroupId != group.mMeta.mGroupId) // this prevents any attempt to display the wrong index. Navigate() if needed will use mNavigatePendingMsgId
{
#ifdef DEBUG_CHANNEL_POSTS_WIDGET
std::cerr << "Old group: " << mGroup.mMeta.mGroupId << ", new group: " << group.mMeta.mGroupId << ". Celaring selection" << std::endl;
@ -913,12 +913,16 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
{
std::cerr << "Post channel load..." << std::endl;
if(!mSelectedPost.isNull())
if (!mNavigatePendingMsgId.isNull())
navigate(mNavigatePendingMsgId);
else if( (mLastSelectedPosts.count(groupId()) > 0)
&& !mLastSelectedPosts[groupId()].isNull())
{
QModelIndex index = mChannelPostsModel->getIndexOfMessage(mSelectedPost);
QModelIndex index = mChannelPostsModel->getIndexOfMessage(mLastSelectedPosts[groupId()]);
std::cerr << "Setting current index to " << index.row() << ","<< index.column() << " for current post "
<< mSelectedPost.toStdString() << std::endl;
<< mLastSelectedPosts[groupId()].toStdString() << std::endl;
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded
@ -1315,20 +1319,22 @@ bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId& msgId)
{
QModelIndex index = mChannelPostsModel->getIndexOfMessage(msgId);
if(!index.isValid())
{
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
if(!index.isValid())
{
std::cerr << "(EE) Cannot navigate to msg " << msgId << " in channel " << mGroup.mMeta.mGroupId << ": index unknown. Setting mNavigatePendingMsgId." << std::endl;
mSelectedPost = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading.
return true; // we have to return true here, otherwise the caller will intepret the async loading as an error.
}
mNavigatePendingMsgId = msgId; // not found. That means the forum may not be loaded yet. So we keep that post in mind, for after loading.
return true; // we have to return true here, otherwise the caller will intepret the async loading as an error.
}
ui->postsTree->selectionModel()->setCurrentIndex(index,QItemSelectionModel::ClearAndSelect);
ui->postsTree->scrollTo(index);//May change if model reloaded
ui->postsTree->setFocus();
ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS);
ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS);
ui->channel_TW->setCurrentIndex(CHANNEL_TABS_POSTS);
ui->details_TW->setCurrentIndex(CHANNEL_TABS_DETAILS);
mNavigatePendingMsgId.clear();
return true;
}

View File

@ -190,7 +190,8 @@ private:
ChannelPostDelegate *mChannelPostsDelegate;
ChannelPostFilesDelegate *mFilesDelegate;
RsGxsMessageId mSelectedPost;
std::map<RsGxsGroupId,RsGxsMessageId> mLastSelectedPosts;
RsGxsMessageId mNavigatePendingMsgId;
/* UI - from Designer */
Ui::GxsChannelPostsWidgetWithModel *ui;