mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 21:36:29 +03:00
fix: Add Chat-Group-Name-Timestamp header and use it to update group names (#6412)
Add "Chat-Group-Name-Timestamp" message header and use the last-write-wins logic when updating group names (similar to group member timestamps). Note that if the "Chat-Group-Name-Changed" header is absent though, we don't add a system message (`MsgGrpNameChangedBy`) because we don't want to blame anyone.
This commit is contained in:
@@ -2411,9 +2411,19 @@ async fn apply_group_changes(
|
||||
}
|
||||
|
||||
better_msg = Some(stock_str::msg_add_member_local(context, added_addr, from_id).await);
|
||||
} else if let Some(old_name) = mime_parser
|
||||
}
|
||||
|
||||
let group_name_timestamp = mime_parser
|
||||
.get_header(HeaderDef::ChatGroupNameTimestamp)
|
||||
.and_then(|s| s.parse::<i64>().ok());
|
||||
if let Some(old_name) = mime_parser
|
||||
.get_header(HeaderDef::ChatGroupNameChanged)
|
||||
.map(|s| s.trim())
|
||||
.or(match group_name_timestamp {
|
||||
Some(0) => None,
|
||||
Some(_) => Some(chat.name.as_str()),
|
||||
None => None,
|
||||
})
|
||||
{
|
||||
if let Some(grpname) = mime_parser
|
||||
.get_header(HeaderDef::ChatGroupName)
|
||||
@@ -2422,13 +2432,15 @@ async fn apply_group_changes(
|
||||
{
|
||||
let grpname = &sanitize_single_line(grpname);
|
||||
let old_name = &sanitize_single_line(old_name);
|
||||
if chat_id
|
||||
.update_timestamp(
|
||||
context,
|
||||
Param::GroupNameTimestamp,
|
||||
mime_parser.timestamp_sent,
|
||||
)
|
||||
.await?
|
||||
|
||||
let chat_group_name_timestamp =
|
||||
chat.param.get_i64(Param::GroupNameTimestamp).unwrap_or(0);
|
||||
let group_name_timestamp = group_name_timestamp.unwrap_or(mime_parser.timestamp_sent);
|
||||
// To provide group name consistency, compare names if timestamps are equal.
|
||||
if (chat_group_name_timestamp, grpname) < (group_name_timestamp, old_name)
|
||||
&& chat_id
|
||||
.update_timestamp(context, Param::GroupNameTimestamp, group_name_timestamp)
|
||||
.await?
|
||||
{
|
||||
info!(context, "Updating grpname for chat {chat_id}.");
|
||||
context
|
||||
@@ -2437,10 +2449,18 @@ async fn apply_group_changes(
|
||||
.await?;
|
||||
send_event_chat_modified = true;
|
||||
}
|
||||
|
||||
better_msg = Some(stock_str::msg_grp_name(context, old_name, grpname, from_id).await);
|
||||
if mime_parser
|
||||
.get_header(HeaderDef::ChatGroupNameChanged)
|
||||
.is_some()
|
||||
{
|
||||
better_msg.get_or_insert(
|
||||
stock_str::msg_grp_name(context, old_name, grpname, from_id).await,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if let Some(value) = mime_parser.get_header(HeaderDef::ChatContent) {
|
||||
}
|
||||
|
||||
if let (Some(value), None) = (mime_parser.get_header(HeaderDef::ChatContent), &better_msg) {
|
||||
if value == "group-avatar-changed" {
|
||||
if let Some(avatar_action) = &mime_parser.group_avatar {
|
||||
// this is just an explicit message containing the group-avatar,
|
||||
|
||||
Reference in New Issue
Block a user