diff --git a/src/domain/follow.rs b/src/domain/follow.rs index d52eace..ef7c15e 100644 --- a/src/domain/follow.rs +++ b/src/domain/follow.rs @@ -1,11 +1,11 @@ -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use nostr_sdk::prelude::*; #[derive(Debug, Clone)] pub struct Follow { pub followee: PublicKey, pub follower: PublicKey, - pub updated_at: DateTime, + pub updated_at: DateTime, #[allow(unused)] - pub created_at: DateTime, + pub created_at: DateTime, } diff --git a/src/follows_differ.rs b/src/follows_differ.rs index a4eb7e4..37a91f8 100644 --- a/src/follows_differ.rs +++ b/src/follows_differ.rs @@ -3,7 +3,7 @@ use crate::{ domain::{follow::Follow, follow_change::FollowChange}, worker_pool::{WorkerTask, WorkerTaskItem}, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use nostr_sdk::prelude::*; use std::collections::HashMap; use std::sync::Arc; @@ -35,12 +35,6 @@ where } } - fn convert_timestamp(&self, timestamp: Timestamp) -> Result> { - DateTime::from_timestamp(timestamp.as_u64() as i64, 0) - .map(|dt| dt.fixed_offset()) - .ok_or_else(|| "Failed to convert timestamp to datetime".into()) - } - /// Initializes a structure that holds the differences between the stored /// follows and the latest contact list. async fn initialize_follows_diff( @@ -84,12 +78,11 @@ where } } } - async fn process_follows_diff( &self, follows_diff: HashMap, follower: &PublicKey, - event_created_at: DateTime, + event_created_at: DateTime, ) -> Result<(usize, usize, usize)> { let mut followed_counter = 0; let mut unfollowed_counter = 0; @@ -179,7 +172,7 @@ where let WorkerTaskItem { item: event } = worker_task_item; let follower = event.pubkey; - let event_created_at = self.convert_timestamp(event.created_at)?; + let event_created_at = convert_timestamp(event.created_at.as_u64())?; // Get the stored follows and the latest update time from the database let (mut follows_diff, maybe_latest_stored_updated_at) = @@ -218,6 +211,10 @@ where } } +fn convert_timestamp(timestamp: u64) -> Result> { + DateTime::::from_timestamp(timestamp as i64, 0).ok_or("Invalid timestamp".into()) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/repo.rs b/src/repo.rs index f134f6d..fd52c63 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,7 +1,7 @@ use core::panic; use crate::domain::follow::Follow; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use neo4rs::{query, Graph}; use nostr_sdk::prelude::PublicKey; use thiserror::Error; @@ -107,7 +107,7 @@ impl RepoTrait for Repo { "#; let query = query(statement) - .param("updated_at", follow.updated_at) + .param("updated_at", follow.updated_at.naive_utc()) .param("followee_val", follow.followee.to_hex()) .param("follower_val", follow.follower.to_hex()); @@ -163,10 +163,10 @@ impl RepoTrait for Repo { .get::("follower") .map_err(RepoError::Deserialization)?; let updated_at = row - .get::>("updated_at") + .get::>("updated_at") .map_err(RepoError::Deserialization)?; let created_at = row - .get::>("created_at") + .get::>("created_at") .map_err(RepoError::Deserialization)?; follows.push(Follow {