Skip to content

Commit b94964a

Browse files
committed
easier solution for should_do_gossip with less changes. thanks to
iequidoo for suggesting it
1 parent c6a78fb commit b94964a

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/mimefactory.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,31 +1147,34 @@ impl MimeFactory {
11471147
let cmd = msg.param.get_cmd();
11481148
let is_full_msg =
11491149
self.pre_message_mode == Some(PreMessageMode::FullMessage);
1150-
let should_do_gossip = !is_full_msg
1151-
&& (cmd == SystemMessage::MemberAddedToGroup
1152-
|| cmd == SystemMessage::SecurejoinMessage
1153-
|| multiple_recipients && {
1154-
let gossiped_timestamp: Option<i64> = context
1155-
.sql
1156-
.query_get_value(
1157-
"SELECT timestamp
1150+
1151+
if is_full_msg {
1152+
continue;
1153+
}
1154+
1155+
let should_do_gossip = cmd == SystemMessage::MemberAddedToGroup
1156+
|| cmd == SystemMessage::SecurejoinMessage
1157+
|| multiple_recipients && {
1158+
let gossiped_timestamp: Option<i64> = context
1159+
.sql
1160+
.query_get_value(
1161+
"SELECT timestamp
11581162
FROM gossip_timestamp
11591163
WHERE chat_id=? AND fingerprint=?",
1160-
(chat.id, &fingerprint),
1161-
)
1162-
.await?;
1163-
1164-
// `gossip_period == 0` is a special case for testing,
1165-
// enabling gossip in every message.
1166-
//
1167-
// If current time is in the past compared to
1168-
// `gossiped_timestamp`, we also gossip because
1169-
// either the `gossiped_timestamp` or clock is wrong.
1170-
gossip_period == 0
1171-
|| gossiped_timestamp.is_none_or(|ts| {
1172-
now >= ts + gossip_period || now < ts
1173-
})
1174-
});
1164+
(chat.id, &fingerprint),
1165+
)
1166+
.await?;
1167+
1168+
// `gossip_period == 0` is a special case for testing,
1169+
// enabling gossip in every message.
1170+
//
1171+
// If current time is in the past compared to
1172+
// `gossiped_timestamp`, we also gossip because
1173+
// either the `gossiped_timestamp` or clock is wrong.
1174+
gossip_period == 0
1175+
|| gossiped_timestamp
1176+
.is_none_or(|ts| now >= ts + gossip_period || now < ts)
1177+
};
11751178

11761179
let verifier_id: Option<u32> = context
11771180
.sql
@@ -1188,10 +1191,6 @@ impl MimeFactory {
11881191
continue;
11891192
}
11901193

1191-
debug_assert!(
1192-
self.pre_message_mode != Some(PreMessageMode::FullMessage)
1193-
);
1194-
11951194
let header = Aheader {
11961195
addr: addr.clone(),
11971196
public_key: key.clone(),

0 commit comments

Comments
 (0)