Private
Public Access
1
0

first attempt at trying to keep track of locally send id

This commit is contained in:
2025-09-12 12:04:31 -07:00
parent 6261351598
commit 8304b68a64
5 changed files with 113 additions and 11 deletions

View File

@@ -347,7 +347,16 @@ impl Daemon {
self.database
.lock()
.await
.with_repository(|r| r.insert_message(&conversation_id, message.into()))
.with_repository(|r| {
// 1) Insert the server message
r.insert_message(&conversation_id, message.clone().into())?;
// 2) Persist alias local -> server for stable UI ids
r.set_message_alias(
&outgoing_message.guid.to_string(),
&message.id,
&conversation_id,
)
})
.await
.unwrap();
@@ -448,18 +457,38 @@ impl Daemon {
.get(&conversation_id)
.unwrap_or(&empty_vec);
self.database
// Fetch DB messages and an alias map (server_id -> local_id) in one DB access.
let (db_messages, alias_map) = self
.database
.lock()
.await
.with_repository(|r| {
r.get_messages_for_conversation(&conversation_id)
.unwrap()
.into_iter()
.map(|m| m.into()) // Convert db::Message to daemon::Message
.chain(outgoing_messages.into_iter().map(|m| m.into()))
.collect()
let msgs = r.get_messages_for_conversation(&conversation_id).unwrap();
let ids: Vec<String> = msgs.iter().map(|m| m.id.clone()).collect();
let map = r.get_local_ids_for(ids).unwrap_or_default();
(msgs, map)
})
.await
.await;
// Convert DB messages to daemon model, substituting local_id when an alias exists.
let mut result: Vec<Message> = Vec::with_capacity(
db_messages.len() + outgoing_messages.len(),
);
for m in db_messages.into_iter() {
let server_id = m.id.clone();
let mut dm: Message = m.into();
if let Some(local_id) = alias_map.get(&server_id) {
dm.id = local_id.clone();
}
result.push(dm);
}
// Append pending outgoing messages (these already use local_id)
for om in outgoing_messages.iter() {
result.push(om.into());
}
result
}
async fn enqueue_outgoing_message(