diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d81d5f26..daf622cae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Make sure, videochat-room-names are always URL-safe #3231 - Try removing account folder multiple times in case of failure #3229 - Ignore messages from all spam folders if there are many #3246 +- Hide location-only messages instead of displaying empty bubbles #3248 ### Changes diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 7b644df39..333b501de 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -1103,11 +1103,11 @@ INSERT INTO msgs // If you change which information is skipped if the message is trashed, // also change `MsgId::trash()` and `delete_expired_messages()` - let trash = chat_id.is_trash(); + let trash = chat_id.is_trash() || (location_kml_is && msg.is_empty()); stmt.execute(paramsv![ rfc724_mid, - chat_id, + if trash { DC_CHAT_ID_TRASH } else { chat_id }, if trash { ContactId::UNDEFINED } else { from_id }, if trash { ContactId::UNDEFINED } else { to_id }, sort_timestamp, diff --git a/src/location.rs b/src/location.rs index f74c6072d..a85d1b8c8 100644 --- a/src/location.rs +++ b/src/location.rs @@ -755,6 +755,7 @@ mod tests { #![allow(clippy::indexing_slicing)] use super::*; + use crate::dc_receive_imf::dc_receive_imf; use crate::test_utils::TestContext; #[async_std::test] @@ -815,4 +816,68 @@ mod tests { assert!(!is_marker(" ")); assert!(!is_marker("\t")); } + + /// Tests that location.kml is hidden. + #[async_std::test] + async fn receive_location_kml() -> Result<()> { + let alice = TestContext::new_alice().await; + + dc_receive_imf( + &alice, + br#"Subject: Hello +Message-ID: hello@example.net +To: Alice +From: Bob +Date: Mon, 20 Dec 2021 00:00:00 +0000 +Chat-Version: 1.0 +Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no + +Text message."#, + false, + ) + .await?; + let received_msg = alice.get_last_msg().await; + assert_eq!(received_msg.text.unwrap(), "Text message."); + + dc_receive_imf( + &alice, + br#"Subject: locations +MIME-Version: 1.0 +To: +From: +Date: Tue, 21 Dec 2021 00:00:00 +0000 +Chat-Version: 1.0 +Message-ID: +Content-Type: multipart/mixed; boundary="U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF" + + +--U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF +Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no + + + +--U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF +Content-Type: application/vnd.google-earth.kml+xml +Content-Disposition: attachment; filename="location.kml" + + + + +2021-11-21T00:00:00Z10.00000000000000,20.00000000000000 + + + +--U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF--"#, + false, + ) + .await?; + + // Received location message is not visible, last message stays the same. + let received_msg2 = alice.get_last_msg().await; + assert_eq!(received_msg2.id, received_msg.id); + + let locations = get_range(&alice, None, None, 0, 0).await?; + assert_eq!(locations.len(), 1); + Ok(()) + } }