mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
run cargo fmt
This commit is contained in:
@@ -992,318 +992,297 @@ unsafe fn create_or_lookup_group(
|
||||
}
|
||||
// ok_to_continue = true = 18435049525520518667;
|
||||
if ok_to_continue {
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Name\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
grpname = dc_decode_header_words((*optional_field).fld_value)
|
||||
}
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Member-Removed\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrRemoveFromGrp = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 5;
|
||||
let left_group: libc::c_int = (dc_lookup_contact_id_by_addr(context, X_MrRemoveFromGrp)
|
||||
== from_id as libc::c_uint)
|
||||
as libc::c_int;
|
||||
better_msg = context.stock_system_msg(
|
||||
if 0 != left_group {
|
||||
StockMessage::MsgGroupLeft
|
||||
} else {
|
||||
StockMessage::MsgDelMember
|
||||
},
|
||||
as_str(X_MrRemoveFromGrp),
|
||||
"",
|
||||
from_id as u32,
|
||||
)
|
||||
} else {
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Name\x00" as *const u8 as *const libc::c_char,
|
||||
b"Chat-Group-Member-Added\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
grpname = dc_decode_header_words((*optional_field).fld_value)
|
||||
}
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Member-Removed\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrRemoveFromGrp = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 5;
|
||||
let left_group: libc::c_int =
|
||||
(dc_lookup_contact_id_by_addr(context, X_MrRemoveFromGrp)
|
||||
== from_id as libc::c_uint) as libc::c_int;
|
||||
X_MrAddToGrp = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 4;
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrGrpImageChanged = (*optional_field).fld_value
|
||||
}
|
||||
better_msg = context.stock_system_msg(
|
||||
if 0 != left_group {
|
||||
StockMessage::MsgGroupLeft
|
||||
} else {
|
||||
StockMessage::MsgDelMember
|
||||
},
|
||||
as_str(X_MrRemoveFromGrp),
|
||||
StockMessage::MsgAddMember,
|
||||
as_str(X_MrAddToGrp),
|
||||
"",
|
||||
from_id as u32,
|
||||
)
|
||||
} else {
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Member-Added\x00" as *const u8 as *const libc::c_char,
|
||||
b"Chat-Group-Name-Changed\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrAddToGrp = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 4;
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrGrpImageChanged = (*optional_field).fld_value
|
||||
}
|
||||
X_MrGrpNameChanged = 1i32;
|
||||
mime_parser.is_system_message = 2i32;
|
||||
better_msg = context.stock_system_msg(
|
||||
StockMessage::MsgAddMember,
|
||||
as_str(X_MrAddToGrp),
|
||||
"",
|
||||
StockMessage::MsgGrpName,
|
||||
as_str((*optional_field).fld_value),
|
||||
as_str(grpname),
|
||||
from_id as u32,
|
||||
)
|
||||
} else {
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Name-Changed\x00" as *const u8 as *const libc::c_char,
|
||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrGrpNameChanged = 1i32;
|
||||
mime_parser.is_system_message = 2i32;
|
||||
X_MrGrpImageChanged = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 3;
|
||||
better_msg = context.stock_system_msg(
|
||||
StockMessage::MsgGrpName,
|
||||
as_str((*optional_field).fld_value),
|
||||
as_str(grpname),
|
||||
from_id as u32,
|
||||
)
|
||||
} else {
|
||||
optional_field = dc_mimeparser_lookup_optional_field(
|
||||
mime_parser,
|
||||
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
if !optional_field.is_null() {
|
||||
X_MrGrpImageChanged = (*optional_field).fld_value;
|
||||
mime_parser.is_system_message = 3;
|
||||
better_msg = context.stock_system_msg(
|
||||
if strcmp(
|
||||
X_MrGrpImageChanged,
|
||||
b"0\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0
|
||||
{
|
||||
StockMessage::MsgGrpImgDeleted
|
||||
} else {
|
||||
StockMessage::MsgGrpImgChanged
|
||||
},
|
||||
"",
|
||||
"",
|
||||
from_id as u32,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
set_better_msg(mime_parser, &better_msg);
|
||||
chat_id = dc_get_chat_id_by_grpid(
|
||||
context,
|
||||
grpid,
|
||||
&mut chat_id_blocked,
|
||||
&mut chat_id_verified,
|
||||
);
|
||||
if chat_id != 0 as libc::c_uint {
|
||||
if 0 != chat_id_verified
|
||||
&& 0 == check_verified_properties(
|
||||
context,
|
||||
mime_parser,
|
||||
from_id as uint32_t,
|
||||
to_ids,
|
||||
&mut failure_reason,
|
||||
)
|
||||
{
|
||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
||||
}
|
||||
}
|
||||
if chat_id != 0 as libc::c_uint
|
||||
&& 0 == dc_is_contact_in_chat(context, chat_id, from_id as uint32_t)
|
||||
{
|
||||
recreate_member_list = 1
|
||||
}
|
||||
/* check if the group does not exist but should be created */
|
||||
group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
||||
let self_addr = context
|
||||
.sql
|
||||
.get_config(context, "configured_addr")
|
||||
.unwrap_or_default();
|
||||
if chat_id == 0 as libc::c_uint
|
||||
&& 0 == dc_mimeparser_is_mailinglist_message(mime_parser)
|
||||
&& !grpid.is_null()
|
||||
&& !grpname.is_null()
|
||||
&& X_MrRemoveFromGrp.is_null()
|
||||
&& (0 == group_explicitly_left
|
||||
|| !X_MrAddToGrp.is_null() && dc_addr_cmp(&self_addr, as_str(X_MrAddToGrp)))
|
||||
{
|
||||
/*otherwise, a pending "quit" message may pop up*/
|
||||
/*re-create explicitly left groups only if ourself is re-added*/
|
||||
let mut create_verified: libc::c_int = 0;
|
||||
if !dc_mimeparser_lookup_field(mime_parser, "Chat-Verified").is_null() {
|
||||
create_verified = 1;
|
||||
if 0 == check_verified_properties(
|
||||
context,
|
||||
mime_parser,
|
||||
from_id as uint32_t,
|
||||
to_ids,
|
||||
&mut failure_reason,
|
||||
) {
|
||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
||||
}
|
||||
}
|
||||
if 0 == allow_creation {
|
||||
ok_to_continue = false;
|
||||
} else {
|
||||
chat_id = create_group_record(
|
||||
context,
|
||||
grpid,
|
||||
grpname,
|
||||
create_blocked,
|
||||
create_verified,
|
||||
);
|
||||
chat_id_blocked = create_blocked;
|
||||
recreate_member_list = 1;
|
||||
}
|
||||
}
|
||||
// ok_to_continue = false = 281803052766328415
|
||||
if ok_to_continue {
|
||||
/* again, check chat_id */
|
||||
if chat_id <= 9 as libc::c_uint {
|
||||
chat_id = 0 as uint32_t;
|
||||
if 0 != group_explicitly_left {
|
||||
chat_id = 3 as uint32_t
|
||||
} else {
|
||||
create_or_lookup_adhoc_group(
|
||||
context,
|
||||
mime_parser,
|
||||
allow_creation,
|
||||
create_blocked,
|
||||
from_id,
|
||||
to_ids,
|
||||
&mut chat_id,
|
||||
&mut chat_id_blocked,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if !X_MrAddToGrp.is_null() || !X_MrRemoveFromGrp.is_null() {
|
||||
recreate_member_list = 1
|
||||
} else if 0 != X_MrGrpNameChanged
|
||||
&& !grpname.is_null()
|
||||
&& strlen(grpname) < 200
|
||||
{
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET name=? WHERE id=?;",
|
||||
params![as_str(grpname), chat_id as i32],
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
context.call_cb(Event::CHAT_MODIFIED, chat_id as uintptr_t, 0);
|
||||
}
|
||||
}
|
||||
if !X_MrGrpImageChanged.is_null() {
|
||||
let mut ok = 0;
|
||||
let mut grpimage = 0 as *mut libc::c_char;
|
||||
if strcmp(
|
||||
X_MrGrpImageChanged,
|
||||
b"0\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0
|
||||
{
|
||||
StockMessage::MsgGrpImgDeleted
|
||||
} else {
|
||||
StockMessage::MsgGrpImgChanged
|
||||
},
|
||||
"",
|
||||
"",
|
||||
from_id as u32,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
set_better_msg(mime_parser, &better_msg);
|
||||
chat_id =
|
||||
dc_get_chat_id_by_grpid(context, grpid, &mut chat_id_blocked, &mut chat_id_verified);
|
||||
if chat_id != 0 as libc::c_uint {
|
||||
if 0 != chat_id_verified
|
||||
&& 0 == check_verified_properties(
|
||||
context,
|
||||
mime_parser,
|
||||
from_id as uint32_t,
|
||||
to_ids,
|
||||
&mut failure_reason,
|
||||
)
|
||||
{
|
||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
||||
}
|
||||
}
|
||||
if chat_id != 0 as libc::c_uint
|
||||
&& 0 == dc_is_contact_in_chat(context, chat_id, from_id as uint32_t)
|
||||
{
|
||||
recreate_member_list = 1
|
||||
}
|
||||
/* check if the group does not exist but should be created */
|
||||
group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
||||
let self_addr = context
|
||||
.sql
|
||||
.get_config(context, "configured_addr")
|
||||
.unwrap_or_default();
|
||||
if chat_id == 0 as libc::c_uint
|
||||
&& 0 == dc_mimeparser_is_mailinglist_message(mime_parser)
|
||||
&& !grpid.is_null()
|
||||
&& !grpname.is_null()
|
||||
&& X_MrRemoveFromGrp.is_null()
|
||||
&& (0 == group_explicitly_left
|
||||
|| !X_MrAddToGrp.is_null() && dc_addr_cmp(&self_addr, as_str(X_MrAddToGrp)))
|
||||
{
|
||||
/*otherwise, a pending "quit" message may pop up*/
|
||||
/*re-create explicitly left groups only if ourself is re-added*/
|
||||
let mut create_verified: libc::c_int = 0;
|
||||
if !dc_mimeparser_lookup_field(mime_parser, "Chat-Verified").is_null() {
|
||||
create_verified = 1;
|
||||
if 0 == check_verified_properties(
|
||||
context,
|
||||
mime_parser,
|
||||
from_id as uint32_t,
|
||||
to_ids,
|
||||
&mut failure_reason,
|
||||
) {
|
||||
dc_mimeparser_repl_msg_by_error(mime_parser, failure_reason);
|
||||
}
|
||||
}
|
||||
if 0 == allow_creation {
|
||||
ok_to_continue = false;
|
||||
} else {
|
||||
chat_id =
|
||||
create_group_record(context, grpid, grpname, create_blocked, create_verified);
|
||||
chat_id_blocked = create_blocked;
|
||||
recreate_member_list = 1;
|
||||
}
|
||||
}
|
||||
// ok_to_continue = false = 281803052766328415
|
||||
if ok_to_continue {
|
||||
/* again, check chat_id */
|
||||
if chat_id <= 9 as libc::c_uint {
|
||||
chat_id = 0 as uint32_t;
|
||||
if 0 != group_explicitly_left {
|
||||
chat_id = 3 as uint32_t
|
||||
} else {
|
||||
create_or_lookup_adhoc_group(
|
||||
context,
|
||||
mime_parser,
|
||||
allow_creation,
|
||||
create_blocked,
|
||||
from_id,
|
||||
to_ids,
|
||||
&mut chat_id,
|
||||
&mut chat_id_blocked,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if !X_MrAddToGrp.is_null() || !X_MrRemoveFromGrp.is_null() {
|
||||
recreate_member_list = 1
|
||||
} else if 0 != X_MrGrpNameChanged && !grpname.is_null() && strlen(grpname) < 200 {
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET name=? WHERE id=?;",
|
||||
params![as_str(grpname), chat_id as i32],
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
context.call_cb(Event::CHAT_MODIFIED, chat_id as uintptr_t, 0);
|
||||
}
|
||||
}
|
||||
if !X_MrGrpImageChanged.is_null() {
|
||||
let mut ok = 0;
|
||||
let mut grpimage = 0 as *mut libc::c_char;
|
||||
if strcmp(
|
||||
X_MrGrpImageChanged,
|
||||
b"0\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0
|
||||
{
|
||||
ok = 1
|
||||
} else {
|
||||
for part in &mut mime_parser.parts {
|
||||
if part.type_0 == 20 {
|
||||
grpimage = part
|
||||
.param
|
||||
.get(Param::File)
|
||||
.map(|s| s.strdup())
|
||||
.unwrap_or_else(|| std::ptr::null_mut());
|
||||
ok = 1
|
||||
} else {
|
||||
for part in &mut mime_parser.parts {
|
||||
if part.type_0 == 20 {
|
||||
grpimage = part
|
||||
.param
|
||||
.get(Param::File)
|
||||
.map(|s| s.strdup())
|
||||
.unwrap_or_else(|| std::ptr::null_mut());
|
||||
ok = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 != ok {
|
||||
let chat = dc_chat_new(context);
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"New group image set to {}.",
|
||||
if !grpimage.is_null() {
|
||||
"DELETED".to_string()
|
||||
} else {
|
||||
to_string(grpimage)
|
||||
},
|
||||
);
|
||||
dc_chat_load_from_db(chat, chat_id);
|
||||
if grpimage.is_null() {
|
||||
(*chat).param.remove(Param::ProfileImage);
|
||||
} else {
|
||||
(*chat).param.set(Param::ProfileImage, as_str(grpimage));
|
||||
}
|
||||
dc_chat_update_param(chat);
|
||||
dc_chat_unref(chat);
|
||||
free(grpimage as *mut libc::c_void);
|
||||
send_EVENT_CHAT_MODIFIED = 1
|
||||
}
|
||||
}
|
||||
if 0 != recreate_member_list {
|
||||
let skip = if !X_MrRemoveFromGrp.is_null() {
|
||||
X_MrRemoveFromGrp
|
||||
} else {
|
||||
0 as *mut libc::c_char
|
||||
};
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats_contacts WHERE chat_id=?;",
|
||||
params![chat_id as i32],
|
||||
)
|
||||
.ok();
|
||||
if skip.is_null() || !dc_addr_cmp(&self_addr, as_str(skip)) {
|
||||
dc_add_to_chat_contacts_table(context, chat_id, 1);
|
||||
}
|
||||
if from_id > 9 {
|
||||
if !dc_addr_equals_contact(context, &self_addr, from_id as u32)
|
||||
&& (skip.is_null()
|
||||
|| !dc_addr_equals_contact(
|
||||
context,
|
||||
to_string(skip),
|
||||
from_id as u32,
|
||||
))
|
||||
{
|
||||
dc_add_to_chat_contacts_table(
|
||||
context,
|
||||
chat_id,
|
||||
from_id as uint32_t,
|
||||
);
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while i < to_ids_cnt {
|
||||
let to_id = dc_array_get_id(to_ids, i as size_t);
|
||||
if !dc_addr_equals_contact(context, &self_addr, to_id)
|
||||
&& (skip.is_null()
|
||||
|| !dc_addr_equals_contact(context, to_string(skip), to_id))
|
||||
{
|
||||
dc_add_to_chat_contacts_table(context, chat_id, to_id);
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
send_EVENT_CHAT_MODIFIED = 1;
|
||||
dc_reset_gossiped_timestamp(context, chat_id);
|
||||
}
|
||||
if 0 != send_EVENT_CHAT_MODIFIED {
|
||||
context.call_cb(
|
||||
Event::CHAT_MODIFIED,
|
||||
chat_id as uintptr_t,
|
||||
0 as uintptr_t,
|
||||
);
|
||||
}
|
||||
/* check the number of receivers -
|
||||
the only critical situation is if the user hits "Reply" instead of "Reply all" in a non-messenger-client */
|
||||
if to_ids_cnt == 1 && mime_parser.is_send_by_messenger == 0 {
|
||||
let is_contact_cnt: libc::c_int =
|
||||
dc_get_chat_contact_cnt(context, chat_id);
|
||||
if is_contact_cnt > 3 {
|
||||
/* to_ids_cnt==1 may be "From: A, To: B, SELF" as SELF is not counted in to_ids_cnt. So everything up to 3 is no error. */
|
||||
chat_id = 0 as uint32_t;
|
||||
create_or_lookup_adhoc_group(
|
||||
context,
|
||||
mime_parser,
|
||||
allow_creation,
|
||||
create_blocked,
|
||||
from_id,
|
||||
to_ids,
|
||||
&mut chat_id,
|
||||
&mut chat_id_blocked,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if 0 != ok {
|
||||
let chat = dc_chat_new(context);
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
"New group image set to {}.",
|
||||
if !grpimage.is_null() {
|
||||
"DELETED".to_string()
|
||||
} else {
|
||||
to_string(grpimage)
|
||||
},
|
||||
);
|
||||
dc_chat_load_from_db(chat, chat_id);
|
||||
if grpimage.is_null() {
|
||||
(*chat).param.remove(Param::ProfileImage);
|
||||
} else {
|
||||
(*chat).param.set(Param::ProfileImage, as_str(grpimage));
|
||||
}
|
||||
dc_chat_update_param(chat);
|
||||
dc_chat_unref(chat);
|
||||
free(grpimage as *mut libc::c_void);
|
||||
send_EVENT_CHAT_MODIFIED = 1
|
||||
}
|
||||
}
|
||||
if 0 != recreate_member_list {
|
||||
let skip = if !X_MrRemoveFromGrp.is_null() {
|
||||
X_MrRemoveFromGrp
|
||||
} else {
|
||||
0 as *mut libc::c_char
|
||||
};
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats_contacts WHERE chat_id=?;",
|
||||
params![chat_id as i32],
|
||||
)
|
||||
.ok();
|
||||
if skip.is_null() || !dc_addr_cmp(&self_addr, as_str(skip)) {
|
||||
dc_add_to_chat_contacts_table(context, chat_id, 1);
|
||||
}
|
||||
if from_id > 9 {
|
||||
if !dc_addr_equals_contact(context, &self_addr, from_id as u32)
|
||||
&& (skip.is_null()
|
||||
|| !dc_addr_equals_contact(
|
||||
context,
|
||||
to_string(skip),
|
||||
from_id as u32,
|
||||
))
|
||||
{
|
||||
dc_add_to_chat_contacts_table(context, chat_id, from_id as uint32_t);
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
while i < to_ids_cnt {
|
||||
let to_id = dc_array_get_id(to_ids, i as size_t);
|
||||
if !dc_addr_equals_contact(context, &self_addr, to_id)
|
||||
&& (skip.is_null()
|
||||
|| !dc_addr_equals_contact(context, to_string(skip), to_id))
|
||||
{
|
||||
dc_add_to_chat_contacts_table(context, chat_id, to_id);
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
send_EVENT_CHAT_MODIFIED = 1;
|
||||
dc_reset_gossiped_timestamp(context, chat_id);
|
||||
}
|
||||
if 0 != send_EVENT_CHAT_MODIFIED {
|
||||
context.call_cb(Event::CHAT_MODIFIED, chat_id as uintptr_t, 0 as uintptr_t);
|
||||
}
|
||||
/* check the number of receivers -
|
||||
the only critical situation is if the user hits "Reply" instead of "Reply all" in a non-messenger-client */
|
||||
if to_ids_cnt == 1 && mime_parser.is_send_by_messenger == 0 {
|
||||
let is_contact_cnt: libc::c_int = dc_get_chat_contact_cnt(context, chat_id);
|
||||
if is_contact_cnt > 3 {
|
||||
/* to_ids_cnt==1 may be "From: A, To: B, SELF" as SELF is not counted in to_ids_cnt. So everything up to 3 is no error. */
|
||||
chat_id = 0 as uint32_t;
|
||||
create_or_lookup_adhoc_group(
|
||||
context,
|
||||
mime_parser,
|
||||
allow_creation,
|
||||
create_blocked,
|
||||
from_id,
|
||||
to_ids,
|
||||
&mut chat_id,
|
||||
&mut chat_id_blocked,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(grpid as *mut libc::c_void);
|
||||
|
||||
Reference in New Issue
Block a user