@@ -417,100 +417,100 @@ Napi::Value MetaGroupWrapper::memberGetOrConstruct(const Napi::CallbackInfo& inf
417
417
});
418
418
}
419
419
420
- Napi::Value MetaGroupWrapper::memberSetName (const Napi::CallbackInfo& info) {
421
- return wrapResult (info, [&] {
420
+ void MetaGroupWrapper::memberSetName (const Napi::CallbackInfo& info) {
421
+ wrapExceptions (info, [&] {
422
422
assertIsString (info[0 ]);
423
423
assertIsString (info[1 ]);
424
424
425
425
auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
426
426
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
+ }
431
432
});
432
433
}
433
434
434
- Napi::Value MetaGroupWrapper::memberSetInvited (const Napi::CallbackInfo& info) {
435
- return wrapResult (info, [&] {
435
+ void MetaGroupWrapper::memberSetInvited (const Napi::CallbackInfo& info) {
436
+ wrapExceptions (info, [&] {
436
437
assertIsString (info[0 ]);
437
438
assertIsBoolean (info[1 ]);
438
439
auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
439
440
auto failed = toCppBoolean (info[1 ], __PRETTY_FUNCTION__);
440
441
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
+ }
446
447
});
447
448
}
448
449
449
- Napi::Value MetaGroupWrapper::memberSetAccepted (const Napi::CallbackInfo& info) {
450
- return wrapResult (info, [&] {
450
+ void MetaGroupWrapper::memberSetAccepted (const Napi::CallbackInfo& info) {
451
+ wrapExceptions (info, [&] {
451
452
assertInfoLength (info, 1 );
452
453
assertIsString (info[0 ]);
453
454
454
455
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
+ }
460
461
});
461
462
}
462
463
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, [&] {
466
466
assertInfoLength (info, 2 );
467
467
assertIsString (info[0 ]);
468
468
assertIsBoolean (info[1 ]);
469
469
auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
470
470
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
+ }
476
476
});
477
477
}
478
478
479
- Napi::Value MetaGroupWrapper::memberSetAdmin (const Napi::CallbackInfo& info) {
479
+ void MetaGroupWrapper::memberSetAdmin (const Napi::CallbackInfo& info) {
480
480
481
- return wrapResult (info, [&] {
481
+ wrapExceptions (info, [&] {
482
482
assertInfoLength (info, 1 );
483
483
assertIsString (info[0 ]);
484
484
auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
485
485
// Note: this step might add an admin which was removed back once he accepts the promotion,
486
486
// 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 ;
489
489
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);
492
491
});
493
492
}
494
493
495
- Napi::Value MetaGroupWrapper::memberSetProfilePicture (const Napi::CallbackInfo& info) {
494
+ void MetaGroupWrapper::memberSetProfilePicture (const Napi::CallbackInfo& info) {
496
495
497
- return wrapResult (info, [&] {
496
+ wrapExceptions (info, [&] {
498
497
assertInfoLength (info, 2 );
499
498
assertIsString (info[0 ]);
500
499
assertIsObject (info[1 ]);
501
500
502
501
auto pubkeyHex = toCppString (info[0 ], __PRETTY_FUNCTION__);
503
502
auto profilePicture = profile_pic_from_object (info[1 ]);
504
503
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
+ }
509
509
});
510
510
}
511
511
512
- Napi::Value MetaGroupWrapper::membersMarkPendingRemoval (const Napi::CallbackInfo& info) {
513
- return wrapResult (info, [&] {
512
+ void MetaGroupWrapper::membersMarkPendingRemoval (const Napi::CallbackInfo& info) {
513
+ wrapExceptions (info, [&] {
514
514
assertInfoLength (info, 2 );
515
515
auto toUpdateJSValue = info[0 ];
516
516
auto withMessageJSValue = info[1 ];
@@ -522,12 +522,12 @@ Napi::Value MetaGroupWrapper::membersMarkPendingRemoval(const Napi::CallbackInfo
522
522
auto toUpdateJS = toUpdateJSValue.As <Napi::Array>();
523
523
for (uint32_t i = 0 ; i < toUpdateJS.Length (); i++) {
524
524
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
+ }
528
530
}
529
-
530
- return true ;
531
531
});
532
532
}
533
533
0 commit comments