@@ -14,8 +14,13 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
1414 exports,
1515 " UserConfigWrapperNode" ,
1616 {
17- InstanceMethod (" getUserInfo" , &UserConfigWrapper::getUserInfo),
18- InstanceMethod (" setUserInfo" , &UserConfigWrapper::setUserInfo),
17+ InstanceMethod (" getPriority" , &UserConfigWrapper::getPriority),
18+ InstanceMethod (" getName" , &UserConfigWrapper::getName),
19+ InstanceMethod (" getProfilePic" , &UserConfigWrapper::getProfilePic),
20+ InstanceMethod (" setPriority" , &UserConfigWrapper::setPriority),
21+ InstanceMethod (" setName" , &UserConfigWrapper::setName),
22+ InstanceMethod (" setNameTruncated" , &UserConfigWrapper::setNameTruncated),
23+ InstanceMethod (" setProfilePic" , &UserConfigWrapper::setProfilePic),
1924 InstanceMethod (
2025 " getEnableBlindedMsgRequest" ,
2126 &UserConfigWrapper::getEnableBlindedMsgRequest),
@@ -31,56 +36,75 @@ UserConfigWrapper::UserConfigWrapper(const Napi::CallbackInfo& info) :
3136 ConfigBaseImpl{construct<config::UserProfile>(info, " UserConfig" )},
3237 Napi::ObjectWrap<UserConfigWrapper>{info} {}
3338
34- Napi::Value UserConfigWrapper::getUserInfo (const Napi::CallbackInfo& info) {
39+
40+ Napi::Value UserConfigWrapper::getPriority (const Napi::CallbackInfo& info) {
3541 return wrapResult (info, [&] {
3642 auto env = info.Env ();
37- auto user_info_obj = Napi::Object::New (env);
43+ return config.get_nts_priority ();
44+ });
45+ }
3846
39- auto name = config.get_name ();
40- auto priority = config.get_nts_priority ();
47+ Napi::Value UserConfigWrapper::getName (const Napi::CallbackInfo& info) {
48+ return wrapResult (info, [&] {
49+ auto env = info.Env ();
50+ return config.get_name ();
51+ });
52+ }
4153
42- user_info_obj[" name" ] = toJs (env, name);
43- user_info_obj[" priority" ] = toJs (env, priority);
54+ Napi::Value UserConfigWrapper::getProfilePic (const Napi::CallbackInfo& info) {
55+ return wrapResult (info, [&] {
56+ auto env = info.Env ();
57+ return object_from_profile_pic (env, config.get_profile_pic ());
58+ });
59+ }
4460
45- auto profile_pic_obj = object_from_profile_pic (env, config.get_profile_pic ());
46- if (profile_pic_obj) {
47- user_info_obj[" url" ] = profile_pic_obj.Get (" url" );
48- user_info_obj[" key" ] = profile_pic_obj.Get (" key" );
49- } else {
50- user_info_obj[" url" ] = env.Null ();
51- user_info_obj[" key" ] = env.Null ();
52- }
61+ void UserConfigWrapper::setPriority (const Napi::CallbackInfo& info) {
62+ return wrapExceptions (info, [&] {
63+ auto env = info.Env ();
64+ assertInfoLength (info, 1 );
65+ auto priority = info[0 ];
66+ assertIsNumber (priority);
5367
54- return user_info_obj;
68+ auto new_priority = toPriority (priority, config.get_nts_priority ());
69+ config.set_nts_priority (new_priority);
5570 });
5671}
5772
58- Napi::Value UserConfigWrapper::setUserInfo (const Napi::CallbackInfo& info) {
59- return wrapResult (info, [&] {
60- assertInfoLength (info, 3 );
61-
73+ void UserConfigWrapper::setName (const Napi::CallbackInfo& info) {
74+ return wrapExceptions (info, [&] {
75+ auto env = info. Env ( );
76+ assertInfoLength (info, 1 );
6277 auto name = info[0 ];
63- auto priority = info[1 ];
64- auto profile_pic_obj = info[2 ];
78+ assertIsString (name);
6579
66- assertIsStringOrNull (name);
67- assertIsNumber (priority);
68- std::string new_name;
80+ auto new_name = name.As <Napi::String>().Utf8Value ();
81+ // this will throw if the name is too long
82+ config.set_name (new_name);
83+ });
84+ }
6985
70- if (name.IsString ())
71- new_name = name.As <Napi::String>().Utf8Value ();
86+ void UserConfigWrapper::setNameTruncated (const Napi::CallbackInfo& info) {
87+ return wrapExceptions (info, [&] {
88+ auto env = info.Env ();
89+ assertInfoLength (info, 1 );
90+ auto name = info[0 ];
91+ assertIsString (name);
7292
93+ auto new_name = name.As <Napi::String>().Utf8Value ();
94+ // this will truncate silently if the name is too long
7395 config.set_name_truncated (new_name);
96+ });
97+ }
7498
75- auto new_priority = toPriority (priority, config.get_nts_priority ());
76- config.set_nts_priority (new_priority);
99+ void UserConfigWrapper::setProfilePic (const Napi::CallbackInfo& info) {
100+ return wrapExceptions (info, [&] {
101+ assertInfoLength (info, 1 );
102+ auto profile_pic_obj = info[0 ];
77103
78104 if (!profile_pic_obj.IsNull () && !profile_pic_obj.IsUndefined ())
79105 assertIsObject (profile_pic_obj);
80106
81107 config.set_profile_pic (profile_pic_from_object (profile_pic_obj));
82-
83- return config.get_name ();
84108 });
85109}
86110
0 commit comments