Skip to content

Commit fc81cef

Browse files
committed
refactor: Rename chat::create_group_chat() to create_group()
If we use modules (which are actually namespaces), we can use shorter names. Another approach is to only use modules for internal code incapsulation and use full names like deltachat-ffi does.
1 parent 04c2585 commit fc81cef

File tree

19 files changed

+162
-166
lines changed

19 files changed

+162
-166
lines changed

deltachat-ffi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ pub unsafe extern "C" fn dc_create_group_chat(
17301730
}
17311731
let ctx = &*context;
17321732

1733-
block_on(chat::create_group_chat(ctx, &to_string_lossy(name)))
1733+
block_on(chat::create_group(ctx, &to_string_lossy(name)))
17341734
.context("Failed to create group chat")
17351735
.log_err(ctx)
17361736
.map(|id| id.to_u32())

deltachat-jsonrpc/src/api.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,7 @@ impl CommandApi {
968968
/// This may be useful if you want to show some help for just created groups.
969969
async fn create_group_chat(&self, account_id: u32, name: String) -> Result<u32> {
970970
let ctx = self.get_context(account_id).await?;
971-
chat::create_group_chat(&ctx, &name)
972-
.await
973-
.map(|id| id.to_u32())
971+
chat::create_group(&ctx, &name).await.map(|id| id.to_u32())
974972
}
975973

976974
/// Create a new unencrypted group chat.
@@ -979,7 +977,7 @@ impl CommandApi {
979977
/// address-contacts.
980978
async fn create_group_chat_unencrypted(&self, account_id: u32, name: String) -> Result<u32> {
981979
let ctx = self.get_context(account_id).await?;
982-
chat::create_group_chat_unencrypted(&ctx, &name)
980+
chat::create_group_unencrypted(&ctx, &name)
983981
.await
984982
.map(|id| id.to_u32())
985983
}

deltachat-repl/src/cmdline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
731731
}
732732
"creategroup" => {
733733
ensure!(!arg1.is_empty(), "Argument <name> missing.");
734-
let chat_id = chat::create_group_chat(&context, arg1).await?;
734+
let chat_id = chat::create_group(&context, arg1).await?;
735735

736736
println!("Group#{chat_id} created successfully.");
737737
}

src/chat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,12 +3401,12 @@ pub async fn get_past_chat_contacts(context: &Context, chat_id: ChatId) -> Resul
34013401
}
34023402

