File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -98,19 +98,26 @@ impl MsgId {
9898 Ok ( ( ) )
9999 }
100100
101+ /// Updates the message download state. Returns `Ok` if the message doesn't exist anymore.
101102 pub ( crate ) async fn update_download_state (
102103 self ,
103104 context : & Context ,
104105 download_state : DownloadState ,
105106 ) -> Result < ( ) > {
106- let msg = Message :: load_from_db ( context, self ) . await ?;
107- context
107+ if context
108108 . sql
109109 . execute (
110110 "UPDATE msgs SET download_state=? WHERE id=?;" ,
111111 ( download_state, self ) ,
112112 )
113- . await ?;
113+ . await ?
114+ == 0
115+ {
116+ return Ok ( ( ) ) ;
117+ }
118+ let Some ( msg) = Message :: load_from_db_optional ( context, self ) . await ? else {
119+ return Ok ( ( ) ) ;
120+ } ;
114121 context. emit_event ( EventType :: MsgsChanged {
115122 chat_id : msg. chat_id ,
116123 msg_id : self ,
@@ -322,11 +329,17 @@ mod tests {
322329 DownloadState :: InProgress ,
323330 DownloadState :: Failure ,
324331 DownloadState :: Done ,
332+ DownloadState :: Done ,
325333 ] {
326334 msg_id. update_download_state ( & t, * s) . await ?;
327335 let msg = Message :: load_from_db ( & t, msg_id) . await ?;
328336 assert_eq ! ( msg. download_state( ) , * s) ;
329337 }
338+ msg_id. delete_from_db ( & t) . await ?;
339+ // Nothing to do is ok.
340+ msg_id
341+ . update_download_state ( & t, DownloadState :: Done )
342+ . await ?;
330343
331344 Ok ( ( ) )
332345 }
You can’t perform that action at this time.
0 commit comments