mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
Move event emitting for a new message to a separate function
This commit is contained in:
16
src/chat.rs
16
src/chat.rs
@@ -545,6 +545,16 @@ impl ChatId {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emits an appropriate event for a message. `important` is whether a notification should be
|
||||||
|
/// shown.
|
||||||
|
pub(crate) fn emit_msg_event(self, context: &Context, msg_id: MsgId, important: bool) {
|
||||||
|
if important {
|
||||||
|
context.emit_incoming_msg(self, msg_id);
|
||||||
|
} else {
|
||||||
|
context.emit_msgs_changed(self, msg_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Deletes a chat.
|
/// Deletes a chat.
|
||||||
pub async fn delete(self, context: &Context) -> Result<()> {
|
pub async fn delete(self, context: &Context) -> Result<()> {
|
||||||
ensure!(
|
ensure!(
|
||||||
@@ -3469,11 +3479,7 @@ pub async fn add_device_msg_with_importance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !msg_id.is_unset() {
|
if !msg_id.is_unset() {
|
||||||
if important {
|
chat_id.emit_msg_event(context, msg_id, important);
|
||||||
context.emit_incoming_msg(chat_id, msg_id);
|
|
||||||
} else {
|
|
||||||
context.emit_msgs_changed(chat_id, msg_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
|
|||||||
@@ -356,11 +356,7 @@ pub(crate) async fn receive_imf_inner(
|
|||||||
} else if !chat_id.is_trash() {
|
} else if !chat_id.is_trash() {
|
||||||
let fresh = received_msg.state == MessageState::InFresh;
|
let fresh = received_msg.state == MessageState::InFresh;
|
||||||
for msg_id in &received_msg.msg_ids {
|
for msg_id in &received_msg.msg_ids {
|
||||||
if incoming && fresh {
|
chat_id.emit_msg_event(context, *msg_id, incoming && fresh);
|
||||||
context.emit_incoming_msg(chat_id, *msg_id);
|
|
||||||
} else {
|
|
||||||
context.emit_msgs_changed(chat_id, *msg_id);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user