diff --git a/CMakeLists.txt b/CMakeLists.txt index a972e9c8..5dd7edac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ endif() project(libsession-util - VERSION 1.0.90 + VERSION 1.1.0 DESCRIPTION "Session client utility library" LANGUAGES ${LANGS}) diff --git a/external/oxen-encoding b/external/oxen-encoding index d9d2228a..fc85dfd3 160000 --- a/external/oxen-encoding +++ b/external/oxen-encoding @@ -1 +1 @@ -Subproject commit d9d2228a099176b4293e86d62524872d92ae6288 +Subproject commit fc85dfd352e8474bc7195b0ba881838bd72ebea6 diff --git a/include/session/config/user_profile.h b/include/session/config/user_profile.h index 9cd153ff..651f46af 100644 --- a/include/session/config/user_profile.h +++ b/include/session/config/user_profile.h @@ -208,6 +208,47 @@ LIBSESSION_EXPORT int user_profile_get_nts_expiry(const config_object* conf); /// - `expiry` -- [in] Integer of the expiry timer in seconds LIBSESSION_EXPORT void user_profile_set_nts_expiry(config_object* conf, int expiry); +/// API: user_profile/user_profile_get_blinded_msgreqs +/// +/// Returns true if blinded message requests should be retrieved (from SOGS servers), false if they +/// should be ignored. +/// +/// Declaration: +/// ```cpp +/// INT user_profile_get_blinded_msgreqs( +/// [in] const config_object* conf +/// ); +/// ``` +/// +/// Inputs: +/// - `conf` -- [in] Pointer to the config object +/// +/// Outputs: +/// - `int` -- Will be -1 if the config does not have the value explicitly set, 0 if the setting is +/// explicitly disabled, and 1 if the setting is explicitly enabled. +LIBSESSION_EXPORT int user_profile_get_blinded_msgreqs(const config_object* conf); + +/// API: user_profile/user_profile_set_blinded_msgreqs +/// +/// Sets whether blinded message requests should be retrieved from SOGS servers. Set to 1 (or any +/// positive value) to enable; 0 to disable; and -1 to clear the setting. +/// +/// Declaration: +/// ```cpp +/// VOID user_profile_set_blinded_msgreqs( +/// [in] config_object* conf, +/// [in] int enabled +/// ); +/// ``` +/// +/// Inputs: +/// - `conf` -- [in] Pointer to the config object +/// - `enabled` -- [in] true if they should be enabled, false if disabled +/// +/// Outputs: +/// - `void` -- Returns Nothing +LIBSESSION_EXPORT void user_profile_set_blinded_msgreqs(config_object* conf, int enabled); + #ifdef __cplusplus } // extern "C" #endif diff --git a/include/session/config/user_profile.hpp b/include/session/config/user_profile.hpp index 54b4cb3a..e077b40a 100644 --- a/include/session/config/user_profile.hpp +++ b/include/session/config/user_profile.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include "base.hpp" @@ -20,6 +21,9 @@ using namespace std::literals; /// + - the priority value for the "Note to Self" pseudo-conversation (higher = higher in the /// conversation list). Omitted when 0. -1 means hidden. /// e - the expiry timer (in seconds) for the "Note to Self" pseudo-conversation. Omitted when 0. +/// M - set to 1 if blinded message request retrieval is enabled, 0 if retrieval is *disabled*, and +/// omitted if the setting has not been explicitly set (or has been explicitly cleared for some +/// reason). class UserProfile final : public ConfigBase { @@ -154,6 +158,35 @@ class UserProfile final : public ConfigBase { /// Inputs: /// - `timer` -- Default to 0 seconds, will set the expiry timer void set_nts_expiry(std::chrono::seconds timer = 0s); + + /// API: user_profile/UserProfile::get_blinded_msgreqs + /// + /// Accesses whether or not blinded message requests are enabled for the client. Can have three + /// values: + /// + /// - std::nullopt -- the value has not been given an explicit value so the client should use + /// its default. + /// - true -- the value is explicitly enabled (i.e. user wants blinded message requests) + /// - false -- the value is explicitly disabled (i.e. user disabled blinded message requests) + /// + /// Inputs: None + /// + /// Outputs: + /// - `std::optional` - true/false if blinded message requests are enabled or disabled; + /// `std::nullopt` if the option has not been set either way. + std::optional get_blinded_msgreqs() const; + + /// API: user_profile/UserProfile::set_blinded_msgreqs + /// + /// Sets whether blinded message requests (i.e. from SOGS servers you are connected to) should + /// be enabled or not. This is typically invoked with either `true` or `false`, but can also be + /// called with `std::nullopt` to explicitly clear the value. + /// + /// Inputs: + /// - `enabled` -- true if blinded message requests should be retrieved, false if they should + /// not, and `std::nullopt` to drop the setting from the config (and thus use the client's + /// default). + void set_blinded_msgreqs(std::optional enabled); }; } // namespace session::config diff --git a/src/config/user_profile.cpp b/src/config/user_profile.cpp index d8d0bb03..1c5a3df2 100644 --- a/src/config/user_profile.cpp +++ b/src/config/user_profile.cpp @@ -126,3 +126,29 @@ LIBSESSION_C_API int user_profile_get_nts_expiry(const config_object* conf) { LIBSESSION_C_API void user_profile_set_nts_expiry(config_object* conf, int expiry) { unbox(conf)->set_nts_expiry(std::max(0, expiry) * 1s); } + +void UserProfile::set_blinded_msgreqs(std::optional value) { + if (!value) + data["M"].erase(); + else + data["M"] = static_cast(*value); +} + +std::optional UserProfile::get_blinded_msgreqs() const { + if (auto* M = data["M"].integer(); M) + return static_cast(*M); + return std::nullopt; +} + +LIBSESSION_C_API int user_profile_get_blinded_msgreqs(const config_object* conf) { + if (auto opt = unbox(conf)->get_blinded_msgreqs()) + return static_cast(*opt); + return -1; +} + +LIBSESSION_C_API void user_profile_set_blinded_msgreqs(config_object* conf, int enabled) { + std::optional val; + if (enabled >= 0) + val = static_cast(enabled); + unbox(conf)->set_blinded_msgreqs(std::move(val)); +} diff --git a/tests/Catch2 b/tests/Catch2 index 5df88da1..6e79e682 160000 --- a/tests/Catch2 +++ b/tests/Catch2 @@ -1 +1 @@ -Subproject commit 5df88da16e276f853cc0c45f4b570419be77dd43 +Subproject commit 6e79e682b726f524310d55dec8ddac4e9c52fb5f diff --git a/tests/test_config_userprofile.cpp b/tests/test_config_userprofile.cpp index 38a87c06..47c547b2 100644 --- a/tests/test_config_userprofile.cpp +++ b/tests/test_config_userprofile.cpp @@ -245,6 +245,14 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") { user_profile_set_nts_expiry(conf2, 86400); CHECK(user_profile_get_nts_expiry(conf2) == 86400); + CHECK(user_profile_get_blinded_msgreqs(conf2) == -1); + user_profile_set_blinded_msgreqs(conf2, 0); + CHECK(user_profile_get_blinded_msgreqs(conf2) == 0); + user_profile_set_blinded_msgreqs(conf2, -1); + CHECK(user_profile_get_blinded_msgreqs(conf2) == -1); + user_profile_set_blinded_msgreqs(conf2, 1); + CHECK(user_profile_get_blinded_msgreqs(conf2) == 1); + // Both have changes, so push need a push CHECK(config_needs_push(conf)); CHECK(config_needs_push(conf2)); @@ -318,6 +326,8 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") { CHECK(user_profile_get_nts_priority(conf2) == 9); CHECK(user_profile_get_nts_expiry(conf) == 86400); CHECK(user_profile_get_nts_expiry(conf2) == 86400); + CHECK(user_profile_get_blinded_msgreqs(conf) == 1); + CHECK(user_profile_get_blinded_msgreqs(conf2) == 1); config_confirm_pushed(conf, to_push->seqno, "fakehash4"); config_confirm_pushed(conf2, to_push2->seqno, "fakehash4");