mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 19:06:35 +03:00
feat: mark messages as "fresh"
this adds an api to make the newest incoming message of a chat as "fresh", so that UI can offer a "mark chat unread" option as usual for messengers (eg. swipe right on iOS toggels between "read" and "unread"). "mark unread" is one of the most requested missing features, used by many ppl to organize their every day messenger usage - tho "pinning" and "saved messages" are similar, it seems to be missed often. we follow a very simple approach here and just reset the state to `MessageState::InFresh`. this does not introduce new states or flows. therefore, chats without any incoming message cannot be marked as fresh. in practise, this is probably not really an issue, as the "mark fresh" is usually used to undo a "mark noticed" operation - and then you have incoming message. also, most status messages as "all messages are e2ee" count as incoming. to avoid double sending of MDN, we remove `Param::WantsMdn` once the MDN is scheduled. in case MDN are used for syncing, MDN is still sent as before. many other messenger show a "badge without number", if we want that as well, we can always track the "manually set as fresh" state in a parameter. but for now, it is fine without and showing a "1", which alsso makes sense as badges may be summed up. there is an iOS pr that uses this new feature, jsonrpc is left out until api is settled. also out of scope is synchronisation - main reason is that "mark noticed" is not synced as well, so we avoid an imbalance here. both, "mark noticed" as well as "mark fresh" should be synced however, as soon as this feature is merged.
This commit is contained in:
32
src/chat.rs
32
src/chat.rs
@@ -3406,6 +3406,38 @@ pub(crate) async fn mark_old_messages_as_noticed(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Marks last incoming message in a chat as fresh.
|
||||
pub async fn markfresh_chat(context: &Context, chat_id: ChatId) -> Result<()> {
|
||||
let affected_rows = context
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE msgs
|
||||
SET state=?1
|
||||
WHERE id=(SELECT id
|
||||
FROM msgs
|
||||
WHERE state IN (?1, ?2, ?3) AND hidden=0 AND chat_id=?4
|
||||
ORDER BY timestamp DESC, id DESC
|
||||
LIMIT 1)
|
||||
AND state!=?1",
|
||||
(
|
||||
MessageState::InFresh,
|
||||
MessageState::InNoticed,
|
||||
MessageState::InSeen,
|
||||
chat_id,
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
|
||||
if affected_rows == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
context.emit_msgs_changed_without_msg_id(chat_id);
|
||||
chatlist_events::emit_chatlist_item_changed(context, chat_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns all database message IDs of the given types.
|
||||
///
|
||||
/// If `chat_id` is None, return messages from any chat.
|
||||
|
||||
Reference in New Issue
Block a user