Skip to content

Commit

Permalink
feat: add 'group created instructions' as info message (#4916)
Browse files Browse the repository at this point in the history
Before, it was shown by UI when the chat is empty, however, in case of
verified groups, this is never the case any longer as the 'e2ee now
guaranteed' is always added.
  • Loading branch information
r10s authored Nov 5, 2023
1 parent fd07708 commit 939b4b2
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 17 deletions.
5 changes: 5 additions & 0 deletions deltachat-ffi/deltachat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
* @}
*/
Expand Down
1 change: 1 addition & 0 deletions node/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions node/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions node/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_1_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions python/tests/test_2_increation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
13 changes: 3 additions & 10 deletions python/tests/test_3_offline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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
7 changes: 7 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
1 change: 1 addition & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ mod tests {
"send_port",
"send_security",
"server_flags",
"skip_start_messages",
"smtp_certificate_checks",
"socks5_host",
"socks5_port",
Expand Down
8 changes: 8 additions & 0 deletions src/stock_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 <account name (account addr)>". The
Expand Down
4 changes: 4 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ impl TestContext {
}
});

ctx.set_config(Config::SkipStartMessages, Some("1"))
.await
.unwrap();

Self {
ctx,
dir,
Expand Down

0 comments on commit 939b4b2

Please sign in to comment.