Skip to content

Commit 4980e28

Browse files
committed
fix: add proFeaturesForMessage linking
1 parent fa8daef commit 4980e28

File tree

7 files changed

+64
-54
lines changed

7 files changed

+64
-54
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(ENABLE_ONIONREQ OFF)
3737
# as it is not part of the archive. We actually don't care about it on session-desktop
3838
set(SUBMODULE_CHECK OFF)
3939

40-
file(GLOB SOURCE_FILES src/*.cpp src/groups/*.cpp src/multi_encrypt/*.cpp)
40+
file(GLOB SOURCE_FILES src/*.cpp src/groups/*.cpp )
4141

4242
add_subdirectory(libsession-util)
4343

include/multi_encrypt/multi_encrypt.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace session::nodeapi {
2020

2121
namespace log = oxen::log;
2222

23-
auto cat = log::Cat("multi_encrypt");
2423

2524
inline std::vector<unsigned char> extractPlaintext(
2625
const Napi::Object& obj, const std::string identifier) {

include/pro/pro.hpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <span>
99
#include <vector>
1010

11+
#include "../meta/meta_base_wrapper.hpp"
1112
#include "../utilities.hpp"
1213
#include "oxen/log.hpp"
1314
#include "pro/types.hpp"
@@ -17,8 +18,10 @@
1718
#include "session/session_protocol.hpp"
1819

1920
namespace session::nodeapi {
21+
namespace log = oxen::log;
2022

2123
class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
24+
2225
public:
2326
ProWrapper(const Napi::CallbackInfo& info) : Napi::ObjectWrap<ProWrapper>{info} {
2427
throw std::invalid_argument("ProWrapper is static and doesn't need to be constructed");
@@ -49,6 +52,7 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
4952

5053
assertInfoLength(info, 1);
5154
assertIsObject(info[0]);
55+
auto env = info.Env();
5256

5357
auto first = info[0].As<Napi::Object>();
5458

@@ -67,20 +71,31 @@ class ProWrapper : public Napi::ObjectWrap<ProWrapper> {
6771
proFeatures.push_back(item);
6872
}
6973

70-
SESSION_PROTOCOL_PRO_EXTRA_FEATURES flags;
74+
SESSION_PROTOCOL_PRO_EXTRA_FEATURES flags = 0;
7175
for (std::string& feature : proFeatures) {
72-
if (feature == "10K_CHARACTER_LIMIT") {
73-
flags |= SESSION_PROTOCOL_PRO_FEATURES_10K_CHARACTER_LIMIT;
74-
} else if (feature == "PRO_BADGE") {
75-
flags |= SESSION_PROTOCOL_PRO_FEATURES_PRO_BADGE;
76+
// Note: 10K_CHARACTER_LIMIT cannot be requested by the caller
77+
if (feature == "PRO_BADGE") {
78+
flags |= SESSION_PROTOCOL_PRO_EXTRA_FEATURES_PRO_BADGE;
7679
} else if (feature == "ANIMATED_AVATAR") {
77-
flags |= SESSION_PROTOCOL_PRO_FEATURES_ANIMATED_AVATAR;
80+
flags |= SESSION_PROTOCOL_PRO_EXTRA_FEATURES_ANIMATED_AVATAR;
7881
}
7982
}
8083
assertIsString(first.Get("utf16"), "proFeaturesForMessage.utf16");
8184
std::u16string utf16 = first.Get("utf16").As<Napi::String>().Utf16Value();
82-
return session::pro_features_for_utf16((utf16.data()), utf16.length(), flags);
85+
auto pro_features_msg =
86+
session::pro_features_for_utf16((utf16.data()), utf16.length(), flags);
87+
88+
auto obj = Napi::Object::New(env);
89+
90+
obj["success"] = toJs(env, pro_features_msg.success);
91+
obj["error"] =
92+
pro_features_msg.error.size() ? toJs(env, pro_features_msg.error) : env.Null();
93+
obj["codepointCount"] = toJs(env, pro_features_msg.codepoint_count);
94+
obj["proFeatures"] = proFeaturesToJs(env, pro_features_msg.features);
95+
96+
return obj;
8397
});
8498
};
8599
};
100+
86101
}; // namespace session::nodeapi

include/pro/types.hpp

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "../utilities.hpp"
1212
#include "oxen/log.hpp"
13+
#include "pro/pro.hpp"
1314
#include "session/attachments.hpp"
1415
#include "session/config/user_profile.hpp"
1516
#include "session/multi_encrypt.hpp"
@@ -72,32 +73,6 @@ struct toJs_impl<session::DecodedEnvelope> {
7273
}
7374
};
7475

75-
template <>
76-
struct toJs_impl<SESSION_PROTOCOL_PRO_FEATURES> {
77-
Napi::Object operator()(const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset) {
78-
Napi::Array arr = Napi::Array::New(env);
79-
uint32_t index = 0;
80-
81-
if (bitset == SESSION_PROTOCOL_PRO_FEATURES_NIL) {
82-
return arr;
83-
}
84-
85-
if (bitset & (SESSION_PROTOCOL_PRO_FEATURES_10K_CHARACTER_LIMIT)) {
86-
arr[index] = Napi::String::New(env, "10K_CHARACTER_LIMIT");
87-
index++;
88-
}
89-
if (bitset & SESSION_PROTOCOL_PRO_FEATURES_PRO_BADGE) {
90-
arr[index++] = Napi::String::New(env, "PRO_BADGE");
91-
index++;
92-
}
93-
if (bitset & SESSION_PROTOCOL_PRO_FEATURES_ANIMATED_AVATAR) {
94-
arr[index++] = Napi::String::New(env, "ANIMATED_AVATAR");
95-
index++;
96-
}
97-
return arr;
98-
}
99-
};
100-
10176
template <>
10277
struct toJs_impl<session::DecodedPro> {
10378
Napi::Object operator()(const Napi::Env& env, const session::DecodedPro decoded_pro) {
@@ -110,22 +85,7 @@ struct toJs_impl<session::DecodedPro> {
11085
: decoded_pro.status == ProStatus::Valid ? "Valid"
11186
: "Expired");
11287
obj["proProof"] = toJs(env, decoded_pro.proof);
113-
obj["proFeatures"] = toJs(env, decoded_pro.features);
114-
115-
return obj;
116-
}
117-
};
118-
119-
template <>
120-
struct toJs_impl<session::ProFeaturesForMsg> {
121-
Napi::Object operator()(
122-
const Napi::Env& env, const session::ProFeaturesForMsg pro_features_msg) {
123-
auto obj = Napi::Object::New(env);
124-
125-
obj["success"] = toJs(env, pro_features_msg.success);
126-
obj["error"] = toJs(env, pro_features_msg.error);
127-
obj["codepointCount"] = toJs(env, pro_features_msg.codepoint_count);
128-
obj["proFeatures"] = toJs(env, pro_features_msg.features);
88+
obj["proFeatures"] = proFeaturesToJs(env, decoded_pro.features);
12989

13090
return obj;
13191
}

include/utilities.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <unordered_set>
1111
#include <vector>
1212

13+
#include "oxen/log.hpp"
1314
#include "oxenc/hex.h"
1415
#include "session/config/namespaces.hpp"
1516
#include "session/config/profile_pic.hpp"
17+
#include "session/session_protocol.hpp"
1618
#include "session/types.h"
1719
#include "session/types.hpp"
1820
#include "utilities.hpp"
@@ -21,6 +23,8 @@ namespace session::nodeapi {
2123

2224
using namespace std::literals;
2325

26+
inline auto cat = oxen::log::Cat("nodeapi");
27+
2428
static void checkOrThrow(bool condition, const char* msg) {
2529
if (!condition)
2630
throw std::invalid_argument{msg};
@@ -119,6 +123,11 @@ struct toJs_impl<session::config::Namespace> {
119123
}
120124
};
121125

126+
template <>
127+
struct toJs_impl<size_t> {
128+
auto operator()(const Napi::Env& env, size_t b) const { return Napi::Number::New(env, (b)); }
129+
};
130+
122131
template <typename T>
123132
struct toJs_impl<T, std::enable_if_t<std::is_arithmetic_v<T>>> {
124133
auto operator()(const Napi::Env& env, T n) const { return Napi::Number::New(env, n); }
@@ -362,6 +371,8 @@ Napi::Object decrypt_result_to_JS(
362371

363372
confirm_pushed_entry_t confirm_pushed_entry_from_JS(const Napi::Env& env, const Napi::Object& obj);
364373

374+
Napi::Object proFeaturesToJs(const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset);
375+
365376
std::span<const uint8_t> from_hex_to_span(std::string_view x);
366377

367378
template <std::size_t N>
@@ -386,8 +397,7 @@ std::array<uint8_t, N> from_hex_to_array(std::string x) {
386397
std::vector<unsigned char> from_hex_to_vector(std::string_view x);
387398

388399
std::span<const uint8_t> from_base64_to_span(std::string_view x);
389-
std::vector<unsigned char> from_base64_to_vector(std::string_view x) ;
390-
400+
std::vector<unsigned char> from_base64_to_vector(std::string_view x);
391401

392402
// Concept to match containers with a size() method
393403
template <typename T>

src/utilities.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,32 @@ confirm_pushed_entry_t confirm_pushed_entry_from_JS(const Napi::Env& env, const
345345
return confirmed_pushed_entry;
346346
}
347347

348+
Napi::Object proFeaturesToJs(const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset) {
349+
Napi::Array arr = Napi::Array::New(env);
350+
uint32_t index = 0;
351+
352+
if (bitset == SESSION_PROTOCOL_PRO_FEATURES_NIL) {
353+
return arr;
354+
}
355+
356+
if (bitset & (SESSION_PROTOCOL_PRO_FEATURES_10K_CHARACTER_LIMIT)) {
357+
arr[index] = Napi::String::New(env, "10K_CHARACTER_LIMIT");
358+
index++;
359+
}
360+
if (bitset & SESSION_PROTOCOL_PRO_FEATURES_PRO_BADGE) {
361+
arr[index++] = Napi::String::New(env, "PRO_BADGE");
362+
index++;
363+
}
364+
if (bitset & SESSION_PROTOCOL_PRO_FEATURES_ANIMATED_AVATAR) {
365+
arr[index++] = Napi::String::New(env, "ANIMATED_AVATAR");
366+
index++;
367+
}
368+
369+
370+
371+
return arr;
372+
}
373+
348374
std::span<const uint8_t> from_hex_to_span(std::string_view x) {
349375
return session::to_span(oxenc::from_hex(x));
350376
}

types/pro/pro.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ declare module 'libsession_util_nodejs' {
7373
* If provided (here) as an input, it will be ignored.
7474
*/
7575
proFeatures: ProFeatures;
76-
}) => WithProFeatures & { success: boolean; error: string | null; codePointCount: number };
76+
}) => WithProFeatures & { success: boolean; error: string | null; codepointCount: number };
7777
};
7878

7979
export type ProActionsCalls = MakeWrapperActionCalls<ProWrapper>;

0 commit comments

Comments
 (0)