Added new base class GxsMessageFramePostWidget for post-based services like Channels and Posted.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7466 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-07-23 18:51:56 +00:00
parent b1f7523248
commit 1de9e4a842
11 changed files with 620 additions and 1032 deletions

View File

@ -24,7 +24,6 @@
#include <QMessageBox> #include <QMessageBox>
#include "PostedCreatePostDialog.h" #include "PostedCreatePostDialog.h"
#include "ui_PostedCreatePostDialog.h" #include "ui_PostedCreatePostDialog.h"
#include "PostedUserTypes.h"
#include "util/TokenQueue.h" #include "util/TokenQueue.h"
#include "gui/Identity/IdDialog.h" #include "gui/Identity/IdDialog.h"
@ -89,7 +88,7 @@ void PostedCreatePostDialog::createPost()
uint32_t token; uint32_t token;
mPosted->createPost(token, post); mPosted->createPost(token, post);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_POST); // mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_POST);
accept(); accept();
} }

View File

@ -28,57 +28,29 @@
#include "PostedCreatePostDialog.h" #include "PostedCreatePostDialog.h"
#include "PostedItem.h" #include "PostedItem.h"
#include "PostedUserTypes.h"
#include "gui/Identity/IdDialog.h" #include "gui/Identity/IdDialog.h"
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include <retroshare/rsposted.h> #include <retroshare/rsposted.h>
/*********************** **** **** **** ***********************/
/** Request / Response of Data ********************************/
/*********************** **** **** **** ***********************/
//#define POSTEDDIALOG_LISTING 1
//#define POSTEDDIALOG_CURRENTFORUM 2
#define POSTEDDIALOG_INSERTTHREADS 3
//#define POSTEDDIALOG_INSERTCHILD 4
//#define POSTEDDIALOG_INSERT_POST 5
//#define POSTEDDIALOG_REPLY_MESSAGE 6
/****************************************************************
*/
// token types to deal with
#define POSTED_DEFAULT_LISTING_LENGTH 10 #define POSTED_DEFAULT_LISTING_LENGTH 10
#define POSTED_MAX_INDEX 10000 #define POSTED_MAX_INDEX 10000
/** Constructor */ /** Constructor */
PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent) PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent)
: GxsMessageFrameWidget(rsPosted, parent), : GxsMessageFramePostWidget(rsPosted, parent),
ui(new Ui::PostedListWidget) ui(new Ui::PostedListWidget)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this); ui->setupUi(this);
/* Setup UI helper */ /* Setup UI helper */
mStateHelper = new UIStateHelper(this); mStateHelper->addWidget(mTokenTypePosts, ui->hotSortButton);
mStateHelper->addWidget(mTokenTypePosts, ui->newSortButton);
mStateHelper->addWidget(mTokenTypePosts, ui->topSortButton);
// No progress yet mStateHelper->addWidget(mTokenTypeGroupData, ui->submitPostButton);
// mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->loadingLabel, UISTATE_LOADING_VISIBLE); // mStateHelper->addWidget(mTokenTypeGroupData, ui->subscribeToolButton);
// mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressBar, UISTATE_LOADING_VISIBLE);
// mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressLabel, UISTATE_LOADING_VISIBLE);
// mStateHelper->addLoadPlaceholder(TOKEN_TYPE_GROUP_DATA, ui->nameLabel);
// mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->postButton);
// mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel);
// mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->subscribeToolButton);
/* Setup Queue */
mPostedQueue = new TokenQueue(rsPosted->getTokenService(), this);
mSubscribeFlags = 0;
connect(ui->hotSortButton, SIGNAL(clicked()), this, SLOT(getRankings())); connect(ui->hotSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
connect(ui->newSortButton, SIGNAL(clicked()), this, SLOT(getRankings())); connect(ui->newSortButton, SIGNAL(clicked()), this, SLOT(getRankings()));
@ -94,6 +66,8 @@ PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent
mPostIndex = 0; mPostIndex = 0;
mPostShow = POSTED_DEFAULT_LISTING_LENGTH; mPostShow = POSTED_DEFAULT_LISTING_LENGTH;
mTokenTypeVote = nextTokenType();
ui->hotSortButton->setChecked(true); ui->hotSortButton->setChecked(true);
/* fill in the available OwnIds for signing */ /* fill in the available OwnIds for signing */
@ -114,58 +88,6 @@ PostedListWidget::~PostedListWidget()
processSettings(false); processSettings(false);
} }
void PostedListWidget::updateDisplay(bool complete)
{
std::cerr << "rsPosted->updateDisplay()";
std::cerr << std::endl;
if (complete) {
/* Fill complete */
requestGroupData();
requestPosts();
return;
}
if (mPostedId.isNull()) {
return;
}
bool updateGroup = false;
const std::list<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mPostedId) != grpIdsMeta.end()) {
updateGroup = true;
}
const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mPostedId.isNull() && std::find(grpIds.begin(), grpIds.end(), mPostedId) != grpIds.end()) {
updateGroup = true;
/* Do we need to fill all posts? */
requestPosts();
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
getAllMsgIds(msgs);
if (!msgs.empty())
{
std::cerr << "rsPosted->msgsChanged():";
std::cerr << std::endl;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit;
mit = msgs.find(mPostedId);
if(mit != msgs.end())
{
std::cerr << "current Group -> updating Displayed Items";
std::cerr << std::endl;
updateDisplayedItems(mit->second);
}
}
}
if (updateGroup) {
requestGroupData();
}
}
void PostedListWidget::processSettings(bool load) void PostedListWidget::processSettings(bool load)
{ {
// Settings->beginGroup(QString("PostedListWidget")); // Settings->beginGroup(QString("PostedListWidget"));
@ -179,38 +101,11 @@ void PostedListWidget::processSettings(bool load)
// Settings->endGroup(); // Settings->endGroup();
} }
void PostedListWidget::setGroupId(const RsGxsGroupId &groupId)
{
if (mPostedId == groupId) {
if (!groupId.isNull()) {
return;
}
}
mPostedId = groupId;
mName = mPostedId.isNull () ? "" : tr("Loading");
emit groupChanged(this);
fillComplete();
}
QString PostedListWidget::groupName(bool withUnreadCount)
{
QString name = mPostedId.isNull () ? tr("No name") : mName;
// if (withUnreadCount && mUnreadCount) {
// name += QString(" (%1)").arg(mUnreadCount);
// }
return name;
}
QIcon PostedListWidget::groupIcon() QIcon PostedListWidget::groupIcon()
{ {
// if (mStateHelper->isLoading(TOKEN_TYPE_GROUP_DATA) || mStateHelper->isLoading(TOKEN_TYPE_POSTS)) { if (mStateHelper->isLoading(mTokenTypeGroupData) || mStateHelper->isLoading(mTokenTypePosts)) {
// return QIcon(":/images/kalarm.png"); // return QIcon(":/images/kalarm.png");
// } }
// if (mNewCount) { // if (mNewCount) {
// return QIcon(":/images/message-state-new.png"); // return QIcon(":/images/message-state-new.png");
@ -247,14 +142,14 @@ void PostedListWidget::openComments(uint32_t /*feed_type*/, const RsGxsGroupId &
void PostedListWidget::newPost() void PostedListWidget::newPost()
{ {
if (mPostedId.isNull()) if (groupId().isNull())
return; return;
if (!IS_GROUP_SUBSCRIBED(mSubscribeFlags)) { if (!IS_GROUP_SUBSCRIBED(subscribeFlags())) {
return; return;
} }
PostedCreatePostDialog *cp = new PostedCreatePostDialog(mPostedQueue, rsPosted, mPostedId, this); PostedCreatePostDialog *cp = new PostedCreatePostDialog(mTokenQueue, rsPosted, groupId(), this);
cp->show(); cp->show();
/* window will destroy itself! */ /* window will destroy itself! */
@ -290,7 +185,7 @@ void PostedListWidget::updateShowText()
void PostedListWidget::getRankings() void PostedListWidget::getRankings()
{ {
if (mPostedId.isNull()) if (groupId().isNull())
return; return;
std::cerr << "PostedListWidget::getRankings()"; std::cerr << "PostedListWidget::getRankings()";
@ -368,50 +263,7 @@ void PostedListWidget::submitVote(const RsGxsGrpMsgIdPair &msgId, bool up)
uint32_t token; uint32_t token;
rsPosted->createVote(token, vote); rsPosted->createVote(token, vote);
mPostedQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_VOTE); mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, mTokenTypeVote);
}
/*****************************************************************************************/
void PostedListWidget::updateDisplayedItems(const std::vector<RsGxsMessageId> &msgIds)
{
mPostedQueue->cancelActiveRequestTokens(TOKEN_USER_TYPE_POST_MOD);
if (mPostedId.isNull()) {
mStateHelper->setActive(TOKEN_USER_TYPE_POST, false);
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, false);
mStateHelper->clear(TOKEN_USER_TYPE_POST);
emit groupChanged(this);
return;
}
if (msgIds.empty()) {
return;
}
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, true);
emit groupChanged(this);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
GxsMsgReq msgs;
msgs[mPostedId] = msgIds;
std::cerr << "PostedListWidget::updateDisplayedItems(" << mPostedId << ")";
std::cerr << std::endl;
std::vector<RsGxsMessageId>::const_iterator it;
for(it = msgIds.begin(); it != msgIds.end(); it++)
{
std::cerr << "\t\tMsgId: " << *it;
std::cerr << std::endl;
}
uint32_t token;
mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgs, TOKEN_USER_TYPE_POST_MOD);
} }
void PostedListWidget::createNewGxsId() void PostedListWidget::createNewGxsId()
@ -422,6 +274,8 @@ void PostedListWidget::createNewGxsId()
ui->idChooser->setDefaultId(dlg.getLastIdName()); ui->idChooser->setDefaultId(dlg.getLastIdName());
} }
/*****************************************************************************************/
void PostedListWidget::acknowledgeVoteMsg(const uint32_t &token) void PostedListWidget::acknowledgeVoteMsg(const uint32_t &token)
{ {
RsGxsGrpMsgIdPair msgId; RsGxsGrpMsgIdPair msgId;
@ -437,76 +291,9 @@ void PostedListWidget::loadVoteData(const uint32_t &/*token*/)
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
void PostedListWidget::requestGroupData()
{
#ifdef DEBUG_POSTED
std::cerr << "PostedListWidget::requestGroupData()";
std::cerr << std::endl;
#endif
mSubscribeFlags = 0;
mPostedQueue->cancelActiveRequestTokens(TOKEN_USER_TYPE_TOPIC);
if (mPostedId.isNull()) {
mStateHelper->setActive(TOKEN_USER_TYPE_TOPIC, false);
mStateHelper->setLoading(TOKEN_USER_TYPE_TOPIC, false);
mStateHelper->clear(TOKEN_USER_TYPE_TOPIC);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(TOKEN_USER_TYPE_TOPIC, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mPostedId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mPostedQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_USER_TYPE_TOPIC);
}
void PostedListWidget::loadGroupData(const uint32_t &token)
{
std::cerr << "PostedListWidget::loadGroupData()";
std::cerr << std::endl;
std::vector<RsPostedGroup> groups;
rsPosted->getGroupData(token, groups);
mStateHelper->setLoading(TOKEN_USER_TYPE_TOPIC, false);
if (groups.size() == 1)
{
insertPostedDetails(groups[0]);
}
else
{
std::cerr << "PostedListWidget::loadGroupData() ERROR Invalid Number of Groups...";
std::cerr << std::endl;
mStateHelper->setActive(TOKEN_USER_TYPE_TOPIC, false);
mStateHelper->clear(TOKEN_USER_TYPE_TOPIC);
}
emit groupChanged(this);
}
void PostedListWidget::insertPostedDetails(const RsPostedGroup &group) void PostedListWidget::insertPostedDetails(const RsPostedGroup &group)
{ {
mStateHelper->setActive(TOKEN_USER_TYPE_TOPIC, true); if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
mSubscribeFlags = group.mMeta.mSubscribeFlags;
/* set name */
mName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
if (mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
{ {
mStateHelper->setWidgetEnabled(ui->submitPostButton, true); mStateHelper->setWidgetEnabled(ui->submitPostButton, true);
} }
@ -515,7 +302,7 @@ void PostedListWidget::insertPostedDetails(const RsPostedGroup &group)
mStateHelper->setWidgetEnabled(ui->submitPostButton, false); mStateHelper->setWidgetEnabled(ui->submitPostButton, false);
} }
// ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(mSubscribeFlags)); // ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags));
} }
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
@ -523,78 +310,6 @@ void PostedListWidget::insertPostedDetails(const RsPostedGroup &group)
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
void PostedListWidget::requestPosts()
{
std::cerr << "PostedListWidget::loadCurrentForumThreads(" << mPostedId << ")";
std::cerr << std::endl;
clearPosts();
mPostedQueue->cancelActiveRequestTokens(TOKEN_USER_TYPE_POST);
if (mPostedId.isNull())
{
std::cerr << "PostedListWidget::loadCurrentForumThreads() Empty GroupId .. ignoring Req";
std::cerr << std::endl;
mStateHelper->setActive(TOKEN_USER_TYPE_POST, false);
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, false);
mStateHelper->clear(TOKEN_USER_TYPE_POST);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, true);
emit groupChanged(this);
/* initiate loading */
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_LATEST;
std::list<RsGxsGroupId> grpIds;
grpIds.push_back(mPostedId);
std::cerr << "PostedListWidget::requestGroupThreadData_InsertThreads(" << mPostedId << ")";
std::cerr << std::endl;
uint32_t token;
mPostedQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grpIds, TOKEN_USER_TYPE_POST);
}
void PostedListWidget::acknowledgePostMsg(const uint32_t &token)
{
RsGxsGrpMsgIdPair msgId;
// just acknowledge, don't load anything
rsPosted->acknowledgeMsg(token, msgId);
}
void PostedListWidget::loadPostData(const uint32_t &token)
{
std::cerr << "PostedListWidget::loadGroupThreadData_InsertThreads()";
std::cerr << std::endl;
mStateHelper->setActive(TOKEN_USER_TYPE_POST, true);
clearPosts();
std::vector<RsPostedPost> posts;
rsPosted->getPostData(token, posts);
std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); vit++)
{
RsPostedPost& p = *vit;
loadPost(p);
}
applyRanking();
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, false);
emit groupChanged(this);
}
void PostedListWidget::loadPost(const RsPostedPost &post) void PostedListWidget::loadPost(const RsPostedPost &post)
{ {
PostedItem *item = new PostedItem(this, 0, post, true); PostedItem *item = new PostedItem(this, 0, post, true);
@ -602,13 +317,20 @@ void PostedListWidget::loadPost(const RsPostedPost &post)
mPosts.insert(post.mMeta.mMsgId, item); mPosts.insert(post.mMeta.mMsgId, item);
//QLayout *alayout = ui.scrollAreaWidgetContents->layout(); //QLayout *alayout = ui.scrollAreaWidgetContents->layout();
//alayout->addWidget(item); //alayout->addWidget(item);
mPostList.push_back(item); mPostItems.push_back(item);
} }
static bool CmpPIHot(const PostedItem *a, const PostedItem *b) static bool CmpPIHot(const GxsFeedItem *a, const GxsFeedItem *b)
{ {
const RsPostedPost &postA = a->getPost(); const PostedItem *aa = dynamic_cast<const PostedItem*>(a);
const RsPostedPost &postB = b->getPost(); const PostedItem *bb = dynamic_cast<const PostedItem*>(b);
if (!aa || !bb) {
return true;
}
const RsPostedPost &postA = aa->getPost();
const RsPostedPost &postB = bb->getPost();
if (postA.mHotScore == postB.mHotScore) if (postA.mHotScore == postB.mHotScore)
{ {
@ -618,10 +340,17 @@ static bool CmpPIHot(const PostedItem *a, const PostedItem *b)
return (postA.mHotScore > postB.mHotScore); return (postA.mHotScore > postB.mHotScore);
} }
static bool CmpPITop(const PostedItem *a, const PostedItem *b) static bool CmpPITop(const GxsFeedItem *a, const GxsFeedItem *b)
{ {
const RsPostedPost &postA = a->getPost(); const PostedItem *aa = dynamic_cast<const PostedItem*>(a);
const RsPostedPost &postB = b->getPost(); const PostedItem *bb = dynamic_cast<const PostedItem*>(b);
if (!aa || !bb) {
return true;
}
const RsPostedPost &postA = aa->getPost();
const RsPostedPost &postB = bb->getPost();
if (postA.mTopScore == postB.mTopScore) if (postA.mTopScore == postB.mTopScore)
{ {
@ -631,9 +360,16 @@ static bool CmpPITop(const PostedItem *a, const PostedItem *b)
return (postA.mTopScore > postB.mTopScore); return (postA.mTopScore > postB.mTopScore);
} }
static bool CmpPINew(const PostedItem *a, const PostedItem *b) static bool CmpPINew(const GxsFeedItem *a, const GxsFeedItem *b)
{ {
return (a->getPost().mNewScore > b->getPost().mNewScore); const PostedItem *aa = dynamic_cast<const PostedItem*>(a);
const PostedItem *bb = dynamic_cast<const PostedItem*>(b);
if (!aa || !bb) {
return true;
}
return (aa->getPost().mNewScore > bb->getPost().mNewScore);
} }
void PostedListWidget::applyRanking() void PostedListWidget::applyRanking()
@ -651,17 +387,17 @@ void PostedListWidget::applyRanking()
case RsPosted::HotRankType: case RsPosted::HotRankType:
std::cerr << "PostedListWidget::applyRanking() HOT"; std::cerr << "PostedListWidget::applyRanking() HOT";
std::cerr << std::endl; std::cerr << std::endl;
mPostList.sort(CmpPIHot); qSort(mPostItems.begin(), mPostItems.end(), CmpPIHot);
break; break;
case RsPosted::NewRankType: case RsPosted::NewRankType:
std::cerr << "PostedListWidget::applyRanking() NEW"; std::cerr << "PostedListWidget::applyRanking() NEW";
std::cerr << std::endl; std::cerr << std::endl;
mPostList.sort(CmpPINew); qSort(mPostItems.begin(), mPostItems.end(), CmpPINew);
break; break;
case RsPosted::TopRankType: case RsPosted::TopRankType:
std::cerr << "PostedListWidget::applyRanking() TOP"; std::cerr << "PostedListWidget::applyRanking() TOP";
std::cerr << std::endl; std::cerr << std::endl;
mPostList.sort(CmpPITop); qSort(mPostItems.begin(), mPostItems.end(), CmpPITop);
break; break;
} }
mLastSortMethod = mSortMethod; mLastSortMethod = mSortMethod;
@ -673,10 +409,12 @@ void PostedListWidget::applyRanking()
QLayout *alayout = ui->scrollAreaWidgetContents->layout(); QLayout *alayout = ui->scrollAreaWidgetContents->layout();
int counter = 0; int counter = 0;
time_t min_ts = 0; time_t min_ts = 0;
std::list<PostedItem *>::iterator it; foreach (GxsFeedItem *feedItem, mPostItems)
for(it = mPostList.begin(); it != mPostList.end(); it++)
{ {
PostedItem *item = (*it); PostedItem *item = dynamic_cast<PostedItem*>(feedItem);
if (!item) {
continue;
}
std::cerr << "PostedListWidget::applyRanking() Item: " << item; std::cerr << "PostedListWidget::applyRanking() Item: " << item;
std::cerr << std::endl; std::cerr << std::endl;
@ -720,47 +458,9 @@ void PostedListWidget::applyRanking()
void PostedListWidget::clearPosts() void PostedListWidget::clearPosts()
{ {
std::cerr << "PostedListWidget::clearPosts()" << std::endl; GxsMessageFramePostWidget::clearPosts();
std::list<PostedItem *> postedItems;
std::list<PostedItem *>::iterator pit;
QLayout *alayout = ui->scrollAreaWidgetContents->layout();
int count = alayout->count();
for(int i = 0; i < count; i++)
{
QLayoutItem *litem = alayout->itemAt(i);
if (!litem)
{
std::cerr << "PostedListWidget::clearPosts() missing litem";
std::cerr << std::endl;
continue;
}
PostedItem *item = dynamic_cast<PostedItem *>(litem->widget());
if (item)
{
std::cerr << "PostedListWidget::clearPosts() item: " << item;
std::cerr << std::endl;
postedItems.push_back(item);
}
else
{
std::cerr << "PostedListWidget::clearPosts() Found Child, which is not a PostedItem???";
std::cerr << std::endl;
}
}
for(pit = postedItems.begin(); pit != postedItems.end(); pit++)
{
PostedItem *item = *pit;
alayout->removeWidget(item);
delete item;
}
mPosts.clear(); mPosts.clear();
mPostList.clear();
} }
void PostedListWidget::shallowClearPosts() void PostedListWidget::shallowClearPosts()
@ -804,22 +504,6 @@ void PostedListWidget::shallowClearPosts()
} }
} }
void PostedListWidget::setAllMessagesRead(bool read)
{
// if (mPostedId.isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) {
// return;
// }
// QList<GxsChannelPostItem *>::iterator mit;
// for (mit = mChannelPostItems.begin(); mit != mChannelPostItems.end(); ++mit) {
// GxsChannelPostItem *item = *mit;
// RsGxsGrpMsgIdPair msgPair = std::make_pair(item->groupId(), item->messageId());
// uint32_t token;
// rsGxsChannels->setMessageReadStatus(token, msgPair, read);
// }
}
//void PostedListWidget::subscribeGroup(bool subscribe) //void PostedListWidget::subscribeGroup(bool subscribe)
//{ //{
// if (mChannelId.isNull()) { // if (mChannelId.isNull()) {
@ -831,15 +515,52 @@ void PostedListWidget::setAllMessagesRead(bool read)
//// mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE); //// mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE);
//} //}
void PostedListWidget::updateCurrentDisplayComplete(const uint32_t &token) //void PostedListWidget::acknowledgeSubscribeChange(const uint32_t &token)
{ //{
std::cerr << "PostedListWidget::updateCurrentDisplayComplete()"; // std::cerr << "PostedListWidget::acknowledgeSubscribeChange()";
std::cerr << std::endl; // std::cerr << std::endl;
// std::vector<RsPostedPost> posts;
// RsGxsGroupId groupId;
// rsPosted->acknowledgeGrp(token, groupId);
// insertGroups();
//}
bool PostedListWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData)
{
std::vector<RsPostedGroup> groups;
rsPosted->getGroupData(token, groups);
if (groups.size() == 1)
{
insertPostedDetails(groups[0]);
metaData = groups[0].mMeta;
return true;
}
return false;
}
void PostedListWidget::insertPosts(const uint32_t &token)
{
std::vector<RsPostedPost> posts; std::vector<RsPostedPost> posts;
rsPosted->getPostData(token, posts); rsPosted->getPostData(token, posts);
mStateHelper->setActive(TOKEN_USER_TYPE_POST, true); std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); vit++)
{
RsPostedPost& p = *vit;
loadPost(p);
}
applyRanking();
}
void PostedListWidget::insertRelatedPosts(const uint32_t &token)
{
std::vector<RsPostedPost> posts;
rsPosted->getRelatedPosts(token, posts);
std::vector<RsPostedPost>::iterator vit; std::vector<RsPostedPost>::iterator vit;
for(vit = posts.begin(); vit != posts.end(); vit++) for(vit = posts.begin(); vit != posts.end(); vit++)
@ -871,22 +592,15 @@ void PostedListWidget::updateCurrentDisplayComplete(const uint32_t &token)
} }
applyRanking(); applyRanking();
mStateHelper->setLoading(TOKEN_USER_TYPE_POST, false);
emit groupChanged(this);
} }
//void PostedListWidget::acknowledgeSubscribeChange(const uint32_t &token) void PostedListWidget::setMessageRead(GxsFeedItem *item, bool read)
//{ {
// std::cerr << "PostedListWidget::acknowledgeSubscribeChange()"; RsGxsGrpMsgIdPair msgPair = std::make_pair(item->groupId(), item->messageId());
// std::cerr << std::endl;
// std::vector<RsPostedPost> posts; uint32_t token;
// RsGxsGroupId groupId; rsPosted->setMessageReadStatus(token, msgPair, read);
// rsPosted->acknowledgeGrp(token, groupId); }
// insertGroups();
//}
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/
@ -897,58 +611,21 @@ void PostedListWidget::loadRequest(const TokenQueue *queue, const TokenRequest &
std::cerr << "PostedListWidget::loadRequest() UserType: " << req.mUserType; std::cerr << "PostedListWidget::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl; std::cerr << std::endl;
if (queue == mPostedQueue) if (queue == mTokenQueue)
{ {
/* now switch on req */ /* now switch on req */
switch(req.mUserType) if (req.mUserType == mTokenTypeVote) {
{ switch(req.mAnsType)
case TOKEN_USER_TYPE_TOPIC: {
switch(req.mAnsType) case RS_TOKREQ_ANSTYPE_ACK:
{ acknowledgeVoteMsg(req.mToken);
case RS_TOKREQ_ANSTYPE_DATA: break;
loadGroupData(req.mToken); default:
break; std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
default: break;
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl; }
break; return;
} }
break;
case TOKEN_USER_TYPE_POST:
switch(req.mAnsType)
{
case RS_TOKREQ_ANSTYPE_ACK:
acknowledgePostMsg(req.mToken);
break;
case RS_TOKREQ_ANSTYPE_DATA:
loadPostData(req.mToken);
break;
default:
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
break;
}
break;
case TOKEN_USER_TYPE_VOTE:
switch(req.mAnsType)
{
case RS_TOKREQ_ANSTYPE_ACK:
acknowledgeVoteMsg(req.mToken);
break;
default:
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
break;
}
break;
case TOKEN_USER_TYPE_POST_MOD:
switch(req.mAnsType)
{
case RS_TOKREQ_ANSTYPE_DATA:
updateCurrentDisplayComplete(req.mToken);
break;
default:
std::cerr << "Error, unexpected anstype:" << req.mAnsType << std::endl;
break;
}
break;
// case TOKEN_USER_TYPE_POST_RANKINGS: // case TOKEN_USER_TYPE_POST_RANKINGS:
// switch(req.mAnsType) // switch(req.mAnsType)
// { // {
@ -962,10 +639,7 @@ void PostedListWidget::loadRequest(const TokenQueue *queue, const TokenRequest &
// case TOKEN_USER_TYPE_SUBSCRIBE_CHANGE: // case TOKEN_USER_TYPE_SUBSCRIBE_CHANGE:
// acknowledgeSubscribeChange(req.mToken); // acknowledgeSubscribeChange(req.mToken);
// break; // break;
default:
std::cerr << "PostedListWidget::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
}
} }
GxsMessageFramePostWidget::loadRequest(queue, req);
} }

