mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
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:
25
src/chat.rs
25
src/chat.rs
@@ -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*/
|
/*this also makes sure, not contacts are added to special or normal chats*/
|
||||||
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
ensure!(
|
ensure!(
|
||||||
real_group_exists(context, chat_id).await,
|
chat.typ == Chattype::Group,
|
||||||
"{} is not a group where one can add members",
|
"{} is not a group where one can add members",
|
||||||
chat_id
|
chat_id
|
||||||
);
|
);
|
||||||
@@ -2352,22 +2352,6 @@ pub(crate) async fn add_contact_to_chat_ex(
|
|||||||
Ok(true)
|
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(
|
pub(crate) async fn reset_gossiped_timestamp(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: ChatId,
|
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 */
|
/* 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. */
|
/* 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 {
|
if let Ok(chat) = Chat::load_from_db(context, chat_id).await {
|
||||||
ensure!(!chat.is_mailing_list(), "Mailing lists can't be changed");
|
if chat.typ == Chattype::Group {
|
||||||
if real_group_exists(context, chat_id).await {
|
|
||||||
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 {
|
||||||
emit_event!(
|
emit_event!(
|
||||||
context,
|
context,
|
||||||
@@ -2646,7 +2629,7 @@ pub async fn set_chat_name(
|
|||||||
let chat = Chat::load_from_db(context, chat_id).await?;
|
let chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
let mut msg = Message::default();
|
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 {
|
if chat.name == new_name {
|
||||||
success = true;
|
success = true;
|
||||||
} else if !is_contact_in_chat(context, chat_id, DC_CONTACT_ID_SELF).await {
|
} 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");
|
ensure!(!chat_id.is_special(), "Invalid chat ID");
|
||||||
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
ensure!(
|
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"
|
"Failed to set profile image; group does not exist"
|
||||||
);
|
);
|
||||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||||
|
|||||||
Reference in New Issue
Block a user