2018-12-25 15:34:59 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
* gui/NewsFeed.cpp *
|
|
|
|
* *
|
|
|
|
* Copyright (c) 2008 Robert Fernie <retroshare.project@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
#include <QDateTime>
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include "NewsFeed.h"
|
2014-11-15 12:24:49 -05:00
|
|
|
#include "ui_NewsFeed.h"
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2017-05-30 16:23:31 -04:00
|
|
|
#include <retroshare/rsbanlist.h>
|
2014-11-17 19:49:21 -05:00
|
|
|
#include <retroshare/rsgxschannels.h>
|
|
|
|
#include <retroshare/rsgxsforums.h>
|
2012-09-04 16:04:49 -04:00
|
|
|
#include <retroshare/rsmsgs.h>
|
2017-05-30 16:23:31 -04:00
|
|
|
#include <retroshare/rsnotify.h>
|
|
|
|
#include <retroshare/rspeers.h>
|
2013-01-08 17:07:52 -05:00
|
|
|
#include <retroshare/rsplugin.h>
|
2017-05-30 16:23:31 -04:00
|
|
|
#include <retroshare/rsposted.h>
|
2010-07-31 14:19:12 -04:00
|
|
|
|
2019-12-01 16:35:16 -05:00
|
|
|
#include "util/qtthreadsutils.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "feeds/ChatMsgItem.h"
|
|
|
|
#include "feeds/GxsCircleItem.h"
|
|
|
|
#include "feeds/GxsChannelGroupItem.h"
|
|
|
|
#include "feeds/GxsChannelPostItem.h"
|
|
|
|
#include "feeds/GxsForumGroupItem.h"
|
|
|
|
#include "feeds/GxsForumMsgItem.h"
|
2008-07-04 10:41:24 -04:00
|
|
|
#include "feeds/MsgItem.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "feeds/NewsFeedUserNotify.h"
|
2010-05-20 17:00:59 -04:00
|
|
|
#include "feeds/PeerItem.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "feeds/PostedGroupItem.h"
|
2011-07-11 11:53:41 -04:00
|
|
|
#include "feeds/SecurityItem.h"
|
2015-06-02 17:36:26 -04:00
|
|
|
#include "feeds/SecurityIpItem.h"
|
2011-07-11 11:53:41 -04:00
|
|
|
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "settings/rsettingswin.h"
|
2009-12-14 12:13:10 -05:00
|
|
|
#include "settings/rsharesettings.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
|
2012-01-17 15:36:36 -05:00
|
|
|
#include "chat/ChatDialog.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "Posted/PostedItem.h"
|
2012-04-26 19:41:14 -04:00
|
|
|
#include "msgs/MessageComposer.h"
|
2017-05-30 16:23:31 -04:00
|
|
|
#include "msgs/MessageInterface.h"
|
|
|
|
|
2013-01-08 17:07:52 -05:00
|
|
|
#include "common/FeedNotify.h"
|
2014-11-15 12:24:49 -05:00
|
|
|
#include "notifyqt.h"
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
#define ROLE_RECEIVED FEED_TREEWIDGET_SORTROLE
|
|
|
|
|
2015-02-07 20:01:48 -05:00
|
|
|
#define TOKEN_TYPE_GROUP 1
|
|
|
|
#define TOKEN_TYPE_MESSAGE 2
|
|
|
|
#define TOKEN_TYPE_PUBLISHKEY 3
|
2014-11-17 19:49:21 -05:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/*****
|
|
|
|
* #define NEWS_DEBUG 1
|
|
|
|
****/
|
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
static NewsFeed *instance = NULL;
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/** Constructor */
|
2019-12-14 12:24:46 -05:00
|
|
|
NewsFeed::NewsFeed(QWidget *parent) : MainPage(parent), ui(new Ui::NewsFeed)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2019-12-03 15:28:44 -05:00
|
|
|
mEventHandlerId =0; // needed to force intialization by registerEventsHandler()
|
2019-12-01 16:35:16 -05:00
|
|
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event) { handleEvent(event); }, mEventHandlerId );
|
|
|
|
|
2013-01-08 17:07:52 -05:00
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
2014-11-15 12:24:49 -05:00
|
|
|
ui->setupUi(this);
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
if (!instance) {
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
ui->feedWidget->enableRemove(true);
|
|
|
|
|
2015-01-20 13:06:56 -05:00
|
|
|
ui->sortComboBox->addItem(tr("Newest on top"), Qt::DescendingOrder);
|
|
|
|
ui->sortComboBox->addItem(tr("Oldest on top"), Qt::AscendingOrder);
|
|
|
|
|
|
|
|
connect(ui->sortComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(sortChanged(int)));
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
connect(ui->removeAllButton, SIGNAL(clicked()), ui->feedWidget, SLOT(clear()));
|
2019-12-19 15:04:18 -05:00
|
|
|
connect(ui->feedWidget, SIGNAL(feedCountChanged()), this, SLOT(sendNewsFeedChanged()),Qt::QueuedConnection);
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2017-02-28 15:41:45 -05:00
|
|
|
connect(ui->feedOptionsButton, SIGNAL(clicked()), this, SLOT(feedoptions()));
|
|
|
|
ui->feedOptionsButton->hide(); // (csoler) Hidden until we repare the system to display a specific settings page.
|
|
|
|
|
2013-09-08 11:08:36 -04:00
|
|
|
QString hlp_str = tr(
|
2015-06-30 12:44:58 -04:00
|
|
|
" <h1><img width=\"32\" src=\":/icons/help_64.png\"> News Feed</h1> \
|
2017-02-25 17:52:57 -05:00
|
|
|
<p>The Log Feed displays the last events on your network, sorted by the time you received them. \
|
2013-09-08 11:08:36 -04:00
|
|
|
This gives you a summary of the activity of your friends. \
|
|
|
|
You can configure which events to show by pressing on <b>Options</b>. </p> \
|
|
|
|
<p>The various events shown are: \
|
|
|
|
<ul> \
|
|
|
|
<li>Connection attempts (useful to make friends with new people and control who's trying to reach you)</li> \
|
|
|
|
<li>Channel and Forum posts</li> \
|
|
|
|
<li>New Channels and Forums you can subscribe to</li> \
|
|
|
|
<li>Private messages from your friends</li> \
|
|
|
|
</ul> </p> \
|
|
|
|
") ;
|
2013-07-18 15:32:12 -04:00
|
|
|
|
2017-02-25 17:52:57 -05:00
|
|
|
registerHelpButton(ui->helpButton,hlp_str,"NewFeed") ;
|
2014-11-15 12:24:49 -05:00
|
|
|
|
2015-01-20 13:06:56 -05:00
|
|
|
// load settings
|
|
|
|
processSettings(true);
|
2013-07-19 08:18:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
NewsFeed::~NewsFeed()
|
|
|
|
{
|
2019-12-01 16:35:16 -05:00
|
|
|
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
|
|
|
|
2015-01-20 13:06:56 -05:00
|
|
|
// save settings
|
|
|
|
processSettings(false);
|
|
|
|
|
2013-07-19 08:18:58 -04:00
|
|
|
if (instance == this) {
|
|
|
|
instance = NULL;
|
|
|
|
}
|
2013-07-18 15:32:12 -04:00
|
|
|
}
|
|
|
|
|
2013-06-21 20:05:02 -04:00
|
|
|
UserNotify *NewsFeed::getUserNotify(QObject *parent)
|
|
|
|
{
|
|
|
|
return new NewsFeedUserNotify(this, parent);
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:06:56 -05:00
|
|
|
void NewsFeed::processSettings(bool load)
|
|
|
|
{
|
|
|
|
Settings->beginGroup("NewsFeed");
|
|
|
|
|
|
|
|
if (load) {
|
|
|
|
// load settings
|
|
|
|
|
|
|
|
// state of sort order
|
|
|
|
Qt::SortOrder sortOrder = (Qt::SortOrder) Settings->value("SortOrder", Qt::AscendingOrder).toInt();
|
|
|
|
ui->sortComboBox->setCurrentIndex(ui->sortComboBox->findData(sortOrder));
|
|
|
|
sortChanged(ui->sortComboBox->currentIndex());
|
|
|
|
} else {
|
|
|
|
// save settings
|
|
|
|
|
|
|
|
// state of sort order
|
|
|
|
Settings->setValue("SortOrder", ui->sortComboBox->itemData(ui->sortComboBox->currentIndex()).toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
Settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewsFeed::sortChanged(int index)
|
2014-11-15 12:24:49 -05:00
|
|
|
{
|
2015-01-20 13:06:56 -05:00
|
|
|
Qt::SortOrder sortOrder = (Qt::SortOrder) ui->sortComboBox->itemData(index).toInt();
|
|
|
|
ui->feedWidget->setSortRole(ROLE_RECEIVED, sortOrder);
|
2014-11-15 12:24:49 -05:00
|
|
|
}
|
|
|
|
|
2019-12-01 16:35:16 -05:00
|
|
|
// handler for the new notification system in libretroshare.
|
|
|
|
|
|
|
|
void NewsFeed::handleEvent(std::shared_ptr<const RsEvent> event)
|
2019-12-07 16:26:26 -05:00
|
|
|
{
|
|
|
|
// /!\ Absolutely no access to Qt structures (such as Settings) should happen here!!!
|
|
|
|
|
|
|
|
RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewsFeed::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
2019-12-01 16:35:16 -05:00
|
|
|
{
|
|
|
|
uint flags = Settings->getNewsFeedFlags();
|
|
|
|
|
2019-12-03 15:28:44 -05:00
|
|
|
if(event->mType == RsEventType::AUTHSSL_CONNECTION_AUTENTICATION && (flags & RS_FEED_TYPE_SECURITY))
|
2019-12-07 16:26:26 -05:00
|
|
|
handleSecurityEvent(event);
|
2019-12-02 14:53:51 -05:00
|
|
|
|
2019-12-11 18:00:51 -05:00
|
|
|
if(event->mType == RsEventType::PEER_CONNECTION && (flags & RS_FEED_TYPE_PEER))
|
2019-12-07 16:26:26 -05:00
|
|
|
handleConnectionEvent(event);
|
2019-12-11 18:00:51 -05:00
|
|
|
|
|
|
|
if(event->mType == RsEventType::GXS_CIRCLES && (flags & RS_FEED_TYPE_CIRCLE))
|
|
|
|
handleCircleEvent(event);
|
2019-12-12 15:23:42 -05:00
|
|
|
|
|
|
|
if(event->mType == RsEventType::GXS_CHANNELS && (flags & RS_FEED_TYPE_CHANNEL))
|
|
|
|
handleChannelEvent(event);
|
|
|
|
|
|
|
|
if(event->mType == RsEventType::GXS_FORUMS && (flags & RS_FEED_TYPE_FORUM))
|
|
|
|
handleForumEvent(event);
|
|
|
|
|
2019-12-13 17:58:17 -05:00
|
|
|
if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED))
|
2019-12-13 17:40:21 -05:00
|
|
|
handleMailEvent(event);
|
|
|
|
|
2019-12-13 17:58:17 -05:00
|
|
|
if(event->mType == RsEventType::MAIL_STATUS_CHANGE && (flags & RS_FEED_TYPE_MSG))
|
2019-12-12 15:23:42 -05:00
|
|
|
handlePostedEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-12-13 17:40:21 -05:00
|
|
|
void NewsFeed::handleMailEvent(std::shared_ptr<const RsEvent> event)
|
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
const RsMailStatusEvent *pe =
|
|
|
|
dynamic_cast<const RsMailStatusEvent*>(event.get());
|
|
|
|
if(!pe) return;
|
2019-12-13 17:40:21 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(pe->mMailStatusEventCode)
|
|
|
|
{
|
|
|
|
case RsMailStatusEventCode::NEW_MESSAGE:
|
|
|
|
for(auto msgid: pe->mChangedMsgIds)
|
|
|
|
addFeedItem( new MsgItem(this, NEWSFEED_MESSAGELIST, msgid, false));
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-13 17:40:21 -05:00
|
|
|
}
|
|
|
|
|
2019-12-12 15:23:42 -05:00
|
|
|
void NewsFeed::handlePostedEvent(std::shared_ptr<const RsEvent> event)
|
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
const RsGxsPostedEvent *pe =
|
|
|
|
dynamic_cast<const RsGxsPostedEvent*>(event.get());
|
|
|
|
if(!pe) return;
|
2019-12-12 15:23:42 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(pe->mPostedEventCode)
|
|
|
|
{
|
|
|
|
case RsPostedEventCode::NEW_POSTED_GROUP:
|
|
|
|
addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true));
|
|
|
|
break;
|
|
|
|
case RsPostedEventCode::NEW_MESSAGE:
|
|
|
|
addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true));
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-12 15:23:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewsFeed::handleForumEvent(std::shared_ptr<const RsEvent> event)
|
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
const RsGxsForumEvent *pe = dynamic_cast<const RsGxsForumEvent*>(event.get());
|
|
|
|
if(!pe) return;
|
2019-12-12 15:23:42 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(pe->mForumEventCode)
|
|
|
|
{
|
|
|
|
case RsForumEventCode::UPDATED_FORUM:
|
|
|
|
case RsForumEventCode::NEW_FORUM:
|
|
|
|
addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true));
|
|
|
|
break;
|
|
|
|
case RsForumEventCode::UPDATED_MESSAGE:
|
|
|
|
case RsForumEventCode::NEW_MESSAGE:
|
|
|
|
addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true));
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-12 15:23:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void NewsFeed::handleChannelEvent(std::shared_ptr<const RsEvent> event)
|
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
const RsGxsChannelEvent* pe =
|
|
|
|
dynamic_cast<const RsGxsChannelEvent*>(event.get());
|
|
|
|
if(!pe) return;
|
2019-12-12 15:23:42 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(pe->mChannelEventCode)
|
|
|
|
{
|
|
|
|
case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]];
|
|
|
|
case RsChannelEventCode::NEW_CHANNEL:
|
|
|
|
addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true));
|
|
|
|
break;
|
|
|
|
case RsChannelEventCode::UPDATED_MESSAGE: // [[fallthrough]];
|
|
|
|
case RsChannelEventCode::NEW_MESSAGE:
|
|
|
|
addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true));
|
|
|
|
break;
|
|
|
|
case RsChannelEventCode::RECEIVED_PUBLISH_KEY:
|
|
|
|
addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true));
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-02 14:53:51 -05:00
|
|
|
}
|
|
|
|
|
2019-12-11 18:00:51 -05:00
|
|
|
void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
|
|
|
|
{
|
|
|
|
const RsGxsCircleEvent *pe = dynamic_cast<const RsGxsCircleEvent*>(event.get());
|
|
|
|
if(!pe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RsGxsCircleDetails details;
|
|
|
|
|
|
|
|
if(!rsGxsCircles->getCircleDetails(pe->mCircleId,details))
|
|
|
|
{
|
|
|
|
std::cerr << "(EE) Cannot get information about circle " << pe->mCircleId << ". Not in cache?" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the circle is one of which we belong to. If so, then notify in the GUI about other members leaving/subscribing
|
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
if(details.mAmIAllowed || details.mAmIAdmin)
|
2019-12-11 18:00:51 -05:00
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(pe->mCircleEventType)
|
|
|
|
{
|
|
|
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST:
|
|
|
|
// only show membership requests if we're an admin of that circle
|
|
|
|
if(details.mAmIAdmin)
|
|
|
|
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REQ),true);
|
|
|
|
break;
|
|
|
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
|
|
|
|
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_JOIN),true);
|
|
|
|
break;
|
|
|
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE:
|
|
|
|
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_LEAVE),true);
|
|
|
|
break;
|
|
|
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE:
|
|
|
|
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_INVIT_REC),true);
|
|
|
|
break;
|
|
|
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
|
|
|
|
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED),true);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-11 18:00:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:44 -05:00
|
|
|
void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)
|
2019-12-02 14:53:51 -05:00
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
const RsConnectionEvent *pe = dynamic_cast<const RsConnectionEvent*>(event.get());
|
|
|
|
if(!pe) return;
|
2019-12-03 15:28:44 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
auto& e(*pe);
|
2019-12-03 15:28:44 -05:00
|
|
|
|
2019-12-22 16:29:14 -05:00
|
|
|
#ifdef NEWS_DEBUG
|
2019-12-02 14:53:51 -05:00
|
|
|
std::cerr << "NotifyQt: handling connection event from peer " << e.mSslId << std::endl;
|
2019-12-22 16:29:14 -05:00
|
|
|
#endif
|
2019-12-02 14:53:51 -05:00
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
switch(e.mConnectionInfoCode)
|
|
|
|
{
|
|
|
|
case RsConnectionEventCode::PEER_CONNECTED:
|
|
|
|
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_CONNECT, false), true);
|
2019-12-07 15:43:28 -05:00
|
|
|
break;
|
2020-01-06 18:54:49 -05:00
|
|
|
case RsConnectionEventCode::PEER_DISCONNECTED: // not handled yet
|
|
|
|
break;
|
|
|
|
case RsConnectionEventCode::PEER_TIME_SHIFT:
|
|
|
|
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_OFFSET, false),false);
|
|
|
|
break;
|
|
|
|
case RsConnectionEventCode::PEER_REPORTS_WRONG_IP:
|
|
|
|
addFeedItemIfUnique(new SecurityIpItem(
|
|
|
|
this, e.mSslId, e.mOwnLocator.toString(),
|
|
|
|
e.mReportedLocator.toString(),
|
|
|
|
RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED,
|
|
|
|
false ), false);
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2019-12-01 16:35:16 -05:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:44 -05:00
|
|
|
void NewsFeed::handleSecurityEvent(std::shared_ptr<const RsEvent> event)
|
2019-12-01 16:35:16 -05:00
|
|
|
{
|
2019-12-03 15:28:44 -05:00
|
|
|
const RsAuthSslConnectionAutenticationEvent *pe = dynamic_cast<const RsAuthSslConnectionAutenticationEvent*>(event.get());
|
|
|
|
|
|
|
|
if(!pe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto& e(*pe);
|
2019-12-22 16:29:14 -05:00
|
|
|
#ifdef NEWS_DEBUG
|
2019-12-17 15:41:21 -05:00
|
|
|
std::cerr << "NotifyQt: handling security event from (" << e.mSslId << "," << e.mPgpId << ") error code: " << (int)e.mErrorCode << std::endl;
|
2019-12-22 16:29:14 -05:00
|
|
|
#endif
|
2019-12-01 16:35:16 -05:00
|
|
|
uint flags = Settings->getNewsFeedFlags();
|
|
|
|
|
2020-01-06 18:54:49 -05:00
|
|
|
if(e.mErrorCode == RsAuthSslError::PEER_REFUSED_CONNECTION)
|
|
|
|
{
|
2019-12-05 17:43:38 -05:00
|
|
|
addFeedItemIfUnique(new PeerItem(this, NEWSFEED_PEERLIST, e.mSslId, PEER_TYPE_HELLO, false), true );
|
2020-01-06 18:54:49 -05:00
|
|
|
return;
|
|
|
|
}
|
2019-12-05 17:43:38 -05:00
|
|
|
|
2019-12-01 16:35:16 -05:00
|
|
|
uint32_t FeedItemType=0;
|
|
|
|
|
|
|
|
switch(e.mErrorCode)
|
|
|
|
{
|
2020-01-06 18:54:49 -05:00
|
|
|
case RsAuthSslError::NO_CERTIFICATE_SUPPLIED: // fallthrough
|
|
|
|
case RsAuthSslError::MISMATCHED_PGP_ID: // fallthrough
|
|
|
|
case RsAuthSslError::MISSING_AUTHENTICATION_INFO:
|
|
|
|
FeedItemType = RS_FEED_ITEM_SEC_BAD_CERTIFICATE; break;
|
|
|
|
case RsAuthSslError::PGP_SIGNATURE_VALIDATION_FAILED:
|
|
|
|
FeedItemType = RS_FEED_ITEM_SEC_WRONG_SIGNATURE; break;
|
|
|
|
case RsAuthSslError::NOT_A_FRIEND:
|
|
|
|
FeedItemType = RS_FEED_ITEM_SEC_CONNECT_ATTEMPT; break;
|
|
|
|
case RsAuthSslError::IP_IS_BLACKLISTED:
|
|
|
|
FeedItemType = RS_FEED_ITEM_SEC_IP_BLACKLISTED; break;
|
|
|
|
case RsAuthSslError::MISSING_CERTIFICATE:
|
|
|
|
FeedItemType = RS_FEED_ITEM_SEC_MISSING_CERTIFICATE; break;
|
|
|
|
default:
|
|
|
|
return; // display nothing
|
|
|
|
}
|
2019-12-01 16:35:16 -05:00
|
|
|
|
|
|
|
RsPeerDetails det;
|
|
|
|
rsPeers->getPeerDetails(e.mSslId,det) || rsPeers->getGPGDetails(e.mPgpId,det);
|
|
|
|
|
2019-12-05 16:12:36 -05:00
|
|
|
addFeedItemIfUnique(new SecurityItem(this, NEWSFEED_SECLIST, e.mPgpId, e.mSslId, det.location, e.mLocator.toString(), FeedItemType, false), true );
|
2019-12-02 14:53:51 -05:00
|
|
|
|
|
|
|
if (Settings->getMessageFlags() & RS_MESSAGE_CONNECT_ATTEMPT)
|
2019-12-02 16:34:14 -05:00
|
|
|
MessageComposer::addConnectAttemptMsg(e.mPgpId, e.mSslId, QString::fromStdString(det.name + "(" + det.location + ")"));
|
2019-12-01 16:35:16 -05:00
|
|
|
}
|
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
void NewsFeed::testFeeds(uint notifyFlags)
|
|
|
|
{
|
2019-12-14 12:24:46 -05:00
|
|
|
#ifdef TO_REMOVE
|
2012-09-04 16:04:49 -04:00
|
|
|
if (!instance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
instance->ui->feedWidget->enableCountChangedSignal(false);
|
|
|
|
|
2012-09-04 16:04:49 -04:00
|
|
|
uint pos = 0;
|
|
|
|
|
|
|
|
while (notifyFlags) {
|
|
|
|
uint type = notifyFlags & (1 << pos);
|
|
|
|
notifyFlags &= ~(1 << pos);
|
|
|
|
++pos;
|
|
|
|
|
|
|
|
RsFeedItem fi;
|
|
|
|
}
|
2014-11-15 12:24:49 -05:00
|
|
|
|
|
|
|
instance->ui->feedWidget->enableCountChangedSignal(true);
|
|
|
|
|
|
|
|
instance->sendNewsFeedChanged();
|
2019-12-12 15:23:42 -05:00
|
|
|
#endif
|
2019-12-14 12:24:46 -05:00
|
|
|
std::cerr << "(EE) testFeeds() is currently disabled" << std::endl;
|
2014-11-17 19:49:21 -05:00
|
|
|
}
|
|
|
|
|
2013-01-14 17:41:31 -05:00
|
|
|
void NewsFeed::testFeed(FeedNotify *feedNotify)
|
|
|
|
{
|
|
|
|
if (!instance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!feedNotify) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
FeedItem *feedItem = feedNotify->testFeedItem(instance);
|
2013-01-14 17:41:31 -05:00
|
|
|
if (!feedItem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
instance->addFeedItem(feedItem);
|
|
|
|
}
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
void NewsFeed::addFeedItem(FeedItem *item)
|
2010-09-01 16:54:24 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
static const int MAX_FEEDITEM_COUNT = 500 ;
|
2014-01-16 15:51:13 -05:00
|
|
|
|
2010-11-06 15:13:33 -04:00
|
|
|
item->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
2014-01-16 15:51:13 -05:00
|
|
|
// costly, but not really a problem here
|
2014-11-15 12:24:49 -05:00
|
|
|
int feedItemCount;
|
2015-01-20 13:06:56 -05:00
|
|
|
bool fromTop = (ui->sortComboBox->itemData(ui->sortComboBox->currentIndex()).toInt() == Qt::AscendingOrder);
|
2014-11-15 12:24:49 -05:00
|
|
|
|
|
|
|
while ((feedItemCount = ui->feedWidget->feedItemCount()) >= MAX_FEEDITEM_COUNT) {
|
|
|
|
FeedItem *feedItem = ui->feedWidget->feedItem(fromTop ? 0 : feedItemCount - 1);
|
|
|
|
if (!feedItem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->feedWidget->removeFeedItem(feedItem);
|
2014-01-16 15:51:13 -05:00
|
|
|
}
|
2010-11-06 15:13:33 -04:00
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
ui->feedWidget->addFeedItem(item, ROLE_RECEIVED, QDateTime::currentDateTime());
|
2019-12-17 09:11:37 -05:00
|
|
|
sendNewsFeedChanged();
|
2014-11-15 12:24:49 -05:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:30:13 -05:00
|
|
|
void NewsFeed::addFeedItemIfUnique(FeedItem *item, bool replace)
|
2011-07-11 11:53:41 -04:00
|
|
|
{
|
2019-12-03 16:30:13 -05:00
|
|
|
FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier());
|
2014-11-15 12:24:49 -05:00
|
|
|
|
2019-12-03 16:30:13 -05:00
|
|
|
if (feedItem)
|
|
|
|
{
|
|
|
|
if (!replace)
|
|
|
|
{
|
2014-11-15 12:24:49 -05:00
|
|
|
delete item;
|
|
|
|
return;
|
2011-07-11 11:53:41 -04:00
|
|
|
}
|
2014-11-15 12:24:49 -05:00
|
|
|
|
2017-04-27 10:42:25 -04:00
|
|
|
ui->feedWidget->removeFeedItem(feedItem);
|
2011-07-11 11:53:41 -04:00
|
|
|
}
|
2013-01-08 17:07:52 -05:00
|
|
|
|
2011-07-11 11:53:41 -04:00
|
|
|
addFeedItem(item);
|
2019-12-17 09:11:37 -05:00
|
|
|
sendNewsFeedChanged();
|
2011-07-11 11:53:41 -04:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:30:13 -05:00
|
|
|
void NewsFeed::remUniqueFeedItem(FeedItem *item)
|
2017-05-30 16:23:31 -04:00
|
|
|
{
|
2020-01-14 15:43:29 -05:00
|
|
|
//FeedItem *feedItem = ui->feedWidget->findFeedItem(item->uniqueIdentifier());
|
2017-05-30 16:23:31 -04:00
|
|
|
|
2020-01-14 15:43:29 -05:00
|
|
|
ui->feedWidget->removeFeedItem(item);
|
2017-05-30 16:23:31 -04:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
2008-06-20 08:43:23 -04:00
|
|
|
/* FeedHolder Functions (for FeedItem functionality) */
|
2012-10-08 19:06:34 -04:00
|
|
|
QScrollArea *NewsFeed::getScrollArea()
|
|
|
|
{
|
2014-11-15 12:24:49 -05:00
|
|
|
return NULL;
|
2012-10-08 19:06:34 -04:00
|
|
|
}
|
|
|
|
|
2020-01-14 15:43:29 -05:00
|
|
|
void NewsFeed::deleteFeedItem(FeedItem *item, uint32_t /*type*/)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef NEWS_DEBUG
|
2008-06-20 08:43:23 -04:00
|
|
|
std::cerr << "NewsFeed::deleteFeedItem()";
|
|
|
|
std::cerr << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2010-05-04 20:05:36 -04:00
|
|
|
|
2011-08-21 18:28:19 -04:00
|
|
|
if (item) {
|
2020-01-14 15:43:29 -05:00
|
|
|
ui->feedWidget->removeFeedItem(item);
|
2011-08-21 18:28:19 -04:00
|
|
|
item->close ();
|
|
|
|
}
|
2008-06-20 08:43:23 -04:00
|
|
|
}
|
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
void NewsFeed::openChat(const RsPeerId &peerId)
|
2008-06-20 08:43:23 -04:00
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef NEWS_DEBUG
|
2008-06-20 08:43:23 -04:00
|
|
|
std::cerr << "NewsFeed::openChat()";
|
|
|
|
std::cerr << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-06-20 08:43:23 -04:00
|
|
|
|
2014-12-29 16:41:05 -05:00
|
|
|
ChatDialog::chatFriend(ChatId(peerId));
|
2010-08-12 15:45:15 -04:00
|
|
|
}
|
2010-11-06 15:13:33 -04:00
|
|
|
|
2017-05-30 16:23:31 -04:00
|
|
|
void NewsFeed::openComments(uint32_t /*type*/, const RsGxsGroupId &/*groupId*/, const QVector<RsGxsMessageId> &/*versions*/,const RsGxsMessageId &/*msgId*/, const QString &/*title*/)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
std::cerr << "NewsFeed::openComments() Not Handled Yet";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
2014-11-15 12:24:49 -05:00
|
|
|
static void sendNewsFeedChangedCallback(FeedItem *feedItem, void *data)
|
2010-11-06 15:13:33 -04:00
|
|
|
{
|
2014-11-15 12:24:49 -05:00
|
|
|
if (dynamic_cast<PeerItem*>(feedItem) == NULL) {
|
|
|
|
/* don't count PeerItem's */
|
|
|
|
++(*((int*) data));
|
2010-11-06 15:13:33 -04:00
|
|
|
}
|
|
|
|
}
|
2010-11-10 07:24:36 -05:00
|
|
|
|
|
|
|
void NewsFeed::sendNewsFeedChanged()
|
|
|
|
{
|
|
|
|
int count = 0;
|
2014-11-15 12:24:49 -05:00
|
|
|
ui->feedWidget->withAll(sendNewsFeedChangedCallback, &count);
|
2010-11-10 07:24:36 -05:00
|
|
|
|
|
|
|
emit newsFeedChanged(count);
|
|
|
|
}
|
2011-03-24 15:43:52 -04:00
|
|
|
|
|
|
|
void NewsFeed::feedoptions()
|
|
|
|
{
|
2017-01-26 16:35:33 -05:00
|
|
|
SettingsPage::showYourself(this, SettingsPage::Notify);
|
2011-03-24 15:43:52 -04:00
|
|
|
}
|