Skip to content

Commit

Permalink
Split make_historical_event out of get_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Oct 28, 2024
1 parent 71ae9c1 commit b87c630
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions sable_history/src/pg_history_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
.await
.expect("could not parse all records")
Expand All @@ -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<String>,
),
) -> 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,
}
}

0 comments on commit b87c630

Please sign in to comment.