1111#include < vector>
1212
1313#include " session/config/namespaces.hpp"
14+ #include " session/config/profile_pic.hpp"
1415#include " session/types.hpp"
1516#include " utilities.hpp"
1617
@@ -59,20 +60,24 @@ std::vector<unsigned char> toCppBuffer(Napi::Value x, const std::string& identif
5960int64_t toCppInteger (Napi::Value x, const std::string& identifier, bool allowUndefined = false );
6061std::optional<int64_t > maybeNonemptyInt (Napi::Value x, const std::string& identifier);
6162std::optional<bool > maybeNonemptyBoolean (Napi::Value x, const std::string& identifier);
63+ std::optional<std::chrono::sys_seconds> maybeNonemptySysSeconds (
64+ Napi::Value x, const std::string& identifier);
65+
66+ std::chrono::sys_seconds toCppSysSeconds (Napi::Value x, const std::string& identifier);
6267
6368bool toCppBoolean (Napi::Value x, const std::string& identifier);
6469
65- // If the object is null/undef/empty returns nullopt, otherwise if a String returns a std::string of
66- // the value. Throws if something else.
70+ // If the object is null/undef/empty returns nullopt, otherwise if a String returns a
71+ // std::string of the value. Throws if something else.
6772std::optional<std::string> maybeNonemptyString (Napi::Value x, const std::string& identifier);
6873
6974// If the object is null/undef/empty returns nullopt, otherwise if a Uint8Array returns a
7075// std::vector<unsigned char> of the value. Throws if something else.
7176std::optional<std::vector<unsigned char >> maybeNonemptyBuffer (
7277 Napi::Value x, const std::string& identifier);
7378
74- // Implementation struct of toJs(); we add specializations of this for any C++ types we want to be
75- // able to convert into JS types.
79+ // Implementation struct of toJs(); we add specializations of this for any C++ types we want to
80+ // be able to convert into JS types.
7681template <typename T, typename SFINAE = void >
7782struct toJs_impl {
7883 // If this gets instantiated it means we're missing a specialization and so fail to compile:
@@ -176,6 +181,30 @@ struct toJs_impl<std::optional<T>> {
176181 }
177182};
178183
184+ template <>
185+ struct toJs_impl <std::chrono::sys_seconds> {
186+ auto operator ()(const Napi::Env& env, std::chrono::sys_seconds t) const {
187+ return Napi::Number::New (env, t.time_since_epoch ().count ());
188+ }
189+ };
190+
191+ // Returns {"url": "...", "key": buffer} object; both values will be Null if the pic is not set.
192+
193+ template <>
194+ struct toJs_impl <config::profile_pic> {
195+ auto operator ()(const Napi::Env& env, const config::profile_pic& pic) const {
196+ auto obj = Napi::Object::New (env);
197+ if (pic) {
198+ obj[" url" ] = toJs (env, pic.url );
199+ obj[" key" ] = toJs (env, pic.key );
200+ } else {
201+ obj[" url" ] = env.Null ();
202+ obj[" key" ] = env.Null ();
203+ }
204+ return obj;
205+ }
206+ };
207+
179208// Helper for various "get_all" functions that copy [it...end) into a Napi::Array via toJs().
180209// Throws a Napi::Error on any exception.
181210template <typename It, typename EndIt>
@@ -192,8 +221,8 @@ static Napi::Array get_all_impl(const Napi::CallbackInfo& info, size_t size, It
192221 });
193222}
194223
195- // Wraps a string in an optional<string_view> which will be nullopt if the input string is empty.
196- // This is particularly useful with `toJs` to convert empty strings into Null.
224+ // Wraps a string in an optional<string_view> which will be nullopt if the input string is
225+ // empty. This is particularly useful with `toJs` to convert empty strings into Null.
197226inline std::optional<std::string_view> maybe_string (std::string_view val) {
198227 if (val.empty ())
199228 return std::nullopt ;
@@ -231,8 +260,8 @@ auto wrapResult(const Napi::Env& env, Call&& call) {
231260 }
232261}
233262
234- // Similar to wrapResult(), but a small shortcut to allow passing `info` instead of `info.Env()` as
235- // the first argument.
263+ // Similar to wrapResult(), but a small shortcut to allow passing `info` instead of `info.Env()`
264+ // as the first argument.
236265template <typename Call>
237266auto wrapResult (const Napi::CallbackInfo& info, Call&& call) {
238267 return wrapResult (info.Env (), std::forward<Call>(call));
@@ -262,6 +291,10 @@ std::string printable(std::span<const unsigned char> x);
262291 * Keep the current priority if a wrapper
263292 */
264293int64_t toPriority (Napi::Value x, int64_t currentPriority);
294+ int64_t toPriority (int64_t newPriority, int64_t currentPriority);
295+
296+ std::optional<session::config::profile_pic> maybeNonemptyProfilePic (
297+ Napi::Value x, const std::string& identifier);
265298
266299int64_t unix_timestamp_now ();
267300
0 commit comments