.
This commit is contained in:
@@ -351,13 +351,20 @@ impl ChatPanel {
|
||||
let content = value.to_string();
|
||||
let sent_ids = self.sent_ids.clone();
|
||||
|
||||
// Upgrade room and create the rumor synchronously
|
||||
// Upgrade room and create rumor + send task in a single read lock
|
||||
let Some(room_entity) = room.upgrade() else {
|
||||
return;
|
||||
};
|
||||
let Some(rumor) = room_entity.read(cx).rumor(content.clone(), replies, cx) else {
|
||||
window.push_notification("Failed to create message", cx);
|
||||
return;
|
||||
let (rumor, send_task) = match room_entity.read_with(cx, |room, cx| {
|
||||
let rumor = room.rumor(content.clone(), replies, cx)?;
|
||||
let send_task = room.send(rumor.clone(), cx)?;
|
||||
Some((rumor, send_task))
|
||||
}) {
|
||||
Some(pair) => pair,
|
||||
None => {
|
||||
window.push_notification("Failed to create message", cx);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let id = rumor.id.expect("rumor must have an id");
|
||||
@@ -367,12 +374,6 @@ impl ChatPanel {
|
||||
self.insert_reports(id, vec![], cx);
|
||||
self.clear(window, cx);
|
||||
|
||||
// Get the send task
|
||||
let Some(send_task) = room_entity.read(cx).send(rumor, cx) else {
|
||||
window.push_notification("Failed to send message", cx);
|
||||
return;
|
||||
};
|
||||
|
||||
// Spawn a single task to await the send and update reports
|
||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||
let outputs = send_task.await;
|
||||
|
||||
Reference in New Issue
Block a user