rename mailinglists, remove real_group_exists()

renaming mailing lists and setting mailinglists images
(possible locally, but not synced)
was blocked because the function real_group_exists() checked
the chattype on a numerically.

it is not 100% clear to me,
why this function exist at all,
it just checks if a record with type=120 (group) exists under the given id -
this is the same as loading the chat and check chat.typ afterwards.

might be a premature optimisation relict from core-c
or made some error handling easier there.
This commit is contained in:
B. Petersen
2021-02-09 00:35:51 +01:00
committed by bjoern
parent a2d64cbb4c
commit 5922069b77

View File

@@ -2273,7 +2273,7 @@ pub(crate) async fn add_contact_to_chat_ex(
/*this also makes sure, not contacts are added to special or normal chats*/
let mut chat = Chat::load_from_db(context, chat_id).await?;
ensure!(
real_group_exists(context, chat_id).await,
chat.typ == Chattype::Group,
"{} is not a group where one can add members",
chat_id
);
@@ -2352,22 +2352,6 @@ pub(crate) async fn add_contact_to_chat_ex(
Ok(true)
}
async fn real_group_exists(context: &Context, chat_id: ChatId) -> bool {
// check if a group or a verified group exists under the given ID
if !context.sql.is_open().await || chat_id.is_special() {
return false;
}
context
.sql
.exists(
"SELECT id FROM chats WHERE id=? AND type=120;",
paramsv![chat_id],
)
.await
.unwrap_or_default()
}
pub(crate) async fn reset_gossiped_timestamp(
context: &Context,
chat_id: ChatId,
@@ -2538,8 +2522,7 @@ pub async fn remove_contact_from_chat(
/* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */
/* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */
if let Ok(chat) = Chat::load_from_db(context, chat_id).await {
ensure!(!chat.is_mailing_list(), "Mailing lists can't be changed");
if real_group_exists(context, chat_id).await {
if chat.typ == Chattype::Group {
if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF).await {
emit_event!(
context,
@@ -2646,7 +2629,7 @@ pub async fn set_chat_name(
let chat = Chat::load_from_db(context, chat_id).await?;
let mut msg = Message::default();
if real_group_exists(context, chat_id).await {
if chat.typ == Chattype::Group || chat.typ == Chattype::Mailinglist {
if chat.name == new_name {
success = true;
} else if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF).await {
@@ -2713,7 +2696,7 @@ pub async fn set_chat_profile_image(
ensure!(!chat_id.is_special(), "Invalid chat ID");
let mut chat = Chat::load_from_db(context, chat_id).await?;
ensure!(
real_group_exists(context, chat_id).await,
chat.typ == Chattype::Group || chat.typ == Chattype::Mailinglist,
"Failed to set profile image; group does not exist"
);
/* we should respect this - whatever we send to the group, it gets discarded anyway! */