Skip to content

Commit

Permalink
Partial fill-in-the-blanks for message translation
Browse files Browse the repository at this point in the history
  • Loading branch information
spb authored and progval committed Oct 27, 2024
1 parent e5aa0e0 commit 682bbf7
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions sable_network/src/history/local_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<HistoricalEvent> {
match entry.details {
NetworkStateChange::NewMessage(update::NewMessage {
message,
source,

Check warning on line 128 in sable_network/src/history/local_service.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unused variable: `source`
target,

Check warning on line 129 in sable_network/src/history/local_service.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unused variable: `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(),

Check warning on line 140 in sable_network/src/history/local_service.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unreachable expression
})
}
_ => None,
}
}
}

impl<'a, NetworkPolicy: policy::PolicyService> HistoryService
Expand Down

0 comments on commit 682bbf7

Please sign in to comment.