Skip to content

Commit 09bf947

Browse files
committed
fix: Don't emit superflous MsgsChanged event for reactions
1 parent 74ab452 commit 09bf947

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/chat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ pub async fn marknoticed_chat(context: &Context, chat_id: ChatId) -> Result<()>
33543354
AND hidden=1
33553355
AND chat_id=?
33563356
ORDER BY id DESC LIMIT 100", // LIMIT to 100 in order to avoid blocking the UI too long, usually there will be less than 100 messages anyway
3357-
(MessageState::InNoticed, chat_id),
3357+
(MessageState::InFresh, chat_id), // No need to check for InNoticed messages, because reactions are never InNoticed
33583358
|row| {
33593359
let msg_id: MsgId = row.get(0)?;
33603360
let rfc724_mid: String = row.get(1)?;

src/reaction.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ Here's my footer -- [email protected]"
619619
.get_matching_opt(t, |evt| {
620620
matches!(
621621
evt,
622-
EventType::IncomingReaction { .. } | EventType::IncomingMsg { .. }
622+
EventType::IncomingReaction { .. }
623+
| EventType::IncomingMsg { .. }
624+
| EventType::MsgsChanged { .. }
623625
)
624626
})
625627
.await;
@@ -664,7 +666,7 @@ Here's my footer -- [email protected]"
664666

665667
let bob_reaction_msg = bob.pop_sent_msg().await;
666668
let alice_reaction_msg = alice.recv_msg_hidden(&bob_reaction_msg).await;
667-
assert_eq!(alice_reaction_msg.state, MessageState::InNoticed);
669+
assert_eq!(alice_reaction_msg.state, MessageState::InFresh);
668670
assert_eq!(get_chat_msgs(&alice, chat_alice.id).await?.len(), 2);
669671

670672
let reactions = get_msg_reactions(&alice, alice_msg.sender_msg_id).await?;

src/receive_imf.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ pub struct ReceivedMsg {
5454
/// Received message state.
5555
pub state: MessageState,
5656

57+
/// Whether the message is hidden.
58+
pub hidden: bool,
59+
5760
/// Message timestamp for sorting.
5861
pub sort_timestamp: i64,
5962

@@ -192,6 +195,7 @@ pub(crate) async fn receive_imf_inner(
192195
return Ok(Some(ReceivedMsg {
193196
chat_id: DC_CHAT_ID_TRASH,
194197
state: MessageState::Undefined,
198+
hidden: false,
195199
sort_timestamp: 0,
196200
msg_ids,
197201
needs_delete_job: false,
@@ -385,6 +389,7 @@ pub(crate) async fn receive_imf_inner(
385389
received_msg = Some(ReceivedMsg {
386390
chat_id: DC_CHAT_ID_TRASH,
387391
state: MessageState::InSeen,
392+
hidden: false,
388393
sort_timestamp: mime_parser.timestamp_sent,
389394
msg_ids: vec![msg_id],
390395
needs_delete_job: res == securejoin::HandshakeMessage::Done,
@@ -621,7 +626,7 @@ pub(crate) async fn receive_imf_inner(
621626

622627
if let Some(replace_chat_id) = replace_chat_id {
623628
context.emit_msgs_changed_without_msg_id(replace_chat_id);
624-
} else if !chat_id.is_trash() {
629+
} else if !chat_id.is_trash() && !received_msg.hidden {
625630
let fresh = received_msg.state == MessageState::InFresh;
626631
for msg_id in &received_msg.msg_ids {
627632
chat_id.emit_msg_event(context, *msg_id, mime_parser.incoming && fresh);
@@ -1037,8 +1042,6 @@ async fn add_parts(
10371042
// No check for `hidden` because only reactions are such and they should be `InFresh`.
10381043
{
10391044
MessageState::InSeen
1040-
} else if is_reaction {
1041-
MessageState::InNoticed
10421045
} else {
10431046
MessageState::InFresh
10441047
};
@@ -1699,7 +1702,7 @@ RETURNING id
16991702
"Message has {icnt} parts and is assigned to chat #{chat_id}."
17001703
);
17011704

1702-
if !chat_id.is_trash() {
1705+
if !chat_id.is_trash() && !hidden {
17031706
let mut chat = Chat::load_from_db(context, chat_id).await?;
17041707

17051708
// In contrast to most other update-timestamps,
@@ -1737,6 +1740,7 @@ RETURNING id
17371740
Ok(ReceivedMsg {
17381741
chat_id,
17391742
state,
1743+
hidden,
17401744
sort_timestamp,
17411745
msg_ids: created_db_entries,
17421746
needs_delete_job,

0 commit comments

Comments
 (0)