View File

@ -26,20 +26,18 @@
#include <QMap> #include <QMap>
#include "gui/gxs/GxsMessageFrameWidget.h" #include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
#include "util/TokenQueue.h"
class RsPostedGroup; class RsPostedGroup;
class RsPostedPost; class RsPostedPost;
class PostedItem; class PostedItem;
class UIStateHelper;
namespace Ui { namespace Ui {
class PostedListWidget; class PostedListWidget;
} }
class PostedListWidget : public GxsMessageFrameWidget, public FeedHolder, public TokenResponse class PostedListWidget : public GxsMessageFramePostWidget, public FeedHolder
{ {
Q_OBJECT Q_OBJECT
@ -48,11 +46,7 @@ public:
~PostedListWidget(); ~PostedListWidget();
/* GxsMessageFrameWidget */ /* GxsMessageFrameWidget */
virtual RsGxsGroupId groupId() { return mPostedId; }
virtual void setGroupId(const RsGxsGroupId &postedId);
virtual QString groupName(bool withUnreadCount);
virtual QIcon groupIcon(); virtual QIcon groupIcon();
virtual void setAllMessagesRead(bool read);
/* FeedHolder */ /* FeedHolder */
virtual QScrollArea *getScrollArea(); virtual QScrollArea *getScrollArea();
@ -60,11 +54,16 @@ public:
virtual void openChat(const RsPeerId& peerId); virtual void openChat(const RsPeerId& peerId);
virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title); virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title);
/* NEW GXS FNS */ /* GXS functions */
void loadRequest(const TokenQueue *queue, const TokenRequest &req); virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected: protected:
virtual void updateDisplay(bool complete); /* GxsMessageFramePostWidget */
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual void insertPosts(const uint32_t &token);
virtual void insertRelatedPosts(const uint32_t &token);
virtual void setMessageRead(GxsFeedItem *item, bool read);
virtual void clearPosts();
private slots: private slots:
void createNewGxsId(); void createNewGxsId();
@ -84,8 +83,6 @@ private:
void processSettings(bool load); void processSettings(bool load);
void updateShowText(); void updateShowText();
void clearPosts();
/*! /*!
* Only removes it from layout * Only removes it from layout
*/ */
@ -93,18 +90,11 @@ private:
void loadPost(const RsPostedPost &post); void loadPost(const RsPostedPost &post);
void requestGroupData();
void loadGroupData(const uint32_t &token);
void insertPostedDetails(const RsPostedGroup &group); void insertPostedDetails(const RsPostedGroup &group);
// subscribe/unsubscribe ack. // subscribe/unsubscribe ack.
// void acknowledgeSubscribeChange(const uint32_t &token); // void acknowledgeSubscribeChange(const uint32_t &token);
// posts
void acknowledgePostMsg(const uint32_t &token);
void loadPostData(const uint32_t &token);
void requestPosts();
// votes // votes
void acknowledgeVoteMsg(const uint32_t& token); void acknowledgeVoteMsg(const uint32_t& token);
void loadVoteData(const uint32_t &token); void loadVoteData(const uint32_t &token);
@ -114,28 +104,15 @@ private:
//void applyRanking(const PostedRanking& ranks); //void applyRanking(const PostedRanking& ranks);
void applyRanking(); void applyRanking();
// update displayed item
void updateDisplayedItems(const std::vector<RsGxsMessageId>& msgIds);
void updateCurrentDisplayComplete(const uint32_t& token);
private: private:
int mSortMethod; int mSortMethod;
int mLastSortMethod; int mLastSortMethod;
int mPostIndex; int mPostIndex;
int mPostShow; int mPostShow;
int mSubscribeFlags; uint32_t mTokenTypeVote;
RsGxsGroupId mPostedId;
QString mName;
QMap<RsGxsMessageId, PostedItem*> mPosts; QMap<RsGxsMessageId, PostedItem*> mPosts;
std::list<PostedItem *> mPostList;
TokenQueue *mPostedQueue;
//CommentHolder* mCommentHolder;
UIStateHelper *mStateHelper;
/* UI - from Designer */ /* UI - from Designer */
Ui::PostedListWidget *ui; Ui::PostedListWidget *ui;

