Skip to content

Commit

Permalink
refactor: MsgId::update_download_state: Don't fail if the message doe…
Browse files Browse the repository at this point in the history
…sn't exist anymore

If a race happens and the message disappears, there's just nothing to do and no sense to
fail. Follow-up to 22e5bf8.
  • Loading branch information
iequidoo committed Oct 7, 2024
1 parent aacea2d commit 877211b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,26 @@ impl MsgId {
Ok(())
}

/// Updates the message download state. Returns `Ok` if the message doesn't exist anymore.
pub(crate) async fn update_download_state(
self,
context: &Context,
download_state: DownloadState,
) -> Result<()> {
let msg = Message::load_from_db(context, self).await?;
context
if context
.sql
.execute(
"UPDATE msgs SET download_state=? WHERE id=?;",
(download_state, self),
)
.await?;
.await?
== 0
{
return Ok(());
}
let Some(msg) = Message::load_from_db_optional(context, self).await? else {
return Ok(());
};
context.emit_event(EventType::MsgsChanged {
chat_id: msg.chat_id,
msg_id: self,
Expand Down

0 comments on commit 877211b

Please sign in to comment.