mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
added proper update of threads when new msg is poste or received
This commit is contained in:
parent
49dc9bcae2
commit
55022432ef
@ -667,6 +667,18 @@ void RsGxsForumModel::setForum(const RsGxsGroupId& 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)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
@ -699,6 +711,9 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
|
||||
|
||||
void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id)
|
||||
{
|
||||
if(group_id.isNull())
|
||||
return;
|
||||
|
||||
RsThread::async([this, group_id]()
|
||||
{
|
||||
// 1 - get message data from p3GxsForums
|
||||
|
@ -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/rsgxsifacetypes.h"
|
||||
#include <QModelIndex>
|
||||
@ -108,6 +128,8 @@ public:
|
||||
QModelIndex parent(const QModelIndex& child) 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 data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
|
@ -278,24 +278,10 @@ public:
|
||||
{
|
||||
bool left_is_not_pinned = ! left.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)
|
||||
{
|
||||
#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
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PINNED_POST_SORTING
|
||||
std::cerr << "Remote: " << GxsIdRSTreeWidgetItem::operator<(other) << std::endl;
|
||||
#endif
|
||||
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))) ;
|
||||
|
||||
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_AUTHOR,new AuthorItemDelegate()) ;
|
||||
@ -377,22 +362,10 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||
itemDelegate->setOnlyPlainText(true);
|
||||
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 */
|
||||
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("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;
|
||||
|
||||
@ -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_READ, 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 */
|
||||
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>"));
|
||||
#ifdef SUSPENDED_CODE
|
||||
ui->threadTreeWidget->enableColumnCustomize(true);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -468,6 +441,8 @@ void GxsForumThreadWidget::blank()
|
||||
#endif
|
||||
ui->forumName->setText("");
|
||||
|
||||
mThreadModel->clear();
|
||||
|
||||
#ifdef SUSPENDED_CODE
|
||||
mStateHelper->setWidgetEnabled(ui->newthreadButton, false);
|
||||
mStateHelper->setWidgetEnabled(ui->previousButton, false);
|
||||
@ -605,7 +580,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
if (complete) {
|
||||
/* Fill complete */
|
||||
updateGroupData();
|
||||
//insertThreads();
|
||||
mThreadModel->setForum(groupId());
|
||||
insertMessage();
|
||||
|
||||
mIgnoredMsgId.clear();
|
||||
@ -623,7 +598,7 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
if (grpIds.find(groupId())!=grpIds.end()){
|
||||
updateGroup = true;
|
||||
/* Update threads */
|
||||
//insertThreads();
|
||||
mThreadModel->setForum(groupId());
|
||||
} else {
|
||||
std::map<RsGxsGroupId, std::set<RsGxsMessageId> > msgIds;
|
||||
getAllMsgIds(msgIds);
|
||||
@ -633,10 +608,8 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
|
||||
removeMessages(msgIds, mIgnoredMsgId);
|
||||
}
|
||||
|
||||
if (msgIds.find(groupId()) != msgIds.end()) {
|
||||
/* Update threads */
|
||||
//insertThreads();
|
||||
}
|
||||
if (msgIds.find(groupId()) != msgIds.end())
|
||||
mThreadModel->setForum(groupId()); /* Update threads */
|
||||
}
|
||||
|
||||
if (updateGroup) {
|
||||
@ -1646,6 +1619,9 @@ void GxsForumThreadWidget::updateGroupName()
|
||||
}
|
||||
void GxsForumThreadWidget::updateGroupData()
|
||||
{
|
||||
if(groupId().isNull())
|
||||
return;
|
||||
|
||||
mSubscribeFlags = 0;
|
||||
mSignFlags = 0;
|
||||
mThreadId.clear();
|
||||
@ -1692,7 +1668,6 @@ void GxsForumThreadWidget::updateGroupData()
|
||||
*/
|
||||
|
||||
mForumGroup = group;
|
||||
//insertGroupData();
|
||||
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)));
|
||||
|
Loading…
Reference in New Issue
Block a user