added circle invite notifications

This commit is contained in:
csoler 2020-04-28 21:39:38 +02:00
parent f5af7dfeb3
commit 767440afc5
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 64 additions and 6 deletions

View File

@ -183,7 +183,7 @@ enum class RsGxsCircleEventCode: uint8_t
CIRCLE_MEMBERSHIP_JOIN = 0x04,
/** mCircleId contains the circle id and mGxsId is the id that was revoqued * by admin */
CIRCLE_MEMBERSHIP_REVOQUED= 0x05,
CIRCLE_MEMBERSHIP_REVOKED = 0x05,
/** mCircleId contains the circle id */
NEW_CIRCLE = 0x06,

View File

@ -119,7 +119,7 @@ const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REQ = RS_FEED_TYPE_CIRCLE | 0x0001
const uint32_t RS_FEED_ITEM_CIRCLE_INVIT_REC = RS_FEED_TYPE_CIRCLE | 0x0002;
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_LEAVE = RS_FEED_TYPE_CIRCLE | 0x0003;
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_JOIN = RS_FEED_TYPE_CIRCLE | 0x0004;
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED = RS_FEED_TYPE_CIRCLE | 0x0005;
const uint32_t RS_FEED_ITEM_CIRCLE_MEMB_REVOKED = RS_FEED_TYPE_CIRCLE | 0x0005;
const uint32_t RS_MESSAGE_CONNECT_ATTEMPT = 0x0001;

View File

@ -679,6 +679,64 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
}
RsGxsGroupUpdate *grpUpdate = dynamic_cast<RsGxsGroupUpdate*>(*it);
if (grpUpdate && rsEvents)
{
// Happens when the group data has changed. In this case we need to analyse the old and new group in order to detect possible notifications for clients
RsGxsCircleGroupItem *old_circle_grp_item = dynamic_cast<RsGxsCircleGroupItem*>(grpUpdate->mOldGroupItem);
RsGxsCircleGroupItem *new_circle_grp_item = dynamic_cast<RsGxsCircleGroupItem*>(grpUpdate->mNewGroupItem);
const RsGxsCircleId circle_id ( old_circle_grp_item->meta.mGroupId );
if(old_circle_grp_item == nullptr || new_circle_grp_item == nullptr)
{
RsErr() << __PRETTY_FUNCTION__ << " received GxsGroupUpdate item with mOldGroup and mNewGroup not of type RsGxsCircleGroupItem. This is inconsistent!" << std::endl;
delete grpUpdate;
continue;
}
// First of all, we check if there is a difference between the old and new list of invited members
std::list<RsGxsId> added_identities, removed_identities;
std::list<RsGxsId> own_ids_lst;
rsIdentity->getOwnIds(own_ids_lst,false); // retrieve own identities
std::set<RsGxsId> own_ids;
for(auto& id:own_ids_lst)
own_ids.insert(id); // put them in a std::set for O(log(n)) search
for(auto& gxs_id: new_circle_grp_item->gxsIdSet.ids)
if(old_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end() && own_ids.find(gxs_id)!=own_ids.end())
added_identities.push_back(gxs_id);
for(auto& gxs_id: old_circle_grp_item->gxsIdSet.ids)
if(new_circle_grp_item->gxsIdSet.ids.find(gxs_id) == old_circle_grp_item->gxsIdSet.ids.end() && own_ids.find(gxs_id)!=own_ids.end())
removed_identities.push_back(gxs_id);
for(auto& gxs_id:added_identities)
{
auto ev = std::make_shared<RsGxsCircleEvent>();
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE;
ev->mCircleId = circle_id;
ev->mGxsId = gxs_id;
rsEvents->sendEvent(ev);
}
for(auto& gxs_id:removed_identities)
{
auto ev = std::make_shared<RsGxsCircleEvent>();
ev->mCircleEventType = RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOKED;
ev->mCircleId = circle_id;
ev->mGxsId = gxs_id;
rsEvents->sendEvent(ev);
}
}
delete *it;
}
}

View File

@ -438,7 +438,7 @@ void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_INVITE:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOKED:
case RsGxsCircleEventCode::CACHE_DATA_UPDATED:
updateCircles();

View File

@ -329,8 +329,8 @@ void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
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);
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOKED:
addFeedItemIfUnique(new GxsCircleItem(this, NEWSFEED_CIRCLELIST, pe->mCircleId, pe->mGxsId, RS_FEED_ITEM_CIRCLE_MEMB_REVOKED),true);
break;
default: break;
}

View File

@ -136,7 +136,7 @@ void GxsCircleItem::setup()
ui->acceptButton->setHidden(true);
ui->revokeButton->setHidden(true);
}
else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_REVOQUED)
else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_REVOKED)
{
if(rsIdentity->isOwnId(mGxsId))
ui->titleLabel->setText(tr("Your identity %1 has been revoqued from this circle.").arg(idName));