mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Merge pull request #1981 from deltachat/notice-on-answer
basic DC_EVENT_MSGS_NOTICED multi-device-support
This commit is contained in:
@@ -4615,7 +4615,8 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
* Messages were marked noticed or seen.
|
* Messages were marked noticed or seen.
|
||||||
* The ui may update badge counters or stop showing a chatlist-item with a bold font.
|
* The ui may update badge counters or stop showing a chatlist-item with a bold font.
|
||||||
*
|
*
|
||||||
* This event is emitted eg. when calling dc_markseen_msgs(), dc_marknoticed_chat() or dc_marknoticed_contact().
|
* This event is emitted eg. when calling dc_markseen_msgs(), dc_marknoticed_chat() or dc_marknoticed_contact()
|
||||||
|
* or when a chat is answered on another device.
|
||||||
* Do not try to derive the state of an item from just the fact you received the event;
|
* Do not try to derive the state of an item from just the fact you received the event;
|
||||||
* use eg. dc_msg_get_state() or dc_get_fresh_msg_cnt() for this purpose.
|
* use eg. dc_msg_get_state() or dc_get_fresh_msg_cnt() for this purpose.
|
||||||
*
|
*
|
||||||
|
|||||||
35
src/chat.rs
35
src/chat.rs
@@ -1687,12 +1687,34 @@ pub async fn get_chat_msgs(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn marknoticed_chat_if_older_than(
|
||||||
|
context: &Context,
|
||||||
|
chat_id: ChatId,
|
||||||
|
timestamp: i64,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
if let Some(chat_timestamp) = context
|
||||||
|
.sql
|
||||||
|
.query_get_value(
|
||||||
|
context,
|
||||||
|
"SELECT MAX(timestamp) FROM msgs WHERE chat_id=?",
|
||||||
|
paramsv![chat_id],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
if timestamp > chat_timestamp {
|
||||||
|
marknoticed_chat(context, chat_id).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> {
|
pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(), Error> {
|
||||||
|
// "WHERE" below uses the index `(state, hidden, chat_id)`, see get_fresh_msg_cnt() for reasoning
|
||||||
if !context
|
if !context
|
||||||
.sql
|
.sql
|
||||||
.exists(
|
.exists(
|
||||||
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
"SELECT id FROM msgs WHERE state=? AND hidden=0 AND chat_id=?;",
|
||||||
paramsv![chat_id, MessageState::InFresh],
|
paramsv![MessageState::InFresh, chat_id],
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
@@ -1703,10 +1725,11 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<(),
|
|||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE msgs
|
"UPDATE msgs
|
||||||
SET state=13
|
SET state=?
|
||||||
WHERE chat_id=?
|
WHERE state=?
|
||||||
AND state=10;",
|
AND hidden=0
|
||||||
paramsv![chat_id],
|
AND chat_id=?;",
|
||||||
|
paramsv![MessageState::InNoticed, MessageState::InFresh, chat_id],
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -868,6 +868,11 @@ async fn add_parts(
|
|||||||
"Message has {} parts and is assigned to chat #{}.", icnt, chat_id,
|
"Message has {} parts and is assigned to chat #{}.", icnt, chat_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// new outgoing message from another device marks the chat as noticed.
|
||||||
|
if !incoming && !*hidden && !chat_id.is_special() {
|
||||||
|
chat::marknoticed_chat_if_older_than(context, chat_id, sort_timestamp).await?;
|
||||||
|
}
|
||||||
|
|
||||||
// check event to send
|
// check event to send
|
||||||
if chat_id.is_trash() || *hidden {
|
if chat_id.is_trash() || *hidden {
|
||||||
*create_event_to_send = None;
|
*create_event_to_send = None;
|
||||||
|
|||||||
@@ -1360,7 +1360,7 @@ CREATE INDEX devmsglabels_index1 ON devmsglabels (label);
|
|||||||
}
|
}
|
||||||
if dbversion < 68 {
|
if dbversion < 68 {
|
||||||
info!(context, "[migration] v68");
|
info!(context, "[migration] v68");
|
||||||
// the index is used to speed up get_fresh_msg_cnt(), see comment there for more details
|
// the index is used to speed up get_fresh_msg_cnt() (see comment there for more details) and marknoticed_chat()
|
||||||
sql.execute(
|
sql.execute(
|
||||||
"CREATE INDEX IF NOT EXISTS msgs_index7 ON msgs (state, hidden, chat_id);",
|
"CREATE INDEX IF NOT EXISTS msgs_index7 ON msgs (state, hidden, chat_id);",
|
||||||
paramsv![],
|
paramsv![],
|
||||||
|
|||||||
Reference in New Issue
Block a user