Skip to content

Commit 360f32c

Browse files
committed
added constants wrapper to export MAX_NAME_LENGTH for desktop project
1 parent 027e9e0 commit 360f32c

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

shared.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,13 @@ declare module 'libsession_util_nodejs' {
6565

6666
export type BaseWrapperActionsCalls = MakeWrapperActionCalls<BaseConfigWrapper>;
6767
}
68+
69+
/**
70+
* Constants wrapper logic
71+
*/
72+
73+
export type ConstantsWrapper = {
74+
"CONSTANTS": {
75+
MAX_NAME_LENGTH: number
76+
}
77+
}

src/addon.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <napi.h>
22

3+
#include "constants.hpp"
34
#include "contacts_config.hpp"
45
#include "convo_info_volatile_config.hpp"
56
#include "user_config.hpp"
@@ -8,6 +9,7 @@
89
Napi::Object InitAll(Napi::Env env, Napi::Object exports) {
910
using namespace session::nodeapi;
1011

12+
ConstantsWrapper::Init(env, exports);
1113
UserConfigWrapper::Init(env, exports);
1214
ContactsConfigWrapper::Init(env, exports);
1315
UserGroupsWrapper::Init(env, exports);

src/constants.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "constants.hpp"
2+
3+
namespace session::nodeapi {
4+
Napi::Number ConstantsWrapper::MAX_NAME_LENGTH;
5+
6+
ConstantsWrapper::ConstantsWrapper(const Napi::CallbackInfo& info) :
7+
Napi::ObjectWrap<ConstantsWrapper>(info) {}
8+
9+
Napi::Object ConstantsWrapper::Init(Napi::Env env, Napi::Object exports) {
10+
MAX_NAME_LENGTH = Napi::Number::New(env, session::config::contact_info::MAX_NAME_LENGTH);
11+
12+
Napi::Object constants = Napi::Object::New(env);
13+
constants.Set("MAX_NAME_LENGTH", MAX_NAME_LENGTH);
14+
15+
exports.Set("CONSTANTS", constants);
16+
return exports;
17+
}
18+
19+
} // namespace session::nodeapi

src/constants.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <napi.h>
4+
5+
#include "session/config/contacts.hpp"
6+
7+
namespace session::nodeapi {
8+
class ConstantsWrapper : public Napi::ObjectWrap<ConstantsWrapper> {
9+
public:
10+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
11+
ConstantsWrapper(const Napi::CallbackInfo& info);
12+
13+
private:
14+
static Napi::Number MAX_NAME_LENGTH;
15+
};
16+
} // namespace session::nodeapi

src/user_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void UserConfigWrapper::setUserInfo(const Napi::CallbackInfo& info) {
7070
if (name.IsString())
7171
new_name = name.As<Napi::String>().Utf8Value();
7272

73-
config.set_name(new_name);
73+
config.set_name_truncated(new_name);
7474

7575
auto new_priority = toPriority(priority, config.get_nts_priority());
7676
config.set_nts_priority(new_priority);

0 commit comments

Comments
 (0)