View File

@ -1,11 +0,0 @@
#ifndef POSTEDUSERTYPES_H
#define POSTEDUSERTYPES_H
#define TOKEN_USER_TYPE_POST 4
#define TOKEN_USER_TYPE_VOTE 5
#define TOKEN_USER_TYPE_TOPIC 6
#define TOKEN_USER_TYPE_POST_MOD 7
#define TOKEN_USER_TYPE_POST_RANKINGS 8
#define TOKEN_USER_TYPE_SUBSCRIBE_CHANGE 9
#endif // POSTEDUSERTYPES_H

View File

@ -0,0 +1,331 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2014 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "GxsMessageFramePostWidget.h"
#include "GxsFeedItem.h"
#include "gui/common/UIStateHelper.h"
#include "retroshare/rsgxsifacehelper.h"
//#define ENABLE_DEBUG 1
GxsMessageFramePostWidget::GxsMessageFramePostWidget(RsGxsIfaceHelper *ifaceImpl, QWidget *parent)
: GxsMessageFrameWidget(ifaceImpl, parent)
{
mTokenQueue = new TokenQueue(ifaceImpl->getTokenService(), this);
mSubscribeFlags = 0;
mNextTokenType = 0;
mTokenTypeGroupData = nextTokenType();
mTokenTypePosts = nextTokenType();
mTokenTypeRelatedPosts = nextTokenType();
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
}
void GxsMessageFramePostWidget::setGroupId(const RsGxsGroupId &groupId)
{
if (mGroupId == groupId) {
if (!groupId.isNull()) {
return;
}
}
mGroupId = groupId;
mGroupName = mGroupId.isNull () ? "" : tr("Loading");
groupNameChanged(mGroupName);
emit groupChanged(this);
fillComplete();
}
RsGxsGroupId GxsMessageFramePostWidget::groupId()
{
return mGroupId;
}
QString GxsMessageFramePostWidget::groupName(bool withUnreadCount)
{
QString name = mGroupId.isNull () ? tr("No name") : mGroupName;
// if (withUnreadCount && mUnreadCount) {
// name += QString(" (%1)").arg(mUnreadCount);
// }
return name;
}
void GxsMessageFramePostWidget::updateDisplay(bool complete)
{
if (complete) {
/* Fill complete */
requestGroupData();
requestPosts();
return;
}
bool updateGroup = false;
if (mGroupId.isNull()) {
return;
}
const std::list<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mGroupId) != grpIdsMeta.end()) {
updateGroup = true;
}
const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mGroupId.isNull() && std::find(grpIds.begin(), grpIds.end(), mGroupId) != grpIds.end()) {
updateGroup = true;
/* Do we need to fill all posts? */
requestPosts();
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
getAllMsgIds(msgs);
if (!msgs.empty()) {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(mGroupId);
if (mit != msgs.end()) {
requestRelatedPosts(mit->second);
}
}
}
if (updateGroup) {
requestGroupData();
}
}
void GxsMessageFramePostWidget::setAllMessagesRead(bool read)
{
if (mGroupId.isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) {
return;
}
foreach (GxsFeedItem *item, mPostItems) {
setMessageRead(item, read);
}
}
void GxsMessageFramePostWidget::clearPosts()
{
/* clear all messages */
foreach (GxsFeedItem *item, mPostItems) {
delete(item);
}
mPostItems.clear();
}
/**************************************************************/
/** Request / Response of Data ********************************/
/**************************************************************/
void GxsMessageFramePostWidget::requestGroupData()
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::requestGroupData()";
std::cerr << std::endl;
#endif
mSubscribeFlags = 0;
mTokenQueue->cancelActiveRequestTokens(mTokenTypeGroupData);
if (mGroupId.isNull()) {
mStateHelper->setActive(mTokenTypeGroupData, false);
mStateHelper->setLoading(mTokenTypeGroupData, false);
mStateHelper->clear(mTokenTypeGroupData);
mGroupName.clear();
groupNameChanged(mGroupName);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(mTokenTypeGroupData, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mGroupId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, mTokenTypeGroupData);
}
void GxsMessageFramePostWidget::loadGroupData(const uint32_t &token)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::loadGroupData()";
std::cerr << std::endl;
#endif
RsGroupMetaData metaData;
bool ok = insertGroupData(token, metaData);
mStateHelper->setLoading(mTokenTypeGroupData, false);
if (ok) {
mSubscribeFlags = metaData.mSubscribeFlags;
mGroupName = QString::fromUtf8(metaData.mGroupName.c_str());
groupNameChanged(mGroupName);
} else {
std::cerr << "GxsMessageFramePostWidget::loadGroupData() ERROR Not just one Group";
std::cerr << std::endl;
mStateHelper->clear(mTokenTypeGroupData);
mGroupName.clear();
groupNameChanged(mGroupName);
}
mStateHelper->setActive(mTokenTypeGroupData, ok);
emit groupChanged(this);
}
void GxsMessageFramePostWidget::requestPosts()
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::requestPosts()";
std::cerr << std::endl;
#endif
/* Request all posts */
clearPosts();
mTokenQueue->cancelActiveRequestTokens(mTokenTypePosts);
if (mGroupId.isNull()) {
mStateHelper->setActive(mTokenTypePosts, false);
mStateHelper->setLoading(mTokenTypePosts, false);
mStateHelper->clear(mTokenTypePosts);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(mTokenTypePosts, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mGroupId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
uint32_t token;
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, mTokenTypePosts);
}
void GxsMessageFramePostWidget::loadPosts(const uint32_t &token)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::loadPosts()";
std::cerr << std::endl;
#endif
mStateHelper->setActive(mTokenTypePosts, true);
insertPosts(token);
mStateHelper->setLoading(mTokenTypePosts, false);
emit groupChanged(this);
}
void GxsMessageFramePostWidget::requestRelatedPosts(const std::vector<RsGxsMessageId> &msgIds)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::requestRelatedPosts()";
std::cerr << std::endl;
#endif
mTokenQueue->cancelActiveRequestTokens(mTokenTypeRelatedPosts);
if (mGroupId.isNull()) {
mStateHelper->setActive(mTokenTypePosts, false);
mStateHelper->setLoading(mTokenTypePosts, false);
mStateHelper->clear(mTokenTypePosts);
emit groupChanged(this);
return;
}
if (msgIds.empty()) {
return;
}
mStateHelper->setLoading(mTokenTypePosts, true);
emit groupChanged(this);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_VERSIONS;
uint32_t token;
std::vector<RsGxsGrpMsgIdPair> relatedMsgIds;
for (std::vector<RsGxsMessageId>::const_iterator msgIt = msgIds.begin(); msgIt != msgIds.end(); ++msgIt) {
relatedMsgIds.push_back(RsGxsGrpMsgIdPair(mGroupId, *msgIt));
}
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, relatedMsgIds, mTokenTypeRelatedPosts);
}
void GxsMessageFramePostWidget::loadRelatedPosts(const uint32_t &token)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::loadRelatedPosts()";
std::cerr << std::endl;
#endif
mStateHelper->setActive(mTokenTypePosts, true);
insertRelatedPosts(token);
mStateHelper->setLoading(mTokenTypePosts, false);
emit groupChanged(this);
}
void GxsMessageFramePostWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef ENABLE_DEBUG
std::cerr << "GxsMessageFramePostWidget::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
#endif
if (queue == mTokenQueue)
{
if (req.mUserType == mTokenTypeGroupData) {
loadGroupData(req.mToken);
} else if (req.mUserType == mTokenTypePosts) {
loadPosts(req.mToken);
} else if (req.mUserType == mTokenTypeRelatedPosts) {
loadRelatedPosts(req.mToken);
} else {
std::cerr << "GxsMessageFramePostWidget::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
}
}
}

