Skip to content

Commit 77c4103

Browse files
committed
Added missing profile_updated and priority values
1 parent 0cda077 commit 77c4103

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

include/session/config/contacts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ typedef struct contacts_blinded_contact {
4545

4646
char name[101]; // This will be a 0-length string when unset
4747
user_profile_pic profile_pic;
48+
int64_t profile_updated; // unix timestamp (seconds)
49+
50+
int priority;
4851

4952
bool legacy_blinding;
5053
int64_t created; // unix timestamp (seconds)

include/session/config/contacts.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ namespace session::config {
6161
/// alive as empty dicts get pruned).
6262
/// p - profile url (string)
6363
/// q - profile decryption key (binary)
64+
/// t - The `profile_updated` unix timestamp (seconds) for this contacts profile information.
65+
/// + - the conversation priority; -1 means hidden; omitted means not pinned; otherwise an
66+
/// integer value >0, where a higher priority means the conversation is meant to appear
67+
/// earlier in the pinned conversation list.
6468
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
6569
/// equivalent "j"oined field). Omitted if 0.
6670
/// y - flag indicating whether the blinded message request is using legac"y" blinding.
@@ -122,6 +126,13 @@ struct blinded_contact_info {
122126
const std::string session_id() const; // in hex
123127
std::string name;
124128
profile_pic profile_picture;
129+
std::chrono::sys_seconds profile_updated{}; /// The unix timestamp (seconds) that this
130+
/// profile information was last updated.
131+
int priority = 0; // If >0 then this message is pinned; higher values mean higher priority
132+
// (i.e. pinned earlier in the pinned list). If negative then this
133+
// conversation is hidden. Otherwise (0) this is a regular, unpinned
134+
// conversation.
135+
125136
bool legacy_blinding;
126137
std::chrono::sys_seconds created{}; // Unix timestamp (seconds) when this contact was added
127138

@@ -142,7 +153,7 @@ struct blinded_contact_info {
142153
/// - `c` -- Return Parameter that will be filled with data in blinded_contact_info
143154
void into(contacts_blinded_contact& c) const;
144155

145-
/// API: contacts/contact_info::set_name
156+
/// API: contacts/blinded_contact_info::set_name
146157
///
147158
/// Sets a name; this is exactly the same as assigning to .name directly,
148159
/// except that we throw an exception if the given name is longer than MAX_NAME_LENGTH.

src/config/contacts.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ void blinded_contact_info::load(const dict& info_dict) {
332332
} else {
333333
profile_picture.clear();
334334
}
335+
profile_updated = ts_or_epoch(info_dict, "t");
336+
priority = int_or_0(info_dict, "+");
335337
legacy_blinding = int_or_0(info_dict, "y");
336338
created = ts_or_epoch(info_dict, "j");
337339
}
@@ -350,6 +352,8 @@ void blinded_contact_info::into(contacts_blinded_contact& c) const {
350352
} else {
351353
copy_c_str(c.profile_pic.url, "");
352354
}
355+
c.profile_updated = profile_updated.time_since_epoch().count();
356+
c.priority = priority;
353357
c.legacy_blinding = legacy_blinding;
354358
c.created = created.time_since_epoch().count();
355359
}
@@ -363,6 +367,8 @@ blinded_contact_info::blinded_contact_info(const contacts_blinded_contact& c) {
363367
profile_picture.url = c.profile_pic.url;
364368
profile_picture.key.assign(c.profile_pic.key, c.profile_pic.key + 32);
365369
}
370+
profile_updated = to_sys_seconds(c.profile_updated);
371+
priority = c.priority;
366372
legacy_blinding = c.legacy_blinding;
367373
created = to_sys_seconds(c.created);
368374
}
@@ -474,7 +480,8 @@ void Contacts::set_blinded(const blinded_contact_info& bc) {
474480
bc.profile_picture.url,
475481
info["q"],
476482
bc.profile_picture.key);
477-
483+
set_ts(info["t"], bc.profile_updated);
484+
set_nonzero_int(info["+"], bc.priority);
478485
set_positive_int(info["y"], bc.legacy_blinding);
479486
set_ts(info["j"], bc.created);
480487
}

