mirror of
https://github.com/chatmail/core.git
synced 2026-05-23 00:36:32 +03:00
Don't unpin chat on sending / receiving not fresh messages (#3967)
This bug was introduced by 3cf78749df - there are three visibility
states: Archived, Pinned and Normal - in the database, this "visibility" is named historically
"archived" ... the original code has an AND archived=1 therefore.
This commit is contained in:
52
src/chat.rs
52
src/chat.rs
@@ -544,10 +544,14 @@ impl ChatId {
|
|||||||
msg_state: MessageState,
|
msg_state: MessageState,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if msg_state != MessageState::InFresh {
|
if msg_state != MessageState::InFresh {
|
||||||
context.sql.execute(
|
context
|
||||||
"UPDATE chats SET archived=0 WHERE id=? AND NOT(muted_until=-1 OR muted_until>?)",
|
.sql
|
||||||
paramsv![self, time()],
|
.execute(
|
||||||
).await?;
|
"UPDATE chats SET archived=0 WHERE id=? AND archived=1 \
|
||||||
|
AND NOT(muted_until=-1 OR muted_until>?)",
|
||||||
|
paramsv![self, time()],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let chat = Chat::load_from_db(context, self).await?;
|
let chat = Chat::load_from_db(context, self).await?;
|
||||||
@@ -4690,6 +4694,46 @@ mod tests {
|
|||||||
assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]);
|
assert_eq!(chatlist, vec![chat_id3, chat_id2, chat_id1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_pinned_after_new_msgs() -> Result<()> {
|
||||||
|
let alice = TestContext::new_alice().await;
|
||||||
|
let bob = TestContext::new_bob().await;
|
||||||
|
let alice_chat_id = alice.create_chat(&bob).await.id;
|
||||||
|
let bob_chat_id = bob.create_chat(&alice).await.id;
|
||||||
|
|
||||||
|
assert!(alice_chat_id
|
||||||
|
.set_visibility(&alice, ChatVisibility::Pinned)
|
||||||
|
.await
|
||||||
|
.is_ok());
|
||||||
|
assert_eq!(
|
||||||
|
Chat::load_from_db(&alice, alice_chat_id)
|
||||||
|
.await?
|
||||||
|
.get_visibility(),
|
||||||
|
ChatVisibility::Pinned,
|
||||||
|
);
|
||||||
|
|
||||||
|
send_text_msg(&alice, alice_chat_id, "hi!".into()).await?;
|
||||||
|
assert_eq!(
|
||||||
|
Chat::load_from_db(&alice, alice_chat_id)
|
||||||
|
.await?
|
||||||
|
.get_visibility(),
|
||||||
|
ChatVisibility::Pinned,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.set_text(Some("hi!".into()));
|
||||||
|
let sent_msg = bob.send_msg(bob_chat_id, &mut msg).await;
|
||||||
|
let msg = alice.recv_msg(&sent_msg).await;
|
||||||
|
assert_eq!(msg.chat_id, alice_chat_id);
|
||||||
|
assert_eq!(
|
||||||
|
Chat::load_from_db(&alice, alice_chat_id)
|
||||||
|
.await?
|
||||||
|
.get_visibility(),
|
||||||
|
ChatVisibility::Pinned,
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_set_chat_name() {
|
async fn test_set_chat_name() {
|
||||||
let t = TestContext::new().await;
|
let t = TestContext::new().await;
|
||||||
|
|||||||
Reference in New Issue
Block a user