Skip to content

Commit 3d79bb2

Browse files
authored
Merge pull request #7 from Doy-lee/doyle-split-pro-bitset
Split the bitset into separate profile/message bitsets
2 parents 41cfac4 + 68477ae commit 3d79bb2

19 files changed

+494
-371
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#
2626
cmake -G Ninja -S . -B Build
2727
28+
# Regenerate protobuf files
29+
cmake --build Build --target regen-protobuf --parallel --verbose
30+
2831
# Build
2932
cmake --build Build --parallel --verbose
3033
```

include/session/config/base.hpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,16 @@ class ConfigBase : public ConfigSig {
434434
///
435435
/// Inputs:
436436
/// - `value` -- This will be assigned to the dict if it is missing
437-
void insert_if_missing(config::scalar&& value) {
437+
//
438+
/// Ouputs:
439+
/// - `bool` -- True if the value was inserted, false otherwise
440+
bool insert_if_missing(config::scalar&& value) {
438441
if (!_conf.is_dirty())
439442
if (auto current = get_clean<config::set>(); current && current->count(value))
440-
return;
443+
return false;
441444

442445
get_dirty<config::set>().insert(std::move(value));
446+
return true;
443447
}
444448

445449
/// API: base/ConfigBase::DictFieldProxy::set_erase_impl
@@ -448,28 +452,35 @@ class ConfigBase : public ConfigSig {
448452
///
449453
/// Inputs:
450454
/// - `value` -- This will be deleted from the dict
451-
void set_erase_impl(const config::scalar& value) {
455+
///
456+
/// Outputs:
457+
/// - `bool` -- True if an element was erased, false otherwise
458+
bool set_erase_impl(const config::scalar& value) {
452459
if (!_conf.is_dirty())
453460
if (auto current = get_clean<config::set>(); current && !current->count(value))
454-
return;
461+
return false;
455462

456463
config::dict* data = &_conf.dirty().data();
457464

458465
for (const auto& key : _inter_keys) {
459466
auto it = data->find(key);
460467
data = it != data->end() ? std::get_if<config::dict>(&it->second) : nullptr;
461468
if (!data)
462-
return;
469+
return false;
463470
}
464471

465472
auto it = data->find(_last_key);
466473
if (it == data->end())
467-
return;
474+
return false;
468475
auto& val = it->second;
469-
if (auto* current = std::get_if<config::set>(&val))
476+
bool result = false;
477+
if (auto* current = std::get_if<config::set>(&val)) {
470478
current->erase(value);
471-
else
479+
result = true;
480+
} else {
472481
val.emplace<config::set>();
482+
}
483+
return result;
473484
}
474485

475486
public:
@@ -795,8 +806,8 @@ class ConfigBase : public ConfigSig {
795806
///
796807
/// Inputs:
797808
/// - `value` -- The value to be set
798-
void set_insert(std::string_view value) {
799-
insert_if_missing(config::scalar{std::string{value}});
809+
bool set_insert(std::string_view value) {
810+
return insert_if_missing(config::scalar{std::string{value}});
800811
}
801812

802813
/// API: base/ConfigBase::DictFieldProxy::set_insert(int64_t)
@@ -806,7 +817,7 @@ class ConfigBase : public ConfigSig {
806817
///
807818
/// Inputs:
808819
/// - `value` -- The value to be set
809-
void set_insert(int64_t value) { insert_if_missing(config::scalar{value}); }
820+
bool set_insert(int64_t value) { return insert_if_missing(config::scalar{value}); }
810821

811822
/// API: base/ConfigBase::DictFieldProxy::set_erase(std::string_view)
812823
///
@@ -816,8 +827,11 @@ class ConfigBase : public ConfigSig {
816827
///
817828
/// Inputs:
818829
/// - `value` -- The value to be set
819-
void set_erase(std::string_view value) {
820-
set_erase_impl(config::scalar{std::string{value}});
830+
///
831+
/// Outputs:
832+
/// - `bool` -- True if an element was erased, false otherwise
833+
bool set_erase(std::string_view value) {
834+
return set_erase_impl(config::scalar{std::string{value}});
821835
}
822836

823837
/// API: base/ConfigBase::DictFieldProxy::set_erase(int64_t)
@@ -828,7 +842,10 @@ class ConfigBase : public ConfigSig {
828842
///
829843
/// Inputs:
830844
/// - `value` -- The value to be set
831-
void set_erase(int64_t value) { set_erase_impl(scalar{value}); }
845+
///
846+
/// Outputs:
847+
/// - `bool` -- True if an element was erased, false otherwise
848+
bool set_erase(int64_t value) { return set_erase_impl(scalar{value}); }
832849

833850
/// API: base/ConfigBase::DictFieldProxy::emplace
834851
///

include/session/config/contacts.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct contacts_contact {
3636

3737
int64_t created; // unix timestamp (seconds)
3838

39-
SESSION_PROTOCOL_PRO_FEATURES pro_features;
39+
session_protocol_pro_profile_bitset profile_bitset = {};
4040

4141
} contacts_contact;
4242

@@ -55,7 +55,7 @@ typedef struct contacts_blinded_contact {
5555
bool legacy_blinding;
5656
int64_t created; // unix timestamp (seconds)
5757

58-
SESSION_PROTOCOL_PRO_FEATURES pro_features;
58+
session_protocol_pro_profile_bitset profile_bitset = {};
5959

6060
} contacts_blinded_contact;
6161

include/session/config/contacts.hpp

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace session::config {
4848
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
4949
/// equivalent "j"oined field). Omitted if 0.
5050
/// t - The `profile_updated` unix timestamp (seconds) for this contacts profile information.
51-
/// f - session pro features bitset for this contact
51+
/// f - session pro profile features bitset for this contact
5252
///
5353
/// b - dict of blinded contacts. This is a nested dict where the outer keys are the BASE_URL of
5454
/// the community the blinded contact originated from and the outer value is a dict containing:
@@ -70,7 +70,7 @@ namespace session::config {
7070
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
7171
/// equivalent "j"oined field). Omitted if 0.
7272
/// y - flag indicating whether the blinded message request is using legac"y" blinding.
73-
/// f - session pro features bitset for this blinded contact
73+
/// f - session pro profile features bitset for this blinded contact
7474

7575
struct contact_info {
7676
static constexpr size_t MAX_NAME_LENGTH = 100;
@@ -96,7 +96,7 @@ struct contact_info {
9696
std::chrono::seconds exp_timer{0}; // The expiration timer (in seconds)
9797
int64_t created = 0; // Unix timestamp (seconds) when this contact was added
9898

99-
SESSION_PROTOCOL_PRO_FEATURES pro_features = SESSION_PROTOCOL_PRO_FEATURES_NIL;
99+
ProProfileBitset profile_bitset = {};
100100

101101
explicit contact_info(std::string sid);
102102

@@ -122,25 +122,6 @@ struct contact_info {
122122
void set_nickname(std::string nickname);
123123
void set_nickname_truncated(std::string nickname);
124124

125-
/// API: contacts/contact_info::get_pro_features
126-
///
127-
/// Retrieves the bitset indicating which pro features the user currently has enabled.
128-
///
129-
/// Inputs: None
130-
///
131-
/// Outputs:
132-
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
133-
SESSION_PROTOCOL_PRO_FEATURES get_pro_features() const;
134-
135-
/// API: contacts/contact_info::set_pro_features
136-
///
137-
/// Updates the pro features bitset for this contact. Note: If the bitset provided contains the
138-
/// '10K_CHARACTER_LIMIT' feature then it will be removed.
139-
///
140-
/// Inputs:
141-
/// - `features` -- The updated pro features bitset to use.
142-
void set_pro_features(SESSION_PROTOCOL_PRO_FEATURES features);
143-
144125
private:
145126
friend class Contacts;
146127
void load(const dict& info_dict);
@@ -160,7 +141,7 @@ struct blinded_contact_info {
160141
bool legacy_blinding;
161142
std::chrono::sys_seconds created{}; // Unix timestamp (seconds) when this contact was added
162143

163-
SESSION_PROTOCOL_PRO_FEATURES pro_features = SESSION_PROTOCOL_PRO_FEATURES_NIL;
144+
ProProfileBitset profile_bitset = {};
164145

165146
blinded_contact_info() = default;
166147
explicit blinded_contact_info(
@@ -219,25 +200,6 @@ struct blinded_contact_info {
219200
/// - `std::string` -- Returns the pubkey
220201
std::string community_pubkey_hex() const { return comm.pubkey_hex(); }
221202

222-
/// API: contacts/blinded_contact_info::get_pro_features
223-
///
224-
/// Retrieves the bitset indicating which pro features the user currently has enabled.
225-
///
226-
/// Inputs: None
227-
///
228-
/// Outputs:
229-
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
230-
SESSION_PROTOCOL_PRO_FEATURES get_pro_features() const;
231-
232-
/// API: contacts/blinded_contact_info::set_pro_features
233-
///
234-
/// Updates the pro features bitset for this contact. Note: If the bitset provided contains the
235-
/// '10K_CHARACTER_LIMIT' feature then it will be removed.
236-
///
237-
/// Inputs:
238-
/// - `features` -- The updated pro features bitset to use.
239-
void set_pro_features(SESSION_PROTOCOL_PRO_FEATURES features);
240-
241203
private:
242204
friend class Contacts;
243205
friend struct session::config::comm_iterator_helper;
@@ -480,9 +442,8 @@ class Contacts : public ConfigBase {
480442
///
481443
/// Inputs:
482444
/// - `session_id` -- hex string of the session id
483-
/// - `features` -- The updated pro features bitset to use. Note: If the bitset provided
484-
/// contains the '10K_CHARACTER_LIMIT' feature then it will be removed.
485-
void set_pro_features(std::string_view session_id, SESSION_PROTOCOL_PRO_FEATURES features);
445+
/// - `features` -- The updated profile features to use
446+
void set_pro_features(std::string_view session_id, ProProfileBitset features);
486447

487448
/// API: contacts/contacts::erase
488449
///

include/session/config/user_profile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ LIBSESSION_EXPORT bool user_profile_remove_pro_config(config_object* conf);
348348
/// - `conf` -- [in] Pointer to the config object
349349
///
350350
/// Outputs:
351-
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
352-
LIBSESSION_EXPORT SESSION_PROTOCOL_PRO_FEATURES
351+
/// - `session_protocol_pro_profile_bitset` - bitset indicating which profile features are enabled.
352+
LIBSESSION_EXPORT session_protocol_pro_profile_bitset
353353
user_profile_get_pro_features(const config_object* conf);
354354

355355
/// API: user_profile/user_profile_set_pro_badge

include/session/config/user_profile.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ class UserProfile : public ConfigBase {
285285
/// Inputs: None
286286
///
287287
/// Outputs:
288-
/// - `SESSION_PROTOCOL_PRO_FEATURES` - bitset indicating which pro features are enabled.
289-
SESSION_PROTOCOL_PRO_FEATURES get_pro_features() const;
288+
/// - Bitset with individual bits set on it corresponding to
289+
/// SESSION_PROTOCOL_PRO_PROFILE_FEATURES_BITSET. It is possible to receive bits set that don't
290+
/// have a corresponding enum value if you are receiving a bitset from a newer client with newer
291+
/// features enabled. These flags should be ignored by clients that do not recognise them.
292+
ProProfileBitset get_profile_bitset() const;
290293

291294
/// API: user_profile/UserProfile::set_pro_badge
292295
///

0 commit comments

Comments
 (0)