mirror of
https://github.com/chatmail/core.git
synced 2026-10-01 18:50:39 +03:00
fix: Don't make message OutDelivered after successful resending to new broadcast member
Follow-up to 970222f. We shouldn't update the message state to `OutDelivered` if message sending
failed before and the message was re-sent successfully only to a new broadcast member.
This commit is contained in:
+18
-3
@@ -140,8 +140,20 @@ SELECT ?1, rfc724_mid, pre_rfc724_mid, timestamp, ?, ? FROM msgs WHERE id=?1
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn set_delivered(self, context: &Context) -> Result<()> {
|
||||
update_msg_state(context, self, MessageState::OutDelivered).await?;
|
||||
/// Returns whether the message state is updated to `OutDelivered`.
|
||||
pub(crate) async fn set_delivered(self, context: &Context) -> Result<bool> {
|
||||
if context
|
||||
.sql
|
||||
.execute(
|
||||
// Only update `OutPending` i.e. if the message is (re-)sent to all chat members.
|
||||
"UPDATE msgs SET state=?, error='' WHERE id=? AND state=?",
|
||||
(MessageState::OutDelivered, self, MessageState::OutPending),
|
||||
)
|
||||
.await?
|
||||
== 0
|
||||
{
|
||||
return Ok(false);
|
||||
}
|
||||
let chat_id: Option<ChatId> = context
|
||||
.sql
|
||||
.query_get_value("SELECT chat_id FROM msgs WHERE id=?", (self,))
|
||||
@@ -153,7 +165,7 @@ SELECT ?1, rfc724_mid, pre_rfc724_mid, timestamp, ?, ? FROM msgs WHERE id=?1
|
||||
if let Some(chat_id) = chat_id {
|
||||
chatlist_events::emit_chatlist_item_changed(context, chat_id);
|
||||
}
|
||||
Ok(())
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Bad evil escape hatch.
|
||||
@@ -1414,6 +1426,9 @@ pub enum MessageState {
|
||||
/// The user has pressed the "send" button but the message is not
|
||||
/// yet sent and is pending in some way. Maybe we're offline (no
|
||||
/// checkmark).
|
||||
///
|
||||
/// This state means that the message is being (re-)sent to all chat members. It shalln't be
|
||||
/// used e.g. for resending only to a new broadcast member.
|
||||
OutPending = 20,
|
||||
|
||||
/// *Unrecoverable* error (*recoverable* errors result in pending
|
||||
|
||||
Reference in New Issue
Block a user