tests/test_config_contacts.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,8 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
926926
CHECK(c.session_id() == "150000000000000000000000000000000000000000000000000000000000000000");
927927
CHECK(c.name.empty());
928928
CHECK_FALSE(c.profile_picture);
929+
CHECK(c.profile_updated == std::chrono::sys_seconds{});
930+
CHECK(c.priority == 0);
929931
CHECK(c.legacy_blinding);
930932
CHECK(c.created.time_since_epoch() == 0s);
931933

@@ -934,13 +936,17 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
934936
CHECK(std::get<seqno_t>(contacts.push()) == 0);
935937

936938
c.set_name("Joe");
939+
c.profile_updated = std::chrono::sys_seconds{1s};
937940
c.created = session::to_sys_seconds(created_ts * 1'000);
941+
c.priority = 1;
938942
contacts.set_blinded(c);
939943

940944
REQUIRE(contacts.get_blinded(definitely_real_id).has_value());
941945

942946
CHECK(contacts.get_blinded(definitely_real_id)->name == "Joe");
943947
CHECK_FALSE(contacts.get_blinded(definitely_real_id)->profile_picture);
948+
CHECK(contacts.get_blinded(definitely_real_id)->profile_updated.time_since_epoch() == 1s);
949+
CHECK(contacts.get_blinded(definitely_real_id)->priority == 1);
944950
CHECK(contacts.get_blinded(definitely_real_id)->legacy_blinding);
945951
CHECK(contacts.get_blinded(definitely_real_id)->session_id() == definitely_real_id);
946952

@@ -969,6 +975,8 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
969975
REQUIRE(x);
970976
CHECK(x->name == "Joe");
971977
CHECK_FALSE(x->profile_picture);
978+
CHECK(x->profile_updated.time_since_epoch() == 1s);
979+
CHECK(x->priority == 1);
972980
CHECK(x->created.time_since_epoch() == created_ts * 1s);
973981
CHECK(x->legacy_blinding == true);
974982

@@ -996,11 +1004,13 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
9961004
auto blinded = contacts.blinded();
9971005
std::vector<std::string> session_ids;
9981006
std::vector<std::string> names;
1007+
std::vector<std::chrono::sys_seconds> profile_updateds;
9991008
std::vector<bool> legacy_blindings;
10001009
CHECK(blinded.size() == 2);
10011010
for (const auto& cc : blinded) {
10021011
session_ids.push_back(cc.session_id());
10031012
names.emplace_back(cc.name.empty() ? "(N/A)" : cc.name);
1013+
profile_updateds.emplace_back(cc.profile_updated);
10041014
legacy_blindings.emplace_back(cc.legacy_blinding);
10051015
}
10061016

@@ -1010,6 +1020,8 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
10101020
CHECK(session_ids[1] == another_id);
10111021
CHECK(names[0] == "Joe");
10121022
CHECK(names[1] == "(N/A)");
1023+
CHECK(profile_updateds[0].time_since_epoch() == 1s);
1024+
CHECK(profile_updateds[1].time_since_epoch() == 0s);
10131025
CHECK(legacy_blindings[0]);
10141026
CHECK_FALSE(legacy_blindings[1]);
10151027

@@ -1080,17 +1092,21 @@ TEST_CASE("Contacts", "[config][blinded_contacts]") {
10801092
auto blinded2 = contacts.blinded();
10811093
session_ids.clear();
10821094
names.clear();
1095+
profile_updateds.clear();
10831096
legacy_blindings.clear();
10841097
for (const auto& cc : blinded2) {
10851098
session_ids.push_back(cc.session_id());
10861099
names.emplace_back(cc.name.empty() ? "(N/A)" : cc.name);
1100+
profile_updateds.emplace_back(cc.profile_updated);
10871101
legacy_blindings.emplace_back(cc.legacy_blinding);
10881102
}
10891103
REQUIRE(session_ids.size() == 2);
10901104
CHECK(session_ids[0] == another_id);
10911105
CHECK(session_ids[1] == third_id);
10921106
CHECK(names[0] == "(N/A)");
10931107
CHECK(names[1] == "Name 3");
1108+
CHECK(profile_updateds[0].time_since_epoch() == 0s);
1109+
CHECK(profile_updateds[1].time_since_epoch() == 0s);
10941110
CHECK_FALSE(legacy_blindings[0]);
10951111
CHECK(legacy_blindings[1]);
10961112

0 commit comments

Comments
 (0)