View File

@ -0,0 +1,86 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2014 RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef GXSMESSAGEFRAMEPOSTWIDGET_H
#define GXSMESSAGEFRAMEPOSTWIDGET_H
#include "GxsMessageFrameWidget.h"
#include "util/TokenQueue.h"
class GxsFeedItem;
class UIStateHelper;
class GxsMessageFramePostWidget : public GxsMessageFrameWidget, public TokenResponse
{
Q_OBJECT
public:
explicit GxsMessageFramePostWidget(RsGxsIfaceHelper *ifaceImpl, QWidget *parent = NULL);
/* GxsMessageFrameWidget */
virtual RsGxsGroupId groupId();
virtual void setGroupId(const RsGxsGroupId &groupId);
virtual QString groupName(bool withUnreadCount);
// virtual QIcon groupIcon() = 0;
virtual void setAllMessagesRead(bool read);
/* GXS functions */
uint32_t nextTokenType() { return ++mNextTokenType; }
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
int subscribeFlags() { return mSubscribeFlags; }
protected:
virtual void updateDisplay(bool complete);
virtual void groupNameChanged(const QString &/*name*/) {}
virtual void setMessageRead(GxsFeedItem *item, bool read) = 0;
virtual void clearPosts();
/* GXS functions */
void requestGroupData();
void loadGroupData(const uint32_t &token);
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData) = 0;
void requestPosts();
void loadPosts(const uint32_t &token);
virtual void insertPosts(const uint32_t &token) = 0;
void requestRelatedPosts(const std::vector<RsGxsMessageId> &msgIds);
void loadRelatedPosts(const uint32_t &token);
virtual void insertRelatedPosts(const uint32_t &token) = 0;
protected:
TokenQueue *mTokenQueue;
uint32_t mTokenTypeGroupData;
uint32_t mTokenTypePosts;
uint32_t mTokenTypeRelatedPosts;
UIStateHelper *mStateHelper;
QList<GxsFeedItem*> mPostItems;
private:
RsGxsGroupId mGroupId; /* current group */
QString mGroupName;
int mSubscribeFlags;
uint32_t mNextTokenType;
};
#endif // GXSMESSAGEFRAMEPOSTWIDGET_H

