always set chat_id on DC_EVENT_MSGS_NOTICED

This commit is contained in:
B. Petersen
2020-09-24 12:10:48 +02:00
parent f3c7d2f9c6
commit e9733e7525
4 changed files with 20 additions and 31 deletions

View File

@@ -260,10 +260,9 @@ impl Contact {
Ok(contact_id)
}
/// Mark all messages sent by the given contact
/// as *noticed*. See also dc_marknoticed_chat() and dc_markseen_msgs()
///
/// Calling this function usually results in the event `#DC_EVENT_MSGS_NOTICED`.
/// Mark messages from a contact as noticed.
/// The contact is expected to belong to the deaddrop,
/// therefore, DC_EVENT_MSGS_NOTICED(DC_CHAT_ID_DEADDROP) is emitted.
pub async fn mark_noticed(context: &Context, id: u32) {
if context
.sql
@@ -274,7 +273,7 @@ impl Contact {
.await
.is_ok()
{
context.emit_event(EventType::MsgsNoticed(ChatId::new(0)));
context.emit_event(EventType::MsgsNoticed(ChatId::new(DC_CHAT_ID_DEADDROP)));
}
}

View File

@@ -187,7 +187,7 @@ pub enum EventType {
IncomingMsg { chat_id: ChatId, msg_id: MsgId },
/// Messages were seen or noticed.
/// If chat_id is 0, this affects multiple chats.
/// chat id is always set.
#[strum(props(id = "2008"))]
MsgsNoticed(ChatId),

View File

@@ -1255,9 +1255,8 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> bool {
.await
.unwrap_or_default();
let mut send_event = false;
let mut last_chat_id = ChatId::new(0);
let mut chat_ids_are_unique = true;
// we expect all messages belong to the same chat or to the deaddrop.
let mut updated_chat_id = ChatId::new(0);
for (id, curr_chat_id, curr_state, curr_blocked) in msgs.into_iter() {
if let Err(err) = id.start_ephemeral_timer(context).await {
@@ -1278,28 +1277,16 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> bool {
job::Job::new(Action::MarkseenMsgOnImap, id.to_u32(), Params::new(), 0),
)
.await;
send_event = true;
updated_chat_id = curr_chat_id;
}
} else if curr_state == MessageState::InFresh {
update_msg_state(context, id, MessageState::InNoticed).await;
send_event = true;
}
if last_chat_id.is_unset() {
last_chat_id = curr_chat_id;
} else if last_chat_id != curr_chat_id {
chat_ids_are_unique = false;
updated_chat_id = ChatId::new(DC_CHAT_ID_DEADDROP);
}
}
if send_event {
context.emit_event(EventType::MsgsNoticed(
if chat_ids_are_unique && !last_chat_id.is_unset() {
last_chat_id
} else {
ChatId::new(0)
},
));
if !updated_chat_id.is_unset() {
context.emit_event(EventType::MsgsNoticed(updated_chat_id));
}
true