Skip to content

Commit 13ee0d1

Browse files
committed
feat: Don't update self-{avatar,status} from received messages
The normal way of synchronizing self-avatar and -status nowadays is sync messages.
1 parent 75f38f1 commit 13ee0d1

File tree

5 files changed

+28
-128
lines changed

5 files changed

+28
-128
lines changed

src/config/config_tests.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ async fn test_sync() -> Result<()> {
278278
Ok(())
279279
}
280280

281-
/// Sync message mustn't be sent if self-{status,avatar} is changed by a self-sent message.
282281
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
283282
async fn test_no_sync_on_self_sent_msg() -> Result<()> {
284283
let mut tcm = TestContextManager::new();
@@ -288,7 +287,7 @@ async fn test_no_sync_on_self_sent_msg() -> Result<()> {
288287
a.set_config_bool(Config::SyncMsgs, true).await?;
289288
}
290289

291-
let status = "Synced via usual message";
290+
let status = "Sent via usual message";
292291
alice0.set_config(Config::Selfstatus, Some(status)).await?;
293292
alice0.send_sync_msg().await?;
294293
alice0.pop_sent_sync_msg().await;
@@ -297,7 +296,7 @@ async fn test_no_sync_on_self_sent_msg() -> Result<()> {
297296
tcm.send_recv(alice0, alice1, "hi Alice!").await;
298297
assert_eq!(
299298
alice1.get_config(Config::Selfstatus).await?,
300-
Some(status.to_string())
299+
Some(status1.to_string())
301300
);
302301
sync(alice1, alice0).await;
303302
assert_eq!(
@@ -328,7 +327,7 @@ async fn test_no_sync_on_self_sent_msg() -> Result<()> {
328327
alice1
329328
.get_config(Config::Selfavatar)
330329
.await?
331-
.filter(|path| path.ends_with(".png"))
330+
.filter(|path| path.ends_with(".jpg"))
332331
.is_some()
333332
);
334333
sync(alice1, alice0).await;

src/contact.rs

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,15 @@ async fn import_vcard_contact(context: &Context, contact: &VcardContact) -> Resu
383383
None => None,
384384
};
385385
if let Some(path) = path {
386-
// Currently this value doesn't matter as we don't import the contact of self.
387-
let was_encrypted = false;
388-
if let Err(e) =
389-
set_profile_image(context, id, &AvatarAction::Change(path), was_encrypted).await
390-
{
386+
if let Err(e) = set_profile_image(context, id, &AvatarAction::Change(path)).await {
391387
warn!(
392388
context,
393389
"import_vcard_contact: Could not set avatar for {}: {e:#}.", contact.addr
394390
);
395391
}
396392
}
397393
if let Some(biography) = &contact.biography {
398-
if let Err(e) = set_status(context, id, biography.to_owned(), false, false).await {
394+
if let Err(e) = set_status(context, id, biography.to_owned()).await {
399395
warn!(
400396
context,
401397
"import_vcard_contact: Could not set biography for {}: {e:#}.", contact.addr
@@ -1817,39 +1813,29 @@ WHERE type=? AND id IN (
18171813
/// The given profile image is expected to be already in the blob directory
18181814
/// as profile images can be set only by receiving messages, this should be always the case, however.
18191815
///
1820-
/// For contact SELF, the image is not saved in the contact-database but as Config::Selfavatar;
1821-
/// this typically happens if we see message with our own profile image.
1816+
/// For contact SELF, the image is not saved in the contact-database but as Config::Selfavatar.
18221817
pub(crate) async fn set_profile_image(
18231818
context: &Context,
18241819
contact_id: ContactId,
18251820
profile_image: &AvatarAction,
1826-
was_encrypted: bool,
18271821
) -> Result<()> {
18281822
let mut contact = Contact::get_by_id(context, contact_id).await?;
18291823
let changed = match profile_image {
18301824
AvatarAction::Change(profile_image) => {
18311825
if contact_id == ContactId::SELF {
1832-
if was_encrypted {
1833-
context
1834-
.set_config_ex(Nosync, Config::Selfavatar, Some(profile_image))
1835-
.await?;
1836-
} else {
1837-
info!(context, "Do not use unencrypted selfavatar.");
1838-
}
1826+
context
1827+
.set_config_ex(Nosync, Config::Selfavatar, Some(profile_image))
1828+
.await?;
18391829
} else {
18401830
contact.param.set(Param::ProfileImage, profile_image);
18411831
}
18421832
true
18431833
}
18441834
AvatarAction::Delete => {
18451835
if contact_id == ContactId::SELF {
1846-
if was_encrypted {
1847-
context
1848-
.set_config_ex(Nosync, Config::Selfavatar, None)
1849-
.await?;
1850-
} else {
1851-
info!(context, "Do not use unencrypted selfavatar deletion.");
1852-
}
1836+
context
1837+
.set_config_ex(Nosync, Config::Selfavatar, None)
1838+
.await?;
18531839
} else {
18541840
contact.param.remove(Param::ProfileImage);
18551841
}
@@ -1866,22 +1852,16 @@ pub(crate) async fn set_profile_image(
18661852

18671853
/// Sets contact status.
18681854
///
1869-
/// For contact SELF, the status is not saved in the contact table, but as Config::Selfstatus. This
1870-
/// is only done if message is sent from Delta Chat and it is encrypted, to synchronize signature
1871-
/// between Delta Chat devices.
1855+
/// For contact SELF, the status is not saved in the contact table, but as Config::Selfstatus.
18721856
pub(crate) async fn set_status(
18731857
context: &Context,
18741858
contact_id: ContactId,
18751859
status: String,
1876-
encrypted: bool,
1877-
has_chat_version: bool,
18781860
) -> Result<()> {
18791861
if contact_id == ContactId::SELF {
1880-
if encrypted && has_chat_version {
1881-
context
1882-
.set_config_ex(Nosync, Config::Selfstatus, Some(&status))
1883-
.await?;
1884-
}
1862+
context
1863+
.set_config_ex(Nosync, Config::Selfstatus, Some(&status))
1864+
.await?;
18851865
} else {
18861866
let mut contact = Contact::get_by_id(context, contact_id).await?;
18871867

src/contact/contact_tests.rs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
use crate::chat::{Chat, ProtectionStatus, get_chat_contacts, send_text_msg};
55
use crate::chatlist::Chatlist;
66
use crate::receive_imf::receive_imf;
7-
use crate::test_utils::{self, TestContext, TestContextManager, TimeShiftFalsePositiveNote};
7+
use crate::test_utils::{self, TestContext, TestContextManager, TimeShiftFalsePositiveNote, sync};
88

99
#[test]
1010
fn test_contact_id_values() {
@@ -831,8 +831,7 @@ CCCB 5AA9 F6E1 141C 9431
831831
Ok(())
832832
}
833833

834-
/// Tests that status is synchronized when sending encrypted BCC-self messages and not
835-
/// synchronized when the message is not encrypted.
834+
/// Tests that self-status is not synchronized from outgoing messages.
836835
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
837836
async fn test_synchronize_status() -> Result<()> {
838837
let mut tcm = TestContextManager::new();
@@ -851,39 +850,22 @@ async fn test_synchronize_status() -> Result<()> {
851850
.await?;
852851
let chat = alice1.create_email_chat(bob).await;
853852

854-
// Alice sends a message to Bob from the first device.
853+
// Alice sends an unencrypted message to Bob from the first device.
855854
send_text_msg(alice1, chat.id, "Hello".to_string()).await?;
856855
let sent_msg = alice1.pop_sent_msg().await;
857856

858-
// Message is not encrypted.
859-
let message = sent_msg.load_from_db().await;
860-
assert!(!message.get_showpadlock());
861-
862857
// Alice's second devices receives a copy of outgoing message.
863858
alice2.recv_msg(&sent_msg).await;
864-
865-
// Bob receives message.
866-
bob.recv_msg(&sent_msg).await;
867-
868-
// Message was not encrypted, so status is not copied.
869859
assert_eq!(alice2.get_config(Config::Selfstatus).await?, default_status);
870860

871861
// Alice sends encrypted message.
872862
let chat = alice1.create_chat(bob).await;
873863
send_text_msg(alice1, chat.id, "Hello".to_string()).await?;
874864
let sent_msg = alice1.pop_sent_msg().await;
875865

876-
// Second message is encrypted.
877-
let message = sent_msg.load_from_db().await;
878-
assert!(message.get_showpadlock());
879-
880866
// Alice's second devices receives a copy of second outgoing message.
881867
alice2.recv_msg(&sent_msg).await;
882-
883-
assert_eq!(
884-
alice2.get_config(Config::Selfstatus).await?,
885-
Some("New status".to_string())
886-
);
868+
assert_eq!(alice2.get_config(Config::Selfstatus).await?, default_status);
887869

888870
Ok(())
889871
}
@@ -896,9 +878,9 @@ async fn test_selfavatar_changed_event() -> Result<()> {
896878
// Alice has two devices.
897879
let alice1 = &tcm.alice().await;
898880
let alice2 = &tcm.alice().await;
899-
900-
// Bob has one device.
901-
let bob = &tcm.bob().await;
881+
for a in [alice1, alice2] {
882+
a.set_config_bool(Config::SyncMsgs, true).await?;
883+
}
902884

903885
assert_eq!(alice1.get_config(Config::Selfavatar).await?, None);
904886

@@ -914,17 +896,7 @@ async fn test_selfavatar_changed_event() -> Result<()> {
914896
.get_matching(|e| matches!(e, EventType::SelfavatarChanged))
915897
.await;
916898

917-
// Alice sends a message.
918-
let alice1_chat_id = alice1.create_chat(bob).await.id;
919-
send_text_msg(alice1, alice1_chat_id, "Hello".to_string()).await?;
920-
let sent_msg = alice1.pop_sent_msg().await;
921-
922-
// The message is encrypted.
923-
let message = sent_msg.load_from_db().await;
924-
assert!(message.get_showpadlock());
925-
926-
// Alice's second device receives a copy of the outgoing message.
927-
alice2.recv_msg(&sent_msg).await;
899+
sync(alice1, alice2).await;
928900

929901
// Alice's second device applies the selfavatar.
930902
assert!(alice2.get_config(Config::Selfavatar).await?.is_some());

src/reaction.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,42 +1002,6 @@ Content-Disposition: reaction\n\
10021002
Ok(())
10031003
}
10041004

1005-
/// Regression test for reaction resetting self-status.
1006-
///
1007-
/// Reactions do not contain the status,
1008-
/// but should not result in self-status being reset on other devices.
1009-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1010-
async fn test_reaction_status_multidevice() -> Result<()> {
1011-
let mut tcm = TestContextManager::new();
1012-
let alice1 = tcm.alice().await;
1013-
let alice2 = tcm.alice().await;
1014-
1015-
alice1
1016-
.set_config(Config::Selfstatus, Some("New status"))
1017-
.await?;
1018-
1019-
let alice2_msg = tcm.send_recv(&alice1, &alice2, "Hi!").await;
1020-
assert_eq!(
1021-
alice2.get_config(Config::Selfstatus).await?.as_deref(),
1022-
Some("New status")
1023-
);
1024-
1025-
// Alice reacts to own message from second device,
1026-
// first device receives rection.
1027-
{
1028-
send_reaction(&alice2, alice2_msg.id, "👍").await?;
1029-
let msg = alice2.pop_sent_msg().await;
1030-
alice1.recv_msg_hidden(&msg).await;
1031-
}
1032-
1033-
// Check that the status is still the same.
1034-
assert_eq!(
1035-
alice1.get_config(Config::Selfstatus).await?.as_deref(),
1036-
Some("New status")
1037-
);
1038-
Ok(())
1039-
}
1040-
10411005
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
10421006
async fn test_send_reaction_multidevice() -> Result<()> {
10431007
let mut tcm = TestContextManager::new();

src/receive_imf.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ pub(crate) async fn receive_imf_inner(
917917
}
918918

919919
if let Some(avatar_action) = &mime_parser.user_avatar {
920-
if from_id != ContactId::UNDEFINED
920+
if !matches!(from_id, ContactId::UNDEFINED | ContactId::SELF)
921921
&& context
922922
.update_contacts_timestamp(
923923
from_id,
@@ -926,14 +926,7 @@ pub(crate) async fn receive_imf_inner(
926926
)
927927
.await?
928928
{
929-
if let Err(err) = contact::set_profile_image(
930-
context,
931-
from_id,
932-
avatar_action,
933-
mime_parser.was_encrypted(),
934-
)
935-
.await
936-
{
929+
if let Err(err) = contact::set_profile_image(context, from_id, avatar_action).await {
937930
warn!(context, "receive_imf cannot update profile image: {err:#}.");
938931
};
939932
}
@@ -945,7 +938,7 @@ pub(crate) async fn receive_imf_inner(
945938
// Ignore footers from mailinglists as they are often created or modified by the mailinglist
946939
// software.
947940
if !mime_parser.is_mailinglist_message()
948-
&& from_id != ContactId::UNDEFINED
941+
&& !matches!(from_id, ContactId::UNDEFINED | ContactId::SELF)
949942
&& context
950943
.update_contacts_timestamp(
951944
from_id,
@@ -954,15 +947,7 @@ pub(crate) async fn receive_imf_inner(
954947
)
955948
.await?
956949
{
957-
if let Err(err) = contact::set_status(
958-
context,
959-
from_id,
960-
footer.clone(),
961-
mime_parser.was_encrypted(),
962-
mime_parser.has_chat_version(),
963-
)
964-
.await
965-
{
950+
if let Err(err) = contact::set_status(context, from_id, footer.clone()).await {
966951
warn!(context, "Cannot update contact status: {err:#}.");
967952
}
968953
}

0 commit comments

Comments
 (0)