diff --git a/libretroshare/src/retroshare/rsevents.h b/libretroshare/src/retroshare/rsevents.h index d03d3ab32..9e0d81cc2 100644 --- a/libretroshare/src/retroshare/rsevents.h +++ b/libretroshare/src/retroshare/rsevents.h @@ -61,7 +61,7 @@ enum class RsEventType : uint32_t /// @see pqissl PEER_CONNECTION = 4, - /// @see RsGxsChanges + /// @see RsGxsChanges // this one should probably be removed because it's not used anywhere GXS_CHANGES = 5, /// Emitted when a peer state changes, @see RsPeers @@ -73,6 +73,15 @@ enum class RsEventType : uint32_t /// @see RsGxsCircleEvent GXS_CIRCLES = 8, + /// @see RsGxsChannelEvent + GXS_CHANNELS = 9, + + /// @see RsGxsForumEvent + GXS_FORUMS = 10, + + /// @see RsGxsPostedEvent + GXS_POSTED = 11, + MAX /// Used to detect invalid event type passed }; diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 4b82792f2..378f6d1b6 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -102,6 +102,34 @@ struct RsGxsChannelPost : RsSerializable ~RsGxsChannelPost() override; }; +struct RsGxsChannelEvent: RsEvent +{ + RsGxsChannelEvent() + : RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(UNKNOWN) {} + + enum ChannelEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_CHANNEL = 0x01, // emitted when new channel is received + UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel (group and msg id) + RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received. + }; + + ChannelEventCode mChannelEventCode; + RsGxsGroupId mChannelGroupId; + RsGxsMessageId mChannelMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mChannelEventCode); + RS_SERIAL_PROCESS(mChannelGroupId); + RS_SERIAL_PROCESS(mChannelMsgId); + } +}; class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService { diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index 3be38691d..cb3e42eb9 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -104,6 +104,33 @@ struct RsGxsForumMsg : RsSerializable ~RsGxsForumMsg() override; }; +struct RsGxsForumEvent: RsEvent +{ + RsGxsForumEvent() + : RsEvent(RsEventType::GXS_FORUMS), mForumEventCode(UNKNOWN) {} + + enum ForumEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_FORUM = 0x01, // emitted when new forum is received + UPDATED_FORUM = 0x02, // emitted when existing forum is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular forum (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular forum (group and msg id) + }; + + ForumEventCode mForumEventCode; + RsGxsGroupId mForumGroupId; + RsGxsMessageId mForumMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + + RS_SERIAL_PROCESS(mForumEventCode); + RS_SERIAL_PROCESS(mForumGroupId); + RS_SERIAL_PROCESS(mForumMsgId); + } +}; class RsGxsForums: public RsGxsIfaceHelper { diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index a42f06c40..c5c565bb0 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -68,6 +68,32 @@ class RsPostedGroup std::ostream &operator<<(std::ostream &out, const RsPostedGroup &group); std::ostream &operator<<(std::ostream &out, const RsPostedPost &post); +struct RsGxsPostedEvent: RsEvent +{ + RsGxsPostedEvent() + : RsEvent(RsEventType::GXS_POSTED), mPostedEventCode(UNKNOWN) {} + + enum PostedEventCode: uint8_t { + UNKNOWN = 0x00, + NEW_POSTED_GROUP = 0x01, + NEW_MESSAGE = 0x02 + }; + + PostedEventCode mPostedEventCode; + RsPeerId mAuthorId; + RsGxsGroupId mPostedGroupId; + RsGxsMessageId mPostedMsgId; + + ///* @see RsEvent @see RsSerializable + void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override + { + RsEvent::serial_process(j, ctx); + RS_SERIAL_PROCESS(mPostedEventCode); + RS_SERIAL_PROCESS(mAuthorId); + RS_SERIAL_PROCESS(mPostedGroupId); + RS_SERIAL_PROCESS(mPostedMsgId); + } +}; class RsPosted : public RsGxsIfaceHelper, public RsGxsCommentService { diff --git a/retroshare-gui/src/gui/NewsFeed.cpp b/retroshare-gui/src/gui/NewsFeed.cpp index 942262b8d..7be597630 100644 --- a/retroshare-gui/src/gui/NewsFeed.cpp +++ b/retroshare-gui/src/gui/NewsFeed.cpp @@ -81,10 +81,6 @@ NewsFeed::NewsFeed(QWidget *parent) : /* Invoke the Qt Designer generated object setup routine */ ui->setupUi(this); - mTokenQueueChannel = NULL; - mTokenQueueForum = NULL; - mTokenQueuePosted = NULL; - setUpdateWhenInvisible(true); if (!instance) { @@ -134,16 +130,6 @@ NewsFeed::~NewsFeed() if (instance == this) { instance = NULL; } - - if (mTokenQueueChannel) { - delete(mTokenQueueChannel); - } - if (mTokenQueueForum) { - delete(mTokenQueueForum); - } - if (mTokenQueuePosted) { - delete(mTokenQueuePosted); - } } UserNotify *NewsFeed::getUserNotify(QObject *parent) @@ -199,6 +185,79 @@ void NewsFeed::handleEvent_main_thread(std::shared_ptr event) if(event->mType == RsEventType::GXS_CIRCLES && (flags & RS_FEED_TYPE_CIRCLE)) handleCircleEvent(event); + + 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); + + if(event->mType == RsEventType::GXS_POSTED && (flags & RS_FEED_TYPE_POSTED)) + handlePostedEvent(event); +} + +void NewsFeed::handlePostedEvent(std::shared_ptr event) +{ + const RsGxsPostedEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mPostedEventCode) + { + case RsGxsPostedEvent::NEW_POSTED_GROUP: addFeedItem( new PostedGroupItem(this, NEWSFEED_POSTEDNEWLIST, pe->mPostedGroupId, false, true)); + break; + + case RsGxsPostedEvent::NEW_MESSAGE: addFeedItem( new PostedItem(this, NEWSFEED_POSTEDMSGLIST, pe->mPostedGroupId, pe->mPostedMsgId, false, true)); + break; + + default: + break; + } +} + +void NewsFeed::handleForumEvent(std::shared_ptr event) +{ + const RsGxsForumEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mForumEventCode) + { + case RsGxsForumEvent::UPDATED_FORUM: + case RsGxsForumEvent::NEW_FORUM: addFeedItem(new GxsForumGroupItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, false, true)); + break; + + case RsGxsForumEvent::UPDATED_MESSAGE: + case RsGxsForumEvent::NEW_MESSAGE: addFeedItem(new GxsForumMsgItem(this, NEWSFEED_FORUMNEWLIST, pe->mForumGroupId, pe->mForumMsgId, false, true)); + break; + + default: + break; + } +} + +void NewsFeed::handleChannelEvent(std::shared_ptr event) +{ + const RsGxsChannelEvent *pe = dynamic_cast(event.get()); + if(!pe) + return; + + switch(pe->mChannelEventCode) + { + case RsGxsChannelEvent::UPDATED_CHANNEL: + case RsGxsChannelEvent::NEW_CHANNEL: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, false, true)); + break; + + case RsGxsChannelEvent::UPDATED_MESSAGE: + case RsGxsChannelEvent::NEW_MESSAGE: addFeedItem(new GxsChannelPostItem(this, NEWSFEED_CHANNELNEWLIST, pe->mChannelGroupId, pe->mChannelMsgId, false, true)); + break; + + case RsGxsChannelEvent::RECEIVED_PUBLISH_KEY: addFeedItem(new GxsChannelGroupItem(this, NEWSFEED_CHANNELPUBKEYLIST, pe->mChannelGroupId, false, true)); + break; + + default: + break; + } } void NewsFeed::handleCircleEvent(std::shared_ptr event) @@ -248,7 +307,6 @@ void NewsFeed::handleCircleEvent(std::shared_ptr event) } } - void NewsFeed::handleConnectionEvent(std::shared_ptr event) { const RsConnectionEvent *pe = dynamic_cast(event.get()); @@ -360,7 +418,6 @@ void NewsFeed::updateDisplay() if (flags & RS_FEED_TYPE_SECURITY_IP) addFeedItemSecurityWrongExternalIpReported(fi, false); break; -#endif case RS_FEED_ITEM_CHANNEL_NEW: if (flags & RS_FEED_TYPE_CHANNEL) @@ -442,6 +499,7 @@ void NewsFeed::updateDisplay() if (flags & RS_FEED_TYPE_POSTED) addFeedItemPostedMsg(fi); break; +#endif #if 0 case RS_FEED_ITEM_BLOG_NEW: @@ -494,7 +552,6 @@ void NewsFeed::updateDisplay() void NewsFeed::testFeeds(uint notifyFlags) { -#ifdef TODO if (!instance) { return; } @@ -510,6 +567,7 @@ void NewsFeed::testFeeds(uint notifyFlags) RsFeedItem fi; +#ifdef TODO switch(type) { case RS_FEED_TYPE_PEER: fi.mId1 = rsPeers->getOwnId().toStdString(); @@ -652,12 +710,12 @@ void NewsFeed::testFeeds(uint notifyFlags) break; } +#endif } instance->ui->feedWidget->enableCountChangedSignal(true); instance->sendNewsFeedChanged(); -#endif } #ifdef TO_REMOVE @@ -697,7 +755,6 @@ void NewsFeed::loadCircleGroup(const uint32_t &token) } } } -#endif void NewsFeed::loadChannelGroup(const uint32_t &token) { @@ -970,9 +1027,11 @@ void NewsFeed::loadPostedMessage(const uint32_t &token) instance->addFeedItemPostedMsg(fi); } } +#endif void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) { +#ifdef TO_REMOVE if (queue == mTokenQueueChannel) { switch (req.mUserType) { case TOKEN_TYPE_GROUP: @@ -994,7 +1053,6 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) } } -#ifdef TO_REMOVE if (queue == mTokenQueueCircle) { switch (req.mUserType) { case TOKEN_TYPE_GROUP: @@ -1011,7 +1069,6 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) break; } } -#endif if (queue == mTokenQueueForum) { switch (req.mUserType) { @@ -1050,6 +1107,7 @@ void NewsFeed::loadRequest(const TokenQueue *queue, const TokenRequest &req) break; } } +#endif } void NewsFeed::testFeed(FeedNotify *feedNotify) @@ -1167,7 +1225,6 @@ void NewsFeed::addFeedItemPeerHello(const RsFeedItem &fi) std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) { @@ -1183,7 +1240,6 @@ void NewsFeed::addFeedItemPeerNew(const RsFeedItem &fi) #endif } -#ifdef TO_REMOVE void NewsFeed::addFeedItemPeerOffset(const RsFeedItem &fi) { /* make new widget */ @@ -1254,7 +1310,6 @@ void NewsFeed::addFeedItemSecurityUnknownOut(const RsFeedItem &fi) std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest) { @@ -1270,7 +1325,6 @@ void NewsFeed::addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTes #endif } -#ifdef TO_REMOVE void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest) { /* make new widget */ @@ -1284,7 +1338,6 @@ void NewsFeed::addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, std::cerr << std::endl; #endif } -#endif void NewsFeed::addFeedItemChannelNew(const RsFeedItem &fi) { @@ -1468,6 +1521,7 @@ void NewsFeed::addFeedItemPostedMsg(const RsFeedItem &fi) std::cerr << std::endl; #endif } +#endif #if 0 void NewsFeed::addFeedItemBlogNew(const RsFeedItem &fi) diff --git a/retroshare-gui/src/gui/NewsFeed.h b/retroshare-gui/src/gui/NewsFeed.h index 08cde3660..dba5f1f46 100644 --- a/retroshare-gui/src/gui/NewsFeed.h +++ b/retroshare-gui/src/gui/NewsFeed.h @@ -107,37 +107,13 @@ private: void handleSecurityEvent(std::shared_ptr event); void handleConnectionEvent(std::shared_ptr event); void handleCircleEvent(std::shared_ptr event); + void handleForumEvent(std::shared_ptr event); + void handlePostedEvent(std::shared_ptr event); + void handleChannelEvent(std::shared_ptr event); void addFeedItem(FeedItem *item); void addFeedItemIfUnique(FeedItem *item, bool replace); void remUniqueFeedItem(FeedItem *item); - - void addFeedItemPeerConnect(const RsFeedItem &fi); - void addFeedItemPeerDisconnect(const RsFeedItem &fi); - void addFeedItemPeerHello(const RsFeedItem &fi); - void addFeedItemPeerNew(const RsFeedItem &fi); - void addFeedItemPeerOffset(const RsFeedItem &fi); - - void addFeedItemSecurityConnectAttempt(const RsFeedItem &fi); - void addFeedItemSecurityAuthDenied(const RsFeedItem &fi); - void addFeedItemSecurityUnknownIn(const RsFeedItem &fi); - void addFeedItemSecurityUnknownOut(const RsFeedItem &fi); - void addFeedItemSecurityIpBlacklisted(const RsFeedItem &fi, bool isTest); - void addFeedItemSecurityWrongExternalIpReported(const RsFeedItem &fi, bool isTest); - - void addFeedItemChannelNew(const RsFeedItem &fi); -// void addFeedItemChannelUpdate(const RsFeedItem &fi); - void addFeedItemChannelMsg(const RsFeedItem &fi); - void addFeedItemChannelPublishKey(const RsFeedItem &fi); - - void addFeedItemForumNew(const RsFeedItem &fi); -// void addFeedItemForumUpdate(const RsFeedItem &fi); - void addFeedItemForumMsg(const RsFeedItem &fi); - - void addFeedItemPostedNew(const RsFeedItem &fi); -// void addFeedItemPostedUpdate(const RsFeedItem &fi); - void addFeedItemPostedMsg(const RsFeedItem &fi); - #if 0 void addFeedItemBlogNew(const RsFeedItem &fi); void addFeedItemBlogMsg(const RsFeedItem &fi); @@ -147,27 +123,7 @@ private: void addFeedItemMessage(const RsFeedItem &fi); void addFeedItemFilesNew(const RsFeedItem &fi); - void addFeedItemCircleMembReq(const RsFeedItem &fi); - void remFeedItemCircleMembReq(const RsFeedItem &fi); - void addFeedItemCircleInvitRec(const RsFeedItem &fi); - - virtual void loadChannelGroup(const uint32_t &token); - virtual void loadChannelPost(const uint32_t &token); - virtual void loadChannelPublishKey(const uint32_t &token); - - virtual void loadForumGroup(const uint32_t &token); - virtual void loadForumMessage(const uint32_t &token); - virtual void loadForumPublishKey(const uint32_t &token); - - virtual void loadPostedGroup(const uint32_t &token); - virtual void loadPostedMessage(const uint32_t &token); - private: - TokenQueue *mTokenQueueChannel; - TokenQueue *mTokenQueueCircle; - TokenQueue *mTokenQueueForum; - TokenQueue *mTokenQueuePosted; - /* UI - from Designer */ Ui::NewsFeed *ui;