Skip to content

Commit e2c64d3

Browse files
committed
chore: rename to_seconds to to_epoch_seconds
1 parent 6b0cbbc commit e2c64d3

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

include/session/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ inline std::string utf8_truncate(std::string val, size_t n) {
203203

204204
// Helper function to transform a timestamp provided in seconds, milliseconds or microseconds to
205205
// seconds
206-
inline int64_t to_seconds(int64_t timestamp) {
206+
inline int64_t to_epoch_seconds(int64_t timestamp) {
207207
return timestamp > 9'000'000'000'000 ? timestamp / 1'000'000
208208
: timestamp > 9'000'000'000 ? timestamp / 1'000
209209
: timestamp;

src/config/contacts.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void contact_info::load(const dict& info_dict) {
9797
} else {
9898
notifications = notify_mode::defaulted;
9999
}
100-
mute_until = to_seconds(maybe_int(info_dict, "!").value_or(0));
100+
mute_until = to_epoch_seconds(maybe_int(info_dict, "!").value_or(0));
101101

102102
int exp_mode_ = maybe_int(info_dict, "e").value_or(0);
103103
if (exp_mode_ >= static_cast<int>(expiration_mode::none) &&
@@ -118,7 +118,7 @@ void contact_info::load(const dict& info_dict) {
118118
}
119119
}
120120

121-
created = to_seconds(maybe_int(info_dict, "j").value_or(0));
121+
created = to_epoch_seconds(maybe_int(info_dict, "j").value_or(0));
122122
}
123123

124124
void contact_info::into(contacts_contact& c) const {
@@ -136,12 +136,12 @@ void contact_info::into(contacts_contact& c) const {
136136
c.blocked = blocked;
137137
c.priority = priority;
138138
c.notifications = static_cast<CONVO_NOTIFY_MODE>(notifications);
139-
c.mute_until = to_seconds(mute_until);
139+
c.mute_until = to_epoch_seconds(mute_until);
140140
c.exp_mode = static_cast<CONVO_EXPIRATION_MODE>(exp_mode);
141141
c.exp_seconds = exp_timer.count();
142142
if (c.exp_seconds <= 0 && c.exp_mode != CONVO_EXPIRATION_NONE)
143143
c.exp_mode = CONVO_EXPIRATION_NONE;
144-
c.created = to_seconds(created);
144+
c.created = to_epoch_seconds(created);
145145
}
146146

147147
contact_info::contact_info(const contacts_contact& c) : session_id{c.session_id, 66} {
@@ -159,12 +159,12 @@ contact_info::contact_info(const contacts_contact& c) : session_id{c.session_id,
159159
blocked = c.blocked;
160160
priority = c.priority;
161161
notifications = static_cast<notify_mode>(c.notifications);
162-
mute_until = to_seconds(c.mute_until);
162+
mute_until = to_epoch_seconds(c.mute_until);
163163
exp_mode = static_cast<expiration_mode>(c.exp_mode);
164164
exp_timer = exp_mode == expiration_mode::none ? 0s : std::chrono::seconds{c.exp_seconds};
165165
if (exp_timer <= 0s && exp_mode != expiration_mode::none)
166166
exp_mode = expiration_mode::none;
167-
created = to_seconds(c.created);
167+
created = to_epoch_seconds(c.created);
168168
}
169169

170170
std::optional<contact_info> Contacts::get(std::string_view pubkey_hex) const {
@@ -240,7 +240,7 @@ void Contacts::set(const contact_info& contact) {
240240
if (notify == notify_mode::mentions_only)
241241
notify = notify_mode::all;
242242
set_positive_int(info["@"], static_cast<int>(notify));
243-
set_positive_int(info["!"], to_seconds(contact.mute_until));
243+
set_positive_int(info["!"], to_epoch_seconds(contact.mute_until));
244244

245245
set_pair_if(
246246
contact.exp_mode != expiration_mode::none && contact.exp_timer > 0s,
@@ -249,7 +249,7 @@ void Contacts::set(const contact_info& contact) {
249249
info["E"],
250250
contact.exp_timer.count());
251251

252-
set_positive_int(info["j"], to_seconds(contact.created));
252+
set_positive_int(info["j"], to_epoch_seconds(contact.created));
253253
}
254254

255255
LIBSESSION_C_API void contacts_set(config_object* conf, const contacts_contact* contact) {
@@ -314,7 +314,7 @@ void Contacts::set_expiry(
314314

315315
void Contacts::set_created(std::string_view session_id, int64_t timestamp) {
316316
auto c = get_or_construct(session_id);
317-
c.created = to_seconds(timestamp);
317+
c.created = to_epoch_seconds(timestamp);
318318
set(c);
319319
}
320320

src/config/groups/info.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,32 +83,32 @@ void Info::set_expiry_timer(std::chrono::seconds expiration_timer) {
8383
}
8484

8585
void Info::set_created(int64_t timestamp) {
86-
set_positive_int(data["c"], to_seconds(timestamp));
86+
set_positive_int(data["c"], to_epoch_seconds(timestamp));
8787
}
8888

8989
std::optional<int64_t> Info::get_created() const {
9090
if (auto* ts = data["c"].integer())
91-
return to_seconds(*ts);
91+
return to_epoch_seconds(*ts);
9292
return std::nullopt;
9393
}
9494

9595
void Info::set_delete_before(int64_t timestamp) {
96-
set_positive_int(data["d"], to_seconds(timestamp));
96+
set_positive_int(data["d"], to_epoch_seconds(timestamp));
9797
}
9898

9999
std::optional<int64_t> Info::get_delete_before() const {
100100
if (auto* ts = data["d"].integer())
101-
return to_seconds(*ts);
101+
return to_epoch_seconds(*ts);
102102
return std::nullopt;
103103
}
104104

105105
void Info::set_delete_attach_before(int64_t timestamp) {
106-
set_positive_int(data["D"], to_seconds(timestamp));
106+
set_positive_int(data["D"], to_epoch_seconds(timestamp));
107107
}
108108

109109
std::optional<int64_t> Info::get_delete_attach_before() const {
110110
if (auto* ts = data["D"].integer())
111-
return to_seconds(*ts);
111+
return to_epoch_seconds(*ts);
112112
return std::nullopt;
113113
}
114114

src/config/user_groups.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ namespace session::config {
3636
template <typename T>
3737
static void base_into(const base_group_info& self, T& c) {
3838
c.priority = self.priority;
39-
c.joined_at = to_seconds(self.joined_at);
39+
c.joined_at = to_epoch_seconds(self.joined_at);
4040
c.notifications = static_cast<CONVO_NOTIFY_MODE>(self.notifications);
41-
c.mute_until = to_seconds(self.mute_until);
41+
c.mute_until = to_epoch_seconds(self.mute_until);
4242
c.invited = self.invited;
4343
}
4444

4545
template <typename T>
4646
static void base_from(base_group_info& self, const T& c) {
4747
self.priority = c.priority;
48-
self.joined_at = to_seconds(c.joined_at);
48+
self.joined_at = to_epoch_seconds(c.joined_at);
4949
self.notifications = static_cast<notify_mode>(c.notifications);
50-
self.mute_until = to_seconds(c.mute_until);
50+
self.mute_until = to_epoch_seconds(c.mute_until);
5151
self.invited = c.invited;
5252
}
5353

@@ -129,15 +129,15 @@ void legacy_group_info::into(ugroups_legacy_group_info& c) && {
129129

130130
void base_group_info::load(const dict& info_dict) {
131131
priority = maybe_int(info_dict, "+").value_or(0);
132-
joined_at = to_seconds(std::max<int64_t>(0, maybe_int(info_dict, "j").value_or(0)));
132+
joined_at = to_epoch_seconds(std::max<int64_t>(0, maybe_int(info_dict, "j").value_or(0)));
133133

134134
int notify = maybe_int(info_dict, "@").value_or(0);
135135
if (notify >= 0 && notify <= 3)
136136
notifications = static_cast<notify_mode>(notify);
137137
else
138138
notifications = notify_mode::defaulted;
139139

140-
mute_until = to_seconds(maybe_int(info_dict, "!").value_or(0));
140+
mute_until = to_epoch_seconds(maybe_int(info_dict, "!").value_or(0));
141141

142142
invited = maybe_int(info_dict, "i").value_or(0);
143143
}
@@ -407,9 +407,9 @@ void UserGroups::set(const community_info& c) {
407407

408408
void UserGroups::set_base(const base_group_info& bg, DictFieldProxy& info) const {
409409
set_nonzero_int(info["+"], bg.priority);
410-
set_positive_int(info["j"], to_seconds(bg.joined_at));
410+
set_positive_int(info["j"], to_epoch_seconds(bg.joined_at));
411411
set_positive_int(info["@"], static_cast<int>(bg.notifications));
412-
set_positive_int(info["!"], to_seconds(bg.mute_until));
412+
set_positive_int(info["!"], to_epoch_seconds(bg.mute_until));
413413
set_flag(info["i"], bg.invited);
414414
// We don't set n here because it's subtly different in the three group types
415415
}

0 commit comments

Comments
 (0)