Skip to content

Commit

Permalink
feat: add keys for group when provided for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Jul 8, 2024
1 parent 737a3e4 commit 945b66d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/groups/meta_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class MetaGroup {
shared_ptr<config::groups::Keys> keys,
session::ustring edGroupPubKey,
std::optional<session::ustring> edGroupSecKey) :
info{info}, members{members}, keys{keys} {

this->edGroupPubKey = oxenc::to_hex(edGroupPubKey);
this->edGroupSecKey = edGroupSecKey ? oxenc::to_hex(*edGroupSecKey) : nullptr;
};

explicit MetaGroup(const Napi::CallbackInfo& info) {}
info{info}, members{members}, keys{keys}, edGroupPubKey{oxenc::to_hex(edGroupPubKey)} {

if (edGroupSecKey.has_value()) {
this->edGroupSecKey = oxenc::to_hex(*edGroupSecKey);
} else {
this->edGroupSecKey = std::nullopt;
}
}
};

} // namespace session::nodeapi
} // namespace session::nodeapi
35 changes: 1 addition & 34 deletions src/groups/meta_group_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,7 @@ namespace session::nodeapi {

MetaGroupWrapper::MetaGroupWrapper(const Napi::CallbackInfo& info) :
meta_group{std::move(MetaBaseWrapper::constructGroupWrapper(info, "MetaGroupWrapper"))},
Napi::ObjectWrap<MetaGroupWrapper>{info} {
auto env = info.Env();
// this->meta_group->members->logger = [env](session::config::LogLevel, std::string_view x) {
// std::string toLog = "libsession-util:MetaGroup:Member: " + std::string(x) + "\n";

// Napi::Function consoleLog =
// env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
// consoleLog.Call({Napi::String::New(env, toLog)});
// };
// this->meta_group->info->logger = [env](session::config::LogLevel, std::string_view x) {
// std::string toLog = "libsession-util:MetaGroup:Info: " + std::string(x) + "\n";

// Napi::Function consoleLog =
// env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
// consoleLog.Call({Napi::String::New(env, toLog)});
// };
// this->meta_group->keys->logger = [env](
// session::config::LogLevel,
// std::string_view x) {
// std::string toLog = "libsession-util:MetaGroup:Keys: " + std::string(x) + "\n";

// Napi::Function consoleLog =
// env.Global().Get("console").As<Napi::Object>().Get("log").As<Napi::Function>();
// consoleLog.Call({Napi::String::New(env, toLog)});
// };
}
Napi::ObjectWrap<MetaGroupWrapper>{info} {}

void MetaGroupWrapper::Init(Napi::Env env, Napi::Object exports) {
MetaBaseWrapper::NoBaseClassInitHelper<MetaGroupWrapper>(
Expand Down Expand Up @@ -152,8 +127,6 @@ Napi::Value MetaGroupWrapper::needsDump(const Napi::CallbackInfo& info) {

Napi::Value MetaGroupWrapper::metaDump(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
auto env = info.Env();

oxenc::bt_dict_producer combined;

// NOTE: the keys have to be in ascii-sorted order:
Expand All @@ -168,8 +141,6 @@ Napi::Value MetaGroupWrapper::metaDump(const Napi::CallbackInfo& info) {

Napi::Value MetaGroupWrapper::metaMakeDump(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
auto env = info.Env();

oxenc::bt_dict_producer combined;

// NOTE: the keys have to be in ascii-sorted order:
Expand All @@ -192,7 +163,6 @@ void MetaGroupWrapper::metaConfirmPushed(const Napi::CallbackInfo& info) {

auto groupInfo = obj.Get("groupInfo");
auto groupMember = obj.Get("groupMember");
auto groupKeys = obj.Get("groupKeys");

if (!groupInfo.IsNull() && !groupInfo.IsUndefined()) {
assertIsArray(groupInfo);
Expand Down Expand Up @@ -429,7 +399,6 @@ Napi::Value MetaGroupWrapper::memberGetAllPendingRemovals(const Napi::CallbackIn

Napi::Value MetaGroupWrapper::memberGet(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
auto env = info.Env();
assertInfoLength(info, 1);
assertIsString(info[0]);

Expand All @@ -440,7 +409,6 @@ Napi::Value MetaGroupWrapper::memberGet(const Napi::CallbackInfo& info) {

Napi::Value MetaGroupWrapper::memberGetOrConstruct(const Napi::CallbackInfo& info) {
return wrapResult(info, [&] {
auto env = info.Env();
assertInfoLength(info, 1);
assertIsString(info[0]);

Expand Down Expand Up @@ -475,7 +443,6 @@ Napi::Value MetaGroupWrapper::memberSetInvited(const Napi::CallbackInfo& info) {
this->meta_group->members->set(m);

return this->meta_group->members->get_or_construct(pubkeyHex);

});
}

Expand Down
4 changes: 3 additions & 1 deletion src/meta/meta_base_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MetaBaseWrapper {
std::optional<ustring_view> dumped_keys;

if (dumped_meta) {

auto dumped_meta_str = from_unsigned_sv(*dumped_meta);

oxenc::bt_dict_consumer combined{dumped_meta_str};
Expand Down Expand Up @@ -101,7 +102,8 @@ class MetaBaseWrapper {
*info,
*members);

return std::make_unique<session::nodeapi::MetaGroup>(info, members, keys,group_ed25519_pubkey, group_ed25519_secretkey);
return std::make_unique<session::nodeapi::MetaGroup>(
info, members, keys, group_ed25519_pubkey, group_ed25519_secretkey);
});
}
};
Expand Down
1 change: 0 additions & 1 deletion src/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <type_traits>
#include <unordered_set>
#include <vector>
#include <stdexcept>

#include "session/config/namespaces.hpp"
#include "session/types.hpp"
Expand Down

0 comments on commit 945b66d

Please sign in to comment.