From b87c630da48d8a5daf93ec378a555aa64bf2e66a Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Mon, 28 Oct 2024 19:14:01 +0100 Subject: [PATCH] Split make_historical_event out of get_entries --- sable_history/src/pg_history_service.rs | 56 +++++++++++-------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/sable_history/src/pg_history_service.rs b/sable_history/src/pg_history_service.rs index cf60410b..b2f39171 100644 --- a/sable_history/src/pg_history_service.rs +++ b/sable_history/src/pg_history_service.rs @@ -139,37 +139,7 @@ impl<'a> HistoryService for PgHistoryService<'a> { } .await .expect("could not query messages") - .map(|row| { - row.map( - |( - id, - timestamp, - message_type, - text, - source_nick, - source_ident, - source_vhost, - source_account, - ): ( - uuid::Uuid, - NaiveDateTime, - crate::types::MessageType, - String, - String, - String, - String, - _, - )| HistoricalEvent::Message { - id: MessageId::new(id.try_into().expect("Message id is a non-v7 UUID")), - timestamp: timestamp.and_utc().timestamp(), - source: format!("{}!{}@{}", source_nick, source_ident, source_vhost), - source_account, - message_type: message_type.into(), - target: channel.name.clone(), // assume it's the same - text, - }, - ) - }) + .map_ok(|row| make_historical_event(&channel, row)) .try_collect::>() .await .expect("could not parse all records") @@ -196,3 +166,27 @@ impl<'a> HistoryService for PgHistoryService<'a> { } } } + +fn make_historical_event( + channel: &crate::models::Channel, + (id, timestamp, message_type, text, source_nick, source_ident, source_vhost, source_account): ( + uuid::Uuid, + NaiveDateTime, + crate::types::MessageType, + String, + String, + String, + String, + Option, + ), +) -> HistoricalEvent { + HistoricalEvent::Message { + id: MessageId::new(id.try_into().expect("Message id is a non-v7 UUID")), + timestamp: timestamp.and_utc().timestamp(), + source: format!("{}!{}@{}", source_nick, source_ident, source_vhost), + source_account, + message_type: message_type.into(), + target: channel.name.clone(), // assume it's the same + text, + } +}