View File

@ -6,6 +6,8 @@ RsGxsUpdateBroadcastWidget::RsGxsUpdateBroadcastWidget(RsGxsIfaceHelper *ifaceIm
{ {
mBase = new RsGxsUpdateBroadcastBase(ifaceImpl, this); mBase = new RsGxsUpdateBroadcastBase(ifaceImpl, this);
connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool))); connect(mBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
mInterfaceHelper = ifaceImpl;
} }
RsGxsUpdateBroadcastWidget::~RsGxsUpdateBroadcastWidget() RsGxsUpdateBroadcastWidget::~RsGxsUpdateBroadcastWidget()

View File

@ -31,6 +31,8 @@ public:
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIdsMeta(); const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &getMsgIdsMeta();
void getAllMsgIds(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds); void getAllMsgIds(std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgIds);
RsGxsIfaceHelper *interfaceHelper() { return mInterfaceHelper; }
protected: protected:
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
@ -42,4 +44,5 @@ private slots:
private: private:
RsGxsUpdateBroadcastBase *mBase; RsGxsUpdateBroadcastBase *mBase;
RsGxsIfaceHelper *mInterfaceHelper;
}; };

View File

@ -35,13 +35,6 @@
* #define DEBUG_CHANNEL * #define DEBUG_CHANNEL
***/ ***/
//#define USE_THREAD
#define TOKEN_TYPE_MESSAGE_CHANGE 4
#define TOKEN_TYPE_GROUP_DATA 6
#define TOKEN_TYPE_POSTS 7
#define TOKEN_TYPE_RELATEDPOSTS 8
/* Filters */ /* Filters */
#define FILTER_TITLE 1 #define FILTER_TITLE 1
#define FILTER_MSG 2 #define FILTER_MSG 2
@ -50,31 +43,27 @@
/** Constructor */ /** Constructor */
GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) : GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) :
GxsMessageFrameWidget(rsGxsChannels, parent), GxsMessageFramePostWidget(rsGxsChannels, parent),
ui(new Ui::GxsChannelPostsWidget) ui(new Ui::GxsChannelPostsWidget)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this); ui->setupUi(this);
/* Setup UI helper */ /* Setup UI helper */
mStateHelper = new UIStateHelper(this);
// No progress yet // No progress yet
mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->loadingLabel, UISTATE_LOADING_VISIBLE); mStateHelper->addWidget(mTokenTypePosts, ui->loadingLabel, UISTATE_LOADING_VISIBLE);
// mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressBar, UISTATE_LOADING_VISIBLE); // mStateHelper->addWidget(mTokenTypePosts, ui->progressBar, UISTATE_LOADING_VISIBLE);
// mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressLabel, UISTATE_LOADING_VISIBLE); // mStateHelper->addWidget(mTokenTypePosts, ui->progressLabel, UISTATE_LOADING_VISIBLE);
mStateHelper->addLoadPlaceholder(TOKEN_TYPE_GROUP_DATA, ui->nameLabel); mStateHelper->addLoadPlaceholder(mTokenTypeGroupData, ui->nameLabel);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->postButton); mStateHelper->addWidget(mTokenTypeGroupData, ui->postButton);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel); mStateHelper->addWidget(mTokenTypeGroupData, ui->logoLabel);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->subscribeToolButton); mStateHelper->addWidget(mTokenTypeGroupData, ui->subscribeToolButton);
mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this);
connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg())); connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg()));
connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool))); connect(ui->subscribeToolButton, SIGNAL(subscribe(bool)), this, SLOT(subscribeGroup(bool)));
// connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)));
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_TITLE, tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_TITLE, tr("Search Title"));
@ -92,7 +81,6 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid
ui->nameLabel->setMinimumWidth(20); ui->nameLabel->setMinimumWidth(20);
mSubscribeFlags = 0;
mInProcessSettings = false; mInProcessSettings = false;
/* load settings */ /* load settings */
@ -121,48 +109,6 @@ GxsChannelPostsWidget::~GxsChannelPostsWidget()
delete(mAutoDownloadAction); delete(mAutoDownloadAction);
} }
void GxsChannelPostsWidget::updateDisplay(bool complete)
{
if (complete) {
/* Fill complete */
requestGroupData();
requestPosts();
return;
}
bool updateGroup = false;
if (mChannelId.isNull()) {
return;
}
const std::list<RsGxsGroupId> &grpIdsMeta = getGrpIdsMeta();
if (std::find(grpIdsMeta.begin(), grpIdsMeta.end(), mChannelId) != grpIdsMeta.end()) {
updateGroup = true;
}
const std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) {
updateGroup = true;
/* Do we need to fill all posts? */
requestPosts();
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
getAllMsgIds(msgs);
if (!msgs.empty())
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(mChannelId);
if(mit != msgs.end())
{
requestRelatedPosts(mit->second);
}
}
}
if (updateGroup) {
requestGroupData();
}
}
void GxsChannelPostsWidget::processSettings(bool load) void GxsChannelPostsWidget::processSettings(bool load)
{ {
mInProcessSettings = true; mInProcessSettings = true;
@ -178,36 +124,19 @@ void GxsChannelPostsWidget::processSettings(bool load)
mInProcessSettings = false; mInProcessSettings = false;
} }
void GxsChannelPostsWidget::setGroupId(const RsGxsGroupId &groupId) void GxsChannelPostsWidget::groupNameChanged(const QString &name)
{ {
if (mChannelId == groupId) { if (groupId().isNull()) {
if (!groupId.isNull()) { ui->nameLabel->setText(tr("No Channel Selected"));
return; ui->logoLabel->setPixmap(QPixmap(":/images/channels.png"));
} } else {
ui->nameLabel->setText(name);
} }
mChannelId = groupId;
ui->nameLabel->setText(mChannelId.isNull () ? "" : tr("Loading"));
emit groupChanged(this);
fillComplete();
}
QString GxsChannelPostsWidget::groupName(bool withUnreadCount)
{
QString name = mChannelId.isNull () ? tr("No name") : ui->nameLabel->text();
// if (withUnreadCount && mUnreadCount) {
// name += QString(" (%1)").arg(mUnreadCount);
// }
return name;
} }
QIcon GxsChannelPostsWidget::groupIcon() QIcon GxsChannelPostsWidget::groupIcon()
{ {
if (mStateHelper->isLoading(TOKEN_TYPE_GROUP_DATA) || mStateHelper->isLoading(TOKEN_TYPE_POSTS)) { if (mStateHelper->isLoading(mTokenTypeGroupData) || mStateHelper->isLoading(mTokenTypePosts)) {
return QIcon(":/images/kalarm.png"); return QIcon(":/images/kalarm.png");
} }
@ -243,31 +172,22 @@ void GxsChannelPostsWidget::openComments(uint32_t /*type*/, const RsGxsGroupId &
void GxsChannelPostsWidget::createMsg() void GxsChannelPostsWidget::createMsg()
{ {
if (mChannelId.isNull()) { if (groupId().isNull()) {
return; return;
} }
if (!IS_GROUP_SUBSCRIBED(mSubscribeFlags)) { if (!IS_GROUP_SUBSCRIBED(subscribeFlags())) {
return; return;
} }
CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(mChannelId); CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(groupId());
msgDialog->show(); msgDialog->show();
/* window will destroy itself! */ /* window will destroy itself! */
} }
//void GxsChannelPostsWidget::channelMsgReadSatusChanged(const QString& channelId, const QString& /*msgId*/, int /*status*/)
//{
// updateMessageSummaryList(channelId.toStdString());
//}
void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group) void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
{ {
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, true);
mSubscribeFlags = group.mMeta.mSubscribeFlags;
/* IMAGE */ /* IMAGE */
QPixmap chanImage; QPixmap chanImage;
if (group.mImage.mData != NULL) { if (group.mImage.mData != NULL) {
@ -277,10 +197,7 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
} }
ui->logoLabel->setPixmap(chanImage); ui->logoLabel->setPixmap(chanImage);
/* set Channel name */ if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
ui->nameLabel->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str()));
if (mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
{ {
mStateHelper->setWidgetEnabled(ui->postButton, true); mStateHelper->setWidgetEnabled(ui->postButton, true);
} }
@ -289,22 +206,12 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
mStateHelper->setWidgetEnabled(ui->postButton, false); mStateHelper->setWidgetEnabled(ui->postButton, false);
} }
ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(mSubscribeFlags)); ui->subscribeToolButton->setSubscribed(IS_GROUP_SUBSCRIBED(group.mMeta.mSubscribeFlags));
bool autoDownload = rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId); bool autoDownload = rsGxsChannels->getChannelAutoDownload(group.mMeta.mGroupId);
setAutoDownload(autoDownload); setAutoDownload(autoDownload);
} }
static bool sortChannelMsgSummaryAsc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2)
{
return (msg1.mMeta.mPublishTs > msg2.mMeta.mPublishTs);
}
static bool sortChannelMsgSummaryDesc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2)
{
return (msg1.mMeta.mPublishTs < msg2.mMeta.mPublishTs);
}
void GxsChannelPostsWidget::filterChanged(int filter) void GxsChannelPostsWidget::filterChanged(int filter)
{ {
if (mInProcessSettings) { if (mInProcessSettings) {
@ -321,10 +228,13 @@ void GxsChannelPostsWidget::filterItems(const QString& text)
int filter = ui->filterLineEdit->currentFilter(); int filter = ui->filterLineEdit->currentFilter();
/* Search exisiting item */ /* Search exisiting item */
QList<GxsChannelPostItem*>::iterator lit; QList<GxsFeedItem*>::iterator lit;
for (lit = mChannelPostItems.begin(); lit != mChannelPostItems.end(); lit++) for (lit = mPostItems.begin(); lit != mPostItems.end(); lit++)
{ {
GxsChannelPostItem *item = *lit; GxsChannelPostItem *item = dynamic_cast<GxsChannelPostItem*>(*lit);
if (!item) {
continue;
}
filterItem(item,text,filter); filterItem(item,text,filter);
} }
} }
@ -362,6 +272,16 @@ bool GxsChannelPostsWidget::filterItem(GxsChannelPostItem *pItem, const QString
return (bVisible); return (bVisible);
} }
static bool sortChannelMsgSummaryAsc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2)
{
return (msg1.mMeta.mPublishTs > msg2.mMeta.mPublishTs);
}
static bool sortChannelMsgSummaryDesc(const RsGxsChannelPost &msg1, const RsGxsChannelPost &msg2)
{
return (msg1.mMeta.mPublishTs < msg2.mMeta.mPublishTs);
}
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related) void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related)
{ {
std::vector<RsGxsChannelPost>::const_iterator it; std::vector<RsGxsChannelPost>::const_iterator it;
@ -381,9 +301,9 @@ void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &po
{ {
GxsChannelPostItem *item = NULL; GxsChannelPostItem *item = NULL;
if (related) { if (related) {
foreach (GxsChannelPostItem *loopItem, mChannelPostItems) { foreach (GxsFeedItem *loopItem, mPostItems) {
if (loopItem->messageId() == it->mMeta.mMsgId) { if (loopItem->messageId() == it->mMeta.mMsgId) {
item = loopItem; item = dynamic_cast<GxsChannelPostItem*>(loopItem);
break; break;
} }
} }
@ -396,7 +316,7 @@ void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &po
if (!ui->filterLineEdit->text().isEmpty()) if (!ui->filterLineEdit->text().isEmpty())
filterItem(item, ui->filterLineEdit->text(), ui->filterLineEdit->currentFilter()); filterItem(item, ui->filterLineEdit->text(), ui->filterLineEdit->currentFilter());
mChannelPostItems.push_back(item); mPostItems.push_back(item);
if (related) { if (related) {
ui->verticalLayout->insertWidget(0, item); ui->verticalLayout->insertWidget(0, item);
} else { } else {
@ -406,181 +326,14 @@ void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &po
} }
} }
#if 0
void GxsChannelPostsWidget::updateChannelMsgs()
{
if (fillThread) {
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::updateChannelMsgs() stop current fill thread" << std::endl;
#endif
// stop current fill thread
GxsChannelFillThread *thread = fillThread;
fillThread = NULL;
thread->stop();
delete(thread);
progressLabel->hide();
progressBar->hide();
}
if (!rsChannels) {
return;
}
/* replace all the messages with new ones */
QList<ChanMsgItem *>::iterator mit;
for (mit = mChanMsgItems.begin(); mit != mChanMsgItems.end(); mit++) {
delete (*mit);
}
mChanMsgItems.clear();
ChannelInfo ci;
if (!rsChannels->getChannelInfo(mChannelId, ci)) {
postButton->setEnabled(false);
nameLabel->setText(tr("No Channel Selected"));
logoLabel->setPixmap(QPixmap(":/images/channels.png"));
logoLabel->setEnabled(false);
return;
}
QPixmap chanImage;
if (ci.pngImageLen != 0) {
chanImage.loadFromData(ci.pngChanImage, ci.pngImageLen, "PNG");
} else {
chanImage = QPixmap(CHAN_DEFAULT_IMAGE);
}
logoLabel->setPixmap(chanImage);
logoLabel->setEnabled(true);
/* set Channel name */
nameLabel->setText(QString::fromStdWString(ci.channelName));
if (ci.channelFlags & RS_DISTRIB_PUBLISH) {
postButton->setEnabled(true);
} else {
postButton->setEnabled(false);
}
if (!(ci.channelFlags & RS_DISTRIB_ADMIN) &&
(ci.channelFlags & RS_DISTRIB_SUBSCRIBED)) {
actionEnable_Auto_Download->setEnabled(true);
} else {
actionEnable_Auto_Download->setEnabled(false);
}
#ifdef USE_THREAD
progressLabel->show();
progressBar->reset();
progressBar->show();
// create fill thread
fillThread = new GxsChannelFillThread(this, mChannelId);
// connect thread
connect(fillThread, SIGNAL(finished()), this, SLOT(fillThreadFinished()), Qt::BlockingQueuedConnection);
connect(fillThread, SIGNAL(addMsg(QString,QString,int,int)), this, SLOT(fillThreadAddMsg(QString,QString,int,int)), Qt::BlockingQueuedConnection);
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::updateChannelMsgs() Start fill thread" << std::endl;
#endif
// start thread
fillThread->start();
#else
std::list<ChannelMsgSummary> msgs;
std::list<ChannelMsgSummary>::iterator it;
rsChannels->getChannelMsgList(mChannelId, msgs);
msgs.sort(sortChannelMsgSummary);
for (it = msgs.begin(); it != msgs.end(); it++) {
ChanMsgItem *cmi = new ChanMsgItem(this, 0, mChannelId, it->msgId, true);
mChanMsgItems.push_back(cmi);
verticalLayout_2->addWidget(cmi);
}
#endif
}
void GxsChannelPostsWidget::fillThreadFinished()
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished()" << std::endl;
#endif
// thread has finished
GxsChannelFillThread *thread = dynamic_cast<GxsChannelFillThread*>(sender());
if (thread) {
if (thread == fillThread) {
// current thread has finished, hide progressbar and release thread
progressBar->hide();
progressLabel->hide();
fillThread = NULL;
}
#ifdef DEBUG_CHANNEL
if (thread->wasStopped()) {
// thread was stopped
std::cerr << "GxsChannelPostsWidget::fillThreadFinished() Thread was stopped" << std::endl;
}
#endif
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished() Delete thread" << std::endl;
#endif
thread->deleteLater();
thread = NULL;
}
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished done()" << std::endl;
#endif
}
void GxsChannelPostsWidget::fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count)
{
if (sender() == fillThread) {
// show fill progress
if (count) {
progressBar->setValue(current * progressBar->maximum() / count);
}
lockLayout(NULL, true);
ChanMsgItem *cmi = new ChanMsgItem(this, 0, channelId.toStdString(), channelMsgId.toStdString(), true);
mChanMsgItems.push_back(cmi);
verticalLayout->addWidget(cmi);
cmi->show();
lockLayout(cmi, false);
}
}
#endif
void GxsChannelPostsWidget::setAllMessagesRead(bool read)
{
if (mChannelId.isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) {
return;
}
QList<GxsChannelPostItem *>::iterator mit;
for (mit = mChannelPostItems.begin(); mit != mChannelPostItems.end(); ++mit) {
GxsChannelPostItem *item = *mit;
RsGxsGrpMsgIdPair msgPair = std::make_pair(item->groupId(), item->messageId());
uint32_t token;
rsGxsChannels->setMessageReadStatus(token, msgPair, read);
}
}
void GxsChannelPostsWidget::subscribeGroup(bool subscribe) void GxsChannelPostsWidget::subscribeGroup(bool subscribe)
{ {
if (mChannelId.isNull()) { if (groupId().isNull()) {
return; return;
} }
uint32_t token; uint32_t token;
rsGxsChannels->subscribeToGroup(token, mChannelId, subscribe); rsGxsChannels->subscribeToGroup(token, groupId(), subscribe);
// mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE); // mChannelQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_SUBSCRIBE_CHANGE);
} }
@ -605,237 +358,41 @@ void GxsChannelPostsWidget::toggleAutoDownload()
} }
} }
void GxsChannelPostsWidget::clearPosts() bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData)
{ {
/* replace all the messages with new ones */
QList<GxsChannelPostItem *>::iterator mit;
for (mit = mChannelPostItems.begin(); mit != mChannelPostItems.end(); mit++) {
delete (*mit);
}
mChannelPostItems.clear();
}
/**********************************************************************************************
* New Stuff here.
*************/
/*********************** **** **** **** ***********************/
/** Request / Response of Data ********************************/
/*********************** **** **** **** ***********************/
void GxsChannelPostsWidget::requestGroupData()
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::requestGroupData()";
std::cerr << std::endl;
#endif
mSubscribeFlags = 0;
mChannelQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_DATA);
if (mChannelId.isNull()) {
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->clear(TOKEN_TYPE_GROUP_DATA);
ui->nameLabel->setText(tr("No Channel Selected"));
ui->logoLabel->setPixmap(QPixmap(":/images/channels.png"));
emit groupChanged(this);
return;
}
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mChannelId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mChannelQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_GROUP_DATA);
}
void GxsChannelPostsWidget::loadGroupData(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadGroupData()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelGroup> groups; std::vector<RsGxsChannelGroup> groups;
rsGxsChannels->getGroupData(token, groups); rsGxsChannels->getGroupData(token, groups);
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, false);
if (groups.size() == 1) if (groups.size() == 1)
{ {
insertChannelDetails(groups[0]); insertChannelDetails(groups[0]);
} metaData = groups[0].mMeta;
else return true;
{
std::cerr << "GxsChannelPostsWidget::loadGroupData() ERROR Not just one Group";
std::cerr << std::endl;
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->clear(TOKEN_TYPE_GROUP_DATA);
} }
emit groupChanged(this); return false;
} }
void GxsChannelPostsWidget::requestPosts() void GxsChannelPostsWidget::insertPosts(const uint32_t &token)
{ {
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::requestPosts()";
std::cerr << std::endl;
#endif
/* Request all posts */
clearPosts();
mChannelQueue->cancelActiveRequestTokens(TOKEN_TYPE_POSTS);
if (mChannelId.isNull()) {
mStateHelper->setActive(TOKEN_TYPE_POSTS, false);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
mStateHelper->clear(TOKEN_TYPE_POSTS);
emit groupChanged(this);
return;
}
mStateHelper->setLoading(TOKEN_TYPE_POSTS, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(mChannelId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
uint32_t token;
mChannelQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_POSTS);
}
void GxsChannelPostsWidget::loadPosts(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadPosts()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getPostData(token, posts); rsGxsChannels->getPostData(token, posts);
mStateHelper->setActive(TOKEN_TYPE_POSTS, true);
insertChannelPosts(posts, false); insertChannelPosts(posts, false);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
emit groupChanged(this);
} }
void GxsChannelPostsWidget::requestRelatedPosts(const std::vector<RsGxsMessageId> &msgIds) void GxsChannelPostsWidget::insertRelatedPosts(const uint32_t &token)
{ {
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::requestRelatedPosts()";
std::cerr << std::endl;
#endif
mChannelQueue->cancelActiveRequestTokens(TOKEN_TYPE_RELATEDPOSTS);
if (mChannelId.isNull()) {
mStateHelper->setActive(TOKEN_TYPE_POSTS, false);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
mStateHelper->clear(TOKEN_TYPE_POSTS);
emit groupChanged(this);
return;
}
if (msgIds.empty()) {
return;
}
mStateHelper->setLoading(TOKEN_TYPE_POSTS, true);
emit groupChanged(this);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
opts.mOptions = RS_TOKREQOPT_MSG_VERSIONS;
uint32_t token;
std::vector<RsGxsGrpMsgIdPair> relatedMsgIds;
for (std::vector<RsGxsMessageId>::const_iterator msgIt = msgIds.begin(); msgIt != msgIds.end(); ++msgIt) {
relatedMsgIds.push_back(RsGxsGrpMsgIdPair(mChannelId, *msgIt));
}
mChannelQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, relatedMsgIds, TOKEN_TYPE_RELATEDPOSTS);
}
void GxsChannelPostsWidget::loadRelatedPosts(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadRelatedPosts()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelPost> posts; std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getRelatedPosts(token, posts); rsGxsChannels->getRelatedPosts(token, posts);
mStateHelper->setActive(TOKEN_TYPE_POSTS, true);
insertChannelPosts(posts, true); insertChannelPosts(posts, true);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
emit groupChanged(this);
} }
void GxsChannelPostsWidget::acknowledgeMessageUpdate(const uint32_t &token) void GxsChannelPostsWidget::setMessageRead(GxsFeedItem *item, bool read)
{ {
#ifdef DEBUG_CHANNEL RsGxsGrpMsgIdPair msgPair = std::make_pair(item->groupId(), item->messageId());
std::cerr << "GxsChannelPostsWidget::acknowledgeMessageUpdate() TODO";
std::cerr << std::endl;
#endif
std::pair<RsGxsGroupId, RsGxsMessageId> msgId; uint32_t token;
rsGxsChannels->acknowledgeMsg(token, msgId); rsGxsChannels->setMessageReadStatus(token, msgPair, read);
if (msgId.first == mChannelId)
{
requestPosts();
}
}
void GxsChannelPostsWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
#endif
if (queue == mChannelQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case TOKEN_TYPE_MESSAGE_CHANGE:
acknowledgeMessageUpdate(req.mToken);
break;
case TOKEN_TYPE_GROUP_DATA:
loadGroupData(req.mToken);
break;
case TOKEN_TYPE_POSTS:
loadPosts(req.mToken);
break;
case TOKEN_TYPE_RELATEDPOSTS:
loadRelatedPosts(req.mToken);
break;
default:
std::cerr << "GxsChannelPostsWidget::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
}
}
} }

