Automatically include apub hashtag with posts (fixes #3906)

This commit is contained in:
Felix Ableitner 2024-03-14 16:08:48 +01:00
parent 255e695633
commit 3c63a91859
2 changed files with 22 additions and 1 deletions

View file

@ -5,7 +5,7 @@ use crate::{
objects::{read_from_string_or_source_opt, verify_is_remote_object}, objects::{read_from_string_or_source_opt, verify_is_remote_object},
protocol::{ protocol::{
objects::{ objects::{
page::{Attachment, AttributedTo, Page, PageType}, page::{Attachment, AttributedTo, Hashtag, HashtagType, Page, PageType},
LanguageTag, LanguageTag,
}, },
ImageObject, ImageObject,
@ -124,6 +124,11 @@ impl Object for ApubPost {
}) })
.into_iter() .into_iter()
.collect(); .collect();
let hashtag = Hashtag {
href: self.ap_id.clone().into(),
name: format!("#{}", &community.name),
kind: HashtagType::Hashtag,
};
let page = Page { let page = Page {
kind: PageType::Page, kind: PageType::Page,
@ -144,6 +149,7 @@ impl Object for ApubPost {
updated: self.updated, updated: self.updated,
audience: Some(community.actor_id.into()), audience: Some(community.actor_id.into()),
in_reply_to: None, in_reply_to: None,
tag: vec![hashtag],
}; };
Ok(page) Ok(page)
} }

View file

@ -66,6 +66,8 @@ pub struct Page {
pub(crate) updated: Option<DateTime<Utc>>, pub(crate) updated: Option<DateTime<Utc>>,
pub(crate) language: Option<LanguageTag>, pub(crate) language: Option<LanguageTag>,
pub(crate) audience: Option<ObjectId<ApubCommunity>>, pub(crate) audience: Option<ObjectId<ApubCommunity>>,
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) tag: Vec<Hashtag>,
} }
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
@ -140,6 +142,19 @@ pub(crate) struct AttributedToPeertube {
pub id: ObjectId<UserOrCommunity>, pub id: ObjectId<UserOrCommunity>,
} }
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Hashtag {
pub(crate) href: Url,
pub(crate) name: String,
#[serde(rename = "type")]
pub(crate) kind: HashtagType,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum HashtagType {
Hashtag,
}
impl Page { impl Page {
/// Only mods can change the post's locked status. So if it is changed from the default value, /// Only mods can change the post's locked status. So if it is changed from the default value,
/// it is a mod action and needs to be verified as such. /// it is a mod action and needs to be verified as such.