diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 67d643bc61..74eee7c6f4 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -7275,6 +7275,11 @@ void dc_event_unref(dc_event_t* event); /// Used in info messages. #define DC_STR_CHAT_PROTECTION_DISABLED 171 +/// "Others will only see this group after you sent a first message." +/// +/// Used as the first info messages in newly created groups. +#define DC_STR_NEW_GROUP_SEND_FIRST_MESSAGE 172 + /** * @} */ diff --git a/node/constants.js b/node/constants.js index b9c990c774..3da36a27c8 100644 --- a/node/constants.js +++ b/node/constants.js @@ -239,6 +239,7 @@ module.exports = { DC_STR_MSGGRPNAME: 15, DC_STR_MSGLOCATIONDISABLED: 65, DC_STR_MSGLOCATIONENABLED: 64, + DC_STR_NEW_GROUP_SEND_FIRST_MESSAGE: 172, DC_STR_NOMESSAGES: 1, DC_STR_NOT_CONNECTED: 121, DC_STR_NOT_SUPPORTED_BY_PROVIDER: 113, diff --git a/node/lib/constants.ts b/node/lib/constants.ts index 6cc08f1441..ba5a2ed499 100644 --- a/node/lib/constants.ts +++ b/node/lib/constants.ts @@ -239,6 +239,7 @@ export enum C { DC_STR_MSGGRPNAME = 15, DC_STR_MSGLOCATIONDISABLED = 65, DC_STR_MSGLOCATIONENABLED = 64, + DC_STR_NEW_GROUP_SEND_FIRST_MESSAGE = 172, DC_STR_NOMESSAGES = 1, DC_STR_NOT_CONNECTED = 121, DC_STR_NOT_SUPPORTED_BY_PROVIDER = 113, diff --git a/node/test/test.js b/node/test/test.js index b5bfdaab1f..d8f7290718 100644 --- a/node/test/test.js +++ b/node/test/test.js @@ -667,9 +667,9 @@ describe('Offline Tests with unconfigured account', function () { const lot = chatList.getSummary(0) strictEqual(lot.getId(), 0, 'lot has no id') - strictEqual(lot.getState(), C.DC_STATE_UNDEFINED, 'correct state') + strictEqual(lot.getState(), C.DC_STATE_IN_NOTICED, 'correct state') - const text = 'No messages.' + const text = 'Others will only see this group after you sent a first message.' context.createGroupChat('groupchat1111') chatList = context.getChatList(0, 'groupchat1111', null) strictEqual( diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index 9555c4aadf..ac227da1ed 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -489,7 +489,7 @@ def test_forward_messages(acfactory, lp): lp.sec("ac2: check new chat has a forwarded message") assert chat3.is_promoted() messages = chat3.get_messages() - assert len(messages) == 1 + assert len(messages) == 2 msg = messages[-1] assert msg.is_forwarded() ac2.delete_messages(messages) @@ -1957,7 +1957,7 @@ def test_system_group_msg_from_blocked_user(acfactory, lp): chat_on_ac2.send_text("This will arrive") msg = ac1._evtracker.wait_next_incoming_message() assert msg.text == "This will arrive" - message_texts = [m.text for m in chat_on_ac1.get_messages()] + message_texts = [m.text for m in chat_on_ac1.get_messages() if not m.is_system_message()] assert len(message_texts) == 2 assert "First group message" in message_texts assert "This will arrive" in message_texts diff --git a/python/tests/test_2_increation.py b/python/tests/test_2_increation.py index 2f053e0028..320d245cd4 100644 --- a/python/tests/test_2_increation.py +++ b/python/tests/test_2_increation.py @@ -26,7 +26,7 @@ def wait_msgs_changed(account, msgs_list): break else: account.log(f"waiting mismatch data1={data1} data2={data2}") - return ev.data1, ev.data2 + return ev.data2 class TestOnlineInCreation: @@ -71,11 +71,11 @@ def test_forward_increation(self, acfactory, data, lp): lp.sec("forward the message while still in creation") chat2 = ac1.create_group_chat("newgroup") chat2.add_contact(ac2) - wait_msgs_changed(ac1, [(0, 0)]) # why not chat id? + ac1._evtracker.consume_events() ac1.forward_messages([prepared_original], chat2) # XXX there might be two EVENT_MSGS_CHANGED and only one of them # is the one caused by forwarding - _, forwarded_id = wait_msgs_changed(ac1, [(chat2.id, None)]) + forwarded_id = wait_msgs_changed(ac1, [(chat2.id, None)]) forwarded_msg = ac1.get_message_by_id(forwarded_id) assert forwarded_msg.is_out_preparing() diff --git a/python/tests/test_3_offline.py b/python/tests/test_3_offline.py index 4b040c65a2..66caf8e1e7 100644 --- a/python/tests/test_3_offline.py +++ b/python/tests/test_3_offline.py @@ -5,8 +5,6 @@ import pytest import deltachat as dc -from deltachat.capi import ffi, lib -from deltachat.cutil import iter_array from deltachat.tracker import ImexFailed from deltachat import Account, account_hookimpl, Message @@ -802,6 +800,7 @@ def wait_events(cond): def test_audit_log_view_without_daymarker(self, ac1, lp): lp.sec("ac1: test audit log (show only system messages)") chat = ac1.create_group_chat(name="audit log sample data") + # promote chat chat.send_text("hello") assert chat.is_promoted() @@ -811,12 +810,6 @@ def test_audit_log_view_without_daymarker(self, ac1, lp): chat.set_name("audit log test group") chat.send_text("a message in between") - lp.sec("check message count of all messages") - assert len(chat.get_messages()) == 4 - lp.sec("check message count of only system messages (without daymarkers)") - dc_array = ffi.gc( - lib.dc_get_chat_msgs(ac1._dc_context, chat.id, dc.const.DC_GCM_INFO_ONLY, 0), - lib.dc_array_unref, - ) - assert len(list(iter_array(dc_array, lambda x: x))) == 2 + sysmessages = [x for x in chat.get_messages() if x.is_system_message()] + assert len(sysmessages) == 3 diff --git a/src/chat.rs b/src/chat.rs index 60512c5920..cbcdda81d8 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3145,6 +3145,13 @@ pub async fn create_group_chat( .await?; } + if !context.get_config_bool(Config::Bot).await? + && !context.get_config_bool(Config::SkipStartMessages).await? + { + let text = stock_str::new_group_send_first_message(context).await; + add_info_msg(context, chat_id, &text, create_smeared_timestamp(context)).await?; + } + Ok(chat_id) } diff --git a/src/config.rs b/src/config.rs index 1ffba283eb..1440b381db 100644 --- a/src/config.rs +++ b/src/config.rs @@ -266,6 +266,10 @@ pub enum Config { /// True if it is a bot account. Bot, + /// True when to skip initial start messages in groups. + #[strum(props(default = "0"))] + SkipStartMessages, + /// Whether we send a warning if the password is wrong (set to false when we send a warning /// because we do not want to send a second warning) #[strum(props(default = "0"))] diff --git a/src/context.rs b/src/context.rs index 58d43b3741..556d6afa41 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1315,6 +1315,7 @@ mod tests { "send_port", "send_security", "server_flags", + "skip_start_messages", "smtp_certificate_checks", "socks5_host", "socks5_port", diff --git a/src/stock_str.rs b/src/stock_str.rs index 888c474c42..55693da147 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -413,6 +413,9 @@ pub enum StockMessage { #[strum(props(fallback = "%1$s sent a message from another device."))] ChatProtectionDisabled = 171, + + #[strum(props(fallback = "Others will only see this group after you sent a first message."))] + NewGroupSendFirstMessage = 172, } impl StockMessage { @@ -1284,6 +1287,11 @@ pub(crate) async fn aeap_explanation_and_link( .replace2(new_addr) } +/// Stock string: `Others will only see this group after you sent a first message.`. +pub(crate) async fn new_group_send_first_message(context: &Context) -> String { + translated(context, StockMessage::NewGroupSendFirstMessage).await +} + /// Text to put in the [`Qr::Backup`] rendered SVG image. /// /// The default is "Scan to set up second device for ". The diff --git a/src/test_utils.rs b/src/test_utils.rs index fe02cfa1f7..3807a25cbb 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -374,6 +374,10 @@ impl TestContext { } }); + ctx.set_config(Config::SkipStartMessages, Some("1")) + .await + .unwrap(); + Self { ctx, dir,