mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
always set chat_id on DC_EVENT_MSGS_NOTICED
This commit is contained in:
@@ -1503,11 +1503,13 @@ void dc_forward_msgs (dc_context_t* context, const uint3
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark all messages sent by the given contact
|
* Mark all messages sent by the given contact as _noticed_.
|
||||||
* as _noticed_. See also dc_marknoticed_chat() and
|
* This function is typically used to ignore a user in the deaddrop temporarily ("Not now" button).
|
||||||
* dc_markseen_msgs()
|
|
||||||
*
|
*
|
||||||
* Calling this function usually results in the event #DC_EVENT_MSGS_NOTICED.
|
* The contact is expected to belong to the deaddrop;
|
||||||
|
* only one #DC_EVENT_MSGS_NOTICED with chat_id=DC_CHAT_ID_DEADDROP may be emitted.
|
||||||
|
*
|
||||||
|
* See also dc_marknoticed_chat() and dc_markseen_msgs()
|
||||||
*
|
*
|
||||||
* @memberof dc_context_t
|
* @memberof dc_context_t
|
||||||
* @param context The context object.
|
* @param context The context object.
|
||||||
@@ -1526,7 +1528,8 @@ void dc_marknoticed_contact (dc_context_t* context, uint32_t co
|
|||||||
* Moreover, if messages belong to a chat with ephemeral messages enabled,
|
* Moreover, if messages belong to a chat with ephemeral messages enabled,
|
||||||
* the ephemeral timer is started for these messages.
|
* the ephemeral timer is started for these messages.
|
||||||
*
|
*
|
||||||
* Calling this function usually results in the event #DC_EVENT_MSGS_NOTICED.
|
* The given messages are expected to belong to the same chat or to the deaddrop;
|
||||||
|
* only one #DC_EVENT_MSGS_NOTICED event with this chat may be emitted.
|
||||||
*
|
*
|
||||||
* @memberof dc_context_t
|
* @memberof dc_context_t
|
||||||
* @param context The context object.
|
* @param context The context object.
|
||||||
@@ -4607,7 +4610,7 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
* 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.
|
||||||
*
|
*
|
||||||
* @param data1 (int) chat_id or 0 if the event affects multiple chats.
|
* @param data1 (int) chat_id
|
||||||
* @param data2 0
|
* @param data2 0
|
||||||
*/
|
*/
|
||||||
#define DC_EVENT_MSGS_NOTICED 2008
|
#define DC_EVENT_MSGS_NOTICED 2008
|
||||||
|
|||||||
@@ -260,10 +260,9 @@ impl Contact {
|
|||||||
Ok(contact_id)
|
Ok(contact_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark all messages sent by the given contact
|
/// Mark messages from a contact as noticed.
|
||||||
/// as *noticed*. See also dc_marknoticed_chat() and dc_markseen_msgs()
|
/// The contact is expected to belong to the deaddrop,
|
||||||
///
|
/// therefore, DC_EVENT_MSGS_NOTICED(DC_CHAT_ID_DEADDROP) is emitted.
|
||||||
/// Calling this function usually results in the event `#DC_EVENT_MSGS_NOTICED`.
|
|
||||||
pub async fn mark_noticed(context: &Context, id: u32) {
|
pub async fn mark_noticed(context: &Context, id: u32) {
|
||||||
if context
|
if context
|
||||||
.sql
|
.sql
|
||||||
@@ -274,7 +273,7 @@ impl Contact {
|
|||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
context.emit_event(EventType::MsgsNoticed(ChatId::new(0)));
|
context.emit_event(EventType::MsgsNoticed(ChatId::new(DC_CHAT_ID_DEADDROP)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ pub enum EventType {
|
|||||||
IncomingMsg { chat_id: ChatId, msg_id: MsgId },
|
IncomingMsg { chat_id: ChatId, msg_id: MsgId },
|
||||||
|
|
||||||
/// Messages were seen or noticed.
|
/// Messages were seen or noticed.
|
||||||
/// If chat_id is 0, this affects multiple chats.
|
/// chat id is always set.
|
||||||
#[strum(props(id = "2008"))]
|
#[strum(props(id = "2008"))]
|
||||||
MsgsNoticed(ChatId),
|
MsgsNoticed(ChatId),
|
||||||
|
|
||||||
|
|||||||
@@ -1255,9 +1255,8 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> bool {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut send_event = false;
|
// we expect all messages belong to the same chat or to the deaddrop.
|
||||||
let mut last_chat_id = ChatId::new(0);
|
let mut updated_chat_id = ChatId::new(0);
|
||||||
let mut chat_ids_are_unique = true;
|
|
||||||
|
|
||||||
for (id, curr_chat_id, curr_state, curr_blocked) in msgs.into_iter() {
|
for (id, curr_chat_id, curr_state, curr_blocked) in msgs.into_iter() {
|
||||||
if let Err(err) = id.start_ephemeral_timer(context).await {
|
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),
|
job::Job::new(Action::MarkseenMsgOnImap, id.to_u32(), Params::new(), 0),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
send_event = true;
|
updated_chat_id = curr_chat_id;
|
||||||
}
|
}
|
||||||
} else if curr_state == MessageState::InFresh {
|
} else if curr_state == MessageState::InFresh {
|
||||||
update_msg_state(context, id, MessageState::InNoticed).await;
|
update_msg_state(context, id, MessageState::InNoticed).await;
|
||||||
send_event = true;
|
updated_chat_id = ChatId::new(DC_CHAT_ID_DEADDROP);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if send_event {
|
if !updated_chat_id.is_unset() {
|
||||||
context.emit_event(EventType::MsgsNoticed(
|
context.emit_event(EventType::MsgsNoticed(updated_chat_id));
|
||||||
if chat_ids_are_unique && !last_chat_id.is_unset() {
|
|
||||||
last_chat_id
|
|
||||||
} else {
|
|
||||||
ChatId::new(0)
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|||||||
Reference in New Issue
Block a user