Skip to content

Commit 5c30417

Browse files
committed
Re-enabled the profile_updated timestamp updating
1 parent b68ae75 commit 5c30417

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/config/user_profile.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ void UserProfile::set_name(std::string_view new_name) {
2929
throw std::invalid_argument{"Invalid profile name: exceeds maximum length"};
3030
set_nonempty_str(data["n"], new_name);
3131

32-
// const auto target_timestamp = (data["t"].integer_or(0) >= data["T"].integer_or(0) ? "t" :
33-
// "T"); data[target_timestamp] = ts_now();
32+
const auto target_timestamp = (data["t"].integer_or(0) >= data["T"].integer_or(0) ? "t" : "T");
33+
data[target_timestamp] = ts_now();
3434
}
3535
void UserProfile::set_name_truncated(std::string new_name) {
3636
set_name(utf8_truncate(std::move(new_name), contact_info::MAX_NAME_LENGTH));
@@ -59,7 +59,7 @@ void UserProfile::set_profile_pic(std::string_view url, std::span<const unsigned
5959
if (url.empty() || key.size() != 32)
6060
set_reupload_profile_pic({});
6161

62-
// data["t"] = ts_now();
62+
data["t"] = ts_now();
6363
}
6464

6565
void UserProfile::set_profile_pic(profile_pic pic) {
@@ -69,7 +69,7 @@ void UserProfile::set_profile_pic(profile_pic pic) {
6969
void UserProfile::set_reupload_profile_pic(
7070
std::string_view url, std::span<const unsigned char> key) {
7171
set_pair_if(!url.empty() && key.size() == 32, data["P"], url, data["Q"], key);
72-
// data["T"] = ts_now();
72+
data["T"] = ts_now();
7373
}
7474

7575
void UserProfile::set_reupload_profile_pic(profile_pic pic) {
@@ -100,8 +100,8 @@ void UserProfile::set_blinded_msgreqs(std::optional<bool> value) {
100100
else
101101
data["M"] = static_cast<int>(*value);
102102

103-
// const auto target_timestamp = (data["t"].integer_or(0) >= data["T"].integer_or(0) ? "t" :
104-
// "T"); data[target_timestamp] = ts_now();
103+
const auto target_timestamp = (data["t"].integer_or(0) >= data["T"].integer_or(0) ? "t" : "T");
104+
data[target_timestamp] = ts_now();
105105
}
106106

107107
std::optional<bool> UserProfile::get_blinded_msgreqs() const {
@@ -111,11 +111,11 @@ std::optional<bool> UserProfile::get_blinded_msgreqs() const {
111111
}
112112

113113
std::chrono::sys_seconds UserProfile::get_profile_updated() const {
114-
// if (auto t = data["t"].sys_seconds()) {
115-
// if (auto T = data["T"].sys_seconds(); T && *T > *t)
116-
// return *T;
117-
// return *t;
118-
// }
114+
if (auto t = data["t"].sys_seconds()) {
115+
if (auto T = data["T"].sys_seconds(); T && *T > *t)
116+
return *T;
117+
return *t;
118+
}
119119
return std::chrono::sys_seconds{};
120120
}
121121

tests/test_config_userprofile.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") {
460460
CHECK(session::to_vector(std::span<const unsigned char>{pic.key, 32}) ==
461461
"qwert\0yuio1234567890123456789012"_bytes);
462462

463-
#if 0
464463
// Reupload the "current" pic and confirm it gets returned
465464
strcpy(p.url, "testUrl");
466465
memcpy(p.key, "secret78901234567890123456789000", 32);
@@ -532,14 +531,4 @@ TEST_CASE("user profile C API", "[config][user_profile][c]") {
532531
INFO("Checking if raw_value " << raw_value << " is within the range [" << before_seconds << ", "
533532
<< after_seconds << "]");
534533
CHECK((raw_value >= before_seconds && raw_value <= after_seconds));
535-
#else
536-
// Ensure the timestamp doesn't get updated
537-
strcpy(p.url, "testUrl");
538-
memcpy(p.key, "secret78901234567890123456789000", 32);
539-
CHECK(0 == user_profile_set_reupload_pic(conf, p));
540-
CHECK(0 == user_profile_set_pic(conf, p));
541-
CHECK(0 == user_profile_set_name(conf, "Test"));
542-
user_profile_set_blinded_msgreqs(conf, 1);
543-
CHECK(user_profile_get_profile_updated(conf) == 0);
544-
#endif
545534
}

0 commit comments

Comments
 (0)