Profiles: Add more updated info for submissions, profiles
This commit is contained in:
parent
e9b9a83042
commit
504baf208a
|
@ -54,6 +54,7 @@ pub(super) fn note(
|
||||||
}
|
}
|
||||||
|
|
||||||
let published = note.published().req("published")?;
|
let published = note.published().req("published")?;
|
||||||
|
let updated = note.updated();
|
||||||
let attributed_to = note
|
let attributed_to = note
|
||||||
.attributed_to()
|
.attributed_to()
|
||||||
.req("attributed to")?
|
.req("attributed to")?
|
||||||
|
@ -176,6 +177,7 @@ pub(super) fn note(
|
||||||
title: title.to_owned(),
|
title: title.to_owned(),
|
||||||
description,
|
description,
|
||||||
published: Some(published.into()),
|
published: Some(published.into()),
|
||||||
|
updated: updated.map(|u| u.into()),
|
||||||
files: existing_files,
|
files: existing_files,
|
||||||
visibility: find_visibility(note),
|
visibility: find_visibility(note),
|
||||||
local_only: false,
|
local_only: false,
|
||||||
|
|
|
@ -97,6 +97,7 @@ pub(crate) fn person(
|
||||||
let public_key = person.ext_one.public_key.public_key_pem.clone();
|
let public_key = person.ext_one.public_key.public_key_pem.clone();
|
||||||
let public_key_id = person.ext_one.public_key.id.clone();
|
let public_key_id = person.ext_one.public_key.id.clone();
|
||||||
let published = person.published().req("published")?.into();
|
let published = person.published().req("published")?.into();
|
||||||
|
let updated = person.updated().map(|u| u.into());
|
||||||
|
|
||||||
let login_required = person
|
let login_required = person
|
||||||
.to()
|
.to()
|
||||||
|
@ -136,6 +137,7 @@ pub(crate) fn person(
|
||||||
login_required: Some(login_required),
|
login_required: Some(login_required),
|
||||||
icon,
|
icon,
|
||||||
banner,
|
banner,
|
||||||
|
updated,
|
||||||
})))
|
})))
|
||||||
} else {
|
} else {
|
||||||
Ok(Ok(Box::new(CreateProfile {
|
Ok(Ok(Box::new(CreateProfile {
|
||||||
|
@ -153,6 +155,7 @@ pub(crate) fn person(
|
||||||
icon,
|
icon,
|
||||||
banner,
|
banner,
|
||||||
published,
|
published,
|
||||||
|
updated,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +223,7 @@ pub(crate) fn update_person(
|
||||||
.map(|s| s.to_owned());
|
.map(|s| s.to_owned());
|
||||||
let public_key_id = person.ext_one.public_key.id.clone();
|
let public_key_id = person.ext_one.public_key.id.clone();
|
||||||
let public_key = person.ext_one.public_key.public_key_pem.clone();
|
let public_key = person.ext_one.public_key.public_key_pem.clone();
|
||||||
|
let updated = person.updated().map(|u| u.into());
|
||||||
|
|
||||||
let login_required = person
|
let login_required = person
|
||||||
.to()
|
.to()
|
||||||
|
@ -252,6 +256,7 @@ pub(crate) fn update_person(
|
||||||
login_required: Some(login_required),
|
login_required: Some(login_required),
|
||||||
icon,
|
icon,
|
||||||
banner,
|
banner,
|
||||||
|
updated,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,6 +272,7 @@ pub struct CreateSubmission {
|
||||||
local_only: bool,
|
local_only: bool,
|
||||||
logged_in_only: bool,
|
logged_in_only: bool,
|
||||||
sensitive: bool,
|
sensitive: bool,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreateSubmission {
|
impl CreateSubmission {
|
||||||
|
@ -287,6 +288,7 @@ impl CreateSubmission {
|
||||||
local_only: false,
|
local_only: false,
|
||||||
logged_in_only: false,
|
logged_in_only: false,
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
|
updated: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -470,6 +472,7 @@ pub struct CreateProfile {
|
||||||
icon: Option<Uuid>,
|
icon: Option<Uuid>,
|
||||||
banner: Option<Uuid>,
|
banner: Option<Uuid>,
|
||||||
published: DateTime<Utc>,
|
published: DateTime<Utc>,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CreateProfile {
|
impl CreateProfile {
|
||||||
|
@ -485,6 +488,7 @@ impl CreateProfile {
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
|
updated: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,6 +508,7 @@ pub struct UpdateProfile {
|
||||||
login_required: Option<bool>,
|
login_required: Option<bool>,
|
||||||
icon: Option<Uuid>,
|
icon: Option<Uuid>,
|
||||||
banner: Option<Uuid>,
|
banner: Option<Uuid>,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateProfile {
|
impl UpdateProfile {
|
||||||
|
@ -530,6 +535,7 @@ impl UpdateProfile {
|
||||||
login_required: None,
|
login_required: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
|
updated: Some(Utc::now()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,6 +550,7 @@ impl UpdateProfile {
|
||||||
login_required: None,
|
login_required: None,
|
||||||
icon: Some(icon),
|
icon: Some(icon),
|
||||||
banner: None,
|
banner: None,
|
||||||
|
updated: Some(Utc::now()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,6 +565,7 @@ impl UpdateProfile {
|
||||||
login_required: None,
|
login_required: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: Some(banner),
|
banner: Some(banner),
|
||||||
|
updated: Some(Utc::now()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,6 +580,7 @@ impl UpdateProfile {
|
||||||
login_required: Some(login_required),
|
login_required: Some(login_required),
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
|
updated: Some(Utc::now()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ impl Action for CreateProfile {
|
||||||
if let Some(icon) = self.icon {
|
if let Some(icon) = self.icon {
|
||||||
changes.icon(icon);
|
changes.icon(icon);
|
||||||
}
|
}
|
||||||
|
if let Some(updated) = self.updated {
|
||||||
|
changes.updated(updated);
|
||||||
|
}
|
||||||
|
|
||||||
let profile = if changes.any_changes() {
|
let profile = if changes.any_changes() {
|
||||||
ctx.store.profiles.update(&changes)?
|
ctx.store.profiles.update(&changes)?
|
||||||
|
@ -88,6 +91,9 @@ impl Action for UpdateProfile {
|
||||||
if let Some(description_source) = &self.description_source {
|
if let Some(description_source) = &self.description_source {
|
||||||
changes.description_source(description_source);
|
changes.description_source(description_source);
|
||||||
}
|
}
|
||||||
|
if let Some(updated) = self.updated {
|
||||||
|
changes.updated(updated);
|
||||||
|
}
|
||||||
|
|
||||||
let previous_banner = profile.banner();
|
let previous_banner = profile.banner();
|
||||||
let previous_icon = profile.icon();
|
let previous_icon = profile.icon();
|
||||||
|
|
|
@ -27,6 +27,9 @@ impl Action for CreateSubmission {
|
||||||
if let Some(description) = &self.description {
|
if let Some(description) = &self.description {
|
||||||
changes.description(&hyaenidae_content::html(description));
|
changes.description(&hyaenidae_content::html(description));
|
||||||
}
|
}
|
||||||
|
if let Some(updated) = self.updated {
|
||||||
|
changes.updated(updated);
|
||||||
|
}
|
||||||
|
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
changes.add_file(*file);
|
changes.add_file(*file);
|
||||||
|
|
|
@ -149,6 +149,9 @@ impl Outbound for ProfileCreated {
|
||||||
let image = build_image(banner, ctx)?;
|
let image = build_image(banner, ctx)?;
|
||||||
person.set_image(image);
|
person.set_image(image);
|
||||||
}
|
}
|
||||||
|
if let Some(updated) = profile.updated() {
|
||||||
|
person.set_updated(updated.into());
|
||||||
|
}
|
||||||
if !profile.login_required() {
|
if !profile.login_required() {
|
||||||
person.add_to(public());
|
person.add_to(public());
|
||||||
}
|
}
|
||||||
|
@ -265,6 +268,9 @@ impl Outbound for ProfileUpdated {
|
||||||
let image = build_image(banner, ctx)?;
|
let image = build_image(banner, ctx)?;
|
||||||
person.set_image(image);
|
person.set_image(image);
|
||||||
}
|
}
|
||||||
|
if let Some(updated) = profile.updated() {
|
||||||
|
person.set_updated(updated.into());
|
||||||
|
}
|
||||||
if !profile.login_required() {
|
if !profile.login_required() {
|
||||||
person.add_to(public());
|
person.add_to(public());
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub struct ProfileChanges {
|
||||||
login_required: Option<bool>,
|
login_required: Option<bool>,
|
||||||
icon: Option<Uuid>,
|
icon: Option<Uuid>,
|
||||||
banner: Option<Uuid>,
|
banner: Option<Uuid>,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -35,6 +36,7 @@ pub struct Profile {
|
||||||
icon: Option<Uuid>,
|
icon: Option<Uuid>,
|
||||||
banner: Option<Uuid>,
|
banner: Option<Uuid>,
|
||||||
published: DateTime<Utc>,
|
published: DateTime<Utc>,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
login_required: bool,
|
login_required: bool,
|
||||||
suspended: bool,
|
suspended: bool,
|
||||||
}
|
}
|
||||||
|
@ -73,9 +75,9 @@ struct StoredProfile {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
banner: Option<Uuid>,
|
banner: Option<Uuid>,
|
||||||
published: DateTime<Utc>,
|
published: DateTime<Utc>,
|
||||||
|
updated: Option<DateTime<Utc>>,
|
||||||
login_required: bool,
|
login_required: bool,
|
||||||
created_at: DateTime<Utc>,
|
created_at: DateTime<Utc>,
|
||||||
updated_at: DateTime<Utc>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
suspended_at: Option<DateTime<Utc>>,
|
suspended_at: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
@ -116,12 +118,18 @@ impl ProfileChanges {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn updated(&mut self, updated: DateTime<Utc>) -> &mut Self {
|
||||||
|
self.updated = Some(updated);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn any_changes(&self) -> bool {
|
pub(crate) fn any_changes(&self) -> bool {
|
||||||
self.display_name.is_some()
|
self.display_name.is_some()
|
||||||
|| self.description.is_some()
|
|| self.description.is_some()
|
||||||
|| self.login_required.is_some()
|
|| self.login_required.is_some()
|
||||||
|| self.icon.is_some()
|
|| self.icon.is_some()
|
||||||
|| self.banner.is_some()
|
|| self.banner.is_some()
|
||||||
|
|| self.updated.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +150,7 @@ impl Profile {
|
||||||
login_required: None,
|
login_required: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
|
updated: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,6 +205,10 @@ impl Profile {
|
||||||
self.published
|
self.published
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn updated(&self) -> Option<DateTime<Utc>> {
|
||||||
|
self.updated
|
||||||
|
}
|
||||||
|
|
||||||
pub fn login_required(&self) -> bool {
|
pub fn login_required(&self) -> bool {
|
||||||
self.login_required
|
self.login_required
|
||||||
}
|
}
|
||||||
|
@ -253,9 +266,9 @@ impl Store {
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
published,
|
published,
|
||||||
|
updated: None,
|
||||||
login_required: true,
|
login_required: true,
|
||||||
created_at: now,
|
created_at: now,
|
||||||
updated_at: now,
|
|
||||||
suspended_at: None,
|
suspended_at: None,
|
||||||
};
|
};
|
||||||
serde_json::to_writer(writer, &stored_profile)?;
|
serde_json::to_writer(writer, &stored_profile)?;
|
||||||
|
@ -365,6 +378,13 @@ impl Store {
|
||||||
|
|
||||||
let mut stored_profile: StoredProfile = serde_json::from_slice(&stored_profile_ivec)?;
|
let mut stored_profile: StoredProfile = serde_json::from_slice(&stored_profile_ivec)?;
|
||||||
|
|
||||||
|
if let Some(updated) = profile_changes.updated {
|
||||||
|
let previously_updated = stored_profile.updated.unwrap_or(stored_profile.published);
|
||||||
|
if updated < previously_updated {
|
||||||
|
return Err(StoreError::Outdated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(login_required) = profile_changes.login_required {
|
if let Some(login_required) = profile_changes.login_required {
|
||||||
stored_profile.login_required = login_required;
|
stored_profile.login_required = login_required;
|
||||||
}
|
}
|
||||||
|
@ -386,7 +406,9 @@ impl Store {
|
||||||
if let Some(banner) = profile_changes.banner {
|
if let Some(banner) = profile_changes.banner {
|
||||||
stored_profile.banner = Some(banner);
|
stored_profile.banner = Some(banner);
|
||||||
}
|
}
|
||||||
stored_profile.updated_at = Utc::now().into();
|
if let Some(updated) = profile_changes.updated {
|
||||||
|
stored_profile.updated = Some(updated);
|
||||||
|
}
|
||||||
|
|
||||||
let stored_profile_vec = serde_json::to_vec(&stored_profile)?;
|
let stored_profile_vec = serde_json::to_vec(&stored_profile)?;
|
||||||
|
|
||||||
|
@ -533,7 +555,7 @@ impl Store {
|
||||||
stored_profile.description = None;
|
stored_profile.description = None;
|
||||||
stored_profile.display_name = None;
|
stored_profile.display_name = None;
|
||||||
stored_profile.suspended_at = Some(now);
|
stored_profile.suspended_at = Some(now);
|
||||||
stored_profile.updated_at = now;
|
stored_profile.updated = Some(now);
|
||||||
let stored_profile_vec = serde_json::to_vec(&stored_profile)?;
|
let stored_profile_vec = serde_json::to_vec(&stored_profile)?;
|
||||||
|
|
||||||
if self
|
if self
|
||||||
|
@ -616,6 +638,7 @@ impl From<StoredProfile> for Profile {
|
||||||
icon: sp.icon,
|
icon: sp.icon,
|
||||||
banner: sp.banner,
|
banner: sp.banner,
|
||||||
published: sp.published,
|
published: sp.published,
|
||||||
|
updated: sp.updated,
|
||||||
login_required: sp.login_required,
|
login_required: sp.login_required,
|
||||||
suspended: sp.suspended_at.is_some(),
|
suspended: sp.suspended_at.is_some(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue