moved UserNotify to MainPage level, and added RsEvent handling code in Posted

This commit is contained in:
csoler 2020-01-26 23:19:20 +01:00
parent 9c65836503
commit fb9282f588
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
28 changed files with 140 additions and 51 deletions

View File

@ -122,6 +122,10 @@ enum class RsChannelEventCode: uint8_t
/// subscription for channel mChannelGroupId changed.
SUBSCRIBE_STATUS_CHANGED = 0x06,
/// existing message has been read or set to unread
READ_STATUS_CHANGED = 0x07,
};
struct RsGxsChannelEvent: RsEvent

View File

@ -72,7 +72,10 @@ enum class RsPostedEventCode: uint8_t
{
UNKNOWN = 0x00,
NEW_POSTED_GROUP = 0x01,
NEW_MESSAGE = 0x02
NEW_MESSAGE = 0x02,
SUBSCRIBE_STATUS_CHANGED = 0x03,
UPDATED_POSTED_GROUP = 0x04,
UPDATED_MESSAGE = 0x05,
};

View File

@ -369,8 +369,8 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(!unprocessedGroups.empty())
request_SpecificSubscribedGroups(unprocessedGroups);
// the call below deletes changes and its content.
RsGxsIfaceHelper::receiveChanges(changes);
// // the call below deletes changes and its content.
// RsGxsIfaceHelper::receiveChanges(changes);
}
void p3GxsChannels::service_tick()
@ -1764,8 +1764,17 @@ void p3GxsChannels::setMessageReadStatus( uint32_t& token,
if (read) status = 0;
setMsgStatusFlags(token, msgId, status, mask);
}
if (rsEvents)
{
auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelMsgId = msgId.second;
ev->mChannelGroupId = msgId.first;
ev->mChannelEventCode = RsChannelEventCode::READ_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
}
/********************************************************************************************/
/********************************************************************************************/

View File

@ -91,8 +91,8 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
for(it = changes.begin(); it != changes.end(); ++it)
{
RsGxsGroupChange *groupChange = dynamic_cast<RsGxsGroupChange *>(*it);
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
if (msgChange)
{
#ifdef POSTBASE_DEBUG
@ -124,30 +124,53 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*it);
/* pass on Group Changes to GUI */
if (groupChange)
if (grpChange && rsEvents)
{
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification";
std::cerr << std::endl;
#endif
std::list<RsGxsGroupId> &groupList = groupChange->mGrpIdList;
switch(grpChange->getType())
{
default:
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
{
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
std::list<RsGxsGroupId>::iterator git;
for (git = grpList.begin(); git != grpList.end(); ++git)
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = *git;
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
for(auto git = groupList.begin(); git != groupList.end(); ++git)
}
break;
case RsGxsNotify::TYPE_PUBLISHED:
case RsGxsNotify::TYPE_RECEIVED_NEW:
{
/* group received */
const std::list<RsGxsGroupId>& grpList = grpChange->mGrpIdList;
for (auto git = grpList.begin(); git != grpList.end(); ++git)
{
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
std::cerr << std::endl;
#endif
if (rsEvents && groupChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW)
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = *git;
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
rsEvents->postEvent(ev);
}
}
break;
}
}
}

View File

@ -133,7 +133,7 @@ FeedReaderDialog::~FeedReaderDialog()
}
}
UserNotify *FeedReaderDialog::getUserNotify(QObject *parent)
UserNotify *FeedReaderDialog::createUserNotify(QObject *parent)
{
return new FeedReaderUserNotify(this, mFeedReader, mNotify, parent);
}

View File

@ -42,11 +42,10 @@ public:
FeedReaderDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent = 0);
~FeedReaderDialog();
virtual UserNotify *getUserNotify(QObject *parent);
static QIcon iconFromFeed(const FeedInfo &feedInfo);
protected:
virtual UserNotify *createUserNotify(QObject *parent) override;
virtual void showEvent(QShowEvent *event);
bool eventFilter(QObject *obj, QEvent *ev);

View File

@ -226,12 +226,11 @@ ChatLobbyWidget::~ChatLobbyWidget()
}
}
UserNotify *ChatLobbyWidget::getUserNotify(QObject *parent)
UserNotify *ChatLobbyWidget::createUserNotify(QObject *parent)
{
if (!myChatLobbyUserNotify){
myChatLobbyUserNotify = new ChatLobbyUserNotify(parent);
connect(myChatLobbyUserNotify, SIGNAL(countChanged(ChatLobbyId, unsigned int)), this, SLOT(updateNotify(ChatLobbyId, unsigned int)));
}
return myChatLobbyUserNotify;
}

View File

@ -63,7 +63,7 @@ public:
virtual QString pageName() const { return tr("Chats") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent); //MainPage
virtual UserNotify *createUserNotify(QObject *parent) override; //MainPage
virtual void updateDisplay();
@ -137,7 +137,7 @@ private:
QAction* showTopicAct;
int getNumColVisible();
ChatLobbyUserNotify* myChatLobbyUserNotify;
ChatLobbyUserNotify* myChatLobbyUserNotify; // local copy that avoids dynamic casts
QAbstractButton* myInviteYesButton;
GxsIdChooser* myInviteIdChooser;

