Skip to content

Commit 85ec8ce

Browse files
committed
feat: Get rid of MessageState::{OutPreparing, OutMdnRcvd} in the db
`OutPreparing` is deprecated since 2024-12-07, replace it with `OutDraft` to let the user review such messages if any. `OutMdnRcvd` is not used in the db for new messages since a30c6ae, `OutDelivered` is stored instead.
1 parent 942172a commit 85ec8ce

9 files changed

Lines changed: 21 additions & 64 deletions

File tree

deltachat-ffi/deltachat.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4020,8 +4020,6 @@ int dc_msg_get_viewtype (const dc_msg_t* msg);
40204020
* Marked as read on IMAP and MDN may be sent. Use dc_markseen_msgs() to mark messages as being seen.
40214021
*
40224022
* Outgoing message states:
4023-
* - @ref DC_STATE_OUT_PREPARING - For files which need time to be prepared before they can be sent,
4024-
* the message enters this state before @ref DC_STATE_OUT_PENDING. Deprecated.
40254023
* - @ref DC_STATE_OUT_DRAFT - Message saved as draft using dc_set_draft()
40264024
* - @ref DC_STATE_OUT_PENDING - The user has pressed the "send" button but the
40274025
* message is not yet sent and is pending in some way. Maybe we're offline (no checkmark).
@@ -5604,13 +5602,6 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
56045602
*/
56055603
#define DC_STATE_IN_SEEN 16
56065604

5607-
/**
5608-
* Outgoing message being prepared. See dc_msg_get_state() for details.
5609-
*
5610-
* @deprecated 2024-12-07
5611-
*/
5612-
#define DC_STATE_OUT_PREPARING 18
5613-
56145605
/**
56155606
* Outgoing message drafted. See dc_msg_get_state() for details.
56165607
*/