34033403
/// Creates an encrypted group chat.
3404-
pub async fn create_group_chat(context: &Context, name: &str) -> Result<ChatId> {
3404+
pub async fn create_group(context: &Context, name: &str) -> Result<ChatId> {
34053405
create_group_ex(context, Sync, create_id(), name).await
34063406
}
34073407

34083408
/// Creates an unencrypted group chat.
3409-
pub async fn create_group_chat_unencrypted(context: &Context, name: &str) -> Result<ChatId> {
3409+
pub async fn create_group_unencrypted(context: &Context, name: &str) -> Result<ChatId> {
34103410
create_group_ex(context, Sync, String::new(), name).await
34113411
}
34123412

@@ -3479,7 +3479,7 @@ pub(crate) async fn create_group_ex(
34793479
/// which would make it hard to grep for it.
34803480
///
34813481
/// After creation, the chat contains no recipients and is in _unpromoted_ state;
3482-
/// see [`create_group_chat`] for more information on the unpromoted state.
3482+
/// see [`create_group`] for more information on the unpromoted state.
34833483
///
34843484
/// Returns the created chat's id.
34853485
pub async fn create_broadcast(context: &Context, chat_name: String) -> Result<ChatId> {

src/chat/chat_tests.rs

Lines changed: 48 additions & 48 deletions
Large diffs are not rendered by default.

src/chatlist.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ mod tests {
481481
use super::*;
482482
use crate::chat::save_msgs;
483483
use crate::chat::{
484-
add_contact_to_chat, create_group_chat, get_chat_contacts, remove_contact_from_chat,
484+
add_contact_to_chat, create_group, get_chat_contacts, remove_contact_from_chat,
485485
send_text_msg,
486486
};
487487
use crate::receive_imf::receive_imf;
@@ -495,9 +495,9 @@ mod tests {
495495
async fn test_try_load() {
496496
let mut tcm = TestContextManager::new();
497497
let bob = &tcm.bob().await;
498-
let chat_id1 = create_group_chat(bob, "a chat").await.unwrap();
499-
let chat_id2 = create_group_chat(bob, "b chat").await.unwrap();
500-
let chat_id3 = create_group_chat(bob, "c chat").await.unwrap();
498+
let chat_id1 = create_group(bob, "a chat").await.unwrap();
499+
let chat_id2 = create_group(bob, "b chat").await.unwrap();
500+
let chat_id3 = create_group(bob, "c chat").await.unwrap();
501501

502502
// check that the chatlist starts with the most recent message
503503
let chats = Chatlist::try_load(bob, 0, None, None).await.unwrap();
@@ -530,7 +530,7 @@ mod tests {
530530

531531
// receive a message from alice
532532
let alice = &tcm.alice().await;
533-
let alice_chat_id = create_group_chat(alice, "alice chat").await.unwrap();
533+
let alice_chat_id = create_group(alice, "alice chat").await.unwrap();
534534
add_contact_to_chat(
535535
alice,
536536
alice_chat_id,
@@ -568,7 +568,7 @@ mod tests {
568568
async fn test_sort_self_talk_up_on_forward() {
569569
let t = TestContext::new_alice().await;
570570
t.update_device_chats().await.unwrap();
571-
create_group_chat(&t, "a chat").await.unwrap();
571+
create_group(&t, "a chat").await.unwrap();
572572

573573
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();
574574
assert_eq!(chats.len(), 3);
@@ -755,7 +755,7 @@ mod tests {
755755
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
756756
async fn test_get_summary_unwrap() {
757757
let t = TestContext::new().await;
758-
let chat_id1 = create_group_chat(&t, "a chat").await.unwrap();
758+
let chat_id1 = create_group(&t, "a chat").await.unwrap();
759759

760760
let mut msg = Message::new_text("foo:\nbar \r\n test".to_string());
761761
chat_id1.set_draft(&t, Some(&mut msg)).await.unwrap();
@@ -771,7 +771,7 @@ mod tests {
771771
async fn test_get_summary_deleted_draft() {
772772
let t = TestContext::new().await;
773773

774-
let chat_id = create_group_chat(&t, "a chat").await.unwrap();
774+
let chat_id = create_group(&t, "a chat").await.unwrap();
775775
let mut msg = Message::new_text("Foobar".to_string());
776776
chat_id.set_draft(&t, Some(&mut msg)).await.unwrap();
777777

@@ -810,9 +810,9 @@ mod tests {
810810
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
811811
async fn test_load_broken() {
812812
let t = TestContext::new_bob().await;
813-
let chat_id1 = create_group_chat(&t, "a chat").await.unwrap();
814-
create_group_chat(&t, "b chat").await.unwrap();
815-
create_group_chat(&t, "c chat").await.unwrap();
813+
let chat_id1 = create_group(&t, "a chat").await.unwrap();
814+
create_group(&t, "b chat").await.unwrap();
815+
create_group(&t, "c chat").await.unwrap();
816816

817817
// check that the chatlist starts with the most recent message
818818
let chats = Chatlist::try_load(&t, 0, None, None).await.unwrap();

src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub enum Chattype {
118118

119119
/// Group chat.
120120
///
121-
/// Created by [`crate::chat::create_group_chat`].
121+
/// Created by [`crate::chat::create_group`].
122122
Group = 120,
123123

124124
/// An (unencrypted) mailing list,

src/ephemeral/ephemeral_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::receive_imf::receive_imf;
1212
use crate::test_utils::{TestContext, TestContextManager};
1313
use crate::timesmearing::MAX_SECONDS_TO_LEND_FROM_FUTURE;
1414
use crate::{
15-
chat::{self, Chat, ChatItem, create_group_chat, send_text_msg},
15+
chat::{self, Chat, ChatItem, create_group, send_text_msg},
1616
tools::IsNoneOrEmpty,
1717
};
1818

@@ -164,7 +164,7 @@ async fn test_ephemeral_enable_disable() -> Result<()> {
164164
async fn test_ephemeral_unpromoted() -> Result<()> {
165165
let alice = TestContext::new_alice().await;
166166

167-
let chat_id = create_group_chat(&alice, "Group name").await?;
167+
let chat_id = create_group(&alice, "Group name").await?;
168168

169169
// Group is unpromoted, the timer can be changed without sending a message.
170170
assert!(chat_id.is_unpromoted(&alice).await?);
@@ -799,7 +799,7 @@ async fn test_ephemeral_timer_non_member() -> Result<()> {
799799
let bob = &tcm.bob().await;
800800

801801
let alice_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
802-
let alice_chat_id = create_group_chat(alice, "Group name").await?;
802+
let alice_chat_id = create_group(alice, "Group name").await?;
803803
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
804804
send_text_msg(alice, alice_chat_id, "Hi!".to_string()).await?;
805805

src/events/chatlist_events.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ mod test_chatlist_events {
6666
use crate::{
6767
EventType,
6868
chat::{
69-
self, ChatId, ChatVisibility, MuteDuration, create_broadcast, create_group_chat,
70-
set_muted,
69+
self, ChatId, ChatVisibility, MuteDuration, create_broadcast, create_group, set_muted,
7170
},
7271
config::Config,
7372
constants::*,
@@ -138,7 +137,7 @@ mod test_chatlist_events {
138137
async fn test_change_chat_visibility() -> Result<()> {
139138
let mut tcm = TestContextManager::new();
140139
let alice = tcm.alice().await;
141-
let chat_id = create_group_chat(&alice, "my_group").await?;
140+
let chat_id = create_group(&alice, "my_group").await?;
142141

143142
chat_id
144143
.set_visibility(&alice, ChatVisibility::Pinned)
@@ -284,7 +283,7 @@ mod test_chatlist_events {
284283
async fn test_delete_chat() -> Result<()> {
285284
let mut tcm = TestContextManager::new();
286285
let alice = tcm.alice().await;
287-
let chat = create_group_chat(&alice, "My Group").await?;
286+
let chat = create_group(&alice, "My Group").await?;
288287

289288
alice.evtracker.clear_events();
290289
chat.delete(&alice).await?;
@@ -294,11 +293,11 @@ mod test_chatlist_events {
294293

295294
/// Create group chat
296295
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
297-
async fn test_create_group_chat() -> Result<()> {
296+
async fn test_create_group() -> Result<()> {
298297
let mut tcm = TestContextManager::new();
299298
let alice = tcm.alice().await;
300299
alice.evtracker.clear_events();
301-
let chat = create_group_chat(&alice, "My Group").await?;
300+
let chat = create_group(&alice, "My Group").await?;
302301
wait_for_chatlist_and_specific_item(&alice, chat).await;
303302
Ok(())
304303
}
@@ -319,7 +318,7 @@ mod test_chatlist_events {
319318
async fn test_mute_chat() -> Result<()> {
320319
let mut tcm = TestContextManager::new();
321320
let alice = tcm.alice().await;
322-
let chat = create_group_chat(&alice, "My Group").await?;
321+
let chat = create_group(&alice, "My Group").await?;
323322

324323
alice.evtracker.clear_events();
325324
chat::set_muted(&alice, chat, MuteDuration::Forever).await?;
@@ -338,7 +337,7 @@ mod test_chatlist_events {
338337
async fn test_mute_chat_expired() -> Result<()> {
339338
let mut tcm = TestContextManager::new();
340339
let alice = tcm.alice().await;
341-
let chat = create_group_chat(&alice, "My Group").await?;
340+
let chat = create_group(&alice, "My Group").await?;
342341

343342
let mute_duration = MuteDuration::Until(
344343
std::time::SystemTime::now()
@@ -358,7 +357,7 @@ mod test_chatlist_events {
358357
async fn test_change_chat_name() -> Result<()> {
359358
let mut tcm = TestContextManager::new();
360359
let alice = tcm.alice().await;
361-
let chat = create_group_chat(&alice, "My Group").await?;
360+
let chat = create_group(&alice, "My Group").await?;
362361

363362
alice.evtracker.clear_events();
364363
chat::set_chat_name(&alice, chat, "New Name").await?;
@@ -372,7 +371,7 @@ mod test_chatlist_events {
372371
async fn test_change_chat_profile_image() -> Result<()> {
373372
let mut tcm = TestContextManager::new();
374373
let alice = tcm.alice().await;
375-
let chat = create_group_chat(&alice, "My Group").await?;
374+
let chat = create_group(&alice, "My Group").await?;
376375

377376
alice.evtracker.clear_events();
378377
let file = alice.dir.path().join("avatar.png");
@@ -445,7 +444,7 @@ mod test_chatlist_events {
445444
async fn test_delete_message() -> Result<()> {
446445
let mut tcm = TestContextManager::new();
447446
let alice = tcm.alice().await;
448-
let chat = create_group_chat(&alice, "My Group").await?;
447+
let chat = create_group(&alice, "My Group").await?;
449448
let message = chat::send_text_msg(&alice, chat, "Hello World".to_owned()).await?;
450449

451450
alice.evtracker.clear_events();
@@ -503,7 +502,7 @@ mod test_chatlist_events {
503502
async fn test_update_after_ephemeral_messages() -> Result<()> {
504503
let mut tcm = TestContextManager::new();
505504
let alice = tcm.alice().await;
506-
let chat = create_group_chat(&alice, "My Group").await?;
505+
let chat = create_group(&alice, "My Group").await?;
507506
chat.set_ephemeral_timer(&alice, crate::ephemeral::Timer::Enabled { duration: 60 })
508507
.await?;
509508
alice
@@ -547,7 +546,7 @@ First thread."#;
547546
let alice = tcm.alice().await;
548547
let bob = tcm.bob().await;
549548

550-
let alice_chatid = chat::create_group_chat(&alice.ctx, "the chat").await?;
549+
let alice_chatid = chat::create_group(&alice.ctx, "the chat").await?;
551550

552551
// Step 1: Generate QR-code, secure-join implied by chatid
553552
let qr = get_securejoin_qr(&alice.ctx, Some(alice_chatid)).await?;
@@ -594,7 +593,7 @@ First thread."#;
594593
async fn test_resend_message() -> Result<()> {
595594
let mut tcm = TestContextManager::new();
596595
let alice = tcm.alice().await;
597-
let chat = create_group_chat(&alice, "My Group").await?;
596+
let chat = create_group(&alice, "My Group").await?;
598597

599598
let msg_id = chat::send_text_msg(&alice, chat, "Hello".to_owned()).await?;
600599
let _ = alice.pop_sent_msg().await;
@@ -614,7 +613,7 @@ First thread."#;
614613
async fn test_reaction() -> Result<()> {
615614
let mut tcm = TestContextManager::new();
616615
let alice = tcm.alice().await;
617-
let chat = create_group_chat(&alice, "My Group").await?;
616+
let chat = create_group(&alice, "My Group").await?;
618617
let msg_id = chat::send_text_msg(&alice, chat, "Hello".to_owned()).await?;
619618
let _ = alice.pop_sent_msg().await;
620619

src/mimefactory/mimefactory_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use super::*;
88
use crate::chat::{
9-
self, ChatId, add_contact_to_chat, create_group_chat, remove_contact_from_chat, send_text_msg,
9+
self, ChatId, add_contact_to_chat, create_group, remove_contact_from_chat, send_text_msg,
1010
};
1111
use crate::chatlist::Chatlist;
1212
use crate::constants;
@@ -351,7 +351,7 @@ async fn test_subject_in_group() -> Result<()> {
351351
let mut tcm = TestContextManager::new();
352352
let t = tcm.alice().await;
353353
let bob = tcm.bob().await;
354-
let group_id = chat::create_group_chat(&t, "groupname").await.unwrap();
354+
let group_id = chat::create_group(&t, "groupname").await.unwrap();
355355
let bob_contact_id = t.add_or_lookup_contact_id(&bob).await;
356356
chat::add_contact_to_chat(&t, group_id, bob_contact_id).await?;
357357

@@ -753,7 +753,7 @@ async fn test_remove_member_bcc() -> Result<()> {
753753
let charlie_contact = Contact::get_by_id(alice, charlie_id).await?;
754754
let charlie_addr = charlie_contact.get_addr();
755755

756-
let alice_chat_id = create_group_chat(alice, "foo").await?;
756+
let alice_chat_id = create_group(alice, "foo").await?;
757757
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
758758
add_contact_to_chat(alice, alice_chat_id, charlie_id).await?;
759759
send_text_msg(alice, alice_chat_id, "Creating a group".to_string()).await?;

0 commit comments

Comments
 (0)