This commit is contained in:
Felix Ableitner 2024-05-30 13:20:00 +02:00
parent 7bcc6f2894
commit 3fb1725301
2 changed files with 33 additions and 3 deletions

View File

@ -35,4 +35,5 @@ pub struct InstanceForm {
pub software: Option<String>,
pub version: Option<String>,
pub updated: Option<DateTime<Utc>>,
pub published: Option<DateTime<Utc>>,
}

View File

@ -224,6 +224,7 @@ impl InstanceWorker {
// Activity send successful, mark instance as alive if it hasn't been updated in a while.
let updated = self.target.updated.unwrap_or(self.target.published);
dbg!(&updated);
if updated.add(Days::new(1)) < Utc::now() {
self.target.updated = Some(Utc::now());
@ -351,8 +352,6 @@ mod test {
let sent = send_activity(data.person.actor_id.clone(), &data.context).await?;
sleep(WORK_FINISHED_RECHECK_DELAY * 2).await;
// receive for successfully sent activity
let inbox_rcv = data.inbox_receiver.recv().await.unwrap();
let parsed_activity = serde_json::from_str::<WithContext<Value>>(&inbox_rcv)?;
@ -377,6 +376,32 @@ mod test {
Ok(())
}
#[tokio::test]
#[serial]
async fn test_update_instance() -> LemmyResult<()> {
let mut data = Data::init().await?;
let published = DateTime::from_timestamp_nanos(0);
let form = InstanceForm::builder()
.domain(data.instance.domain.clone())
.published(Some(published))
.updated(None)
.build();
Instance::update(&mut data.context.pool(), data.instance.id, form).await?;
send_activity(data.person.actor_id.clone(), &data.context).await?;
data.inbox_receiver.recv().await.unwrap();
let instance =
Instance::read_or_create(&mut data.context.pool(), data.instance.domain.clone()).await?;
assert!(instance.updated.is_some());
data.cleanup().await?;
Ok(())
}
async fn listen_activities(
inbox_sender: UnboundedSender<String>,
cancel: CancellationToken,
@ -418,6 +443,10 @@ mod test {
actor_type: ActorType::Person,
actor_apub_id: actor_id,
};
Ok(SentActivity::create(&mut context.pool(), form).await?)
let sent = SentActivity::create(&mut context.pool(), form).await?;
sleep(WORK_FINISHED_RECHECK_DELAY * 2).await;
Ok(sent)
}
}