refactor: do not check for is_trash() in get_last_reaction_if_newer_than()

`Message::load_from_db_optional` does not return trashed messages anymore.
This commit is contained in:
link2xt
2024-04-14 18:01:07 +00:00
parent c069190b68
commit b6c6a63a39

View File

@@ -338,20 +338,26 @@ impl Chat {
context: &Context, context: &Context,
timestamp: i64, timestamp: i64,
) -> Result<Option<(Message, ContactId, String)>> { ) -> Result<Option<(Message, ContactId, String)>> {
if let Some(reaction_timestamp) = self.param.get_i64(Param::LastReactionTimestamp) { if self
if reaction_timestamp > timestamp { .param
.get_i64(Param::LastReactionTimestamp)
.filter(|&reaction_timestamp| reaction_timestamp > timestamp)
.is_none()
{
return Ok(None);
};
let reaction_msg_id = MsgId::new( let reaction_msg_id = MsgId::new(
self.param self.param
.get_int(Param::LastReactionMsgId) .get_int(Param::LastReactionMsgId)
.unwrap_or_default() as u32, .unwrap_or_default() as u32,
); );
// The message reacted to may be deleted physically (`load_from_db()` fails) or marked as a tombstone (`is_trash()`). let Some(reaction_msg) = Message::load_from_db_optional(context, reaction_msg_id).await?
else {
// The message reacted to may be deleted.
// These are no errors as `Param::LastReaction*` are just weak pointers. // These are no errors as `Param::LastReaction*` are just weak pointers.
// Instead, just return `Ok(None)` and let the caller create another summary. // Instead, just return `Ok(None)` and let the caller create another summary.
if let Some(reaction_msg) = return Ok(None);
Message::load_from_db_optional(context, reaction_msg_id).await? };
{
if !reaction_msg.chat_id.is_trash() {
let reaction_contact_id = ContactId::new( let reaction_contact_id = ContactId::new(
self.param self.param
.get_int(Param::LastReactionContactId) .get_int(Param::LastReactionContactId)
@@ -359,25 +365,18 @@ impl Chat {
); );
if let Some(reaction) = context if let Some(reaction) = context
.sql .sql
.query_row_optional( .query_get_value(
r#"SELECT reaction FROM reactions WHERE msg_id=? AND contact_id=?"#, "SELECT reaction FROM reactions WHERE msg_id=? AND contact_id=?",
(reaction_msg.id, reaction_contact_id), (reaction_msg.id, reaction_contact_id),
|row| {
let reaction: String = row.get(0)?;
Ok(reaction)
},
) )
.await? .await?
{ {
return Ok(Some((reaction_msg, reaction_contact_id, reaction))); Ok(Some((reaction_msg, reaction_contact_id, reaction)))
} } else {
}
}
}
}
Ok(None) Ok(None)
} }
} }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {