Don't set draft after creating group (#2805)

* Don't set draft after creating group

* Remove DC_STR_NEWGROUPDRAFT, add note to Changelog

* Fix the (Rust) test

* Also fix python test
This commit is contained in:
Hocuri
2021-11-16 10:44:30 +01:00
committed by GitHub
parent 60d41022ea
commit e0129c3b43
6 changed files with 29 additions and 35 deletions

View File

@@ -1,5 +1,9 @@
# Changelog # Changelog
## Unreleased
- Removed DC_STR_NEWGROUPDRAFT, we don't set draft after creating group anymore #2805
## 1.65.0 ## 1.65.0
### Changes ### Changes

View File

@@ -5613,12 +5613,6 @@ void dc_event_unref(dc_event_t* event);
/// if nothing else is set by the dc_set_config()-option `selfstatus`. /// if nothing else is set by the dc_set_config()-option `selfstatus`.
#define DC_STR_STATUSLINE 13 #define DC_STR_STATUSLINE 13
/// "Hi, i've created the group %1$s for us."
///
/// Used as a draft text after group creation.
/// - %1$s will be replaced by the group name
#define DC_STR_NEWGROUPDRAFT 14
/// "Group name changed from %1$s to %2$s." /// "Group name changed from %1$s to %2$s."
/// ///
/// Used in status messages for group name changes. /// Used in status messages for group name changes.

View File

@@ -265,23 +265,23 @@ class TestOfflineChat:
assert d["draft"] == "" if chat.get_draft() is None else chat.get_draft() assert d["draft"] == "" if chat.get_draft() is None else chat.get_draft()
def test_group_chat_creation_with_translation(self, ac1): def test_group_chat_creation_with_translation(self, ac1):
ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %1$s") ac1.set_stock_translation(const.DC_STR_MSGGRPNAME, "abc %1$s xyz %2$s")
ac1._evtracker.consume_events() ac1._evtracker.consume_events()
with pytest.raises(ValueError): with pytest.raises(ValueError):
ac1.set_stock_translation(const.DC_STR_NEWGROUPDRAFT, "xyz %2$s") ac1.set_stock_translation(const.DC_STR_FILE, "xyz %1$s")
ac1._evtracker.get_matching("DC_EVENT_WARNING")
with pytest.raises(ValueError):
ac1.set_stock_translation(const.DC_STR_CONTACT_NOT_VERIFIED, "xyz %2$s")
ac1._evtracker.get_matching("DC_EVENT_WARNING") ac1._evtracker.get_matching("DC_EVENT_WARNING")
with pytest.raises(ValueError): with pytest.raises(ValueError):
ac1.set_stock_translation(500, "xyz %1$s") ac1.set_stock_translation(500, "xyz %1$s")
ac1._evtracker.get_matching("DC_EVENT_WARNING") ac1._evtracker.get_matching("DC_EVENT_WARNING")
contact1 = ac1.create_contact("some1@example.org", name="some1") chat = ac1.create_group_chat(name="homework", contacts=[])
contact2 = ac1.create_contact("some2@example.org", name="some2") assert chat.get_name() == "homework"
chat = ac1.create_group_chat(name="title1", contacts=[contact1, contact2]) chat.send_text("Now we have a group for homework")
assert chat.get_name() == "title1" assert chat.is_promoted()
assert contact1 in chat.get_contacts() chat.set_name("Homework")
assert contact2 in chat.get_contacts() assert chat.get_messages()[-1].text == "abc homework xyz Homework by me."
assert not chat.is_promoted()
msg = chat.get_draft()
assert msg.text == "xyz title1"
@pytest.mark.parametrize("verified", [True, False]) @pytest.mark.parametrize("verified", [True, False])
def test_group_chat_qr(self, acfactory, ac1, verified): def test_group_chat_qr(self, acfactory, ac1, verified):

View File

@@ -2267,7 +2267,6 @@ pub async fn create_group_chat(
let chat_name = improve_single_line_input(chat_name); let chat_name = improve_single_line_input(chat_name);
ensure!(!chat_name.is_empty(), "Invalid chat name"); ensure!(!chat_name.is_empty(), "Invalid chat name");
let draft_txt = stock_str::new_group_draft(context, &chat_name).await;
let grpid = dc_create_id(); let grpid = dc_create_id();
let row_id = context let row_id = context
@@ -2288,9 +2287,6 @@ pub async fn create_group_chat(
let chat_id = ChatId::new(u32::try_from(row_id)?); let chat_id = ChatId::new(u32::try_from(row_id)?);
if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF).await? { if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF).await? {
add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF).await?; add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF).await?;
let mut draft_msg = Message::new(Viewtype::Text);
draft_msg.set_text(Some(draft_txt));
chat_id.set_draft_raw(context, &mut draft_msg).await?;
} }
context.emit_event(EventType::MsgsChanged { context.emit_event(EventType::MsgsChanged {

View File

@@ -399,10 +399,20 @@ mod tests {
assert_eq!(chats.get_chat_id(1), chat_id2); assert_eq!(chats.get_chat_id(1), chat_id2);
assert_eq!(chats.get_chat_id(2), chat_id1); assert_eq!(chats.get_chat_id(2), chat_id1);
// drafts are sorted to the top // New drafts are sorted to the top
let mut msg = Message::new(Viewtype::Text); // We have to set a draft on the other two messages, too, as
msg.set_text(Some("hello".to_string())); // chat timestamps are only exact to the second and sorting by timestamp
chat_id2.set_draft(&t, Some(&mut msg)).await.unwrap(); // would not work.
// Message timestamps are "smeared" and unique, so we don't have this problem
// if we have any message (can be a draft) in all chats.
// Instead of setting drafts for chat_id1 and chat_id3, we could also sleep
// 2s here.
for chat_id in &[chat_id1, chat_id3, chat_id2] {
let mut msg = Message::new(Viewtype::Text);
msg.set_text(Some("hello".to_string()));
chat_id.set_draft(&t, Some(&mut msg)).await.unwrap();
}
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap(); let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
assert_eq!(chats.get_chat_id(0), chat_id2); assert_eq!(chats.get_chat_id(0), chat_id2);

View File

@@ -56,9 +56,6 @@ pub enum StockMessage {
#[strum(props(fallback = "Sent with my Delta Chat Messenger: https://delta.chat"))] #[strum(props(fallback = "Sent with my Delta Chat Messenger: https://delta.chat"))]
StatusLine = 13, StatusLine = 13,
#[strum(props(fallback = "Hello, I\'ve just created the group \"%1$s\" for us."))]
NewGroupDraft = 14,
#[strum(props(fallback = "Group name changed from \"%1$s\" to \"%2$s\"."))] #[strum(props(fallback = "Group name changed from \"%1$s\" to \"%2$s\"."))]
MsgGrpName = 15, MsgGrpName = 15,
@@ -457,13 +454,6 @@ pub(crate) async fn status_line(context: &Context) -> String {
translated(context, StockMessage::StatusLine).await translated(context, StockMessage::StatusLine).await
} }
/// Stock string: `Hello, I've just created the group "%1$s" for us.`.
pub(crate) async fn new_group_draft(context: &Context, group_name: impl AsRef<str>) -> String {
translated(context, StockMessage::NewGroupDraft)
.await
.replace1(group_name)
}
/// Stock string: `Group name changed from "%1$s" to "%2$s".`. /// Stock string: `Group name changed from "%1$s" to "%2$s".`.
pub(crate) async fn msg_grp_name( pub(crate) async fn msg_grp_name(
context: &Context, context: &Context,