Skip to content

Commit

Permalink
fix: do not get_or_construct except when excplicitely being called
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Jul 9, 2024
1 parent 945b66d commit 52bd57f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
94 changes: 47 additions & 47 deletions src/groups/meta_group_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,100 +417,100 @@ Napi::Value MetaGroupWrapper::memberGetOrConstruct(const Napi::CallbackInfo& inf
});
}

Napi::Value MetaGroupWrapper::memberSetName(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
void MetaGroupWrapper::memberSetName(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertIsString(info[0]);
assertIsString(info[1]);

auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
auto newName = toCppString(info[1], __PRETTY_FUNCTION__);
auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.set_name(newName);
this->meta_group->members->set(m);
return this->meta_group->members->get_or_construct(m.session_id);
auto m = this->meta_group->members->get(pubkeyHex);
if (m) {
m->set_name(newName);
this->meta_group->members->set(*m);
}
});
}

Napi::Value MetaGroupWrapper::memberSetInvited(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
void MetaGroupWrapper::memberSetInvited(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertIsString(info[0]);
assertIsBoolean(info[1]);
auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
auto failed = toCppBoolean(info[1], __PRETTY_FUNCTION__);

auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.set_invited(failed);
this->meta_group->members->set(m);

return this->meta_group->members->get_or_construct(pubkeyHex);
auto m = this->meta_group->members->get(pubkeyHex);
if (m) {
m->set_invited(failed);
this->meta_group->members->set(*m);
}
});
}

Napi::Value MetaGroupWrapper::memberSetAccepted(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
void MetaGroupWrapper::memberSetAccepted(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertInfoLength(info, 1);
assertIsString(info[0]);

auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.set_accepted();

this->meta_group->members->set(m);
return this->meta_group->members->get_or_construct(m.session_id);
auto m = this->meta_group->members->get(pubkeyHex);
if (m) {
m->set_accepted();
this->meta_group->members->set(*m);
}
});
}

