@@ -14,8 +14,13 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
14
14
exports,
15
15
" UserConfigWrapperNode" ,
16
16
{
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),
19
24
InstanceMethod (
20
25
" getEnableBlindedMsgRequest" ,
21
26
&UserConfigWrapper::getEnableBlindedMsgRequest),
@@ -31,56 +36,75 @@ UserConfigWrapper::UserConfigWrapper(const Napi::CallbackInfo& info) :
31
36
ConfigBaseImpl{construct<config::UserProfile>(info, " UserConfig" )},
32
37
Napi::ObjectWrap<UserConfigWrapper>{info} {}
33
38
34
- Napi::Value UserConfigWrapper::getUserInfo (const Napi::CallbackInfo& info) {
39
+
40
+ Napi::Value UserConfigWrapper::getPriority (const Napi::CallbackInfo& info) {
35
41
return wrapResult (info, [&] {
36
42
auto env = info.Env ();
37
- auto user_info_obj = Napi::Object::New (env);
43
+ return config.get_nts_priority ();
44
+ });
45
+ }
38
46
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
+ }
41
53
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
+ }
44
60
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);
53
67
54
- return user_info_obj;
68
+ auto new_priority = toPriority (priority, config.get_nts_priority ());
69
+ config.set_nts_priority (new_priority);
55
70
});
56
71
}
57
72
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 );
62
77
auto name = info[0 ];
63
- auto priority = info[1 ];
64
- auto profile_pic_obj = info[2 ];
78
+ assertIsString (name);
65
79
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
+ }
69
85
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);
72
92
93
+ auto new_name = name.As <Napi::String>().Utf8Value ();
94
+ // this will truncate silently if the name is too long
73
95
config.set_name_truncated (new_name);
96
+ });
97
+ }
74
98
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 ];
77
103
78
104
if (!profile_pic_obj.IsNull () && !profile_pic_obj.IsUndefined ())
79
105
assertIsObject (profile_pic_obj);
80
106
81
107
config.set_profile_pic (profile_pic_from_object (profile_pic_obj));
82
-
83
- return config.get_name ();
84
108
});
85
109
}
86
110
0 commit comments