Allow broadcastlist avatars

This commit is contained in:
Hocuri
2023-10-17 16:36:57 +02:00
parent d4c90e892b
commit 2ea8a6ea9a
3 changed files with 30 additions and 8 deletions

View File

@@ -1591,7 +1591,7 @@ impl Chat {
); );
bail!("Cannot set message, contact for {} not found.", self.id); bail!("Cannot set message, contact for {} not found.", self.id);
} }
} else if self.typ == Chattype::Group } else if (self.typ == Chattype::Group || self.typ == Chattype::Broadcast)
&& self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1 && self.param.get_int(Param::Unpromoted).unwrap_or_default() == 1
{ {
msg.param.set_int(Param::AttachGroupImage, 1); msg.param.set_int(Param::AttachGroupImage, 1);
@@ -3427,12 +3427,8 @@ pub async fn set_chat_profile_image(
) -> Result<()> { ) -> Result<()> {
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!(
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! */ /* we should respect this - whatever we send to the group, it gets discarded anyway! */
if !is_contact_in_chat(context, chat_id, ContactId::SELF).await? { if !chat.is_self_in_chat(context).await? {
context.emit_event(EventType::ErrorSelfNotInGroup( context.emit_event(EventType::ErrorSelfNotInGroup(
"Cannot set chat profile image; self not in group.".into(), "Cannot set chat profile image; self not in group.".into(),
)); ));
@@ -3453,7 +3449,7 @@ pub async fn set_chat_profile_image(
msg.text = stock_str::msg_grp_img_changed(context, ContactId::SELF).await; msg.text = stock_str::msg_grp_img_changed(context, ContactId::SELF).await;
} }
chat.update_param(context).await?; chat.update_param(context).await?;
if chat.is_promoted() && !chat.is_mailing_list() { if chat.is_promoted() && !chat.is_mailing_list() && chat.typ != Chattype::Broadcast {
msg.id = send_msg(context, chat_id, &mut msg).await?; msg.id = send_msg(context, chat_id, &mut msg).await?;
context.emit_msgs_changed(chat_id, msg.id); context.emit_msgs_changed(chat_id, msg.id);
} }

View File

@@ -119,7 +119,7 @@ pub enum Param {
/// For MDN-sending job /// For MDN-sending job
MsgId = b'I', MsgId = b'I',
/// For Groups /// For Groups and Broadcast Lists
/// ///
/// An unpromoted group has not had any messages sent to it and thus only exists on the /// An unpromoted group has not had any messages sent to it and thus only exists on the
/// creator's device. Any changes made to an unpromoted group do not need to send /// creator's device. Any changes made to an unpromoted group do not need to send

View File

@@ -2050,6 +2050,28 @@ async fn apply_mailinglist_changes(
if chat.typ != Chattype::Mailinglist { if chat.typ != Chattype::Mailinglist {
return Ok(()); return Ok(());
} }
let mut send_event_chat_modified = false;
if let Some(avatar_action) = &mime_parser.group_avatar {
info!(context, "Mailinglist-avatar change for {chat_id}.");
if chat
.param
.update_timestamp(Param::AvatarTimestamp, sent_timestamp)?
{
match avatar_action {
AvatarAction::Change(profile_image) => {
chat.param.set(Param::ProfileImage, profile_image);
}
AvatarAction::Delete => {
chat.param.remove(Param::ProfileImage);
}
};
chat.update_param(context).await?;
send_event_chat_modified = true;
}
}
let listid = &chat.grpid; let listid = &chat.grpid;
let new_name = compute_mailinglist_name(mailinglist_header, listid, mime_parser); let new_name = compute_mailinglist_name(mailinglist_header, listid, mime_parser);
@@ -2063,6 +2085,10 @@ async fn apply_mailinglist_changes(
.sql .sql
.execute("UPDATE chats SET name=? WHERE id=?;", (new_name, chat_id)) .execute("UPDATE chats SET name=? WHERE id=?;", (new_name, chat_id))
.await?; .await?;
send_event_chat_modified = true;
}
if send_event_chat_modified {
context.emit_event(EventType::ChatModified(chat_id)); context.emit_event(EventType::ChatModified(chat_id));
} }