2013-03-15 17:02:43 -04:00
|
|
|
/*
|
|
|
|
* Retroshare Gxs Feed Item
|
|
|
|
*
|
|
|
|
* Copyright 2012-2013 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/gxs/GxsFeedItem.h"
|
|
|
|
#include "gui/feeds/FeedHolder.h"
|
2014-05-06 16:19:04 -04:00
|
|
|
#include "gui/gxs/RsGxsUpdateBroadcastBase.h"
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
2014-05-27 17:14:05 -04:00
|
|
|
#include <algorithm>
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
**/
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
#define GXSFEEDITEM_GROUPMETA 5
|
|
|
|
#define GXSFEEDITEM_MESSAGE 6
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
void GxsFeedItem::removeItem()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsFeedItem::removeItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->lockLayout(this, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
hide();
|
|
|
|
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->lockLayout(this, false);
|
|
|
|
mParent->deleteFeedItem(this, mFeedId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::comments(const QString &title)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::comments()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mParent->openComments(mFeedId, mGroupId, mMessageId, title);
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::unsubscribe()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsFeedItem::unsubscribe()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mGxsIface)
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
uint32_t token;
|
|
|
|
mGxsIface->subscribeToGroup(token, mGroupId, false);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::subscribe()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsFeedItem::subscribe()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mGxsIface)
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
uint32_t token;
|
|
|
|
mGxsIface->subscribeToGroup(token, mGroupId, true);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::updateItemStatic()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsFeedItem::updateItemStatic()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
requestMessage();
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
void GxsFeedItem::updateItem()
|
|
|
|
{
|
|
|
|
std::cerr << "GxsFeedItem::updateItem() EMPTY";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
2014-05-06 16:19:04 -04:00
|
|
|
GxsFeedItem::GxsFeedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool loadData, bool autoUpdate) :
|
2014-05-05 19:25:17 -04:00
|
|
|
QWidget(NULL)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::GxsFeedItem()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
/* this are just generally useful for all children */
|
|
|
|
mParent = parent;
|
|
|
|
mFeedId = feedId;
|
|
|
|
mIsHome = isHome;
|
|
|
|
|
|
|
|
/* load data if we can */
|
|
|
|
mGroupId = groupId;
|
|
|
|
mMessageId = messageId;
|
|
|
|
mGxsIface = iface;
|
|
|
|
|
|
|
|
if (loadData && iface)
|
|
|
|
{
|
|
|
|
mLoadQueue = new TokenQueue(iface->getTokenService(), this);
|
|
|
|
requestGroupMeta();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mLoadQueue = NULL;
|
|
|
|
}
|
2014-05-06 16:19:04 -04:00
|
|
|
|
|
|
|
if (mGxsIface && autoUpdate) {
|
|
|
|
/* Connect to update broadcast */
|
|
|
|
mUpdateBroadcastBase = new RsGxsUpdateBroadcastBase(mGxsIface);
|
|
|
|
connect(mUpdateBroadcastBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplay(bool)));
|
|
|
|
} else {
|
|
|
|
mUpdateBroadcastBase = NULL;
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GxsFeedItem::~GxsFeedItem()
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::~GxsFeedItem()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-06 16:19:04 -04:00
|
|
|
if (mUpdateBroadcastBase)
|
|
|
|
{
|
|
|
|
delete(mUpdateBroadcastBase);
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
if (mLoadQueue)
|
|
|
|
{
|
|
|
|
delete mLoadQueue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:19:04 -04:00
|
|
|
void GxsFeedItem::fillDisplay(bool /*complete*/)
|
|
|
|
{
|
|
|
|
const std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = mUpdateBroadcastBase->getMsgIds();
|
|
|
|
if (!msgs.empty())
|
|
|
|
{
|
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::const_iterator mit = msgs.find(groupId());
|
|
|
|
if (mit != msgs.end())
|
|
|
|
{
|
|
|
|
const std::vector<RsGxsMessageId> &msgIds = mit->second;
|
|
|
|
if (std::find(msgIds.begin(), msgIds.end(), messageId()) != msgIds.end()) {
|
|
|
|
requestMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
void GxsFeedItem::requestGroupMeta()
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::requestGroup()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
if (!mLoadQueue)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
std::list<RsGxsGroupId> ids;
|
|
|
|
ids.push_back(mGroupId);
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
|
|
|
|
uint32_t token;
|
|
|
|
mLoadQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, ids, GXSFEEDITEM_GROUPMETA);
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
updateItemStatic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::requestMessage()
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::requestMessage()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
if (!mLoadQueue)
|
|
|
|
{
|
2014-05-06 16:19:04 -04:00
|
|
|
if (mGxsIface)
|
|
|
|
{
|
|
|
|
mLoadQueue = new TokenQueue(mGxsIface->getTokenService(), this);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
RsTokReqOptions opts;
|
|
|
|
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
GxsMsgReq msgIds;
|
|
|
|
std::vector<RsGxsMessageId> &vect_msgIds = msgIds[mGroupId];
|
|
|
|
vect_msgIds.push_back(mMessageId);
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
uint32_t token;
|
|
|
|
mLoadQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, GXSFEEDITEM_MESSAGE);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsFeedItem::loadGroupMeta(const uint32_t &token)
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::loadGroupMeta()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
std::list<RsGroupMetaData> groupMeta;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
if (!mGxsIface->getGroupSummary(token, groupMeta))
|
|
|
|
{
|
|
|
|
std::cerr << "GxsFeedItem::loadGroupMeta() Error getting GroupMeta";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupMeta.size() == 1)
|
|
|
|
{
|
|
|
|
mGroupMeta = *groupMeta.begin();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "GxsFeedItem::loadGroupMeta() ERROR Should be ONE GroupMeta";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
void GxsFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsFeedItem::loadRequest()";
|
|
|
|
std::cerr << std::endl;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
if (queue == mLoadQueue)
|
|
|
|
{
|
|
|
|
switch(req.mUserType)
|
|
|
|
{
|
|
|
|
case GXSFEEDITEM_GROUPMETA:
|
|
|
|
loadGroupMeta(req.mToken);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GXSFEEDITEM_MESSAGE:
|
|
|
|
loadMessage(req.mToken);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
std::cerr << "GxsFeedItem::loadRequest() ERROR: INVALID TYPE";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|