Napi::Value MetaGroupWrapper::memberSetPromoted(const Napi::CallbackInfo& info) {

return wrapResult(info, [&] {
void MetaGroupWrapper::memberSetPromoted(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertInfoLength(info, 2);
assertIsString(info[0]);
assertIsBoolean(info[1]);
auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
auto failed = toCppBoolean(info[1], __PRETTY_FUNCTION__);
auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.set_promoted(failed);

this->meta_group->members->set(m);
return this->meta_group->members->get_or_construct(m.session_id);
auto m = this->meta_group->members->get(pubkeyHex);
if (m) {
m->set_promoted(failed);
this->meta_group->members->set(*m);
}
});
}

Napi::Value MetaGroupWrapper::memberSetAdmin(const Napi::CallbackInfo& info) {
void MetaGroupWrapper::memberSetAdmin(const Napi::CallbackInfo& info) {

return wrapResult(info, [&] {
wrapExceptions(info, [&] {
assertInfoLength(info, 1);
assertIsString(info[0]);
auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
// Note: this step might add an admin which was removed back once he accepts the promotion,
// but there is not much we can do about it
auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.admin = true;
auto m = this->meta_group->members->get(pubkeyHex);
m->admin = true;

this->meta_group->members->set(m);
return this->meta_group->members->get_or_construct(m.session_id);
this->meta_group->members->set(*m);
});
}

Napi::Value MetaGroupWrapper::memberSetProfilePicture(const Napi::CallbackInfo& info) {
void MetaGroupWrapper::memberSetProfilePicture(const Napi::CallbackInfo& info) {

return wrapResult(info, [&] {
wrapExceptions(info, [&] {
assertInfoLength(info, 2);
assertIsString(info[0]);
assertIsObject(info[1]);

auto pubkeyHex = toCppString(info[0], __PRETTY_FUNCTION__);
auto profilePicture = profile_pic_from_object(info[1]);

auto m = this->meta_group->members->get_or_construct(pubkeyHex);
m.profile_picture = profilePicture;
this->meta_group->members->set(m);
return this->meta_group->members->get_or_construct(m.session_id);
auto m = this->meta_group->members->get(pubkeyHex);
if (m) {
m->profile_picture = profilePicture;
this->meta_group->members->set(*m);
}
});
}

Napi::Value MetaGroupWrapper::membersMarkPendingRemoval(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
void MetaGroupWrapper::membersMarkPendingRemoval(const Napi::CallbackInfo& info) {
wrapExceptions(info, [&] {
assertInfoLength(info, 2);
auto toUpdateJSValue = info[0];
auto withMessageJSValue = info[1];
Expand All @@ -522,12 +522,12 @@ Napi::Value MetaGroupWrapper::membersMarkPendingRemoval(const Napi::CallbackInfo
auto toUpdateJS = toUpdateJSValue.As<Napi::Array>();
for (uint32_t i = 0; i < toUpdateJS.Length(); i++) {
auto pubkeyHex = toCppString(toUpdateJS[i], __PRETTY_FUNCTION__);
auto existing = this->meta_group->members->get_or_construct(pubkeyHex);
existing.set_removed(withMessages);
this->meta_group->members->set(existing);
auto existing = this->meta_group->members->get(pubkeyHex);
if (existing) {
existing->set_removed(withMessages);
this->meta_group->members->set(*existing);
}
}

return true;
});
}

Expand Down
14 changes: 7 additions & 7 deletions src/groups/meta_group_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ class MetaGroupWrapper : public Napi::ObjectWrap<MetaGroupWrapper> {
Napi::Value memberGetAllPendingRemovals(const Napi::CallbackInfo& info);
Napi::Value memberGet(const Napi::CallbackInfo& info);
Napi::Value memberGetOrConstruct(const Napi::CallbackInfo& info);
Napi::Value memberSetName(const Napi::CallbackInfo& info);
Napi::Value memberSetInvited(const Napi::CallbackInfo& info);
Napi::Value memberSetAccepted(const Napi::CallbackInfo& info);
Napi::Value memberSetPromoted(const Napi::CallbackInfo& info);
Napi::Value memberSetAdmin(const Napi::CallbackInfo& info);
Napi::Value memberSetProfilePicture(const Napi::CallbackInfo& info);
void memberSetName(const Napi::CallbackInfo& info);
void memberSetInvited(const Napi::CallbackInfo& info);
void memberSetAccepted(const Napi::CallbackInfo& info);
void memberSetPromoted(const Napi::CallbackInfo& info);
void memberSetAdmin(const Napi::CallbackInfo& info);
void memberSetProfilePicture(const Napi::CallbackInfo& info);
Napi::Value memberEraseAndRekey(const Napi::CallbackInfo& info);
Napi::Value membersMarkPendingRemoval(const Napi::CallbackInfo& info);
void membersMarkPendingRemoval(const Napi::CallbackInfo& info);

/** Keys Actions */

Expand Down
14 changes: 7 additions & 7 deletions types/groups/groupmembers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ declare module 'libsession_util_nodejs' {
memberGetAllPendingRemovals: () => Array<GroupMemberGet>;

// setters
memberSetName: (pubkeyHex: PubkeyType, newName: string) => GroupMemberGet;
memberSetInvited: (pubkeyHex: PubkeyType, failed: boolean) => GroupMemberGet;
memberSetPromoted: (pubkeyHex: PubkeyType, failed: boolean) => GroupMemberGet;
memberSetAdmin: (pubkeyHex: PubkeyType) => GroupMemberGet;
memberSetAccepted: (pubkeyHex: PubkeyType) => GroupMemberGet;
memberSetName: (pubkeyHex: PubkeyType, newName: string) => void;
memberSetInvited: (pubkeyHex: PubkeyType, failed: boolean) => void;
memberSetPromoted: (pubkeyHex: PubkeyType, failed: boolean) => void;
memberSetAdmin: (pubkeyHex: PubkeyType) => void;
memberSetAccepted: (pubkeyHex: PubkeyType) => void;
memberSetProfilePicture: (
pubkeyHex: PubkeyType,
profilePicture: ProfilePicture
) => GroupMemberGet;
membersMarkPendingRemoval: (members: Array<PubkeyType>, withMessages: boolean) => boolean;
) => void;
membersMarkPendingRemoval: (members: Array<PubkeyType>, withMessages: boolean) => void;

// eraser
memberEraseAndRekey: (members: Array<PubkeyType>) => boolean;
Expand Down

0 comments on commit 52bd57f

Please sign in to comment.