View File

@ -1114,7 +1114,7 @@ void TransfersDialog::activatePage(TransfersDialog::Page page)
}
}
UserNotify *TransfersDialog::getUserNotify(QObject *parent)
UserNotify *TransfersDialog::createUserNotify(QObject *parent)
{
return new TransferUserNotify(parent);
}

View File

@ -67,7 +67,7 @@ public:
virtual QString pageName() const { return tr("Files") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
virtual UserNotify *createUserNotify(QObject *parent) override;
void activatePage(TransfersDialog::Page page) ;

View File

@ -163,7 +163,7 @@ void FriendsDialog::activatePage(FriendsDialog::Page page)
}
}
UserNotify *FriendsDialog::getUserNotify(QObject *parent)
UserNotify *FriendsDialog::createUserNotify(QObject *parent)
{
return new ChatUserNotify(parent);
}

View File

@ -55,7 +55,7 @@ public:
virtual QString pageName() const { return tr("Network") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
virtual UserNotify *createUserNotify(QObject *parent) override;
static bool isGroupChatActive();
static void groupChatActivate();

View File

@ -31,6 +31,15 @@ MainPage::MainPage(QWidget *parent , Qt::WindowFlags flags ) : QWidget(parent, f
mIcon = QIcon();
mName = "";
mHelp = "";
mUserNotify = nullptr;
}
UserNotify *MainPage::getUserNotify()
{
if(!mUserNotify)
mUserNotify = createUserNotify(this);
return mUserNotify;
}
void MainPage::registerHelpButton(QToolButton *button, const QString& help_html_text, const QString &code_name)

View File

@ -469,7 +469,7 @@ void MainWindow::initStackedPage()
//List All notify before Setting was created
QList<QPair<MainPage*, QPair<QAction*, QListWidgetItem*> > >::iterator notifyIt;
for (notifyIt = notify.begin(); notifyIt != notify.end(); ++notifyIt) {
UserNotify *userNotify = notifyIt->first->getUserNotify(this);
UserNotify *userNotify = notifyIt->first->getUserNotify();
if (userNotify) {
userNotify->initialize(ui->toolBarPage, notifyIt->second.first, notifyIt->second.second);
connect(userNotify, SIGNAL(countChanged()), this, SLOT(updateTrayCombine()));

View File

@ -141,7 +141,7 @@ NewsFeed::~NewsFeed()
}
}
UserNotify *NewsFeed::getUserNotify(QObject *parent)
UserNotify *NewsFeed::createUserNotify(QObject *parent)
{
return new NewsFeedUserNotify(this, parent);
}

View File

@ -70,7 +70,7 @@ public:
virtual QString pageName() const { return tr("Log") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
virtual UserNotify *createUserNotify(QObject *parent) override;
/* FeedHolder Functions (for FeedItem functionality) */
virtual QScrollArea *getScrollArea();

View File

@ -26,6 +26,7 @@
#include "gui/gxs/GxsGroupShareKey.h"
#include "gui/settings/rsharesettings.h"
#include "gui/common/GroupTreeWidget.h"
#include "util/qtthreadsutils.h"
#include <retroshare/rsposted.h>
@ -43,13 +44,41 @@ public:
PostedDialog::PostedDialog(QWidget *parent)
: GxsGroupFrameDialog(rsPosted, parent)
{
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_POSTED, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void PostedDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_POSTED)
{
const RsGxsPostedEvent *e = dynamic_cast<const RsGxsPostedEvent*>(event.get());
if(!e) return;
switch(e->mPostedEventCode)
{
case RsPostedEventCode::NEW_MESSAGE:
case RsPostedEventCode::NEW_POSTED_GROUP: // [[fallthrough]];
case RsPostedEventCode::UPDATED_MESSAGE: // [[fallthrough]];
updateDisplay(false);
break;
case RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED: // [[fallthrough]];
updateDisplay(true);
break;
default: break;
}
}
}
PostedDialog::~PostedDialog()
{
}
UserNotify *PostedDialog::getUserNotify(QObject *parent)
UserNotify *PostedDialog::createUserNotify(QObject *parent)
{
return new PostedUserNotify(rsPosted, parent);
}

View File

@ -40,9 +40,8 @@ public:
virtual QString pageName() const { return tr("Links") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
protected:
virtual UserNotify *createUserNotify(QObject *parent) override;
virtual QString getHelpString() const ;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_POSTED; }
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Posted; }
@ -61,6 +60,9 @@ private:
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId);
virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_DATA; } // request complete group data
virtual void loadGroupSummaryToken(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo, RsUserdata* &userdata);
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
RsEventsHandlerId_t mEventHandlerId;
};
#endif

View File