View File

@ -24,12 +24,10 @@
#include <map> #include <map>
#include "gui/gxs/GxsMessageFrameWidget.h" #include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
#include "util/TokenQueue.h"
namespace Ui { namespace Ui {
class GxsChannelPostsWidget; class GxsChannelPostsWidget;
} }
@ -37,10 +35,8 @@ class GxsChannelPostsWidget;
//class ChanMsgItem; //class ChanMsgItem;
class GxsChannelPostItem; class GxsChannelPostItem;
class QTreeWidgetItem; class QTreeWidgetItem;
class UIStateHelper;
class QBoxLayout;
class GxsChannelPostsWidget : public GxsMessageFrameWidget, public TokenResponse, public FeedHolder class GxsChannelPostsWidget : public GxsMessageFramePostWidget, public FeedHolder
{ {
Q_OBJECT Q_OBJECT
@ -51,23 +47,21 @@ public:
~GxsChannelPostsWidget(); ~GxsChannelPostsWidget();
/* GxsMessageFrameWidget */ /* GxsMessageFrameWidget */
virtual RsGxsGroupId groupId() { return mChannelId; }
virtual void setGroupId(const RsGxsGroupId &channelId);
virtual QString groupName(bool withUnreadCount);
virtual QIcon groupIcon(); virtual QIcon groupIcon();
virtual void setAllMessagesRead(bool read);
/* FeedHolder */ /* FeedHolder */
virtual QScrollArea *getScrollArea(); virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(QWidget *item, uint32_t type); virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(const RsPeerId& peerId); virtual void openChat(const RsPeerId& peerId);
virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title); virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title);
/* NEW GXS FNS */
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected: protected:
virtual void updateDisplay(bool complete); /* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name);
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual void insertPosts(const uint32_t &token);
virtual void insertRelatedPosts(const uint32_t &token);
virtual void setMessageRead(GxsFeedItem *item, bool read);
private slots: private slots:
void createMsg(); void createMsg();
@ -83,39 +77,14 @@ private:
void processSettings(bool load); void processSettings(bool load);
void setAutoDownload(bool autoDl); void setAutoDownload(bool autoDl);
void clearPosts(); bool filterItem(GxsChannelPostItem *pItem, const QString &text, const int filter);
/* NEW GXS FNS */
void requestGroupData();
void loadGroupData(const uint32_t &token);
void requestPosts();
void loadPosts(const uint32_t &token);
void requestRelatedPosts(const std::vector<RsGxsMessageId> &msgIds);
void loadRelatedPosts(const uint32_t &token);
void insertChannelDetails(const RsGxsChannelGroup &group); void insertChannelDetails(const RsGxsChannelGroup &group);
void insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related); void insertChannelPosts(std::vector<RsGxsChannelPost> &posts, bool related);
void acknowledgeMessageUpdate(const uint32_t &token); private:
bool filterItem(GxsChannelPostItem *pItem, const QString &text, const int filter);
RsGxsGroupId mChannelId; /* current Channel */
int mSubscribeFlags;
TokenQueue *mChannelQueue;
/* Layout Pointers */
QBoxLayout *mMsgLayout;
//QList<ChanMsgItem *> mChanMsgItems;
QList<GxsChannelPostItem *> mChannelPostItems;
QAction *mAutoDownloadAction; QAction *mAutoDownloadAction;
UIStateHelper *mStateHelper;
bool mInProcessSettings; bool mInProcessSettings;
/* UI - from Designer */ /* UI - from Designer */

