mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
do set_visibility() in a transaction (#3053)
this avoids archived chats containing fresh messages: before, it could happen that between the two SQL calls a new fresh message arrives, unarchives the chat that is immediately archived by the second SQL call - resulting in an archive chat containing fresh messages. as fresh messages counter are shown on app icon etc. this is pretty weird for the user as they do not see what is "fresh". the other way round, there is no transaction in receive_imf(), however, receive_imf() only unarchives chats, so that is visible and no big issue for the user. the issue is rare at all, however, annoying if you get that as the badge counter may be stuck at "1" nearly forever (until you open the archived chat in question).
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixes
|
||||
- avoid archived, fresh chats #3053
|
||||
|
||||
|
||||
## 1.75.0
|
||||
|
||||
### Changes
|
||||
|
||||
27
src/chat.rs
27
src/chat.rs
@@ -474,22 +474,21 @@ impl ChatId {
|
||||
self
|
||||
);
|
||||
|
||||
if visibility == ChatVisibility::Archived {
|
||||
context
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE msgs SET state=? WHERE chat_id=? AND state=?;",
|
||||
paramsv![MessageState::InNoticed, self, MessageState::InFresh],
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
context
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE chats SET archived=? WHERE id=?;",
|
||||
paramsv![visibility, self],
|
||||
)
|
||||
.transaction(move |transaction| {
|
||||
if visibility == ChatVisibility::Archived {
|
||||
transaction.execute(
|
||||
"UPDATE msgs SET state=? WHERE chat_id=? AND state=?;",
|
||||
paramsv![MessageState::InNoticed, self, MessageState::InFresh],
|
||||
)?;
|
||||
}
|
||||
transaction.execute(
|
||||
"UPDATE chats SET archived=? WHERE id=?;",
|
||||
paramsv![visibility, self],
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
.await?;
|
||||
|
||||
context.emit_event(EventType::MsgsChanged {
|
||||
|
||||
Reference in New Issue
Block a user