@@ -1829,7 +1829,7 @@ pub async fn delete_msgs_ex(
18291829 Ok ( ( ) )
18301830}
18311831
1832- /// Marks requested messages as seen.
1832+ /// Marks requested messages and reactions to them as seen.
18331833pub async fn markseen_msgs ( context : & Context , msg_ids : Vec < MsgId > ) -> Result < ( ) > {
18341834 if msg_ids. is_empty ( ) {
18351835 return Ok ( ( ) ) ;
@@ -1843,10 +1843,18 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
18431843
18441844 let mut msgs = Vec :: with_capacity ( msg_ids. len ( ) ) ;
18451845 for & id in & msg_ids {
1846- if let Some ( msg ) = context
1846+ let Some ( rfc724_mid ) : Option < String > = context
18471847 . sql
1848- . query_row_optional (
1848+ . query_get_value ( "SELECT rfc724_mid FROM msgs WHERE id=?" , ( id, ) )
1849+ . await ?
1850+ else {
1851+ continue ;
1852+ } ;
1853+ context
1854+ . sql
1855+ . query_map (
18491856 "SELECT
1857+ m.id AS id,
18501858 m.chat_id AS chat_id,
18511859 m.state AS state,
18521860 m.ephemeral_timer AS ephemeral_timer,
@@ -1857,9 +1865,11 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
18571865 c.archived AS archived,
18581866 c.blocked AS blocked
18591867 FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id
1860- WHERE m.id=? AND m.chat_id>9" ,
1861- ( id, ) ,
1868+ WHERE (m.id=? OR m.mime_in_reply_to=? AND m.hidden=1)
1869+ AND m.chat_id>9 AND ?<=m.state AND m.state<?" ,
1870+ ( id, rfc724_mid, MessageState :: InFresh , MessageState :: InSeen ) ,
18621871 |row| {
1872+ let id: MsgId = row. get ( "id" ) ?;
18631873 let chat_id: ChatId = row. get ( "chat_id" ) ?;
18641874 let state: MessageState = row. get ( "state" ) ?;
18651875 let param: Params = row. get :: < _ , String > ( "param" ) ?. parse ( ) . unwrap_or_default ( ) ;
@@ -1884,11 +1894,14 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
18841894 ephemeral_timer,
18851895 ) )
18861896 } ,
1897+ |rows| {
1898+ for row in rows {
1899+ msgs. push ( row?) ;
1900+ }
1901+ Ok ( ( ) )
1902+ } ,
18871903 )
1888- . await ?
1889- {
1890- msgs. push ( msg) ;
1891- }
1904+ . await ?;
18921905 }
18931906
18941907 if msgs
@@ -1917,48 +1930,45 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
19171930 _curr_ephemeral_timer,
19181931 ) in msgs
19191932 {
1920- if curr_state == MessageState :: InFresh || curr_state == MessageState :: InNoticed {
1921- update_msg_state ( context, id, MessageState :: InSeen ) . await ?;
1922- info ! ( context, "Seen message {}." , id) ;
1923-
1924- markseen_on_imap_table ( context, & curr_rfc724_mid) . await ?;
1925-
1926- // Read receipts for system messages are never sent to contacts.
1927- // These messages have no place to display received read receipt
1928- // anyway. And since their text is locally generated,
1929- // quoting them is dangerous as it may contain contact names. E.g., for original message
1930- // "Group left by me", a read receipt will quote "Group left by <name>", and the name can
1931- // be a display name stored in address book rather than the name sent in the From field by
1932- // the user.
1933- //
1934- // We also don't send read receipts for contact requests.
1935- // Read receipts will not be sent even after accepting the chat.
1936- let to_id = if curr_blocked == Blocked :: Not
1937- && !curr_hidden
1938- && curr_param. get_bool ( Param :: WantsMdn ) . unwrap_or_default ( )
1939- && curr_param. get_cmd ( ) == SystemMessage :: Unknown
1940- && context. should_send_mdns ( ) . await ?
1941- {
1942- Some ( curr_from_id)
1943- } else if context. get_config_bool ( Config :: BccSelf ) . await ? {
1944- Some ( ContactId :: SELF )
1945- } else {
1946- None
1947- } ;
1948- if let Some ( to_id) = to_id {
1949- context
1950- . sql
1951- . execute (
1952- "INSERT INTO smtp_mdns (msg_id, from_id, rfc724_mid) VALUES(?, ?, ?)" ,
1953- ( id, to_id, curr_rfc724_mid) ,
1954- )
1955- . await
1956- . context ( "failed to insert into smtp_mdns" ) ?;
1957- context. scheduler . interrupt_smtp ( ) . await ;
1958- }
1959- if !curr_hidden {
1960- updated_chat_ids. insert ( curr_chat_id) ;
1961- }
1933+ update_msg_state ( context, id, MessageState :: InSeen ) . await ?;
1934+ info ! ( context, "Seen message {}." , id) ;
1935+
1936+ markseen_on_imap_table ( context, & curr_rfc724_mid) . await ?;
1937+
1938+ // Read receipts for system messages are never sent to contacts. These messages have no
1939+ // place to display received read receipt anyway. And since their text is locally generated,
1940+ // quoting them is dangerous as it may contain contact names. E.g., for original message
1941+ // "Group left by me", a read receipt will quote "Group left by <name>", and the name can be
1942+ // a display name stored in address book rather than the name sent in the From field by the
1943+ // user.
1944+ //
1945+ // We also don't send read receipts for contact requests. Read receipts will not be sent
1946+ // even after accepting the chat.
1947+ let to_id = if curr_blocked == Blocked :: Not
1948+ && !curr_hidden
1949+ && curr_param. get_bool ( Param :: WantsMdn ) . unwrap_or_default ( )
1950+ && curr_param. get_cmd ( ) == SystemMessage :: Unknown
1951+ && context. should_send_mdns ( ) . await ?
1952+ {
1953+ Some ( curr_from_id)
1954+ } else if context. get_config_bool ( Config :: BccSelf ) . await ? {
1955+ Some ( ContactId :: SELF )
1956+ } else {
1957+ None
1958+ } ;
1959+ if let Some ( to_id) = to_id {
1960+ context
1961+ . sql
1962+ . execute (
1963+ "INSERT INTO smtp_mdns (msg_id, from_id, rfc724_mid) VALUES(?, ?, ?)" ,
1964+ ( id, to_id, curr_rfc724_mid) ,
1965+ )
1966+ . await
1967+ . context ( "failed to insert into smtp_mdns" ) ?;
1968+ context. scheduler . interrupt_smtp ( ) . await ;
1969+ }
1970+ if !curr_hidden {
1971+ updated_chat_ids. insert ( curr_chat_id) ;
19621972 }
19631973 archived_chats_maybe_noticed |= curr_state == MessageState :: InFresh
19641974 && !curr_hidden
0 commit comments