Remove trailing 07 from Hashtag
This commit is contained in:
parent
2fe2505a01
commit
f8870af9fe
@ -372,10 +372,10 @@ where
|
|||||||
pub type CustomPerson = Ext1<ApActor<Person>, ApSignature07>;
|
pub type CustomPerson = Ext1<ApActor<Person>, ApSignature07>;
|
||||||
pub type CustomGroup = Ext2<ApActor<Group>, ApSignature07, SourceProperty>;
|
pub type CustomGroup = Ext2<ApActor<Group>, ApSignature07, SourceProperty>;
|
||||||
|
|
||||||
kind!(HashtagType07, Hashtag);
|
kind!(HashtagType, Hashtag);
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Hashtag07 {
|
pub struct Hashtag {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub href: Option<IriString>,
|
pub href: Option<IriString>,
|
||||||
|
|
||||||
@ -383,10 +383,10 @@ pub struct Hashtag07 {
|
|||||||
pub name: Option<AnyString>,
|
pub name: Option<AnyString>,
|
||||||
|
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
inner: Object07<HashtagType07>,
|
inner: Object07<HashtagType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hashtag07 {
|
impl Hashtag {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
href: None,
|
href: None,
|
||||||
@ -395,14 +395,14 @@ impl Hashtag07 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extending(mut inner: Object07<HashtagType07>) -> Result<Self, serde_json::Error> {
|
pub fn extending(mut inner: Object07<HashtagType>) -> Result<Self, serde_json::Error> {
|
||||||
let href = inner.remove("href")?;
|
let href = inner.remove("href")?;
|
||||||
let name = inner.remove("name")?;
|
let name = inner.remove("name")?;
|
||||||
|
|
||||||
Ok(Self { href, name, inner })
|
Ok(Self { href, name, inner })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn retracting(self) -> Result<Object07<HashtagType07>, serde_json::Error> {
|
pub fn retracting(self) -> Result<Object07<HashtagType>, serde_json::Error> {
|
||||||
let Self {
|
let Self {
|
||||||
href,
|
href,
|
||||||
name,
|
name,
|
||||||
@ -416,9 +416,9 @@ impl Hashtag07 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait AsHashtag: markers::Object {
|
pub trait AsHashtag: markers::Object {
|
||||||
fn hashtag_ref(&self) -> &Hashtag07;
|
fn hashtag_ref(&self) -> &Hashtag;
|
||||||
|
|
||||||
fn hashtag_mut(&mut self) -> &mut Hashtag07;
|
fn hashtag_mut(&mut self) -> &mut Hashtag;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HashtagExt: AsHashtag {
|
pub trait HashtagExt: AsHashtag {
|
||||||
@ -465,13 +465,13 @@ pub trait HashtagExt: AsHashtag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Hashtag07 {
|
impl Default for Hashtag {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashtag for Hashtag07 {
|
impl AsHashtag for Hashtag {
|
||||||
fn hashtag_ref(&self) -> &Self {
|
fn hashtag_ref(&self) -> &Self {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -481,22 +481,22 @@ impl AsHashtag for Hashtag07 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Extends<HashtagType07> for Hashtag07 {
|
impl Extends<HashtagType> for Hashtag {
|
||||||
type Error = serde_json::Error;
|
type Error = serde_json::Error;
|
||||||
|
|
||||||
fn extends(base: Base<HashtagType07>) -> Result<Self, Self::Error> {
|
fn extends(base: Base<HashtagType>) -> Result<Self, Self::Error> {
|
||||||
let inner = Object07::extends(base)?;
|
let inner = Object07::extends(base)?;
|
||||||
Self::extending(inner)
|
Self::extending(inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn retracts(self) -> Result<Base<HashtagType07>, Self::Error> {
|
fn retracts(self) -> Result<Base<HashtagType>, Self::Error> {
|
||||||
let inner = self.retracting()?;
|
let inner = self.retracting()?;
|
||||||
inner.retracts()
|
inner.retracts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl markers::Base for Hashtag07 {}
|
impl markers::Base for Hashtag {}
|
||||||
impl markers::Object for Hashtag07 {}
|
impl markers::Object for Hashtag {}
|
||||||
impl<T> HashtagExt for T where T: AsHashtag {}
|
impl<T> HashtagExt for T where T: AsHashtag {}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||||
|
@ -23,7 +23,7 @@ use plume_common::{
|
|||||||
activity_pub::{
|
activity_pub::{
|
||||||
inbox::{AsActor, AsObject, FromId},
|
inbox::{AsActor, AsObject, FromId},
|
||||||
sign::Signer,
|
sign::Signer,
|
||||||
Hashtag07, HashtagType07, Id, IntoId, Licensed, Licensed07,
|
Hashtag, HashtagType, Id, IntoId, Licensed, Licensed07,
|
||||||
LicensedArticle as LicensedArticle07, Source, SourceProperty, ToAsString, ToAsUri,
|
LicensedArticle as LicensedArticle07, Source, SourceProperty, ToAsString, ToAsUri,
|
||||||
PUBLIC_VISIBILITY,
|
PUBLIC_VISIBILITY,
|
||||||
},
|
},
|
||||||
@ -494,7 +494,7 @@ impl Post {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_tags07(&self, conn: &Connection, tags: Vec<Hashtag07>) -> Result<()> {
|
pub fn update_tags07(&self, conn: &Connection, tags: Vec<Hashtag>) -> Result<()> {
|
||||||
let tags_name = tags
|
let tags_name = tags
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string()))
|
.filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string()))
|
||||||
@ -531,7 +531,7 @@ impl Post {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_hashtags07(&self, conn: &Connection, tags: Vec<Hashtag07>) -> Result<()> {
|
pub fn update_hashtags07(&self, conn: &Connection, tags: Vec<Hashtag>) -> Result<()> {
|
||||||
let tags_name = tags
|
let tags_name = tags
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string()))
|
.filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string()))
|
||||||
@ -797,7 +797,7 @@ impl FromId<DbConn> for Post {
|
|||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
tag.clone()
|
tag.clone()
|
||||||
.extend::<Hashtag07, HashtagType07>() // FIXME: Don't clone
|
.extend::<Hashtag, HashtagType>() // FIXME: Don't clone
|
||||||
.map(|hashtag| {
|
.map(|hashtag| {
|
||||||
hashtag.and_then(|t| {
|
hashtag.and_then(|t| {
|
||||||
let tag_name = t.name.clone()?.as_str().to_string();
|
let tag_name = t.name.clone()?.as_str().to_string();
|
||||||
@ -962,7 +962,7 @@ impl AsObject<User, Update07, &DbConn> for PostUpdate {
|
|||||||
.map(|m| mentions.push(m))
|
.map(|m| mentions.push(m))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
serde_json::from_value::<Hashtag07>(tag.clone())
|
serde_json::from_value::<Hashtag>(tag.clone())
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
.and_then(|t| {
|
.and_then(|t| {
|
||||||
let tag_name = t.name.as_ref().ok_or(Error::MissingApProperty)?;
|
let tag_name = t.name.as_ref().ok_or(Error::MissingApProperty)?;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{ap_url, instance::Instance, schema::tags, Connection, Error, Result};
|
use crate::{ap_url, instance::Instance, schema::tags, Connection, Error, Result};
|
||||||
use activitystreams::iri_string::types::IriString;
|
use activitystreams::iri_string::types::IriString;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||||
use plume_common::activity_pub::{Hashtag07, HashtagExt};
|
use plume_common::activity_pub::{Hashtag, HashtagExt};
|
||||||
|
|
||||||
#[derive(Clone, Identifiable, Queryable)]
|
#[derive(Clone, Identifiable, Queryable)]
|
||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
@ -25,8 +25,8 @@ impl Tag {
|
|||||||
find_by!(tags, find_by_name, tag as &str);
|
find_by!(tags, find_by_name, tag as &str);
|
||||||
list_by!(tags, for_post, post_id as i32);
|
list_by!(tags, for_post, post_id as i32);
|
||||||
|
|
||||||
pub fn to_activity07(&self) -> Result<Hashtag07> {
|
pub fn to_activity07(&self) -> Result<Hashtag> {
|
||||||
let mut ht = Hashtag07::new();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href(
|
ht.set_href(
|
||||||
ap_url(&format!(
|
ap_url(&format!(
|
||||||
"{}/tag/{}",
|
"{}/tag/{}",
|
||||||
@ -41,7 +41,7 @@ impl Tag {
|
|||||||
|
|
||||||
pub fn from_activity07(
|
pub fn from_activity07(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
tag: &Hashtag07,
|
tag: &Hashtag,
|
||||||
post: i32,
|
post: i32,
|
||||||
is_hashtag: bool,
|
is_hashtag: bool,
|
||||||
) -> Result<Tag> {
|
) -> Result<Tag> {
|
||||||
@ -55,8 +55,8 @@ impl Tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_activity07(tag: String) -> Result<Hashtag07> {
|
pub fn build_activity07(tag: String) -> Result<Hashtag> {
|
||||||
let mut ht = Hashtag07::new();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href(
|
ht.set_href(
|
||||||
ap_url(&format!(
|
ap_url(&format!(
|
||||||
"{}/tag/{}",
|
"{}/tag/{}",
|
||||||
@ -91,7 +91,7 @@ mod tests {
|
|||||||
conn.test_transaction::<_, Error, _>(|| {
|
conn.test_transaction::<_, Error, _>(|| {
|
||||||
let (posts, _users, _blogs) = fill_database(conn);
|
let (posts, _users, _blogs) = fill_database(conn);
|
||||||
let post_id = posts[0].id;
|
let post_id = posts[0].id;
|
||||||
let mut ht = Hashtag07::new();
|
let mut ht = Hashtag::new();
|
||||||
ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::<IriString>()?);
|
ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::<IriString>()?);
|
||||||
ht.set_name("a_tag".to_string());
|
ht.set_name("a_tag".to_string());
|
||||||
let tag = Tag::from_activity07(conn, &ht, post_id, true)?;
|
let tag = Tag::from_activity07(conn, &ht, post_id, true)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user