mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 14:56:33 +03:00
emit exact chatid events in contact aeap and contact name change
This commit is contained in:
@@ -658,6 +658,7 @@ impl Contact {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut update_addr = false;
|
let mut update_addr = false;
|
||||||
|
let mut updated_name = false;
|
||||||
|
|
||||||
let row_id = context.sql.transaction(|transaction| {
|
let row_id = context.sql.transaction(|transaction| {
|
||||||
let row = transaction.query_row(
|
let row = transaction.query_row(
|
||||||
@@ -761,9 +762,7 @@ impl Contact {
|
|||||||
if count > 0 {
|
if count > 0 {
|
||||||
// Chat name updated
|
// Chat name updated
|
||||||
context.emit_event(EventType::ChatModified(chat_id));
|
context.emit_event(EventType::ChatModified(chat_id));
|
||||||
context.emit_event(EventType::UIChatListItemChanged {
|
updated_name = true;
|
||||||
chat_id: Some(chat_id),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -800,7 +799,39 @@ impl Contact {
|
|||||||
Ok(row_id)
|
Ok(row_id)
|
||||||
}).await?;
|
}).await?;
|
||||||
|
|
||||||
Ok((ContactId::new(row_id), sth_modified))
|
let contact_id = ContactId::new(row_id);
|
||||||
|
|
||||||
|
if updated_name {
|
||||||
|
// update the chats the contact that changed their name is part of
|
||||||
|
// (treefit): could make sense to only update chats where the last message is from the contact, but the db query for that is more expensive
|
||||||
|
for chat_id in Contact::get_chats_with_contact(context, &contact_id).await? {
|
||||||
|
context.emit_event(EventType::UIChatListItemChanged { chat_id: Some(chat_id) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((contact_id, sth_modified))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all chats the contact is part of
|
||||||
|
pub async fn get_chats_with_contact(
|
||||||
|
context: &Context,
|
||||||
|
contact_id: &ContactId,
|
||||||
|
) -> Result<Vec<ChatId>> {
|
||||||
|
context
|
||||||
|
.sql
|
||||||
|
.query_map(
|
||||||
|
"SELECT chat_id FROM chats_contacts WHERE contact_id=?",
|
||||||
|
(contact_id,),
|
||||||
|
|row| {
|
||||||
|
let chat_id: ChatId = row.get(0)?;
|
||||||
|
Ok(chat_id)
|
||||||
|
},
|
||||||
|
|rows| {
|
||||||
|
rows.collect::<std::result::Result<Vec<_>, _>>()
|
||||||
|
.map_err(Into::into)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a number of contacts.
|
/// Add a number of contacts.
|
||||||
|
|||||||
@@ -696,7 +696,10 @@ impl Peerstate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.emit_event(EventType::UIChatListChanged);
|
context.emit_event(EventType::UIChatListChanged);
|
||||||
context.emit_event(EventType::UIChatListItemChanged { chat_id: None });
|
// update the chats the contact is part of
|
||||||
|
for chat_id in Contact::get_chats_with_contact(context, &contact_id).await? {
|
||||||
|
context.emit_event(EventType::UIChatListItemChanged { chat_id: Some(chat_id) });
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user