@@ -1495,73 +1495,9 @@ async fn add_parts(
1495
1495
}
1496
1496
}
1497
1497
1498
- if let Some ( rfc724_mid) = mime_parser. get_header ( HeaderDef :: ChatEdit ) {
1499
- chat_id = DC_CHAT_ID_TRASH ;
1500
- if let Some ( ( original_msg_id, _) ) = rfc724_mid_exists ( context, rfc724_mid) . await ? {
1501
- if let Some ( mut original_msg) =
1502
- Message :: load_from_db_optional ( context, original_msg_id) . await ?
1503
- {
1504
- if original_msg. from_id == from_id {
1505
- if let Some ( part) = mime_parser. parts . first ( ) {
1506
- let edit_msg_showpadlock = part
1507
- . param
1508
- . get_bool ( Param :: GuaranteeE2ee )
1509
- . unwrap_or_default ( ) ;
1510
- if edit_msg_showpadlock || !original_msg. get_showpadlock ( ) {
1511
- let new_text =
1512
- part. msg . strip_prefix ( EDITED_PREFIX ) . unwrap_or ( & part. msg ) ;
1513
- chat:: save_text_edit_to_db ( context, & mut original_msg, new_text)
1514
- . await ?;
1515
- } else {
1516
- warn ! ( context, "Edit message: Not encrypted." ) ;
1517
- }
1518
- }
1519
- } else {
1520
- warn ! ( context, "Edit message: Bad sender." ) ;
1521
- }
1522
- } else {
1523
- warn ! ( context, "Edit message: Database entry does not exist." ) ;
1524
- }
1525
- } else {
1526
- warn ! (
1527
- context,
1528
- "Edit message: rfc724_mid {rfc724_mid:?} not found."
1529
- ) ;
1530
- }
1531
- } else if let Some ( rfc724_mid_list) = mime_parser. get_header ( HeaderDef :: ChatDelete ) {
1498
+ if handle_edit_delete ( context, mime_parser, from_id) . await ? {
1532
1499
chat_id = DC_CHAT_ID_TRASH ;
1533
- if let Some ( part) = mime_parser. parts . first ( ) {
1534
- // See `message::delete_msgs_ex()`, unlike edit requests, DC doesn't send unencrypted
1535
- // deletion requests, so there's no need to support them.
1536
- if part. param . get_bool ( Param :: GuaranteeE2ee ) . unwrap_or ( false ) {
1537
- let mut modified_chat_ids = HashSet :: new ( ) ;
1538
- let mut msg_ids = Vec :: new ( ) ;
1539
-
1540
- let rfc724_mid_vec: Vec < & str > = rfc724_mid_list. split_whitespace ( ) . collect ( ) ;
1541
- for rfc724_mid in rfc724_mid_vec {
1542
- if let Some ( ( msg_id, _) ) =
1543
- message:: rfc724_mid_exists ( context, rfc724_mid) . await ?
1544
- {
1545
- if let Some ( msg) = Message :: load_from_db_optional ( context, msg_id) . await ? {
1546
- if msg. from_id == from_id {
1547
- message:: delete_msg_locally ( context, & msg) . await ?;
1548
- msg_ids. push ( msg. id ) ;
1549
- modified_chat_ids. insert ( msg. chat_id ) ;
1550
- } else {
1551
- warn ! ( context, "Delete message: Bad sender." ) ;
1552
- }
1553
- } else {
1554
- warn ! ( context, "Delete message: Database entry does not exist." ) ;
1555
- }
1556
- } else {
1557
- warn ! ( context, "Delete message: {rfc724_mid:?} not found." ) ;
1558
- }
1559
- }
1560
- message:: delete_msgs_locally_done ( context, & msg_ids, modified_chat_ids) . await ?;
1561
- } else {
1562
- warn ! ( context, "Delete message: Not encrypted." ) ;
1563
- }
1564
- }
1500
+ info ! ( context, "Message edits/deletes existing message (TRASH)." ) ;
1565
1501
}
1566
1502
1567
1503
let mut parts = mime_parser. parts . iter ( ) . peekable ( ) ;
@@ -1830,6 +1766,89 @@ RETURNING id
1830
1766
} )
1831
1767
}
1832
1768
1769
+ /// Checks for "Chat-Edit" and "Chat-Delete" headers,
1770
+ /// and edits/deletes existing messages accordingly.
1771
+ ///
1772
+ /// Returns `true` if this message is an edit/deletion request.
1773
+ async fn handle_edit_delete (
1774
+ context : & Context ,
1775
+ mime_parser : & MimeMessage ,
1776
+ from_id : ContactId ,
1777
+ ) -> Result < bool > {
1778
+ if let Some ( rfc724_mid) = mime_parser. get_header ( HeaderDef :: ChatEdit ) {
1779
+ if let Some ( ( original_msg_id, _) ) = rfc724_mid_exists ( context, rfc724_mid) . await ? {
1780
+ if let Some ( mut original_msg) =
1781
+ Message :: load_from_db_optional ( context, original_msg_id) . await ?
1782
+ {
1783
+ if original_msg. from_id == from_id {
1784
+ if let Some ( part) = mime_parser. parts . first ( ) {
1785
+ let edit_msg_showpadlock = part
1786
+ . param
1787
+ . get_bool ( Param :: GuaranteeE2ee )
1788
+ . unwrap_or_default ( ) ;
1789
+ if edit_msg_showpadlock || !original_msg. get_showpadlock ( ) {
1790
+ let new_text =
1791
+ part. msg . strip_prefix ( EDITED_PREFIX ) . unwrap_or ( & part. msg ) ;
1792
+ chat:: save_text_edit_to_db ( context, & mut original_msg, new_text)
1793
+ . await ?;
1794
+ } else {
1795
+ warn ! ( context, "Edit message: Not encrypted." ) ;
1796
+ }
1797
+ }
1798
+ } else {
1799
+ warn ! ( context, "Edit message: Bad sender." ) ;
1800
+ }
1801
+ } else {
1802
+ warn ! ( context, "Edit message: Database entry does not exist." ) ;
1803
+ }
1804
+ } else {
1805
+ warn ! (
1806
+ context,
1807
+ "Edit message: rfc724_mid {rfc724_mid:?} not found."
1808
+ ) ;
1809
+ }
1810
+
1811
+ Ok ( true )
1812
+ } else if let Some ( rfc724_mid_list) = mime_parser. get_header ( HeaderDef :: ChatDelete ) {
1813
+ if let Some ( part) = mime_parser. parts . first ( ) {
1814
+ // See `message::delete_msgs_ex()`, unlike edit requests, DC doesn't send unencrypted
1815
+ // deletion requests, so there's no need to support them.
1816
+ if part. param . get_bool ( Param :: GuaranteeE2ee ) . unwrap_or ( false ) {
1817
+ let mut modified_chat_ids = HashSet :: new ( ) ;
1818
+ let mut msg_ids = Vec :: new ( ) ;
1819
+
1820
+ let rfc724_mid_vec: Vec < & str > = rfc724_mid_list. split_whitespace ( ) . collect ( ) ;
1821
+ for rfc724_mid in rfc724_mid_vec {
1822
+ if let Some ( ( msg_id, _) ) =
1823
+ message:: rfc724_mid_exists ( context, rfc724_mid) . await ?
1824
+ {
1825
+ if let Some ( msg) = Message :: load_from_db_optional ( context, msg_id) . await ? {
1826
+ if msg. from_id == from_id {
1827
+ message:: delete_msg_locally ( context, & msg) . await ?;
1828
+ msg_ids. push ( msg. id ) ;
1829
+ modified_chat_ids. insert ( msg. chat_id ) ;
1830
+ } else {
1831
+ warn ! ( context, "Delete message: Bad sender." ) ;
1832
+ }
1833
+ } else {
1834
+ warn ! ( context, "Delete message: Database entry does not exist." ) ;
1835
+ }
1836
+ } else {
1837
+ warn ! ( context, "Delete message: {rfc724_mid:?} not found." ) ;
1838
+ }
1839
+ }
1840
+ message:: delete_msgs_locally_done ( context, & msg_ids, modified_chat_ids) . await ?;
1841
+ } else {
1842
+ warn ! ( context, "Delete message: Not encrypted." ) ;
1843
+ }
1844
+ }
1845
+
1846
+ Ok ( true )
1847
+ } else {
1848
+ Ok ( false )
1849
+ }
1850
+ }
1851
+
1833
1852
async fn tweak_sort_timestamp (
1834
1853
context : & Context ,
1835
1854
mime_parser : & mut MimeMessage ,
0 commit comments