fix: address with activity/object time, not now

maybe not the best security-wise because remotes can "control" our
timeline order by putting fake dates but gives better results for users
because discovered objects don't appear just below boosts
This commit is contained in:
əlemi 2024-07-15 01:36:29 +02:00
parent 902aabe36b
commit 3d6c144c55
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -61,31 +61,30 @@ impl Addresser for crate::Context {
(None, None) => Ok(()), (None, None) => Ok(()),
(Some(activity), None) => { (Some(activity), None) => {
let to = expand_addressing(activity.addressed(), tx).await?; let to = expand_addressing(activity.addressed(), tx).await?;
address_to(self, to, Some(activity.internal), None, self.is_local(&activity.id), tx).await address_to(self, to, Some(activity.internal), None, self.is_local(&activity.id), activity.published, tx).await
}, },
(None, Some(object)) => { (None, Some(object)) => {
let to = expand_addressing(object.addressed(), tx).await?; let to = expand_addressing(object.addressed(), tx).await?;
address_to(self, to, None, Some(object.internal), self.is_local(&object.id), tx).await address_to(self, to, None, Some(object.internal), self.is_local(&object.id), object.published, tx).await
}, },
(Some(activity), Some(object)) => { (Some(activity), Some(object)) => {
let to_activity = BTreeSet::from_iter(expand_addressing(activity.addressed(), tx).await?); let to_activity = BTreeSet::from_iter(expand_addressing(activity.addressed(), tx).await?);
let to_object = BTreeSet::from_iter(expand_addressing(object.addressed(), tx).await?); let to_object = BTreeSet::from_iter(expand_addressing(object.addressed(), tx).await?);
let to_common = to_activity.intersection(&to_object).cloned().collect(); let to_common = to_activity.intersection(&to_object).cloned().collect();
address_to(self, to_common, Some(activity.internal), Some(object.internal), self.is_local(&activity.id), tx).await?; address_to(self, to_common, Some(activity.internal), Some(object.internal), self.is_local(&activity.id), activity.published, tx).await?;
let to_only_activity = (&to_activity - &to_object).into_iter().collect(); let to_only_activity = (&to_activity - &to_object).into_iter().collect();
address_to(self, to_only_activity, Some(activity.internal), None, self.is_local(&activity.id), tx).await?; address_to(self, to_only_activity, Some(activity.internal), None, self.is_local(&activity.id), activity.published, tx).await?;
let to_only_object = (&to_object - &to_activity).into_iter().collect(); let to_only_object = (&to_object - &to_activity).into_iter().collect();
address_to(self, to_only_object, None, Some(object.internal), self.is_local(&activity.id), tx).await?; address_to(self, to_only_object, None, Some(object.internal), self.is_local(&activity.id), object.published, tx).await?;
Ok(()) Ok(())
}, },
} }
} }
} }
async fn address_to(ctx: &crate::Context, to: Vec<String>, aid: Option<i64>, oid: Option<i64>, local: bool, tx: &impl ConnectionTrait) -> Result<(), DbErr> { async fn address_to(ctx: &crate::Context, to: Vec<String>, aid: Option<i64>, oid: Option<i64>, local: bool, when: chrono::DateTime<chrono::Utc>, tx: &impl ConnectionTrait) -> Result<(), DbErr> {
// TODO address_to became kind of expensive, with these two selects right away and then another // TODO address_to became kind of expensive, with these two selects right away and then another
// select for each target we're addressing to... can this be improved?? // select for each target we're addressing to... can this be improved??
let now = chrono::Utc::now();
let mut addressing = Vec::new(); let mut addressing = Vec::new();
for target in to.into_iter() for target in to.into_iter()
.filter(|to| !to.is_empty()) .filter(|to| !to.is_empty())
@ -109,7 +108,7 @@ async fn address_to(ctx: &crate::Context, to: Vec<String>, aid: Option<i64>, oid
actor: Set(actor), actor: Set(actor),
activity: Set(aid), activity: Set(aid),
object: Set(oid), object: Set(oid),
published: Set(now), published: Set(when),
} }
); );
} }