diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index be00b4252..3e677af3e 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -32,14 +32,14 @@ /** Constructor */ -PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome) - :GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsPosted, true) +PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome) : + GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsPosted, true, false) { setup(); } -PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome) - :GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, false), +PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome) : + GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, false, false), mPost(post) { setup(); diff --git a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp index f3d29d82b..f1beb296f 100644 --- a/retroshare-gui/src/gui/Posted/PostedListDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListDialog.cpp @@ -319,13 +319,13 @@ void PostedListDialog::updateDisplay(bool /*complete*/) /* update List */ insertGroups(); - std::map > &msgs = getMsgIds(); + const std::map > &msgs = getMsgIds(); if(!msgs.empty()) { std::cerr << "rsPosted->msgsChanged():"; std::cerr << std::endl; - std::map >::iterator mit; + std::map >::const_iterator mit; mit = msgs.find(mCurrTopicId); if(mit != msgs.end()) { diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index a7b2a4892..ba35f0938 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -42,16 +42,14 @@ * #define DEBUG_ITEM 1 ****/ -#define DEBUG_ITEM 1 - #define COLOR_NORMAL QColor(248, 248, 248) #define COLOR_NEW QColor(220, 236, 253) #define SELF_LOAD 1 #define DATA_PROVIDED 2 -GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome) : - GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsGxsChannels, true) +GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : + GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsGxsChannels, true, autoUpdate) { mMode = SELF_LOAD; @@ -59,8 +57,8 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, cons } /** Constructor */ -GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subFlags, bool isHome) : - GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, false) +GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subFlags, bool isHome, bool autoUpdate) : + GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, false, autoUpdate) { std::cerr << "GxsChannelPostItem::GxsChannelPostItem() Direct Load"; std::cerr << std::endl; @@ -75,6 +73,19 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, cons loadPost(post); } +bool GxsChannelPostItem::setPost(const RsGxsChannelPost &post) +{ + if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) { + std::cerr << "GxsChannelPostItem::setPost() - Wrong id, cannot set post"; + std::cerr << std::endl; + return false; + } + + loadPost(post); + + return true; +} + GxsChannelPostItem::~GxsChannelPostItem() { delete(ui); @@ -162,6 +173,7 @@ void GxsChannelPostItem::loadMessage(const uint32_t &token) void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post) { /* fill in */ + #ifdef DEBUG_ITEM std::cerr << "GxsChannelPostItem::loadPost()"; std::cerr << std::endl; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index 0a56ce1c9..0c2fc99db 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -41,11 +41,12 @@ class GxsChannelPostItem : public GxsFeedItem public: /** Default Constructor */ - GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome); - GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subscribeFlags, bool isHome); + GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate); + GxsChannelPostItem(FeedHolder *parent, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subscribeFlags, bool isHome, bool autoUpdate); virtual ~GxsChannelPostItem(); void setFileCleanUpWarning(uint32_t time_left); + bool setPost(const RsGxsChannelPost &post); protected: virtual void loadMessage(const uint32_t &token); diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp index ce996400c..12f95d439 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp @@ -23,6 +23,7 @@ #include "gui/gxs/GxsFeedItem.h" #include "gui/feeds/FeedHolder.h" +#include "gui/gxs/RsGxsUpdateBroadcastBase.h" #include @@ -111,7 +112,7 @@ void GxsFeedItem::updateItem() /***********************************************************/ -GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData) : +GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData, bool autoUpdate) : QWidget(NULL) { std::cerr << "GxsFeedItem::GxsFeedItem()"; @@ -136,6 +137,14 @@ GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId { mLoadQueue = NULL; } + + if (mGxsIface && autoUpdate) { + /* Connect to update broadcast */ + mUpdateBroadcastBase = new RsGxsUpdateBroadcastBase(mGxsIface); + connect(mUpdateBroadcastBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool))); + } else { + mUpdateBroadcastBase = NULL; + } } GxsFeedItem::~GxsFeedItem() @@ -143,12 +152,33 @@ GxsFeedItem::~GxsFeedItem() std::cerr << "GxsFeedItem::~GxsFeedItem()"; std::cerr << std::endl; + if (mUpdateBroadcastBase) + { + delete(mUpdateBroadcastBase); + } + if (mLoadQueue) { delete mLoadQueue; } } +void GxsFeedItem::fillDisplay(bool /*complete*/) +{ + const std::map > &msgs = mUpdateBroadcastBase->getMsgIds(); + if (!msgs.empty()) + { + std::map >::const_iterator mit = msgs.find(groupId()); + if (mit != msgs.end()) + { + const std::vector &msgIds = mit->second; + if (std::find(msgIds.begin(), msgIds.end(), messageId()) != msgIds.end()) { + requestMessage(); + } + } + } +} + void GxsFeedItem::requestGroupMeta() { std::cerr << "GxsFeedItem::requestGroup()"; @@ -177,7 +207,12 @@ void GxsFeedItem::requestMessage() if (!mLoadQueue) { - return; + if (mGxsIface) + { + mLoadQueue = new TokenQueue(mGxsIface->getTokenService(), this); + } else { + return; + } } RsTokReqOptions opts; diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.h b/retroshare-gui/src/gui/gxs/GxsFeedItem.h index cda2cc992..328b3fd11 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.h @@ -29,6 +29,7 @@ #include class FeedHolder; +class RsGxsUpdateBroadcastBase; class GxsFeedItem : public QWidget, public TokenResponse { @@ -36,7 +37,7 @@ class GxsFeedItem : public QWidget, public TokenResponse public: /** Note parent can = NULL */ - GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData); + GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData, bool autoUpdate); virtual ~GxsFeedItem(); RsGxsGroupId groupId() { return mGroupId; } @@ -61,6 +62,10 @@ protected slots: void unsubscribe(); void removeItem(); +private slots: + /* RsGxsUpdateBroadcastBase */ + void fillDisplay(bool complete); + protected: FeedHolder *mParent; uint32_t mFeedId; @@ -76,6 +81,7 @@ private: RsGxsIfaceHelper *mGxsIface; TokenQueue *mLoadQueue; + RsGxsUpdateBroadcastBase *mUpdateBroadcastBase; }; #endif diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastBase.h b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastBase.h index ce3d02cd3..236299e38 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastBase.h +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastBase.h @@ -14,16 +14,17 @@ class RsGxsUpdateBroadcastBase : public QObject Q_OBJECT -protected: +public: RsGxsUpdateBroadcastBase(RsGxsIfaceHelper* ifaceImpl, QWidget *parent = NULL); virtual ~RsGxsUpdateBroadcastBase(); + const std::list &getGrpIds() { return mGrpIds; } + const std::map > &getMsgIds() { return mMsgIds; } + +protected: void fillComplete(); void setUpdateWhenInvisible(bool update) { mUpdateWhenInvisible = update; } - std::list &getGrpIds() { return mGrpIds; } - std::map > &getMsgIds() { return mMsgIds; } - void showEvent(QShowEvent *e); signals: diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp index 7d99ab860..8f00f339d 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp @@ -22,12 +22,12 @@ void RsGxsUpdateBroadcastPage::setUpdateWhenInvisible(bool update) mBase->setUpdateWhenInvisible(update); } -std::list &RsGxsUpdateBroadcastPage::getGrpIds() +const std::list &RsGxsUpdateBroadcastPage::getGrpIds() { return mBase->getGrpIds(); } -std::map > &RsGxsUpdateBroadcastPage::getMsgIds() +const std::map > &RsGxsUpdateBroadcastPage::getMsgIds() { return mBase->getMsgIds(); } diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h index a4dc8a774..9db362fd8 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h @@ -24,8 +24,8 @@ public: void fillComplete(); void setUpdateWhenInvisible(bool update); - std::list &getGrpIds(); - std::map > &getMsgIds(); + const std::list &getGrpIds(); + const std::map > &getMsgIds(); protected: virtual void showEvent(QShowEvent *event); diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.cpp b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.cpp index 2b76d8eee..067b817c4 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.cpp +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.cpp @@ -22,12 +22,12 @@ void RsGxsUpdateBroadcastWidget::setUpdateWhenInvisible(bool update) mBase->setUpdateWhenInvisible(update); } -std::list &RsGxsUpdateBroadcastWidget::getGrpIds() +const std::list &RsGxsUpdateBroadcastWidget::getGrpIds() { return mBase->getGrpIds(); } -std::map > &RsGxsUpdateBroadcastWidget::getMsgIds() +const std::map > &RsGxsUpdateBroadcastWidget::getMsgIds() { return mBase->getMsgIds(); } diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.h b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.h index f3a8226a7..bbecc7dbf 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.h +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastWidget.h @@ -24,8 +24,8 @@ public: void fillComplete(); void setUpdateWhenInvisible(bool update); - std::list &getGrpIds(); - std::map > &getMsgIds(); + const std::list &getGrpIds(); + const std::map > &getMsgIds(); protected: virtual void showEvent(QShowEvent *event); diff --git a/retroshare-gui/src/gui/gxschannels/ChannelDialog.h b/retroshare-gui/src/gui/gxschannels/ChannelDialog.h index 7f48c85a7..984f77f67 100644 --- a/retroshare-gui/src/gui/gxschannels/ChannelDialog.h +++ b/retroshare-gui/src/gui/gxschannels/ChannelDialog.h @@ -60,7 +60,7 @@ public: virtual QWidget *createHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId) { - return new GxsChannelPostItem(NULL, 0, grpId, msgId, true); + return new GxsChannelPostItem(NULL, 0, grpId, msgId, true, true); } virtual QPixmap getServicePixmap() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index b41e24c43..d24d16c47 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -43,8 +43,8 @@ #define TOKEN_TYPE_RELATEDPOSTS 8 /** Constructor */ -GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) - : GxsMessageFrameWidget(rsGxsChannels, parent), +GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) : + GxsMessageFrameWidget(rsGxsChannels, parent), ui(new Ui::GxsChannelPostsWidget) { /* Invoke the Qt Designer generated object setup routine */ @@ -96,16 +96,16 @@ void GxsChannelPostsWidget::updateDisplay(bool complete) return; } - std::list &grpIds = getGrpIds(); + const std::list &grpIds = getGrpIds(); if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) { requestGroupData(mChannelId); /* Do we need to fill all posts? */ requestPosts(mChannelId); } else { - std::map > &msgs = getMsgIds(); + const std::map > &msgs = getMsgIds(); if (!msgs.empty()) { - std::map >::iterator mit = msgs.find(mChannelId); + std::map >::const_iterator mit = msgs.find(mChannelId); if(mit != msgs.end()) { requestRelatedPosts(mChannelId, mit->second); @@ -279,9 +279,10 @@ void GxsChannelPostsWidget::insertChannelPosts(std::vector &po } } if (item) { - //TODO: Update item + item->setPost(*it); + //TODO: Sort timestamp } else { - item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true); + item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true, false); mChannelPostItems.push_back(item); if (related) { ui->verticalLayout->insertWidget(0, item); @@ -626,10 +627,11 @@ void GxsChannelPostsWidget::requestRelatedPosts(const RsGxsGroupId &grpId, const return; } - mStateHelper->setLoading(TOKEN_TYPE_POSTS, true); + if (msgIds.empty()) { + return; + } - std::list groupIds; - groupIds.push_back(grpId); + mStateHelper->setLoading(TOKEN_TYPE_POSTS, true); RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 9b5d01c0b..bb357fdc0 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -318,12 +318,12 @@ void GxsForumThreadWidget::updateDisplay(bool complete) return; } - std::list &grpIds = getGrpIds(); + const std::list &grpIds = getGrpIds(); if (std::find(grpIds.begin(), grpIds.end(), mForumId) != grpIds.end()) { /* Update threads */ insertThreads(); } else { - std::map > &msgIds = getMsgIds(); + const std::map > &msgIds = getMsgIds(); if (msgIds.find(mForumId) != msgIds.end()) { /* Update threads */ insertThreads();