Skip to content

Commit d46e344

Browse files
committed
feat: expose function to get profileUrl+key in hex as a url fragment
1 parent 86dc87e commit d46e344

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

include/user_config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class UserConfigWrapper : public ConfigBaseImpl, public Napi::ObjectWrap<UserCon
2020
Napi::Value getPriority(const Napi::CallbackInfo& info);
2121
Napi::Value getName(const Napi::CallbackInfo& info);
2222
Napi::Value getProfilePic(const Napi::CallbackInfo& info);
23+
Napi::Value getProfilePicWithKeyHex(const Napi::CallbackInfo& info);
24+
2325
void setPriority(const Napi::CallbackInfo& info);
2426
void setName(const Napi::CallbackInfo& info);
2527
void setNameTruncated(const Napi::CallbackInfo& info);

src/user_config.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void UserConfigWrapper::Init(Napi::Env env, Napi::Object exports) {
2020
InstanceMethod("getPriority", &UserConfigWrapper::getPriority),
2121
InstanceMethod("getName", &UserConfigWrapper::getName),
2222
InstanceMethod("getProfilePic", &UserConfigWrapper::getProfilePic),
23+
InstanceMethod(
24+
"getProfilePicWithKeyHex", &UserConfigWrapper::getProfilePicWithKeyHex),
2325
InstanceMethod(
2426
"getProfileUpdatedSeconds",
2527
&UserConfigWrapper::getProfileUpdatedSeconds),
@@ -197,6 +199,19 @@ Napi::Value UserConfigWrapper::getProfileUpdatedSeconds(const Napi::CallbackInfo
197199
});
198200
}
199201

202+
Napi::Value UserConfigWrapper::getProfilePicWithKeyHex(const Napi::CallbackInfo& info) {
203+
return wrapResult(info, [&]() -> std::optional<std::string> {
204+
auto env = info.Env();
205+
auto pic = config.get_profile_pic();
206+
// if pic.key and url are set, return a combined string with both merged by a hash, and the
207+
// key in hex
208+
if (!pic.url.empty() && !pic.key.empty()) {
209+
return std::string(pic.url + "#" + to_hex(pic.key));
210+
}
211+
return std::nullopt;
212+
});
213+
}
214+
200215
Napi::Value UserConfigWrapper::getEnableBlindedMsgRequest(const Napi::CallbackInfo& info) {
201216
return wrapResult(info, [&] {
202217
auto env = info.Env();

types/user/userconfig.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ declare module 'libsession_util_nodejs' {
4545
setReuploadProfilePic: (pic: ProfilePicture) => void;
4646

4747
getProfileUpdatedSeconds: () => number;
48+
/**
49+
* Returns the profile picture url and key merged as a url fragment, or null if not set.
50+
* So this could return something like
51+
* `http://filev2.getsession.org/file/1234#ba7e23ef3d4dc54b706d79c149ec571a4d64043e13771236afc030f6c8118575`
52+
*
53+
*/
54+
getProfilePicWithKeyHex: () => string | undefined;
4855

4956
setEnableBlindedMsgRequest: (msgRequest: boolean) => void;
5057
getEnableBlindedMsgRequest: () => boolean | undefined;
@@ -72,6 +79,7 @@ declare module 'libsession_util_nodejs' {
7279
public setReuploadProfilePic: UserConfigWrapper['setReuploadProfilePic'];
7380
public setUserConfig: UserConfigWrapper['setUserConfig'];
7481
public getProfileUpdatedSeconds: UserConfigWrapper['getProfileUpdatedSeconds'];
82+
public getProfilePicWithKeyHex: UserConfigWrapper['getProfilePicWithKeyHex'];
7583
public getEnableBlindedMsgRequest: UserConfigWrapper['getEnableBlindedMsgRequest'];
7684
public setEnableBlindedMsgRequest: UserConfigWrapper['setEnableBlindedMsgRequest'];
7785
public getNoteToSelfExpiry: UserConfigWrapper['getNoteToSelfExpiry'];
@@ -96,6 +104,7 @@ declare module 'libsession_util_nodejs' {
96104
| MakeActionCall<UserConfigWrapper, 'setReuploadProfilePic'>
97105
| MakeActionCall<UserConfigWrapper, 'setUserConfig'>
98106
| MakeActionCall<UserConfigWrapper, 'getProfileUpdatedSeconds'>
107+
| MakeActionCall<UserConfigWrapper, 'getProfilePicWithKeyHex'>
99108
| MakeActionCall<UserConfigWrapper, 'getEnableBlindedMsgRequest'>
100109
| MakeActionCall<UserConfigWrapper, 'setEnableBlindedMsgRequest'>
101110
| MakeActionCall<UserConfigWrapper, 'getNoteToSelfExpiry'>

0 commit comments

Comments
 (0)