added proper update of threads when new msg is poste or received

This commit is contained in:
csoler 2018-12-03 17:30:46 +01:00
parent 49dc9bcae2
commit 55022432ef
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 48 additions and 36 deletions

View File

@ -667,6 +667,18 @@ void RsGxsForumModel::setForum(const RsGxsGroupId& forum_group_id)
update_posts(forum_group_id); update_posts(forum_group_id);
} }
void RsGxsForumModel::clear()
{
emit layoutAboutToBeChanged();
mPosts.clear();
mPostVersions.clear();
emit layoutChanged();
emit forumLoaded();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
}
void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions) void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<ForumModelPostEntry>& posts,const std::map<RsGxsMessageId,std::vector<std::pair<time_t,RsGxsMessageId> > >& post_versions)
{ {
emit layoutAboutToBeChanged(); emit layoutAboutToBeChanged();
@ -699,6 +711,9 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
{ {
if(group_id.isNull())
return;
RsThread::async([this, group_id]() RsThread::async([this, group_id]()
{ {
// 1 - get message data from p3GxsForums // 1 - get message data from p3GxsForums

View File

@ -1,3 +1,23 @@
/*******************************************************************************
* retroshare-gui/src/gui/gxsforums/GxsForumModel.h *
* *
* Copyright 2018 by Cyril Soler <csoler@users.sourceforge.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include "retroshare/rsgxsforums.h" #include "retroshare/rsgxsforums.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include <QModelIndex> #include <QModelIndex>
@ -108,6 +128,8 @@ public:
QModelIndex parent(const QModelIndex& child) const override; QModelIndex parent(const QModelIndex& child) const override;
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex& index) const override;
void clear() ;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

View File

@ -278,24 +278,10 @@ public:
{ {
bool left_is_not_pinned = ! left.data(RsGxsForumModel::ThreadPinnedRole).toBool(); bool left_is_not_pinned = ! left.data(RsGxsForumModel::ThreadPinnedRole).toBool();
bool right_is_not_pinned = !right.data(RsGxsForumModel::ThreadPinnedRole).toBool(); bool right_is_not_pinned = !right.data(RsGxsForumModel::ThreadPinnedRole).toBool();
#ifdef DEBUG_PINNED_POST_SORTING
std::cerr << "Comparing item date \"" << data(RsGxsForumModel::COLUMN_THREAD_DATE,Qt::DisplayRole).toString().toStdString() << "\" ("
<< data(RsGxsForumModel::COLUMN_THREAD_DATE,ROLE_THREAD_SORT).toUInt() << ", \"" << data(RsGxsForumModel::COLUMN_THREAD_DATE,ROLE_THREAD_SORT).toString().toStdString() << "\" --> " << left_is_not_pinned << ") to \""
<< other.data(RsGxsForumModel::COLUMN_THREAD_DATE,Qt::DisplayRole).toString().toStdString() << "\" ("
<< other.data(RsGxsForumModel::COLUMN_THREAD_DATE,ROLE_THREAD_SORT).toUInt() << ", \"" << other.data(RsGxsForumModel::COLUMN_THREAD_DATE,ROLE_THREAD_SORT).toString().toStdString() << "\" --> " << right_is_not_pinned << ") ";
#endif
if(left_is_not_pinned ^ right_is_not_pinned) if(left_is_not_pinned ^ right_is_not_pinned)
{
#ifdef DEBUG_PINNED_POST_SORTING
std::cerr << "Local: " << ((m_header->sortIndicatorOrder()==Qt::AscendingOrder)?right_is_not_pinned:left_is_not_pinned) << std::endl;
#endif
return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?right_is_not_pinned:left_is_not_pinned ; // always put pinned posts on top return (m_header->sortIndicatorOrder()==Qt::AscendingOrder)?right_is_not_pinned:left_is_not_pinned ; // always put pinned posts on top
}
#ifdef DEBUG_PINNED_POST_SORTING
std::cerr << "Remote: " << GxsIdRSTreeWidgetItem::operator<(other) << std::endl;
#endif
return left.data(RsGxsForumModel::SortRole) < right.data(RsGxsForumModel::SortRole) ; return left.data(RsGxsForumModel::SortRole) < right.data(RsGxsForumModel::SortRole) ;
} }
@ -335,7 +321,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mThreadProxyModel->setFilterRegExp(QRegExp(QString(RsGxsForumModel::FilterString))) ; mThreadProxyModel->setFilterRegExp(QRegExp(QString(RsGxsForumModel::FilterString))) ;
ui->threadTreeWidget->setSortingEnabled(true); ui->threadTreeWidget->setSortingEnabled(true);
//ui->threadTreeWidget->setDynamicSortFilter(true);// is that useful??
ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ; ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ;
ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_AUTHOR,new AuthorItemDelegate()) ; ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_AUTHOR,new AuthorItemDelegate()) ;
@ -377,22 +362,10 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
itemDelegate->setOnlyPlainText(true); itemDelegate->setOnlyPlainText(true);
ui->threadTreeWidget->setItemDelegate(itemDelegate); ui->threadTreeWidget->setItemDelegate(itemDelegate);
#ifdef SUSPENDED_CODE
/* Set text of column "Read" to empty - without this the column has a number as header text */
QTreeWidgetItem *headerItem = ui->threadTreeWidget->headerItem();
headerItem->setText(COLUMN_THREAD_READ, "") ;
headerItem->setText(COLUMN_THREAD_DISTRIBUTION, "");
headerItem->setData(COLUMN_THREAD_READ,Qt::UserRole, tr("Read status")) ; // this is used to display drop menus.
headerItem->setData(COLUMN_THREAD_DISTRIBUTION,Qt::UserRole, tr("Distribution"));
#endif
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), RsGxsForumModel::COLUMN_THREAD_TITLE, tr("Search Title"));
ui->filterLineEdit->addFilter(QIcon(), tr("Date"), RsGxsForumModel::COLUMN_THREAD_DATE, tr("Search Date")); ui->filterLineEdit->addFilter(QIcon(), tr("Date"), RsGxsForumModel::COLUMN_THREAD_DATE, tr("Search Date"));
ui->filterLineEdit->addFilter(QIcon(), tr("Author"), RsGxsForumModel::COLUMN_THREAD_AUTHOR, tr("Search Author")); ui->filterLineEdit->addFilter(QIcon(), tr("Author"), RsGxsForumModel::COLUMN_THREAD_AUTHOR, tr("Search Author"));
//ui->filterLineEdit->addFilter(QIcon(), tr("Content"), RsGxsForumModel::COLUMN_THREAD_CONTENT, tr("Search Content"));
// see processSettings
//ui->filterLineEdit->setCurrentFilter(COLUMN_THREAD_TITLE);
mLastViewType = -1; mLastViewType = -1;
@ -415,7 +388,8 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_AUTHOR, QHeaderView::Interactive); QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_AUTHOR, QHeaderView::Interactive);
QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_READ, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_READ, QHeaderView::Fixed);
QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(ttheader, RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, QHeaderView::Fixed);
ui->threadTreeWidget->header()->setCascadingSectionResizes(true);
ttheader->setCascadingSectionResizes(true);
/* Set header sizes for the fixed columns and resize modes, must be set after processSettings */ /* Set header sizes for the fixed columns and resize modes, must be set after processSettings */
ttheader->hideSection (RsGxsForumModel::COLUMN_THREAD_CONTENT); ttheader->hideSection (RsGxsForumModel::COLUMN_THREAD_CONTENT);
@ -446,7 +420,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
forum visible to all other friends.</p><p>Afterwards you can unsubscribe from the context menu of the forum list at left.</p>")); forum visible to all other friends.</p><p>Afterwards you can unsubscribe from the context menu of the forum list at left.</p>"));
#ifdef SUSPENDED_CODE #ifdef SUSPENDED_CODE
ui->threadTreeWidget->enableColumnCustomize(true); ui->threadTreeWidget->enableColumnCustomize(true);
#endif #endif
} }
@ -468,6 +441,8 @@ void GxsForumThreadWidget::blank()
#endif #endif
ui->forumName->setText(""); ui->forumName->setText("");
mThreadModel->clear();
#ifdef SUSPENDED_CODE #ifdef SUSPENDED_CODE
mStateHelper->setWidgetEnabled(ui->newthreadButton, false); mStateHelper->setWidgetEnabled(ui->newthreadButton, false);
mStateHelper->setWidgetEnabled(ui->previousButton, false); mStateHelper->setWidgetEnabled(ui->previousButton, false);
@ -605,7 +580,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
if (complete) { if (complete) {
/* Fill complete */ /* Fill complete */
updateGroupData(); updateGroupData();
//insertThreads(); mThreadModel->setForum(groupId());
insertMessage(); insertMessage();
mIgnoredMsgId.clear(); mIgnoredMsgId.clear();
@ -623,7 +598,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
if (grpIds.find(groupId())!=grpIds.end()){ if (grpIds.find(groupId())!=grpIds.end()){
updateGroup = true; updateGroup = true;
/* Update threads */ /* Update threads */
//insertThreads(); mThreadModel->setForum(groupId());
} else { } else {
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds; std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds;
getAllMsgIds(msgIds); getAllMsgIds(msgIds);
@ -633,10 +608,8 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
removeMessages(msgIds, mIgnoredMsgId); removeMessages(msgIds, mIgnoredMsgId);
} }
if (msgIds.find(groupId()) != msgIds.end()) { if (msgIds.find(groupId()) != msgIds.end())
/* Update threads */ mThreadModel->setForum(groupId()); /* Update threads */
//insertThreads();
}
} }
if (updateGroup) { if (updateGroup) {
@ -1646,6 +1619,9 @@ void GxsForumThreadWidget::updateGroupName()
} }
void GxsForumThreadWidget::updateGroupData() void GxsForumThreadWidget::updateGroupData()
{ {
if(groupId().isNull())
return;
mSubscribeFlags = 0; mSubscribeFlags = 0;
mSignFlags = 0; mSignFlags = 0;
mThreadId.clear(); mThreadId.clear();
@ -1692,7 +1668,6 @@ void GxsForumThreadWidget::updateGroupData()
*/ */
mForumGroup = group; mForumGroup = group;
//insertGroupData();
mSubscribeFlags = group.mMeta.mSubscribeFlags; mSubscribeFlags = group.mMeta.mSubscribeFlags;
ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags))); ui->threadTreeWidget->setColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION, !IS_GROUP_PGP_KNOWN_AUTHED(mForumGroup.mMeta.mSignFlags) && !(IS_GROUP_PGP_AUTHED(mForumGroup.mMeta.mSignFlags)));