deltachat-ffi/src/lot.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ pub enum LotState {
230230
MsgInFresh = 10,
231231
MsgInNoticed = 13,
232232
MsgInSeen = 16,
233-
MsgOutPreparing = 18,
234233
MsgOutDraft = 19,
235234
MsgOutPending = 20,
236235
MsgOutFailed = 24,
@@ -246,7 +245,6 @@ impl From<MessageState> for LotState {
246245
InFresh => LotState::MsgInFresh,
247246
InNoticed => LotState::MsgInNoticed,
248247
InSeen => LotState::MsgInSeen,
249-
OutPreparing => LotState::MsgOutPreparing,
250248
OutDraft => LotState::MsgOutDraft,
251249
OutPending => LotState::MsgOutPending,
252250
OutFailed => LotState::MsgOutFailed,

deltachat-rpc-client/src/deltachat_rpc_client/const.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class MessageState(IntEnum):
190190
IN_FRESH = 10
191191
IN_NOTICED = 13
192192
IN_SEEN = 16
193-
OUT_PREPARING = 18
194193
OUT_DRAFT = 19
195194
OUT_PENDING = 20
196195
OUT_FAILED = 24

python/src/deltachat/chat.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,6 @@ def send_msg(self, msg: Message) -> Message:
271271
sent out. This is the same object as was passed in, which
272272
has been modified with the new state of the core.
273273
"""
274-
if msg.is_out_preparing():
275-
assert msg.id != 0
276-
# get a fresh copy of dc_msg, the core needs it
277-
maybe_msg = Message.from_db(self.account, msg.id)
278-
if maybe_msg is not None:
279-
msg = maybe_msg
280-
else:
281-
raise ValueError("message does not exist")
282-
283274
sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg)
284275
if sent_id == 0:
285276
raise ValueError("message could not be sent")
@@ -333,26 +324,6 @@ def send_image(self, path):
333324
raise ValueError("message could not be sent")
334325
return Message.from_db(self.account, sent_id)
335326

336-
def send_prepared(self, message):
337-
"""send a previously prepared message.
338-
339-
:param message: a :class:`Message` instance previously returned by
340-
:meth:`prepare_file`.
341-
:raises ValueError: if message can not be sent.
342-
:returns: a :class:`deltachat.message.Message` instance as sent out.
343-
"""
344-
assert message.id != 0 and message.is_out_preparing()
345-
# get a fresh copy of dc_msg, the core needs it
346-
msg = Message.from_db(self.account, message.id)
347-
348-
# pass 0 as chat-id because core-docs say it's ok when out-preparing
349-
sent_id = lib.dc_send_msg(self.account._dc_context, 0, msg._dc_msg)
350-
if sent_id == 0:
351-
raise ValueError("message could not be sent")
352-
assert sent_id == msg.id
353-
# modify message in place to avoid bad state for the caller
354-
msg._dc_msg = Message.from_db(self.account, sent_id)._dc_msg
355-
356327
def set_draft(self, message):
357328
"""set message as draft.
358329

python/src/deltachat/message.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,12 @@ def is_in_seen(self):
351351
def is_outgoing(self):
352352
"""Return True if Message is outgoing."""
353353
return lib.dc_msg_get_state(self._dc_msg) in (
354-
const.DC_STATE_OUT_PREPARING,
355354
const.DC_STATE_OUT_PENDING,
356355
const.DC_STATE_OUT_FAILED,
357356
const.DC_STATE_OUT_MDN_RCVD,
358357
const.DC_STATE_OUT_DELIVERED,
359358
)
360359

361-
def is_out_preparing(self):
362-
"""Return True if Message is outgoing, but its file is being prepared."""
363-
return self._msgstate == const.DC_STATE_OUT_PREPARING
364-
365360
def is_out_pending(self):
366361
"""Return True if Message is outgoing, but is pending (no single checkmark)."""
367362
return self._msgstate == const.DC_STATE_OUT_PENDING

src/chat.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ pub async fn send_msg(context: &Context, chat_id: ChatId, msg: &mut Message) ->
26252625
"chat_id cannot be a special chat: {chat_id}"
26262626
);
26272627

2628-
if msg.state != MessageState::Undefined && msg.state != MessageState::OutPreparing {
2628+
if msg.state != MessageState::Undefined {
26292629
msg.param.remove(Param::GuaranteeE2ee);
26302630
msg.param.remove(Param::ForcePlaintext);
26312631
// create_send_msg_jobs() will update `param` in the db.
@@ -2733,10 +2733,7 @@ async fn prepare_send_msg(
27332733
None
27342734
};
27352735

2736-
if matches!(
2737-
msg.state,
2738-
MessageState::Undefined | MessageState::OutPreparing
2739-
)
2736+
if msg.state == MessageState::Undefined
27402737
// Legacy SecureJoin "v*-request" messages are unencrypted.
27412738
&& msg.param.get_cmd() != SystemMessage::SecurejoinMessage
27422739
&& chat.is_encrypted(context).await?
@@ -2949,8 +2946,8 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
29492946
UPDATE msgs SET
29502947
timestamp=(
29512948
SELECT MAX(timestamp) FROM msgs WHERE
2952-
-- From `InFresh` to `OutMdnRcvd` inclusive except `OutDraft`.
2953-
state IN(10,13,16,18,20,24,26,28) AND
2949+
-- From `InFresh` to `OutDelivered` inclusive, except `OutDraft`.
2950+
state IN(10,13,16,18,20,24,26) AND
29542951
hidden IN(0,1) AND
29552952
chat_id=?
29562953
),

src/message.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,13 +1389,8 @@ pub enum MessageState {
13891389
/// IMAP and MDN may be sent.
13901390
InSeen = 16,
13911391

1392-
/// For files which need time to be prepared before they can be
1393-
/// sent, the message enters this state before
1394-
/// OutPending.
1395-
///
1396-
/// Deprecated 2024-12-07.
1397-
OutPreparing = 18,
1398-
1392+
// Deprecated 2024-12-07. Removed 2026-04.
1393+
// OutPreparing = 18,
13991394
/// Message saved as draft.
14001395
OutDraft = 19,
14011396

@@ -1428,7 +1423,6 @@ impl std::fmt::Display for MessageState {
14281423
Self::InFresh => "Fresh",
14291424
Self::InNoticed => "Noticed",
14301425
Self::InSeen => "Seen",
1431-
Self::OutPreparing => "Preparing",
14321426
Self::OutDraft => "Draft",
14331427
Self::OutPending => "Pending",
14341428
Self::OutFailed => "Failed",
@@ -1445,7 +1439,7 @@ impl MessageState {
14451439
use MessageState::*;
14461440
matches!(
14471441
self,
1448-
OutPreparing | OutPending | OutDelivered | OutMdnRcvd // OutMdnRcvd can still fail because it could be a group message and only some recipients failed.
1442+
OutPending | OutDelivered | OutMdnRcvd // OutMdnRcvd can still fail because it could be a group message and only some recipients failed.
14491443
)
14501444
}
14511445

@@ -1454,7 +1448,7 @@ impl MessageState {
14541448
use MessageState::*;
14551449
matches!(
14561450
self,
1457-
OutPreparing | OutDraft | OutPending | OutFailed | OutDelivered | OutMdnRcvd
1451+
OutDraft | OutPending | OutFailed | OutDelivered | OutMdnRcvd
14581452
)
14591453
}
14601454

src/sql/migrations.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,18 @@ ALTER TABLE contacts ADD COLUMN name_normalized TEXT;
23602360
.await?;
23612361
}
23622362

2363+
inc_and_check(&mut migration_version, 151)?;
2364+
if dbversion < migration_version {
2365+
sql.execute_migration(
2366+
"
2367+
UPDATE msgs SET state=26 WHERE state=28; -- Change OutMdnRcvd to OutDelivered.
2368+
UPDATE msgs SET state=19 WHERE state=18; -- Change OutPreparing to OutDraft.
2369+
",
2370+
migration_version,
2371+
)
2372+
.await?;
2373+
}
2374+
23632375
let new_version = sql
23642376
.get_raw_config_int(VERSION_CFG)
23652377
.await?

src/webxdc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl Context {
544544

545545
let send_now = !matches!(
546546
instance.state,
547-
MessageState::Undefined | MessageState::OutPreparing | MessageState::OutDraft
547+
MessageState::Undefined | MessageState::OutDraft
548548
);
549549

550550
status_update.uid = Some(create_id());

0 commit comments

Comments
 (0)