View File

@ -1180,7 +1180,6 @@ posted {
gui/Posted/PostedItem.h \ gui/Posted/PostedItem.h \
gui/Posted/PostedGroupDialog.h \ gui/Posted/PostedGroupDialog.h \
gui/Posted/PostedCreatePostDialog.h \ gui/Posted/PostedCreatePostDialog.h \
gui/Posted/PostedUserTypes.h \
gui/Posted/PostedUserNotify.h gui/Posted/PostedUserNotify.h
#gui/Posted/PostedCreateCommentDialog.h \ #gui/Posted/PostedCreateCommentDialog.h \
@ -1225,6 +1224,7 @@ gxsgui {
gui/gxs/GxsCreateCommentDialog.h \ gui/gxs/GxsCreateCommentDialog.h \
gui/gxs/GxsGroupFrameDialog.h \ gui/gxs/GxsGroupFrameDialog.h \
gui/gxs/GxsMessageFrameWidget.h \ gui/gxs/GxsMessageFrameWidget.h \
gui/gxs/GxsMessageFramePostWidget.h \
gui/gxs/GxsFeedItem.h \ gui/gxs/GxsFeedItem.h \
gui/gxs/RsGxsUpdateBroadcastBase.h \ gui/gxs/RsGxsUpdateBroadcastBase.h \
gui/gxs/RsGxsUpdateBroadcastWidget.h \ gui/gxs/RsGxsUpdateBroadcastWidget.h \
@ -1259,6 +1259,7 @@ gxsgui {
gui/gxs/GxsCreateCommentDialog.cpp \ gui/gxs/GxsCreateCommentDialog.cpp \
gui/gxs/GxsGroupFrameDialog.cpp \ gui/gxs/GxsGroupFrameDialog.cpp \
gui/gxs/GxsMessageFrameWidget.cpp \ gui/gxs/GxsMessageFrameWidget.cpp \
gui/gxs/GxsMessageFramePostWidget.cpp \
gui/gxs/GxsFeedItem.cpp \ gui/gxs/GxsFeedItem.cpp \
gui/gxs/RsGxsUpdateBroadcastBase.cpp \ gui/gxs/RsGxsUpdateBroadcastBase.cpp \
gui/gxs/RsGxsUpdateBroadcastWidget.cpp \ gui/gxs/RsGxsUpdateBroadcastWidget.cpp \