Skip to content

Commit 77fb662

Browse files
authored
Merge pull request #47 from mpretty-cyro/feature/user-local-setting-storage
Added the ability to locally store arbitrary String -> Bool values and new local enum settings
2 parents b38a0e0 + 3afe525 commit 77fb662

File tree

14 files changed

+859
-68
lines changed

14 files changed

+859
-68
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(CCACHE_PROGRAM)
1717
endif()
1818

1919
project(libsession-util
20-
VERSION 1.4.1
20+
VERSION 1.5.0
2121
DESCRIPTION "Session client utility library"
2222
LANGUAGES ${LANGS})
2323

include/session/config/local.h

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include "base.h"
8+
#include "notify.h"
9+
#include "theme.h"
10+
11+
/// API: local/local_init
12+
///
13+
/// Constructs a local config object and sets a pointer to it in `conf`.
14+
///
15+
/// When done with the object the `config_object` must be destroyed by passing the pointer to
16+
/// config_free() (in `session/config/base.h`).
17+
///
18+
/// Declaration:
19+
/// ```cpp
20+
/// INT local_init(
21+
/// [out] config_object** conf,
22+
/// [in] const unsigned char* ed25519_secretkey,
23+
/// [in] const unsigned char* dump,
24+
/// [in] size_t dumplen,
25+
/// [out] char* error
26+
/// );
27+
/// ```
28+
///
29+
/// Inputs:
30+
/// - `conf` -- [in] Pointer to the config object
31+
/// - `ed25519_secretkey` -- [in] must be the 32-byte secret key seed value. (You can also pass the
32+
/// pointer to the beginning of the 64-byte value libsodium calls the "secret key" as the first 32
33+
/// bytes of that are the seed). This field cannot be null.
34+
/// - `dump` -- [in] if non-NULL this restores the state from the dumped byte string produced by a
35+
/// past instantiation's call to `dump()`. To construct a new, empty profile this should be NULL.
36+
/// - `dumplen` -- [in] the length of `dump` when restoring from a dump, or 0 when `dump` is NULL.
37+
/// - `error` -- [out] the pointer to a buffer in which we will write an error string if an error
38+
/// occurs; error messages are discarded if this is given as NULL. If non-NULL this must be a
39+
/// buffer of at least 256 bytes.
40+
///
41+
/// Outputs:
42+
/// - `int` -- Returns 0 on success; returns a non-zero error code and write the exception message
43+
/// as a C-string into `error` (if not NULL) on failure.
44+
LIBSESSION_EXPORT int local_init(
45+
config_object** conf,
46+
const unsigned char* ed25519_secretkey,
47+
const unsigned char* dump,
48+
size_t dumplen,
49+
char* error) LIBSESSION_WARN_UNUSED;
50+
51+
/// API: local/local_get_notification_content
52+
///
53+
/// Returns the locally stored setting indicating what notification content should be displayed.
54+
///
55+
/// Declaration:
56+
/// ```cpp
57+
/// CLIENT_NOTIFY_CONTENT local_get_notification_content(
58+
/// [in] const config_object* conf
59+
/// );
60+
/// ```
61+
///
62+
/// Inputs:
63+
/// - `conf` -- [in] Pointer to the config object
64+
///
65+
/// Outputs:
66+
/// - `CLIENT_NOTIFY_CONTENT` -- enum indicating the content that should be shown within a
67+
/// notification.
68+
LIBSESSION_EXPORT CLIENT_NOTIFY_CONTENT local_get_notification_content(const config_object* conf);
69+
70+
/// API: local/local_set_notification_content
71+
///
72+
/// Sets the setting indicating what notification content should be displayed.
73+
///
74+
/// Declaration:
75+
/// ```cpp
76+
/// void local_set_notification_content(
77+
/// [in] const config_object* conf
78+
/// [in[ CLIENT_NOTIFY_CONTENT value
79+
/// );
80+
/// ```
81+
///
82+
/// Inputs:
83+
/// - `conf` -- [in] Pointer to the config object
84+
/// - `value` -- [in] Updated notification content setting
85+
///
86+
/// Outputs:
87+
/// - `void` -- Returns Nothing
88+
LIBSESSION_EXPORT void local_set_notification_content(
89+
config_object* conf, CLIENT_NOTIFY_CONTENT value);
90+
91+
/// API: local/local_get_ios_notification_sound
92+
///
93+
/// Returns the setting indicating which sound should play when receiving a notification on iOS.
94+
///
95+
/// Declaration:
96+
/// ```cpp
97+
/// CLIENT_NOTIFY_SOUND local_get_ios_notification_sound(
98+
/// [in] const config_object* conf
99+
/// );
100+
/// ```
101+
///
102+
/// Inputs:
103+
/// - `conf` -- [in] Pointer to the config object
104+
///
105+
/// Outputs:
106+
/// - `int64_t` -- enum indicating the sound that should be played when receiving a
107+
/// notification on iOS.
108+
LIBSESSION_EXPORT int64_t local_get_ios_notification_sound(const config_object* conf);
109+
110+
/// API: local/local_set_ios_notification_sound
111+
///
112+
/// Sets the setting indicating which sound should be played when receiving receiving a
113+
/// notification on iOS.
114+
///
115+
/// Declaration:
116+
/// ```cpp
117+
/// void local_set_ios_notification_sound(
118+
/// [in] const config_object* conf
119+
/// [in[ int64_t value
120+
/// );
121+
/// ```
122+
///
123+
/// Inputs:
124+
/// - `conf` -- [in] Pointer to the config object
125+
/// - `value` -- [in] Updated notification sound setting
126+
///
127+
/// Outputs:
128+
/// - `void` -- Returns Nothing
129+
LIBSESSION_EXPORT void local_set_ios_notification_sound(config_object* conf, int64_t value);
130+
131+
/// API: local/local_get_theme
132+
///
133+
/// Returns the setting indicating which theme the client should use.
134+
///
135+
/// Declaration:
136+
/// ```cpp
137+
/// CLIENT_THEME local_get_theme(
138+
/// [in] const config_object* conf
139+
/// );
140+
/// ```
141+
///
142+
/// Inputs:
143+
/// - `conf` -- [in] Pointer to the config object
144+
///
145+
/// Outputs:
146+
/// - `CLIENT_THEME` -- enum indicating which theme the client should use.
147+
LIBSESSION_EXPORT CLIENT_THEME local_get_theme(const config_object* conf);
148+
149+
/// API: local/local_set_theme
150+
///
151+
/// Sets the setting indicating which theme the client should use.
152+
///
153+
/// Declaration:
154+
/// ```cpp
155+
/// void local_set_theme(
156+
/// [in] const config_object* conf
157+
/// [in[ CLIENT_THEME value
158+
/// );
159+
/// ```
160+
///
161+
/// Inputs:
162+
/// - `conf` -- [in] Pointer to the config object
163+
/// - `value` -- [in] Updated theme setting
164+
///
165+
/// Outputs:
166+
/// - `void` -- Returns Nothing
167+
LIBSESSION_EXPORT void local_set_theme(config_object* conf, CLIENT_THEME value);
168+
169+
/// API: local/local_get_theme_primary_color
170+
///
171+
/// Returns the setting indicating which primary color the client should use.
172+
///
173+
/// Declaration:
174+
/// ```cpp
175+
/// CLIENT_THEME_PRIMARY_COLOR local_get_theme_primary_color(
176+
/// [in] const config_object* conf
177+
/// );
178+
/// ```
179+
///
180+
/// Inputs:
181+
/// - `conf` -- [in] Pointer to the config object
182+
///
183+
/// Outputs:
184+
/// - `CLIENT_THEME` -- enum indicating which primary color the client should use.
185+
LIBSESSION_EXPORT CLIENT_THEME_PRIMARY_COLOR
186+
local_get_theme_primary_color(const config_object* conf);
187+
188+
/// API: local/local_set_theme_primary_color
189+
///
190+
/// Sets the setting indicating which primary color the client should use.
191+
///
192+
/// Declaration:
193+
/// ```cpp
194+
/// void local_set_theme_primary_color(
195+
/// [in] const config_object* conf
196+
/// [in[ CLIENT_THEME_PRIMARY_COLOR value
197+
/// );
198+
/// ```
199+
///
200+
/// Inputs:
201+
/// - `conf` -- [in] Pointer to the config object
202+
/// - `value` -- [in] Updated primary color setting
203+
///
204+
/// Outputs:
205+
/// - `void` -- Returns Nothing
206+
LIBSESSION_EXPORT void local_set_theme_primary_color(
207+
config_object* conf, CLIENT_THEME_PRIMARY_COLOR value);
208+
209+
/// API: local/local_get_setting
210+
///
211+
/// Returns the setting for the provided key.
212+
///
213+
/// Declaration:
214+
/// ```cpp
215+
/// INT local_get_setting(
216+
/// [in] const config_object* conf,
217+
/// [in] const char* key
218+
/// );
219+
/// ```
220+
///
221+
/// Inputs:
222+
/// - `conf` -- [in] Pointer to the config object
223+
/// - `key` -- [in] Pointer to the key as a null-terminated C string
224+
///
225+
/// Outputs:
226+
/// - `int` -- Will be -1 if the config does not have the value explicitly set, 0 if the setting is
227+
/// explicitly disabled, and 1 if the setting is explicitly enabled.
228+
LIBSESSION_EXPORT int local_get_setting(const config_object* conf, const char* key);
229+
230+
/// API: local/local_set_setting
231+
///
232+
/// Sets a setting for the provided key.
233+
///
234+
/// Declaration:
235+
/// ```cpp
236+
/// VOID local_set_setting(
237+
/// [in] config_object* conf,
238+
/// [in] const char* key,
239+
/// [in] int enabled
240+
/// );
241+
/// ```
242+
///
243+
/// Inputs:
244+
/// - `conf` -- [in] Pointer to the config object
245+
/// - `key` -- [in] Pointer to the key as a null-terminated C string
246+
/// - `enabled` -- [in] the value which should be stored
247+
///
248+
/// Outputs:
249+
/// - `void` -- Returns Nothing
250+
LIBSESSION_EXPORT void local_set_setting(config_object* conf, const char* key, int enabled);
251+
252+
/// API: local/local_size_settings
253+
///
254+
/// Returns the number of settings.
255+
///
256+
/// Declaration:
257+
/// ```cpp
258+
/// SIZE_T local_size_settings(
259+
/// [in] const config_object* conf
260+
/// );
261+
/// ```
262+
///
263+
/// Inputs:
264+
/// - `conf` -- [in] Pointer to config_object object
265+
///
266+
/// Outputs:
267+
/// - `size_t` -- Returns the number of settings
268+
LIBSESSION_EXPORT size_t local_size_settings(const config_object* conf);
269+
270+
#ifdef __cplusplus
271+
} // extern "C"
272+
#endif

0 commit comments

Comments
 (0)