From 682bbf78a7ac96a709e9e0097ddc06dc622f1aae Mon Sep 17 00:00:00 2001 From: Stephen Bennett Date: Sun, 27 Oct 2024 14:46:50 +0000 Subject: [PATCH] Partial fill-in-the-blanks for message translation --- sable_network/src/history/local_service.rs | 47 ++++++++++++---------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/sable_network/src/history/local_service.rs b/sable_network/src/history/local_service.rs index f2dad556..2743890d 100644 --- a/sable_network/src/history/local_service.rs +++ b/sable_network/src/history/local_service.rs @@ -47,6 +47,7 @@ impl<'a, NetworkPolicy: policy::PolicyService> LocalHistoryService<'a, NetworkPo // Keep the lock on the NetworkHistoryLog between the backward and the forward // search to make sure both have a consistent state let log = self.node.history(); + let net = self.node.network(); if backward_limit != 0 { let from_ts = if forward_limit == 0 { @@ -114,32 +115,34 @@ impl<'a, NetworkPolicy: policy::PolicyService> LocalHistoryService<'a, NetworkPo .into_iter() .rev() .chain(forward_entries.into_iter()) - .flat_map( - move |HistoryLogEntry { - id: _, - timestamp: _, - source_event: _, - details, - }| match details { - NetworkStateChange::NewMessage(update::NewMessage { - message, - source, - target: _, // assume it's the same as the argument we got - }) => Some(HistoricalEvent::Message { - id: *message, - message_type: crate::network::state::MessageType::Notice, // TODO - source: "".to_string(), // TODO - source_account: None, // TODO - target, - text: "".to_string(), // TODO - }), - _ => None, - }, - )) + .flat_map(move |entry| Self::translate_log_entry(entry, &net))) } else { Err(HistoryError::InvalidTarget(target)) } } + + fn translate_log_entry(entry: HistoryLogEntry, net: &Network) -> Option { + match entry.details { + NetworkStateChange::NewMessage(update::NewMessage { + message, + source, + target, + }) => { + let message = net.message(message).ok()?; + let source = message.source().ok()?; + + Some(HistoricalEvent::Message { + id: *message.id(), + message_type: message.message_type(), + source: source.nuh(), + source_account: source.account_name().map(|n| n.to_string()), + target: todo!(), + text: message.text().to_string(), + }) + } + _ => None, + } + } } impl<'a, NetworkPolicy: policy::PolicyService> HistoryService