mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
feat!: fire MsgRead on subsequent MDNs
BREAKING CHANGE: previously this event only fired
if message state really did just transition
from `DC_STATE_OUT_DELIVERED` to `DC_STATE_OUT_MDN_RCVD`.
Now this is only the case for `MsgRead` events
that have the newly added `first_time == true`.
Closes https://github.com/deltachat/deltachat-desktop/issues/5220.
This is also useful for channels
as it facilitates updating the post (message) read count live.
Despite the fact that it's a breaking change,
this should not be problematic in most cases
because clients mostly use this event as an "it's time to reload"
indicator.
There is a case in Delta Chat Desktop where and adjustment
will be needed:
d1fbb30979/packages/frontend/src/stores/messagelist.ts (L119-L123)
It seems that the message state could later transition
to `DC_STATE_OUT_FAILED`, so we should not uncoditionally set it
to `DC_STATE_OUT_MDN_RCVD`.
Note that this does not expose `first_time` in CFFI.
This commit is contained in:
@@ -192,8 +192,7 @@ pub enum EventType {
|
|||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A single message is read by the receiver. State changed from DC_STATE_OUT_DELIVERED to
|
/// A single message is read by a receiver.
|
||||||
/// DC_STATE_OUT_MDN_RCVD, see `Message.state`.
|
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
MsgRead {
|
MsgRead {
|
||||||
/// ID of the chat which the message belongs to.
|
/// ID of the chat which the message belongs to.
|
||||||
@@ -201,6 +200,12 @@ pub enum EventType {
|
|||||||
|
|
||||||
/// ID of the message that was read.
|
/// ID of the message that was read.
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
|
|
||||||
|
/// Read for the first time (e.g. by just one group member
|
||||||
|
/// / channel subscriber).
|
||||||
|
/// State changed from DC_STATE_OUT_DELIVERED to
|
||||||
|
/// DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state().
|
||||||
|
first_time: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A single message was deleted.
|
/// A single message was deleted.
|
||||||
@@ -540,9 +545,14 @@ impl From<CoreEventType> for EventType {
|
|||||||
chat_id: chat_id.to_u32(),
|
chat_id: chat_id.to_u32(),
|
||||||
msg_id: msg_id.to_u32(),
|
msg_id: msg_id.to_u32(),
|
||||||
},
|
},
|
||||||
CoreEventType::MsgRead { chat_id, msg_id } => MsgRead {
|
CoreEventType::MsgRead {
|
||||||
|
chat_id,
|
||||||
|
msg_id,
|
||||||
|
first_time,
|
||||||
|
} => MsgRead {
|
||||||
chat_id: chat_id.to_u32(),
|
chat_id: chat_id.to_u32(),
|
||||||
msg_id: msg_id.to_u32(),
|
msg_id: msg_id.to_u32(),
|
||||||
|
first_time,
|
||||||
},
|
},
|
||||||
CoreEventType::MsgDeleted { chat_id, msg_id } => MsgDeleted {
|
CoreEventType::MsgDeleted { chat_id, msg_id } => MsgDeleted {
|
||||||
chat_id: chat_id.to_u32(),
|
chat_id: chat_id.to_u32(),
|
||||||
|
|||||||
@@ -171,14 +171,19 @@ pub enum EventType {
|
|||||||
msg_id: MsgId,
|
msg_id: MsgId,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A single message is read by the receiver. State changed from DC_STATE_OUT_DELIVERED to
|
/// A single message is read by a receiver.
|
||||||
/// DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state().
|
|
||||||
MsgRead {
|
MsgRead {
|
||||||
/// ID of the chat which the message belongs to.
|
/// ID of the chat which the message belongs to.
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
|
|
||||||
/// ID of the message that was read.
|
/// ID of the message that was read.
|
||||||
msg_id: MsgId,
|
msg_id: MsgId,
|
||||||
|
|
||||||
|
/// Read for the first time (e.g. by just one group member
|
||||||
|
/// / channel subscriber).
|
||||||
|
/// State changed from DC_STATE_OUT_DELIVERED to
|
||||||
|
/// DC_STATE_OUT_MDN_RCVD, see dc_msg_get_state().
|
||||||
|
first_time: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// A single message was deleted.
|
/// A single message was deleted.
|
||||||
|
|||||||
@@ -2596,8 +2596,12 @@ async fn handle_mdn(
|
|||||||
(msg_id, from_id, timestamp_sent),
|
(msg_id, from_id, timestamp_sent),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
context.emit_event(EventType::MsgRead {
|
||||||
|
chat_id,
|
||||||
|
msg_id,
|
||||||
|
first_time: !has_mdns,
|
||||||
|
});
|
||||||
if !has_mdns {
|
if !has_mdns {
|
||||||
context.emit_event(EventType::MsgRead { chat_id, msg_id });
|
|
||||||
// note(treefit): only matters if it is the last message in chat (but probably too expensive to check, debounce also solves it)
|
// note(treefit): only matters if it is the last message in chat (but probably too expensive to check, debounce also solves it)
|
||||||
chatlist_events::emit_chatlist_item_changed(context, chat_id);
|
chatlist_events::emit_chatlist_item_changed(context, chat_id);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user