Skip to content

Commit 52bd57f

Browse files
committed
fix: do not get_or_construct except when excplicitely being called
1 parent 945b66d commit 52bd57f

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

src/groups/meta_group_wrapper.cpp

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/groups/meta_group_wrapper.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ class MetaGroupWrapper : public Napi::ObjectWrap<MetaGroupWrapper> {
7373
Napi::Value memberGetAllPendingRemovals(const Napi::CallbackInfo& info);
7474
Napi::Value memberGet(const Napi::CallbackInfo& info);
7575
Napi::Value memberGetOrConstruct(const Napi::CallbackInfo& info);
76-
Napi::Value memberSetName(const Napi::CallbackInfo& info);
77-
Napi::Value memberSetInvited(const Napi::CallbackInfo& info);
78-
Napi::Value memberSetAccepted(const Napi::CallbackInfo& info);
79-
Napi::Value memberSetPromoted(const Napi::CallbackInfo& info);
80-
Napi::Value memberSetAdmin(const Napi::CallbackInfo& info);
81-
Napi::Value memberSetProfilePicture(const Napi::CallbackInfo& info);
76+
void memberSetName(const Napi::CallbackInfo& info);
77+
void memberSetInvited(const Napi::CallbackInfo& info);
78+
void memberSetAccepted(const Napi::CallbackInfo& info);
79+
void memberSetPromoted(const Napi::CallbackInfo& info);
80+
void memberSetAdmin(const Napi::CallbackInfo& info);
81+
void memberSetProfilePicture(const Napi::CallbackInfo& info);
8282
Napi::Value memberEraseAndRekey(const Napi::CallbackInfo& info);
83-
Napi::Value membersMarkPendingRemoval(const Napi::CallbackInfo& info);
83+
void membersMarkPendingRemoval(const Napi::CallbackInfo& info);
8484

8585
/** Keys Actions */
8686

types/groups/groupmembers.d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ declare module 'libsession_util_nodejs' {
3535
memberGetAllPendingRemovals: () => Array<GroupMemberGet>;
3636

3737
// setters
38-
memberSetName: (pubkeyHex: PubkeyType, newName: string) => GroupMemberGet;
39-
memberSetInvited: (pubkeyHex: PubkeyType, failed: boolean) => GroupMemberGet;
40-
memberSetPromoted: (pubkeyHex: PubkeyType, failed: boolean) => GroupMemberGet;
41-
memberSetAdmin: (pubkeyHex: PubkeyType) => GroupMemberGet;
42-
memberSetAccepted: (pubkeyHex: PubkeyType) => GroupMemberGet;
38+
memberSetName: (pubkeyHex: PubkeyType, newName: string) => void;
39+
memberSetInvited: (pubkeyHex: PubkeyType, failed: boolean) => void;
40+
memberSetPromoted: (pubkeyHex: PubkeyType, failed: boolean) => void;
41+
memberSetAdmin: (pubkeyHex: PubkeyType) => void;
42+
memberSetAccepted: (pubkeyHex: PubkeyType) => void;
4343
memberSetProfilePicture: (
4444
pubkeyHex: PubkeyType,
4545
profilePicture: ProfilePicture
46-
) => GroupMemberGet;
47-
membersMarkPendingRemoval: (members: Array<PubkeyType>, withMessages: boolean) => boolean;
46+
) => void;
47+
membersMarkPendingRemoval: (members: Array<PubkeyType>, withMessages: boolean) => void;
4848

4949
// eraser
5050
memberEraseAndRekey: (members: Array<PubkeyType>) => boolean;

0 commit comments

Comments
 (0)