@@ -417,100 +417,100 @@ Napi::Value MetaGroupWrapper::memberGetOrConstruct(const Napi::CallbackInfo& inf
417417 });
418418}
419419
420- Napi::Value MetaGroupWrapper::memberSetName (const Napi::CallbackInfo& info) {
421- return wrapResult (info, [&] {
420+ void MetaGroupWrapper::memberSetName (const Napi::CallbackInfo& info) {
421+ wrapExceptions (info, [&] {
422422 assertIsString (info[0 ]);
423423 assertIsString (info[1 ]);
424424
425425 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
426426 auto newName = toCppString (info[1 ], __PRETTY_FUNCTION__);
427- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
428- m.set_name (newName);
429- this ->meta_group ->members ->set (m);
430- return this ->meta_group ->members ->get_or_construct (m.session_id );
427+ auto m = this ->meta_group ->members ->get (pubkeyHex);
428+ if (m) {
429+ m->set_name (newName);
430+ this ->meta_group ->members ->set (*m);
431+ }
431432 });
432433}
433434
434- Napi::Value MetaGroupWrapper::memberSetInvited (const Napi::CallbackInfo& info) {
435- return wrapResult (info, [&] {
435+ void MetaGroupWrapper::memberSetInvited (const Napi::CallbackInfo& info) {
436+ wrapExceptions (info, [&] {
436437 assertIsString (info[0 ]);
437438 assertIsBoolean (info[1 ]);
438439 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
439440 auto failed = toCppBoolean (info[1 ], __PRETTY_FUNCTION__);
440441
441- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
442- m. set_invited (failed);
443- this -> meta_group -> members -> set (m );
444-
445- return this -> meta_group -> members -> get_or_construct (pubkeyHex);
442+ auto m = this ->meta_group ->members ->get (pubkeyHex);
443+ if (m) {
444+ m-> set_invited (failed );
445+ this -> meta_group -> members -> set (*m);
446+ }
446447 });
447448}
448449
449- Napi::Value MetaGroupWrapper::memberSetAccepted (const Napi::CallbackInfo& info) {
450- return wrapResult (info, [&] {
450+ void MetaGroupWrapper::memberSetAccepted (const Napi::CallbackInfo& info) {
451+ wrapExceptions (info, [&] {
451452 assertInfoLength (info, 1 );
452453 assertIsString (info[0 ]);
453454
454455 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
455- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
456- m. set_accepted ();
457-
458- this ->meta_group ->members ->set (m);
459- return this -> meta_group -> members -> get_or_construct (m. session_id );
456+ auto m = this ->meta_group ->members ->get (pubkeyHex);
457+ if (m) {
458+ m-> set_accepted ();
459+ this ->meta_group ->members ->set (* m);
460+ }
460461 });
461462}
462463
463- Napi::Value MetaGroupWrapper::memberSetPromoted (const Napi::CallbackInfo& info) {
464-
465- return wrapResult (info, [&] {
464+ void MetaGroupWrapper::memberSetPromoted (const Napi::CallbackInfo& info) {
465+ wrapExceptions (info, [&] {
466466 assertInfoLength (info, 2 );
467467 assertIsString (info[0 ]);
468468 assertIsBoolean (info[1 ]);
469469 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
470470 auto failed = toCppBoolean (info[1 ], __PRETTY_FUNCTION__);
471- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
472- m. set_promoted (failed);
473-
474- this ->meta_group ->members ->set (m);
475- return this -> meta_group -> members -> get_or_construct (m. session_id );
471+ auto m = this ->meta_group ->members ->get (pubkeyHex);
472+ if (m) {
473+ m-> set_promoted (failed);
474+ this ->meta_group ->members ->set (* m);
475+ }
476476 });
477477}
478478
479- Napi::Value MetaGroupWrapper::memberSetAdmin (const Napi::CallbackInfo& info) {
479+ void MetaGroupWrapper::memberSetAdmin (const Napi::CallbackInfo& info) {
480480
481- return wrapResult (info, [&] {
481+ wrapExceptions (info, [&] {
482482 assertInfoLength (info, 1 );
483483 assertIsString (info[0 ]);
484484 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
485485 // Note: this step might add an admin which was removed back once he accepts the promotion,
486486 // but there is not much we can do about it
487- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
488- m. admin = true ;
487+ auto m = this ->meta_group ->members ->get (pubkeyHex);
488+ m-> admin = true ;
489489
490- this ->meta_group ->members ->set (m);
491- return this ->meta_group ->members ->get_or_construct (m.session_id );
490+ this ->meta_group ->members ->set (*m);
492491 });
493492}
494493
495- Napi::Value MetaGroupWrapper::memberSetProfilePicture (const Napi::CallbackInfo& info) {
494+ void MetaGroupWrapper::memberSetProfilePicture (const Napi::CallbackInfo& info) {
496495
497- return wrapResult (info, [&] {
496+ wrapExceptions (info, [&] {
498497 assertInfoLength (info, 2 );
499498 assertIsString (info[0 ]);
500499 assertIsObject (info[1 ]);
501500
502501 auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
503502 auto profilePicture = profile_pic_from_object (info[1 ]);
504503
505- auto m = this ->meta_group ->members ->get_or_construct (pubkeyHex);
506- m.profile_picture = profilePicture;
507- this ->meta_group ->members ->set (m);
508- return this ->meta_group ->members ->get_or_construct (m.session_id );
504+ auto m = this ->meta_group ->members ->get (pubkeyHex);
505+ if (m) {
506+ m->profile_picture = profilePicture;
507+ this ->meta_group ->members ->set (*m);
508+ }
509509 });
510510}
511511
512- Napi::Value MetaGroupWrapper::membersMarkPendingRemoval (const Napi::CallbackInfo& info) {
513- return wrapResult (info, [&] {
512+ void MetaGroupWrapper::membersMarkPendingRemoval (const Napi::CallbackInfo& info) {
513+ wrapExceptions (info, [&] {
514514 assertInfoLength (info, 2 );
515515 auto toUpdateJSValue = info[0 ];
516516 auto withMessageJSValue = info[1 ];
@@ -522,12 +522,12 @@ Napi::Value MetaGroupWrapper::membersMarkPendingRemoval(const Napi::CallbackInfo
522522 auto toUpdateJS = toUpdateJSValue.As <Napi::Array>();
523523 for (uint32_t i = 0 ; i < toUpdateJS.Length (); i++) {
524524 auto pubkeyHex = toCppString (toUpdateJS[i], __PRETTY_FUNCTION__);
525- auto existing = this ->meta_group ->members ->get_or_construct (pubkeyHex);
526- existing.set_removed (withMessages);
527- this ->meta_group ->members ->set (existing);
525+ auto existing = this ->meta_group ->members ->get (pubkeyHex);
526+ if (existing) {
527+ existing->set_removed (withMessages);
528+ this ->meta_group ->members ->set (*existing);
529+ }
528530 }
529-
530- return true ;
531531 });
532532}
533533
0 commit comments