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-11-17 19:49:21 -05:00
|
|
|
//#include <algorithm>
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
**/
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsFeedItem::GxsFeedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, RsGxsIfaceHelper *iface, bool autoUpdate) :
|
|
|
|
GxsGroupFeedItem(feedHolder, feedId, groupId, isHome, iface, autoUpdate)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
2014-11-17 19:49:21 -05:00
|
|
|
std::cerr << "GxsFeedItem::GxsFeedItem()";
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
/* load data if we can */
|
|
|
|
mMessageId = messageId;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
mTokenTypeMessage = nextTokenType();
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsFeedItem::~GxsFeedItem()
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
2014-11-17 19:49:21 -05:00
|
|
|
std::cerr << "GxsFeedItem::~GxsFeedItem()";
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsFeedItem::comments(const QString &title)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
2014-11-17 19:49:21 -05:00
|
|
|
std::cerr << "GxsFeedItem::comments()";
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (mFeedHolder)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
mFeedHolder->openComments(feedId(), groupId(), messageId(), title);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsFeedItem::copyMessageLink()
|
2014-07-26 19:52:45 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
if (groupId().isNull() || mMessageId.isNull()) {
|
2014-07-26 19:52:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getLinkType() == RetroShareLink::TYPE_UNKNOWN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RetroShareLink link;
|
2014-11-17 19:49:21 -05:00
|
|
|
if (link.createGxsMessageLink(getLinkType(), groupId(), mMessageId, messageName())) {
|
2014-07-26 19:52:45 -04:00
|
|
|
QList<RetroShareLink> urls;
|
|
|
|
urls.push_back(link);
|
|
|
|
RSLinkClipboard::copyLinks(urls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsFeedItem::fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool complete)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsGroupFeedItem::fillDisplay(updateBroadcastBase, complete);
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-07-04 18:17:38 -04:00
|
|
|
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgs;
|
2014-11-17 19:49:21 -05:00
|
|
|
updateBroadcastBase->getAllMsgIds(msgs);
|
2014-07-04 18:17:38 -04:00
|
|
|
|
2014-05-06 16:19:04 -04:00
|
|
|
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::requestMessage()
|
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << "GxsFeedItem::requestMessage()";
|
|
|
|
std::cerr << std::endl;
|
2014-11-17 19:49:21 -05:00
|
|
|
#endif
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-11-19 07:40:42 -05:00
|
|
|
if (!initLoadQueue()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLoadQueue->activeRequestExist(mTokenTypeMessage)) {
|
|
|
|
/* Request already running */
|
|
|
|
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;
|
2014-11-17 19:49:21 -05:00
|
|
|
std::vector<RsGxsMessageId> &vect_msgIds = msgIds[groupId()];
|
2014-05-05 19:25:17 -04:00
|
|
|
vect_msgIds.push_back(mMessageId);
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
uint32_t token;
|
2014-11-17 19:49:21 -05:00
|
|
|
mLoadQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeMessage);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsFeedItem::loadRequest()";
|
2014-05-05 19:25:17 -04:00
|
|
|
std::cerr << std::endl;
|
2014-11-17 19:49:21 -05:00
|
|
|
#endif
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (queue == mLoadQueue) {
|
|
|
|
if (req.mUserType == mTokenTypeMessage) {
|
|
|
|
loadMessage(req.mToken);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-05 19:25:17 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsGroupFeedItem::loadRequest(queue, req);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
bool GxsFeedItem::isLoading()
|
2014-05-05 19:25:17 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
if (GxsGroupFeedItem::isLoading()) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-05 19:25:17 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (mLoadQueue && mLoadQueue->activeRequestExist(mTokenTypeMessage)) {
|
|
|
|
return true;
|
2014-05-05 19:25:17 -04:00
|
|
|
}
|
2014-11-17 19:49:21 -05:00
|
|
|
|
|
|
|
return false;
|
2014-05-05 19:25:17 -04:00
|
|
|
}
|