mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
Merge pull request #2681 from csoler/v0.6-BugFixing_20
Attempt at not reloading full channel data at every change (needs PR #81)
This commit is contained in:
commit
8475a7424d
@ -1 +1 @@
|
||||
Subproject commit 2ddc86fb575a61170f4c06a00152e3e7dc74c8f4
|
||||
Subproject commit 659423769541169457c41f71c8a038e2d64ba079
|
@ -1 +1 @@
|
||||
Subproject commit a9d4447c5660337b4f7945d20e0f4ffd68d918e9
|
||||
Subproject commit 74cd958cf8a3c8b3e2d3f8a22657b5e16bdad476
|
@ -33,11 +33,11 @@
|
||||
|
||||
#include "GxsChannelPostFilesModel.h"
|
||||
|
||||
//#define DEBUG_CHANNEL_MODEL
|
||||
//#define DEBUG_CHANNEL_FILES_MODEL
|
||||
|
||||
Q_DECLARE_METATYPE(ChannelPostFileInfo)
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
static std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
||||
#endif
|
||||
|
||||
@ -161,8 +161,8 @@ QModelIndex RsGxsChannelPostFilesModel::index(int row, int column, const QModelI
|
||||
|
||||
quintptr ref = getChildRef(parent.internalId(),row);
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl;
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
RsDbg() << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) ;
|
||||
#endif
|
||||
return createIndex(row,column,ref) ;
|
||||
}
|
||||
@ -242,7 +242,7 @@ QVariant RsGxsChannelPostFilesModel::headerData(int section, Qt::Orientation /*o
|
||||
|
||||
QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
std::cerr << "calling data(" << index << ") role=" << role << std::endl;
|
||||
#endif
|
||||
|
||||
@ -259,13 +259,13 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
|
||||
quintptr ref = (index.isValid())?index.internalId():0 ;
|
||||
uint32_t entry = 0;
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
std::cerr << "data(" << index << ")" ;
|
||||
#endif
|
||||
|
||||
if(!ref)
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
std::cerr << " [empty]" << std::endl;
|
||||
#endif
|
||||
return QVariant() ;
|
||||
@ -273,7 +273,7 @@ QVariant RsGxsChannelPostFilesModel::data(const QModelIndex &index, int role) co
|
||||
|
||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredFiles.size())
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
|
||||
#endif
|
||||
return QVariant() ;
|
||||
@ -426,7 +426,6 @@ QVariant RsGxsChannelPostFilesModel::userRole(const ChannelPostFileInfo& fmpe,in
|
||||
|
||||
void RsGxsChannelPostFilesModel::clear()
|
||||
{
|
||||
|
||||
initEmptyHierarchy();
|
||||
|
||||
emit channelLoaded();
|
||||
@ -444,7 +443,7 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &
|
||||
for(uint32_t i=0;i<mFiles.size();++i)
|
||||
mFilteredFiles.push_back(i);
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
// debug_dump();
|
||||
#endif
|
||||
|
||||
@ -463,3 +462,61 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list<ChannelPostFileInfo> &
|
||||
|
||||
postMods();
|
||||
}
|
||||
|
||||
void RsGxsChannelPostFilesModel::update_files(std::set<ChannelPostFileInfo>& added_files,std::set<ChannelPostFileInfo>& removed_files)
|
||||
{
|
||||
// 1 - remove common files from both lists
|
||||
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
RsDbg() << "RsGxsChannelPostsFilesModel:: updating files." ;
|
||||
#endif
|
||||
|
||||
for(auto afit=added_files.begin();afit!=added_files.end();)
|
||||
{
|
||||
auto rfit = removed_files.find(*afit);
|
||||
|
||||
if(rfit != removed_files.end())
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
RsDbg() << " Eliminating common file " << rfit->mName ;
|
||||
#endif
|
||||
removed_files.erase(rfit);
|
||||
auto tmp = afit;
|
||||
++tmp;
|
||||
added_files.erase(afit);
|
||||
afit = tmp;
|
||||
}
|
||||
else
|
||||
++afit;
|
||||
}
|
||||
|
||||
RsDbg() << " Remains: " << added_files.size() << " added files and " << removed_files.size() << " removed files" ;
|
||||
|
||||
// 2 - add whatever file remains,
|
||||
|
||||
for(const auto& f:removed_files)
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
RsDbg() << " Removing deleted file " << f.mName ;
|
||||
#endif
|
||||
|
||||
for(uint32_t i=0;i<mFiles.size();++i)
|
||||
if(mFiles[i].mHash == f.mHash)
|
||||
{
|
||||
mFiles[i] = mFiles.back();
|
||||
mFiles.pop_back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 3 - add other files. We do not check that they are duplicates, because the list of files includes duplicates.
|
||||
|
||||
for(const auto& f:added_files )
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_FILES_MODEL
|
||||
RsDbg() << " Adding new file " << f.mName ;
|
||||
#endif
|
||||
mFilteredFiles.push_back(mFiles.size());
|
||||
mFiles.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,34 +41,34 @@ class QTimer;
|
||||
struct ChannelPostFileInfo: public RsGxsFile
|
||||
{
|
||||
ChannelPostFileInfo(const RsGxsFile& gxs_file,rstime_t t)
|
||||
: RsGxsFile(gxs_file),mPublishTime(t)
|
||||
: RsGxsFile(gxs_file),mPublishTime(t)
|
||||
{}
|
||||
|
||||
ChannelPostFileInfo() : mPublishTime(0) {}
|
||||
|
||||
rstime_t mPublishTime;
|
||||
rstime_t mPublishTime; // related post publish time
|
||||
};
|
||||
|
||||
// This class is the item model used by Qt to display the information
|
||||
|
||||
class RsGxsChannelPostFilesModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RsGxsChannelPostFilesModel(QObject *parent = NULL);
|
||||
~RsGxsChannelPostFilesModel(){}
|
||||
explicit RsGxsChannelPostFilesModel(QObject *parent = NULL);
|
||||
~RsGxsChannelPostFilesModel(){}
|
||||
|
||||
enum Columns {
|
||||
COLUMN_FILES_NAME = 0x00,
|
||||
COLUMN_FILES_SIZE = 0x01,
|
||||
COLUMN_FILES_FILE = 0x02,
|
||||
COLUMN_FILES_DATE = 0x03,
|
||||
COLUMN_FILES_NB_COLUMNS = 0x04
|
||||
};
|
||||
enum Columns {
|
||||
COLUMN_FILES_NAME = 0x00,
|
||||
COLUMN_FILES_SIZE = 0x01,
|
||||
COLUMN_FILES_FILE = 0x02,
|
||||
COLUMN_FILES_DATE = 0x03,
|
||||
COLUMN_FILES_NB_COLUMNS = 0x04
|
||||
};
|
||||
|
||||
enum Roles{ SortRole = Qt::UserRole+1,
|
||||
FilterRole = Qt::UserRole+2,
|
||||
enum Roles{ SortRole = Qt::UserRole+1,
|
||||
FilterRole = Qt::UserRole+2,
|
||||
};
|
||||
|
||||
#ifdef TODO
|
||||
@ -77,22 +77,25 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||
|
||||
// This method will asynchroneously update the data
|
||||
void setFiles(const std::list<ChannelPostFileInfo>& files);
|
||||
void setFiles(const std::list<ChannelPostFileInfo>& files);
|
||||
void setFilter(const QStringList &strings, uint32_t &count) ;
|
||||
|
||||
// This method adds/removes the given lists of files. Useful when a single post is updated
|
||||
void update_files(std::set<ChannelPostFileInfo> &added_files, std::set<ChannelPostFileInfo> &removed_files);
|
||||
|
||||
#ifdef TODO
|
||||
QModelIndex getIndexOfFile(const RsFileHash& hash) const;
|
||||
QModelIndex getIndexOfFile(const RsFileHash& hash) const;
|
||||
void setSortMode(SortMode mode) ;
|
||||
|
||||
void setTextColorRead (QColor color) { mTextColorRead = color;}
|
||||
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
|
||||
void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;}
|
||||
void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;}
|
||||
void setTextColorMissing (QColor color) { mTextColorMissing = color;}
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||
void setTextColorRead (QColor color) { mTextColorRead = color;}
|
||||
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
|
||||
void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;}
|
||||
void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;}
|
||||
void setTextColorMissing (QColor color) { mTextColorMissing = color;}
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||
#endif
|
||||
|
||||
// Helper functions
|
||||
@ -112,25 +115,25 @@ public:
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
// Custom item roles
|
||||
|
||||
QVariant sizeHintRole (int col) const;
|
||||
QVariant displayRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant toolTipRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant userRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant sortRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant filterRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant displayRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant toolTipRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant userRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant sortRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
QVariant filterRole (const ChannelPostFileInfo& fmpe, int col) const;
|
||||
#ifdef TODO
|
||||
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant missingRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant missingRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||
QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@ -151,20 +154,20 @@ private:
|
||||
bool mFilteringEnabled;
|
||||
SortMode mSortMode;
|
||||
#endif
|
||||
void preMods() ;
|
||||
void postMods() ;
|
||||
void preMods() ;
|
||||
void postMods() ;
|
||||
|
||||
quintptr getParentRow(quintptr ref,int& row) const;
|
||||
quintptr getChildRef(quintptr ref, int index) const;
|
||||
int getChildrenCount(quintptr ref) const;
|
||||
|
||||
static bool convertTabEntryToRefPointer(uint32_t entry, quintptr& ref);
|
||||
static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry);
|
||||
static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry);
|
||||
|
||||
#ifdef TODO
|
||||
static void generateMissingItem(const RsGxsMessageId &msgId,ChannelPostsModelPostEntry& entry);
|
||||
static void generateMissingItem(const RsGxsMessageId &msgId,ChannelPostsModelPostEntry& entry);
|
||||
#endif
|
||||
void initEmptyHierarchy();
|
||||
void initEmptyHierarchy();
|
||||
|
||||
std::vector<int> mFilteredFiles ; // store the list of files for the post
|
||||
std::vector<ChannelPostFileInfo> mFiles ; // store the list of files for the post
|
||||
|
@ -35,10 +35,10 @@
|
||||
#include "GxsChannelPostsModel.h"
|
||||
#include "GxsChannelPostFilesModel.h"
|
||||
|
||||
//#define DEBUG_CHANNEL_MODEL_DATA
|
||||
//#define DEBUG_CHANNEL_MODEL
|
||||
|
||||
Q_DECLARE_METATYPE(RsMsgMetaData)
|
||||
|
||||
Q_DECLARE_METATYPE(RsGxsChannelPost)
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
||||
@ -47,14 +47,6 @@ RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
||||
: QAbstractItemModel(parent), mTreeMode(RsGxsChannelPostsModel::TREE_MODE_GRID), mColumns(6)
|
||||
{
|
||||
initEmptyHierarchy();
|
||||
|
||||
mEventHandlerId = 0;
|
||||
// Needs to be asynced because this function is called by another thread!
|
||||
|
||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
|
||||
}
|
||||
|
||||
RsGxsChannelPostsModel::~RsGxsChannelPostsModel()
|
||||
@ -72,7 +64,7 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode)
|
||||
triggerViewUpdate();
|
||||
}
|
||||
|
||||
void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments)
|
||||
void RsGxsChannelPostsModel::computeCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments)
|
||||
{
|
||||
// Store posts IDs in a std::map to avoid a quadratic cost
|
||||
|
||||
@ -108,99 +100,6 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
|
||||
}
|
||||
|
||||
|
||||
void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
||||
{
|
||||
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
|
||||
|
||||
if(!e)
|
||||
return;
|
||||
|
||||
switch(e->mChannelEventCode)
|
||||
{
|
||||
case RsChannelEventCode::UPDATED_MESSAGE:
|
||||
case RsChannelEventCode::READ_STATUS_CHANGED:
|
||||
{
|
||||
// Normally we should just emit dataChanged() on the index of the data that has changed:
|
||||
// We need to update the data!
|
||||
|
||||
// make a copy of e, so as to avoid destruction of the shared pointer during async thread execution, since [e] doesn't actually tell
|
||||
// the original shared_ptr that it is copied! So no counter is updated in event, which will be destroyed (as e will be) during or even before
|
||||
// the execution of the lambda.
|
||||
|
||||
RsGxsChannelEvent E(*e);
|
||||
|
||||
if(E.mChannelGroupId == mChannelGroup.mMeta.mGroupId)
|
||||
RsThread::async([this, E]()
|
||||
{
|
||||
// 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject()
|
||||
// At this point we dont know what kind of msg id we have. It can be a vote, a comment or an actual message.
|
||||
|
||||
std::vector<RsGxsChannelPost> posts;
|
||||
std::vector<RsGxsComment> comments;
|
||||
std::vector<RsGxsVote> votes;
|
||||
std::set<RsGxsMessageId> msg_ids{ E.mChannelMsgId };
|
||||
|
||||
if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids, posts,comments,votes))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if what we have actually is a comment or a vote. If so we need to update the actual message they refer to
|
||||
|
||||
if(posts.empty()) // means we have a comment or a vote
|
||||
{
|
||||
msg_ids.clear();
|
||||
|
||||
for(auto c:comments) msg_ids.insert(c.mMeta.mThreadId);
|
||||
for(auto v:votes ) msg_ids.insert(v.mMeta.mThreadId);
|
||||
|
||||
comments.clear();
|
||||
votes.clear();
|
||||
|
||||
if(!rsGxsChannels->getChannelContent(E.mChannelGroupId,msg_ids,posts,comments,votes))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Need to call this in order to get the actuall comment count. The previous call only retrieves the message, since we supplied the message ID.
|
||||
// another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent.
|
||||
|
||||
if(!rsGxsChannels->getChannelComments(E.mChannelGroupId,msg_ids,comments))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << E.mChannelGroupId << "/" << E.mChannelMsgId << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
updateCommentCounts(posts,comments);
|
||||
|
||||
// 2 - update the model in the UI thread.
|
||||
|
||||
RsQThreadUtils::postToObject( [posts,this]()
|
||||
{
|
||||
for(uint32_t i=0;i<posts.size();++i)
|
||||
{
|
||||
// linear search. Not good at all, but normally this is for a single post.
|
||||
|
||||
for(uint32_t j=0;j<mPosts.size();++j)
|
||||
if(mPosts[j].mMeta.mMsgId == posts[i].mMeta.mMsgId)
|
||||
{
|
||||
mPosts[j] = posts[i];
|
||||
|
||||
triggerViewUpdate();
|
||||
}
|
||||
}
|
||||
},this);
|
||||
});
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::initEmptyHierarchy()
|
||||
{
|
||||
beginResetModel();
|
||||
@ -241,7 +140,31 @@ void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)
|
||||
files.push_back(it.second);
|
||||
}
|
||||
|
||||
bool RsGxsChannelPostsModel::postPassesFilter(const RsGxsChannelPost& post,const QStringList& strings,bool only_unread) const
|
||||
{
|
||||
bool passes_strings = true;
|
||||
|
||||
for(auto& s:strings)
|
||||
passes_strings = passes_strings && QString::fromStdString(post.mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
|
||||
|
||||
if(strings.empty())
|
||||
passes_strings = true;
|
||||
|
||||
if(passes_strings && (!only_unread || (IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus))))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count)
|
||||
{
|
||||
mFilteredStrings = strings;
|
||||
mFilterUnread = only_unread;
|
||||
|
||||
updateFilter(count);
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::updateFilter(uint32_t& count)
|
||||
{
|
||||
preMods();
|
||||
|
||||
@ -252,18 +175,8 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre
|
||||
endResetModel();
|
||||
|
||||
for(size_t i=0;i<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(strings.empty())
|
||||
passes_strings = true;
|
||||
|
||||
if(passes_strings && (!only_unread || (IS_MSG_UNREAD(mPosts[i].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[i].mMeta.mMsgStatus))))
|
||||
mFilteredPosts.push_back(i);
|
||||
}
|
||||
if(postPassesFilter(mPosts[i],mFilteredStrings,mFilterUnread))
|
||||
mFilteredPosts.push_back(i);
|
||||
|
||||
count = mFilteredPosts.size();
|
||||
|
||||
@ -292,7 +205,7 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const
|
||||
return mFilteredPosts.size();
|
||||
}
|
||||
|
||||
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
|
||||
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the proper number of rows." ;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -370,7 +283,7 @@ QModelIndex RsGxsChannelPostsModel::index(int row, int column, const QModelIndex
|
||||
|
||||
quintptr ref = getChildRef(parent.internalId(),(mTreeMode == TREE_MODE_GRID)?(column + row*mColumns):row);
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_MODEL_DATA
|
||||
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl;
|
||||
#endif
|
||||
return createIndex(row,column,ref) ;
|
||||
@ -460,7 +373,7 @@ int RsGxsChannelPostsModel::getChildrenCount(quintptr ref) const
|
||||
|
||||
QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_MODEL_DATA
|
||||
std::cerr << "calling data(" << index << ") role=" << role << std::endl;
|
||||
#endif
|
||||
|
||||
@ -477,13 +390,13 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
|
||||
quintptr ref = (index.isValid())?index.internalId():0 ;
|
||||
uint32_t entry = 0;
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_MODEL_DATA
|
||||
std::cerr << "data(" << index << ")" ;
|
||||
#endif
|
||||
|
||||
if(!ref)
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_MODEL_DATA
|
||||
std::cerr << " [empty]" << std::endl;
|
||||
#endif
|
||||
return QVariant() ;
|
||||
@ -491,7 +404,7 @@ QVariant RsGxsChannelPostsModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
#ifdef DEBUG_CHANNEL_MODEL_DATA
|
||||
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
|
||||
#endif
|
||||
return QVariant() ;
|
||||
@ -564,6 +477,79 @@ bool operator<(const RsGxsChannelPost& p1,const RsGxsChannelPost& p2)
|
||||
return p1.mMeta.mPublishTs > p2.mMeta.mPublishTs;
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::updateSinglePost(const RsGxsChannelPost& post,std::set<RsGxsFile>& added_files,std::set<RsGxsFile>& removed_files)
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
RsDbg() << "updating single post for group id=" << currentGroupId() << " and msg id=" << post.mMeta.mMsgId ;
|
||||
#endif
|
||||
added_files.clear();
|
||||
removed_files.clear();
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
// linear search. Not good at all, but normally this is just for a single post.
|
||||
|
||||
bool found = false;
|
||||
const auto& new_post_meta(post.mMeta);
|
||||
|
||||
for(uint32_t j=0;j<mPosts.size();++j)
|
||||
if(new_post_meta.mMsgId == mPosts[j].mMeta.mMsgId) // same post updated
|
||||
{
|
||||
added_files.insert(post.mFiles.begin(),post.mFiles.end());
|
||||
removed_files.insert(mPosts[j].mFiles.begin(),mPosts[j].mFiles.end());
|
||||
|
||||
auto save_ucc = mPosts[j].mUnreadCommentCount;
|
||||
auto save_cc = mPosts[j].mCommentCount;
|
||||
|
||||
mPosts[j] = post;
|
||||
|
||||
mPosts[j].mUnreadCommentCount = save_ucc;
|
||||
mPosts[j].mCommentCount = save_cc;
|
||||
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
RsDbg() << " post is an updated existing post." ;
|
||||
#endif
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
else if( (new_post_meta.mOrigMsgId == mPosts[j].mMeta.mOrigMsgId || new_post_meta.mOrigMsgId == mPosts[j].mMeta.mMsgId)
|
||||
&& mPosts[j].mMeta.mPublishTs < new_post_meta.mPublishTs) // new post version
|
||||
{
|
||||
added_files.insert(post.mFiles.begin(),post.mFiles.end());
|
||||
removed_files.insert(mPosts[j].mFiles.begin(),mPosts[j].mFiles.end());
|
||||
|
||||
auto old_post_id = mPosts[j].mMeta.mMsgId;
|
||||
auto save_ucc = mPosts[j].mUnreadCommentCount;
|
||||
auto save_cc = mPosts[j].mCommentCount;
|
||||
|
||||
mPosts[j] = post;
|
||||
|
||||
mPosts[j].mCommentCount += save_cc;
|
||||
mPosts[j].mUnreadCommentCount += save_ucc;
|
||||
mPosts[j].mOlderVersions.insert(old_post_id);
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
RsDbg() << " post is an new version of an existing post." ;
|
||||
#endif
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
#ifdef DEBUG_CHANNEL_MODEL
|
||||
RsDbg() << " post is an new post.";
|
||||
#endif
|
||||
added_files.insert(post.mFiles.begin(),post.mFiles.end());
|
||||
mPosts.push_back(post);
|
||||
}
|
||||
std::sort(mPosts.begin(),mPosts.end());
|
||||
|
||||
uint32_t count;
|
||||
updateFilter(count);
|
||||
|
||||
triggerViewUpdate();
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
|
||||
{
|
||||
preMods();
|
||||
@ -593,6 +579,8 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
|
||||
emit channelPostsLoaded();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id)
|
||||
{
|
||||
if(group_id.isNull())
|
||||
@ -635,7 +623,7 @@ void RsGxsChannelPostsModel::update_posts(const RsGxsGroupId& group_id)
|
||||
// This shouldn't be needed normally. We need it until a background process computes the number of comments per
|
||||
// post and stores it in the service string. Since we request all data, this process isn't costing much anyway.
|
||||
|
||||
updateCommentCounts(*posts,*comments);
|
||||
computeCommentCounts(*posts,*comments);
|
||||
|
||||
// 2 - update the model in the UI thread.
|
||||
|
||||
@ -801,8 +789,28 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status)
|
||||
if(!rsGxsChannels->setMessageReadStatus(p,read_status))
|
||||
RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl;
|
||||
});
|
||||
|
||||
// 3 - update the local model data, since we don't catch the READ_STATUS_CHANGED event later, to avoid re-loading the msg.
|
||||
|
||||
for(uint32_t i=0;i<mPosts.size();++i)
|
||||
if(read_status)
|
||||
mPosts[i].mMeta.mMsgStatus &= ~(GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD | GXS_SERV::GXS_MSG_STATUS_GUI_NEW);
|
||||
else
|
||||
mPosts[i].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD ;
|
||||
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL));
|
||||
}
|
||||
|
||||
void RsGxsChannelPostsModel::updatePostWithNewComment(const RsGxsMessageId& msg_id)
|
||||
{
|
||||
for(uint32_t i=0;i<mPosts.size();++i)
|
||||
if(mPosts[i].mMeta.mMsgId == msg_id)
|
||||
{
|
||||
++mPosts[i].mUnreadCommentCount;
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(rowCount()-1,mColumns-1,(void*)NULL)); // update everything because we don't know the index.
|
||||
break;
|
||||
}
|
||||
}
|
||||
void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
|
||||
{
|
||||
if(!i.isValid())
|
||||
@ -817,6 +825,18 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta
|
||||
return ;
|
||||
|
||||
rsGxsChannels->setMessageReadStatus(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status);
|
||||
|
||||
// Quick update to the msg itself. Normally setMsgReadStatus will launch an event,
|
||||
// that we can catch to update the msg, but all the information is already here.
|
||||
|
||||
if(read_status)
|
||||
mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus &= ~(GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD | GXS_SERV::GXS_MSG_STATUS_GUI_NEW);
|
||||
else
|
||||
mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
|
||||
|
||||
mPosts[mFilteredPosts[entry]].mUnreadCommentCount = 0;
|
||||
|
||||
emit dataChanged(i,i);
|
||||
}
|
||||
|
||||
QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const
|
||||
|
@ -101,6 +101,7 @@ public:
|
||||
SORT_MODE_CHILDREN_PUBLISH_TS = 0x01,
|
||||
};
|
||||
#endif
|
||||
static void computeCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGxsComment>& comments);
|
||||
|
||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
||||
@ -138,8 +139,11 @@ public:
|
||||
|
||||
void setMsgReadStatus(const QModelIndex &i, bool read_status);
|
||||
void setAllMsgReadStatus(bool read_status);
|
||||
void updatePostWithNewComment(const RsGxsMessageId& msg_id);
|
||||
|
||||
void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ;
|
||||
bool postPassesFilter(const RsGxsChannelPost &post, const QStringList &strings, bool only_unread) const;
|
||||
void updateFilter(uint32_t& count);
|
||||
|
||||
#ifdef TODO
|
||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||
@ -215,6 +219,8 @@ private:
|
||||
|
||||
void update_posts(const RsGxsGroupId& group_id);
|
||||
|
||||
private:
|
||||
|
||||
#ifdef TODO
|
||||
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
|
||||
#endif
|
||||
@ -231,8 +237,13 @@ private:
|
||||
//void computeMessagesHierarchy(const RsGxsChannelGroup& forum_group, const std::vector<RsMsgMetaData> &msgs_array, std::vector<ChannelPostsModelPostEntry> &posts, std::map<RsGxsMessageId, std::vector<std::pair<time_t, RsGxsMessageId> > > &mPostVersions);
|
||||
void createPostsArray(std::vector<RsGxsChannelPost> &posts);
|
||||
void setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost> &posts);
|
||||
void initEmptyHierarchy();
|
||||
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||
public:
|
||||
void updateSinglePost(const RsGxsChannelPost& post, std::set<RsGxsFile>& added_files, std::set<RsGxsFile>& removed_files);
|
||||
private:
|
||||
void initEmptyHierarchy();
|
||||
|
||||
QStringList mFilteredStrings;
|
||||
bool mFilterUnread;
|
||||
|
||||
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering.
|
||||
std::vector<RsGxsChannelPost> mPosts ; // store the list of posts updated from rsForums.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -104,11 +104,11 @@ public:
|
||||
|
||||
/* GxsMessageFrameWidget */
|
||||
virtual QIcon groupIcon() override;
|
||||
virtual void groupIdChanged() override { updateDisplay(true); }
|
||||
virtual void groupIdChanged() override { updateDisplay(true,true); }
|
||||
virtual QString groupName(bool) override;
|
||||
virtual bool navigate(const RsGxsMessageId&) override;
|
||||
|
||||
void updateDisplay(bool complete);
|
||||
void updateDisplay(bool update_group_data, bool update_posts);
|
||||
|
||||
#ifdef TODO
|
||||
/* FeedHolder */
|
||||
@ -141,7 +141,7 @@ protected:
|
||||
|
||||
private slots:
|
||||
void showPostDetails();
|
||||
void updateGroupData();
|
||||
void updateData(bool update_group_data,bool update_posts);
|
||||
void download();
|
||||
void updateDAll_PB();
|
||||
void createMsg();
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit a593b9c808f90cce7d47a5de86c207ef8675945f
|
||||
Subproject commit 5cc37b3e5ad6b64b247e9d2066a9b6c8acae67ce
|
Loading…
Reference in New Issue
Block a user