Notify one deletion per event as Cyril suggested

This commit is contained in:
Gioacchino Mazzurco 2021-01-13 17:24:03 +01:00
parent 045069c3e6
commit cef43fe048
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
5 changed files with 27 additions and 22 deletions

View File

@ -2717,10 +2717,15 @@ void RsGenExchange::processMessageDelete()
msgDeleted.push_back(note.msgIds);
}
for(const auto& msgreq:msgDeleted)
for(const auto& msgit:msgreq)
for(const auto& msg:msgit.second)
mNotifications.push_back(new RsGxsMsgChange(RsGxsNotify::TYPE_MESSAGE_DELETED,msgit.first,msg, false));
/* Three nested for looks like a performance bomb, but as Cyril says here
* https://github.com/RetroShare/RetroShare/pull/2218#pullrequestreview-565194022
* this should actually not explode at all because it is just one message at
* time that get notified */
for(const auto& msd : mMsgDeletePublish)
for(auto& msgMap : msd.mMsgs)
for(auto& msgId : msgMap.second)
mNotifications.push_back(
new RsGxsMsgDeletedChange(msgMap.first, msgId) );
mMsgDeletePublish.clear();
}

View File

@ -97,13 +97,13 @@ private:
bool mMetaChange;
};
struct RsGxsBulkMsgDeletedChange : RsGxsNotify
struct RsGxsMsgDeletedChange : RsGxsNotify
{
RsGxsBulkMsgDeletedChange(
const RsGxsGroupId& gid, const std::set<RsGxsMessageId>& msgsId):
RsGxsNotify(gid), messagesId(msgsId) {}
RsGxsMsgDeletedChange(
const RsGxsGroupId& gid, const RsGxsMessageId& msgId):
RsGxsNotify(gid), messageId(msgId) {}
NotifyType getType() override { return TYPE_MESSAGE_DELETED; }
const std::set<RsGxsMessageId> messagesId;
const RsGxsMessageId messageId;
};

View File

@ -118,7 +118,7 @@ enum class RsForumEventCode: uint8_t
SYNC_PARAMETERS_UPDATED = 0x0a, /// sync and storage times have changed
PINNED_POSTS_CHANGED = 0x0b, /// some posts where pinned or un-pinned
DELETED_FORUM = 0x0c, /// forum was deleted by cleaning
DELETED_POSTS = 13 /// Posts deleted by cleaning
DELETED_POSTS = 0x0d /// Posts deleted by cleaning
};
struct RsGxsForumEvent: RsEvent
@ -129,7 +129,7 @@ struct RsGxsForumEvent: RsEvent
RsForumEventCode mForumEventCode;
RsGxsGroupId mForumGroupId;
std::set<RsGxsMessageId> mForumMsgsId;
RsGxsMessageId mForumMsgId;
std::list<RsGxsId> mModeratorsAdded;
std::list<RsGxsId> mModeratorsRemoved;
@ -141,7 +141,7 @@ struct RsGxsForumEvent: RsEvent
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mForumEventCode);
RS_SERIAL_PROCESS(mForumGroupId);
RS_SERIAL_PROCESS(mForumMsgsId);
RS_SERIAL_PROCESS(mForumMsgId);
RS_SERIAL_PROCESS(mModeratorsAdded);
RS_SERIAL_PROCESS(mModeratorsRemoved);
}

View File

@ -211,7 +211,7 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(msgChange) /* Message received*/
{
auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumMsgsId.insert(msgChange->mMsgId);
ev->mForumMsgId = msgChange->mMsgId;
ev->mForumGroupId = msgChange->mGroupId;
ev->mForumEventCode = RsForumEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
@ -258,8 +258,8 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
case RsGxsNotify::TYPE_MESSAGE_DELETED:
{
rs_view_ptr<RsGxsBulkMsgDeletedChange> delChange =
dynamic_cast<RsGxsBulkMsgDeletedChange*>(gxsChange);
rs_view_ptr<RsGxsMsgDeletedChange> delChange =
dynamic_cast<RsGxsMsgDeletedChange*>(gxsChange);
if(!delChange)
{
@ -272,7 +272,7 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumEventCode = RsForumEventCode::DELETED_POSTS;
ev->mForumGroupId = delChange->mGroupId;
ev->mForumMsgsId = delChange->messagesId;
ev->mForumMsgId = delChange->messageId;
break;
}
case RsGxsNotify::TYPE_GROUP_DELETED:
@ -1053,7 +1053,7 @@ void p3GxsForums::setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair&
{
auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumMsgsId.insert(msgId.second);
ev->mForumMsgId = msgId.second;
ev->mForumGroupId = msgId.first;
ev->mForumEventCode = RsForumEventCode::READ_STATUS_CHANGED;
rsEvents->postEvent(ev);
@ -1084,7 +1084,7 @@ std::error_condition p3GxsForums::setPostKeepForever(
{
auto ev = std::make_shared<RsGxsForumEvent>();
ev->mForumGroupId = forumId;
ev->mForumMsgsId.insert(postId);
ev->mForumMsgId = postId;
ev->mForumEventCode = RsForumEventCode::UPDATED_MESSAGE;
rsEvents->postEvent(ev);
return std::error_condition();

View File

@ -270,9 +270,9 @@ void NewsFeed::handleForumEvent(std::shared_ptr<const RsEvent> event)
case RsForumEventCode::UPDATED_MESSAGE:
case RsForumEventCode::NEW_MESSAGE:
for(const auto& postId: pe->mForumMsgsId)
addFeedItem(new GxsForumMsgItem(
this, NEWSFEED_NEW_FORUM, pe->mForumGroupId, postId,
this, NEWSFEED_NEW_FORUM,
pe->mForumGroupId, pe->mForumMsgId,
false, true ));
break;