@ -23,6 +23,7 @@
#include "PostedListWidget.h"
#include "ui_PostedListWidget.h"
#include "util/qtthreadsutils.h"
#include "gui/gxs/GxsIdDetails.h"
#include "PostedCreatePostDialog.h"
#include "PostedItem.h"
@ -94,7 +95,6 @@ PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent
/* Initialize GUI */
setGroupId(postedId);
}
PostedListWidget::~PostedListWidget()
{
// save settings

View File

@ -1173,6 +1173,8 @@ void GxsGroupFrameDialog::loadGroupStatistics(const uint32_t &token)
}
ui->groupTreeWidget->setUnreadCount(item, mCountChildMsgs ? (stats.mNumThreadMsgsUnread + stats.mNumChildMsgsUnread) : stats.mNumThreadMsgsUnread);
getUserNotify()->updateIcon();
}
/*********************** **** **** **** ***********************/

View File

@ -96,6 +96,8 @@ protected:
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
virtual void checkRequestGroup(const RsGxsGroupId& /* grpId */) {} // overload this one in order to retrieve full group data when the group is browsed
void updateMessageSummaryList(RsGxsGroupId groupId);
private slots:
void todo();
@ -153,7 +155,6 @@ private:
void initUi();
void updateMessageSummaryList(RsGxsGroupId groupId);
void updateSearchResults();
void openGroupInNewTab(const RsGxsGroupId &groupId);

View File

@ -64,7 +64,11 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
switch(e->mChannelEventCode)
{
case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED: updateDisplay(true);
case RsChannelEventCode::READ_STATUS_CHANGED:
updateMessageSummaryList(e->mChannelGroupId);
break;
case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED:
updateDisplay(true);
break;
default:
break;
@ -92,7 +96,7 @@ QString GxsChannelDialog::getHelpString() const
return hlp_str ;
}
UserNotify *GxsChannelDialog::getUserNotify(QObject *parent)
UserNotify *GxsChannelDialog::createUserNotify(QObject *parent)
{
return new GxsChannelUserNotify(rsGxsChannels, parent);
}

View File

@ -39,8 +39,6 @@ public:
virtual QString pageName() const { return tr("Channels") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
void shareOnChannel(const RsGxsGroupId& channel_id, const QList<RetroShareLink>& file_link) ;
protected:
@ -54,6 +52,7 @@ protected:
virtual TurtleRequestId distantSearch(const QString& search_string) ;
virtual void checkRequestGroup(const RsGxsGroupId& grpId) ;
virtual UserNotify *createUserNotify(QObject *parent) override;
private slots:
void toggleAutoDownload();
void setDefaultDirectory();

View File

@ -102,7 +102,7 @@ void GxsForumsDialog::shareInMessage(const RsGxsGroupId& forum_id,const QList<Re
msgDialog->show();
}
UserNotify *GxsForumsDialog::getUserNotify(QObject *parent)
UserNotify *GxsForumsDialog::createUserNotify(QObject *parent)
{
return new GxsForumUserNotify(rsGxsForums, parent);
}

View File

@ -37,11 +37,11 @@ public:
virtual QString pageName() const { return tr("Forums") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
void shareInMessage(const RsGxsGroupId& forum_id, const QList<RetroShareLink>& file_link) ;
protected:
virtual UserNotify *createUserNotify(QObject *parent) override;
virtual QString getHelpString() const ;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Forum; }

View File

@ -325,7 +325,7 @@ MessagesDialog::~MessagesDialog()
processSettings(false);
}
UserNotify *MessagesDialog::getUserNotify(QObject *parent)
UserNotify *MessagesDialog::createUserNotify(QObject *parent)
{
return new MessageUserNotify(parent);
}

View File

@ -50,8 +50,6 @@ public:
virtual QString pageName() const { return tr("Mail") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage
virtual UserNotify *getUserNotify(QObject *parent);
// replaced by shortcut
// virtual void keyPressEvent(QKeyEvent *) ;
@ -64,6 +62,7 @@ signals:
void messagesLoaded();
protected:
virtual UserNotify *createUserNotify(QObject *parent) override;
bool eventFilter(QObject *obj, QEvent *ev);
int getSelectedMessages(QList<QString>& mid);

View File

@ -55,14 +55,19 @@ public:
void setHelpText(QString help) { mHelp = help; }
virtual void retranslateUi() {}
virtual UserNotify *getUserNotify(QObject */*parent*/) { return NULL; }
// Override this if needed.
virtual UserNotify *createUserNotify(QObject */*parent*/) { return NULL; }
// Call this to add some help info to the page. The way the info is
// shown is handled by showHelp() below;
//
void registerHelpButton(QToolButton *button, const QString& help_html_text, const QString &code_name) ;
UserNotify *getUserNotify() ;
protected:
virtual void showEvent(QShowEvent *);
private:
@ -71,6 +76,8 @@ private:
QString mName;
QString mHelp;
QString mHelpCodeName;
UserNotify *mUserNotify;
};
#endif