2323#include < QMessageBox>
2424#include < QCloseEvent>
2525#include < QMenu>
26+ #include < QTimer>
2627
2728#include < algorithm>
2829#include < memory>
@@ -62,6 +63,9 @@ CreateCircleDialog::CreateCircleDialog()
6263 mCircleLoading = false ;
6364 mCloseRequested = false ;
6465 mEventHandlerId = 0 ;
66+ am_I_invited = false ;
67+ am_I_pending = false ;
68+ am_I_circle_admin = false ;
6569
6670 rsEvents->registerEventsHandler (
6771 [this ](std::shared_ptr<const RsEvent> event) { handleEvent (event); },
@@ -373,7 +377,7 @@ void CreateCircleDialog::addMember(const QString& keyId, const QString& idtype,
373377
374378 tree->addTopLevelItem (member);
375379
376- updateMembership ( );
380+ ui. members_groupBox -> setTitle ( tr ( " Invited Members " ) + " ( " + QString::number (ui. treeWidget_membership -> topLevelItemCount ()) + " ) " );
377381}
378382
379383void CreateCircleDialog::addMember (const QString &keyId, const QString &idtype,
@@ -957,6 +961,10 @@ void CreateCircleDialog::fillIdentitiesList(const std::vector<RsGxsIdGroup>& id_
957961
958962 }
959963 }
964+
965+ // Update membership statuses once, after all members have been added to the tree
966+ if (mIsExistingCircle )
967+ updateMembership ();
960968}
961969
962970void CreateCircleDialog::idTypeChanged ()
@@ -1003,6 +1011,7 @@ void CreateCircleDialog::updateMembership()
10031011{
10041012 am_I_invited = false ;
10051013 am_I_pending = false ;
1014+ am_I_circle_admin = false ;
10061015
10071016 RsGxsCircleDetails details;
10081017 if (!rsGxsCircles->getCircleDetails (RsGxsCircleId (mCircleGroup .mMeta .mGroupId ), details)) {
@@ -1109,10 +1118,11 @@ void CreateCircleDialog::MembershipListCustomPopupMenu( QPoint )
11091118 QMenu contextMnu ( this );
11101119
11111120 QTreeWidgetItem *item = ui.treeWidget_membership ->currentItem ();
1121+ if (!item) return ;
11121122
11131123 RsGxsId current_gxs_id (item->text (RSCIRCLEID_COL_KEYID).toStdString ());
11141124
1115- if (item && !mReadOnly && item->text (RSCIRCLEID_COL_STATUS) == tr (" Invited" ))
1125+ if (!mReadOnly && item->text (RSCIRCLEID_COL_STATUS) == tr (" Invited" ))
11161126 contextMnu.addAction (QIcon (" :/images/delete.png" ), tr (" Remove Member" ), this , SLOT (removeMember ()));
11171127
11181128 if (am_I_invited) {
@@ -1163,7 +1173,7 @@ void CreateCircleDialog::acceptInvite()
11631173 QTreeWidgetItem *item = ui.treeWidget_membership ->currentItem ();
11641174 if (!item) return ;
11651175
1166- RsGxsCircleId circleId (item-> text (RSCIRCLEID_COL_KEYID). toStdString () );
1176+ RsGxsCircleId circleId (mCircleGroup . mMeta . mGroupId );
11671177 // Use the chosen identity from your idChooser to accept the invite
11681178 RsGxsId ownId;
11691179 if (ui.idChooser ->getChosenId (ownId) == GxsIdChooser::KnowId) {
@@ -1176,7 +1186,7 @@ void CreateCircleDialog::rejectInvite()
11761186 QTreeWidgetItem *item = ui.treeWidget_membership ->currentItem ();
11771187 if (!item) return ;
11781188
1179- RsGxsCircleId circleId (item-> text (RSCIRCLEID_COL_KEYID). toStdString () );
1189+ RsGxsCircleId circleId (mCircleGroup . mMeta . mGroupId );
11801190 RsGxsId ownId;
11811191 if (ui.idChooser ->getChosenId (ownId) == GxsIdChooser::KnowId) {
11821192 rsGxsCircles->cancelCircleMembership (ownId, circleId);
@@ -1229,19 +1239,12 @@ void CreateCircleDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent>
12291239
12301240 if (pe->mCircleId .isNull () || pe->mCircleId == RsGxsCircleId (mCircleGroup .mMeta .mGroupId ))
12311241 {
1232- // Give it a moment as NewsFeed does to make sure the cache is populated
1233- RsThread::async ([this ]() {
1234- rstime::rs_usleep (500 *1000 ); // 0.5s
1235- RsQThreadUtils::postToObject ( [this ]() {
1236- if (!mCircleLoading && !mIsExternalCircle && !mIsExistingCircle )
1237- {
1238- // Still building or whatever.. just update it directly if we're loaded
1239- }
1240- else if (mIsExistingCircle )
1241- {
1242- loadCircle (RsGxsGroupId (mCircleGroup .mMeta .mGroupId ));
1243- }
1244- }, this );
1242+ // Give it a moment to make sure the cache is populated
1243+ QTimer::singleShot (500 , this , [this ]() {
1244+ if (mIsExistingCircle && !mCircleLoading )
1245+ {
1246+ loadCircle (RsGxsGroupId (mCircleGroup .mMeta .mGroupId ));
1247+ }
12451248 });
12461249 }
12471250 }
0 commit comments