"log",
"serde 1.0.118",
"serde_json",
+ "url",
]
[[package]]
}
// Double check for duplicate community actor_ids
- let actor_id = make_apub_endpoint(EndpointType::Community, &data.name).to_string();
+ let actor_id = make_apub_endpoint(EndpointType::Community, &data.name);
let actor_id_cloned = actor_id.to_owned();
let community_dupe = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &actor_id_cloned)
+ Community::read_from_apub_id(conn, &actor_id_cloned.into())
})
.await?;
if community_dupe.is_ok() {
deleted: None,
nsfw: data.nsfw,
updated: None,
- actor_id: Some(actor_id),
+ actor_id: Some(actor_id.into()),
local: true,
private_key: Some(keypair.private_key),
public_key: Some(keypair.public_key),
} else if data.follow {
// Dont actually add to the community followers here, because you need
// to wait for the accept
- user.send_follow(&community.actor_id()?, context).await?;
+ user.send_follow(&community.actor_id(), context).await?;
} else {
- user.send_unfollow(&community.actor_id()?, context).await?;
+ user.send_unfollow(&community.actor_id(), context).await?;
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
if blocking(context.pool(), unfollow).await?.is_err() {
return Err(APIError::err("community_follower_already_exists").into());
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
- actor_id: Some(make_apub_endpoint(EndpointType::User, &data.username).to_string()),
+ actor_id: Some(make_apub_endpoint(EndpointType::User, &data.username).into()),
bio: None,
local: true,
private_key: Some(user_keypair.private_key),
deleted: None,
updated: None,
actor_id: Some(
- make_apub_endpoint(EndpointType::Community, default_community_name).to_string(),
+ make_apub_endpoint(EndpointType::Community, default_community_name).into(),
),
local: true,
private_key: Some(main_community_keypair.private_key),
let note = NoteExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
- let comment = Comment::from_apub(¬e, context, user.actor_id()?, request_counter).await?;
+ let comment = Comment::from_apub(¬e, context, user.actor_id(), request_counter).await?;
let post_id = comment.post_id;
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
.context(location_info!())?;
let user = get_actor_as_user(&update, context, request_counter).await?;
- let comment = Comment::from_apub(¬e, context, user.actor_id()?, request_counter).await?;
+ let comment = Comment::from_apub(¬e, context, user.actor_id(), request_counter).await?;
let comment_id = comment.id;
let post_id = comment.post_id;
.single_xsd_any_uri()
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, community_uri.as_str())
+ Community::read_from_apub_id(conn, &community_uri.into())
})
.await??;
.single_xsd_any_uri()
.context(location_info!())?;
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, community_uri.as_str())
+ Community::read_from_apub_id(conn, &community_uri.into())
})
.await??;
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
- let post = Post::from_apub(&page, context, user.actor_id()?, request_counter).await?;
+ let post = Post::from_apub(&page, context, user.actor_id(), request_counter).await?;
// Refetch the view
let post_id = post.id;
let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
- let post = Post::from_apub(&page, context, user.actor_id()?, request_counter).await?;
+ let post = Post::from_apub(&page, context, user.actor_id(), request_counter).await?;
let post_id = post.id;
// Refetch the view
let maa = collect_non_local_mentions(&self, &community, context).await?;
- let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
+ let mut create = Create::new(
+ creator.actor_id.to_owned().into_inner(),
+ note.into_any_base()?,
+ );
create
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
let maa = collect_non_local_mentions(&self, &community, context).await?;
- let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
+ let mut update = Update::new(
+ creator.actor_id.to_owned().into_inner(),
+ note.into_any_base()?,
+ );
update
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
})
.await??;
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(delete, &creator, &community, context).await?;
Ok(())
.await??;
// Generate a fake delete activity, with the correct object
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
+ let mut undo = Undo::new(
+ creator.actor_id.to_owned().into_inner(),
+ delete.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, &creator, &community, context).await?;
Ok(())
})
.await??;
- let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut remove = Remove::new(
+ mod_.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(remove, &mod_, &community, context).await?;
Ok(())
.await??;
// Generate a fake delete activity, with the correct object
- let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut remove = Remove::new(
+ mod_.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
+ let mut undo = Undo::new(
+ mod_.actor_id.to_owned().into_inner(),
+ remove.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, &mod_, &community, context).await?;
Ok(())
})
.await??;
- let mut like = Like::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut like = Like::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
like
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(like, &creator, &community, context).await?;
Ok(())
})
.await??;
- let mut dislike = Dislike::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut dislike = Dislike::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
dislike
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(dislike, &creator, &community, context).await?;
Ok(())
})
.await??;
- let mut like = Like::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut like = Like::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
like
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
+ let mut undo = Undo::new(
+ creator.actor_id.to_owned().into_inner(),
+ like.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, &creator, &community, context).await?;
Ok(())
context: &LemmyContext,
) -> Result<MentionsAndAddresses, LemmyError> {
let parent_creator = get_comment_parent_creator(context.pool(), comment).await?;
- let mut addressed_ccs = vec![community.actor_id()?, parent_creator.actor_id()?];
+ let mut addressed_ccs = vec![community.actor_id(), parent_creator.actor_id()];
// Note: dont include community inbox here, as we send to it separately with `send_to_community()`
let mut inboxes = vec![parent_creator.get_shared_inbox_url()?];
link
.href
.to_owned()
- .map(|u| Url::parse(&u))
- .transpose()?
.ok_or_else(|| anyhow!("No href found.").into())
}
#[async_trait::async_trait(?Send)]
impl ActorType for Community {
- fn actor_id_str(&self) -> String {
- self.actor_id.to_owned()
+ fn actor_id(&self) -> Url {
+ self.actor_id.to_owned().into_inner()
}
fn public_key(&self) -> Option<String> {
.context(location_info!())?;
let user = get_or_fetch_and_upsert_user(actor_uri, context, &mut 0).await?;
- let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
+ let mut accept = Accept::new(
+ self.actor_id.to_owned().into_inner(),
+ follow.into_any_base()?,
+ );
accept
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(AcceptType::Accept)?)
- .set_to(user.actor_id()?);
+ .set_to(user.actor_id());
send_activity_single_dest(accept, self, user.get_inbox_url()?, context).await?;
Ok(())
/// If the creator of a community deletes the community, send this to all followers.
async fn send_delete(&self, context: &LemmyContext) -> Result<(), LemmyError> {
- let mut delete = Delete::new(self.actor_id()?, self.actor_id()?);
+ let mut delete = Delete::new(self.actor_id(), self.actor_id());
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
/// If the creator of a community reverts the deletion of a community, send this to all followers.
async fn send_undo_delete(&self, context: &LemmyContext) -> Result<(), LemmyError> {
- let mut delete = Delete::new(self.actor_id()?, self.actor_id()?);
+ let mut delete = Delete::new(self.actor_id(), self.actor_id());
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()?]);
- let mut undo = Undo::new(self.actor_id()?, delete.into_any_base()?);
+ let mut undo = Undo::new(self.actor_id(), delete.into_any_base()?);
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
/// If an admin removes a community, send this to all followers.
async fn send_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
- let mut remove = Remove::new(self.actor_id()?, self.actor_id()?);
+ let mut remove = Remove::new(self.actor_id(), self.actor_id());
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
/// If an admin reverts the removal of a community, send this to all followers.
async fn send_undo_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
- let mut remove = Remove::new(self.actor_id()?, self.actor_id()?);
+ let mut remove = Remove::new(self.actor_id(), self.actor_id());
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_many_ccs(vec![self.get_followers_url()?]);
// Undo that fake activity
- let mut undo = Undo::new(self.actor_id()?, remove.into_any_base()?);
+ let mut undo = Undo::new(self.actor_id(), remove.into_any_base()?);
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
activity: AnyBase,
context: &LemmyContext,
) -> Result<(), LemmyError> {
- let mut announce = Announce::new(self.actor_id.to_owned(), activity);
+ let mut announce = Announce::new(self.actor_id.to_owned().into_inner(), activity);
announce
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(AnnounceType::Announce)?)
.into_iter()
.filter(|i| !i.follower.local)
.map(|u| -> Result<Url, LemmyError> {
- let url = Url::parse(&u.follower.actor_id)?;
+ let url = u.follower.actor_id.into_inner();
let domain = url.domain().context(location_info!())?;
let port = if let Some(port) = url.port() {
format!(":{}", port)
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
-use url::Url;
#[async_trait::async_trait(?Send)]
impl ApubObjectType for Post {
})
.await??;
- let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?);
+ let mut create = Create::new(
+ creator.actor_id.to_owned().into_inner(),
+ page.into_any_base()?,
+ );
create
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(create, creator, &community, context).await?;
Ok(())
})
.await??;
- let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?);
+ let mut update = Update::new(
+ creator.actor_id.to_owned().into_inner(),
+ page.into_any_base()?,
+ );
update
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(update, creator, &community, context).await?;
Ok(())
})
.await??;
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(delete, creator, &community, context).await?;
Ok(())
})
.await??;
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
+ let mut undo = Undo::new(
+ creator.actor_id.to_owned().into_inner(),
+ delete.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, creator, &community, context).await?;
Ok(())
})
.await??;
- let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut remove = Remove::new(
+ mod_.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(remove, mod_, &community, context).await?;
Ok(())
})
.await??;
- let mut remove = Remove::new(mod_.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut remove = Remove::new(
+ mod_.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
remove
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
+ let mut undo = Undo::new(
+ mod_.actor_id.to_owned().into_inner(),
+ remove.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, mod_, &community, context).await?;
Ok(())
})
.await??;
- let mut like = Like::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut like = Like::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
like
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(like, &creator, &community, context).await?;
Ok(())
})
.await??;
- let mut dislike = Dislike::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut dislike = Dislike::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
dislike
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(dislike, &creator, &community, context).await?;
Ok(())
})
.await??;
- let mut like = Like::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut like = Like::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
like
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
// Undo that fake activity
- let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
+ let mut undo = Undo::new(
+ creator.actor_id.to_owned().into_inner(),
+ like.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
- .set_many_ccs(vec![community.actor_id()?]);
+ .set_many_ccs(vec![community.actor_id()]);
send_to_community(undo, &creator, &community, context).await?;
Ok(())
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
-use url::Url;
#[async_trait::async_trait(?Send)]
impl ApubObjectType for PrivateMessage {
let recipient_id = self.recipient_id;
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
- let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
+ let mut create = Create::new(
+ creator.actor_id.to_owned().into_inner(),
+ note.into_any_base()?,
+ );
create
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(CreateType::Create)?)
- .set_to(recipient.actor_id()?);
+ .set_to(recipient.actor_id());
send_activity_single_dest(create, creator, recipient.get_inbox_url()?, context).await?;
Ok(())
let recipient_id = self.recipient_id;
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
- let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
+ let mut update = Update::new(
+ creator.actor_id.to_owned().into_inner(),
+ note.into_any_base()?,
+ );
update
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UpdateType::Update)?)
- .set_to(recipient.actor_id()?);
+ .set_to(recipient.actor_id());
send_activity_single_dest(update, creator, recipient.get_inbox_url()?, context).await?;
Ok(())
let recipient_id = self.recipient_id;
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
- .set_to(recipient.actor_id()?);
+ .set_to(recipient.actor_id());
send_activity_single_dest(delete, creator, recipient.get_inbox_url()?, context).await?;
Ok(())
let recipient_id = self.recipient_id;
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
- let mut delete = Delete::new(creator.actor_id.to_owned(), Url::parse(&self.ap_id)?);
+ let mut delete = Delete::new(
+ creator.actor_id.to_owned().into_inner(),
+ self.ap_id.to_owned().into_inner(),
+ );
delete
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(DeleteType::Delete)?)
- .set_to(recipient.actor_id()?);
+ .set_to(recipient.actor_id());
// Undo that fake activity
- let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
+ let mut undo = Undo::new(
+ creator.actor_id.to_owned().into_inner(),
+ delete.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
- .set_to(recipient.actor_id()?);
+ .set_to(recipient.actor_id());
send_activity_single_dest(undo, creator, recipient.get_inbox_url()?, context).await?;
Ok(())
#[async_trait::async_trait(?Send)]
impl ActorType for User_ {
- fn actor_id_str(&self) -> String {
- self.actor_id.to_owned()
+ fn actor_id(&self) -> Url {
+ self.actor_id.to_owned().into_inner()
}
fn public_key(&self) -> Option<String> {
follow_actor_id: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
- let follow_actor_id = follow_actor_id.to_string();
+ let follow_actor_id = follow_actor_id.to_owned();
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &follow_actor_id)
+ Community::read_from_apub_id(conn, &follow_actor_id.into())
})
.await??;
})
.await?;
- let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
+ let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
follow
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(FollowType::Follow)?)
- .set_to(community.actor_id()?);
+ .set_to(community.actor_id());
send_activity_single_dest(follow, self, community.get_inbox_url()?, context).await?;
Ok(())
follow_actor_id: &Url,
context: &LemmyContext,
) -> Result<(), LemmyError> {
- let follow_actor_id = follow_actor_id.to_string();
+ let follow_actor_id = follow_actor_id.to_owned();
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &follow_actor_id)
+ Community::read_from_apub_id(conn, &follow_actor_id.into())
})
.await??;
- let mut follow = Follow::new(self.actor_id.to_owned(), community.actor_id()?);
+ let mut follow = Follow::new(self.actor_id.to_owned().into_inner(), community.actor_id());
follow
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(FollowType::Follow)?)
- .set_to(community.actor_id()?);
+ .set_to(community.actor_id());
// Undo that fake activity
- let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
+ let mut undo = Undo::new(
+ self.actor_id.to_owned().into_inner(),
+ follow.into_any_base()?,
+ );
undo
.set_many_contexts(lemmy_context()?)
.set_id(generate_activity_id(UndoType::Undo)?)
- .set_to(community.actor_id()?);
+ .set_to(community.actor_id());
send_activity_single_dest(undo, self, community.get_inbox_url()?, context).await?;
Ok(())
let message = SendActivityTask {
activity: serialised_activity.to_owned(),
inbox: i.to_owned(),
- actor_id: actor.actor_id()?,
+ actor_id: actor.actor_id(),
private_key: actor.private_key().context(location_info!())?,
};
if env::var("LEMMY_TEST_SEND_SYNC").is_ok() {
/// Extension for actor public key, which is needed on user and community for HTTP signatures.
///
/// Taken from: https://docs.rs/activitystreams/0.5.0-alpha.17/activitystreams/ext/index.html
-#[derive(Clone, Debug, Default, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeyExtension {
pub public_key: PublicKey,
}
-#[derive(Clone, Debug, Default, Deserialize, Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicKey {
pub id: String,
- pub owner: String,
+ pub owner: Url,
pub public_key_pem: String,
}
) -> Result<Community, LemmyError> {
let apub_id_owned = apub_id.to_owned();
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, apub_id_owned.as_str())
+ Community::read_from_apub_id(conn, &apub_id_owned.into())
})
.await?;
) -> Result<Post, LemmyError> {
let post_ap_id_owned = post_ap_id.to_owned();
let post = blocking(context.pool(), move |conn| {
- Post::read_from_apub_id(conn, post_ap_id_owned.as_str())
+ Post::read_from_apub_id(conn, &post_ap_id_owned.into())
})
.await?;
) -> Result<Comment, LemmyError> {
let comment_ap_id_owned = comment_ap_id.to_owned();
let comment = blocking(context.pool(), move |conn| {
- Comment::read_from_apub_id(conn, comment_ap_id_owned.as_str())
+ Comment::read_from_apub_id(conn, &comment_ap_id_owned.into())
})
.await?;
) -> Result<User_, LemmyError> {
let apub_id_owned = apub_id.to_owned();
let user = blocking(context.pool(), move |conn| {
- User_::read_from_apub_id(conn, apub_id_owned.as_ref())
+ User_::read_from_apub_id(conn, &apub_id_owned.into())
})
.await?;
let mut collection = OrderedCollection::new();
collection
- .set_id(format!("{}/inbox", user.actor_id).parse()?)
+ .set_id(format!("{}/inbox", user.actor_id.into_inner()).parse()?)
.set_many_contexts(lemmy_context()?);
Ok(create_apub_response(&collection))
}
let actor = inbox_verify_http_signature(&activity, &context, request, request_counter).await?;
// Do nothing if we received the same activity before
- let activity_id = get_activity_id(&activity, &actor.actor_id()?)?;
+ let activity_id = get_activity_id(&activity, &actor.actor_id())?;
if is_activity_already_known(context.pool(), &activity_id).await? {
return Ok(HttpResponse::Ok().finish());
}
})
.await??;
let to_and_cc = get_activity_to_and_cc(&activity);
- if !to_and_cc.contains(&&community.actor_id()?) {
+ if !to_and_cc.contains(&&community.actor_id()) {
return Err(anyhow!("Activity delivered to wrong community").into());
}
"Community {} received activity {:?} from {}",
community.name,
&activity.id_unchecked(),
- &actor.actor_id_str()
+ &actor.actor_id()
);
community_receive_message(
) -> Result<HttpResponse, LemmyError> {
// Only users can send activities to the community, so we can get the actor as user
// unconditionally.
- let actor_id = actor.actor_id_str();
+ let actor_id = actor.actor_id();
let user = blocking(&context.pool(), move |conn| {
- User_::read_from_apub_id(&conn, &actor_id)
+ User_::read_from_apub_id(&conn, &actor_id.into())
})
.await??;
check_community_or_site_ban(&user, &to_community, context.pool()).await?;
let any_base = activity.clone().into_any_base()?;
- let actor_url = actor.actor_id()?;
+ let actor_url = actor.actor_id();
let activity_kind = activity.kind().context(location_info!())?;
let do_announce = match activity_kind {
CommunityValidTypes::Follow => {
context: &LemmyContext,
) -> Result<HttpResponse, LemmyError> {
let follow = Follow::from_any_base(activity)?.context(location_info!())?;
- verify_activity_domains_valid(&follow, &user.actor_id()?, false)?;
+ verify_activity_domains_valid(&follow, &user.actor_id(), false)?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
verify_activity_domains_valid(&follow, &user_url, false)?;
let user = blocking(&context.pool(), move |conn| {
- User_::read_from_apub_id(&conn, user_url.as_str())
+ User_::read_from_apub_id(&conn, &user_url.into())
})
.await??;
let community_follower_form = CommunityFollowerForm {
pool: &DbPool,
) -> Result<bool, LemmyError> {
for url in to_and_cc {
- let url = url.to_string();
- let user = blocking(&pool, move |conn| User_::read_from_apub_id(&conn, &url)).await?;
+ let url = url.to_owned();
+ let user = blocking(&pool, move |conn| {
+ User_::read_from_apub_id(&conn, &url.into())
+ })
+ .await?;
if let Ok(u) = user {
if u.local {
return Ok(true);
let url = url.to_string();
// TODO: extremely hacky, we should just store the followers url for each community in the db
if url.ends_with("/followers") {
- let community_url = url.replace("/followers", "");
+ let community_url = Url::parse(&url.replace("/followers", ""))?;
let community = blocking(&pool, move |conn| {
- Community::read_from_apub_id(&conn, &community_url)
+ Community::read_from_apub_id(&conn, &community_url.into())
})
.await??;
if !community.local {
let actor = inbox_verify_http_signature(&activity, &context, request, request_counter).await?;
// Do nothing if we received the same activity before
- let actor_id = actor.actor_id()?;
+ let actor_id = actor.actor_id();
let activity_id = get_activity_id(&activity, &actor_id)?;
if is_activity_already_known(context.pool(), &activity_id).await? {
return Ok(HttpResponse::Ok().finish());
pool: &DbPool,
) -> Result<Option<Community>, LemmyError> {
for url in to_and_cc {
- let url = url.to_string();
- let community = blocking(&pool, move |conn| Community::read_from_apub_id(&conn, &url)).await?;
+ let url = url.to_owned();
+ let community = blocking(&pool, move |conn| {
+ Community::read_from_apub_id(&conn, &url.into())
+ })
+ .await?;
if let Ok(c) = community {
if c.local {
return Ok(Some(c));
let actor = inbox_verify_http_signature(&activity, &context, request, request_counter).await?;
// Do nothing if we received the same activity before
- let activity_id = get_activity_id(&activity, &actor.actor_id()?)?;
+ let activity_id = get_activity_id(&activity, &actor.actor_id())?;
if is_activity_already_known(context.pool(), &activity_id).await? {
return Ok(HttpResponse::Ok().finish());
}
.await??;
let to_and_cc = get_activity_to_and_cc(&activity);
// TODO: we should also accept activities that are sent to community followers
- if !to_and_cc.contains(&&user.actor_id()?) {
+ if !to_and_cc.contains(&&user.actor_id()) {
return Err(anyhow!("Activity delivered to wrong user").into());
}
"User {} received activity {:?} from {}",
user.name,
&activity.id_unchecked(),
- &actor.actor_id_str()
+ &actor.actor_id()
);
user_receive_message(
let any_base = activity.clone().into_any_base()?;
let kind = activity.kind().context(location_info!())?;
- let actor_url = actor.actor_id()?;
+ let actor_url = actor.actor_id();
match kind {
UserValidTypes::Accept => {
receive_accept(&context, any_base, actor, to_user.unwrap(), request_counter).await?;
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let accept = Accept::from_any_base(activity)?.context(location_info!())?;
- verify_activity_domains_valid(&accept, &actor.actor_id()?, false)?;
+ verify_activity_domains_valid(&accept, &actor.actor_id(), false)?;
let object = accept.object().to_owned().one().context(location_info!())?;
let follow = Follow::from_any_base(object)?.context(location_info!())?;
- verify_activity_domains_valid(&follow, &user.actor_id()?, false)?;
+ verify_activity_domains_valid(&follow, &user.actor_id(), false)?;
let community_uri = accept
.actor()?
request_counter: &mut i32,
) -> Result<(), LemmyError> {
let announce = Announce::from_any_base(activity)?.context(location_info!())?;
- verify_activity_domains_valid(&announce, &actor.actor_id()?, false)?;
+ verify_activity_domains_valid(&announce, &actor.actor_id(), false)?;
is_addressed_to_public(&announce)?;
let kind = announce.object().as_single_kind_str();
context: &LemmyContext,
apub_id: Url,
) -> Result<CommunityOrPrivateMessage, LemmyError> {
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.to_owned();
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &ap_id)
+ Community::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(c) = community {
return Ok(CommunityOrPrivateMessage::Community(c));
}
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.to_owned();
let private_message = blocking(context.pool(), move |conn| {
- PrivateMessage::read_from_apub_id(conn, &ap_id)
+ PrivateMessage::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(p) = private_message {
/// implemented by all actors.
#[async_trait::async_trait(?Send)]
pub trait ActorType {
- fn actor_id_str(&self) -> String;
+ fn actor_id(&self) -> Url;
// TODO: every actor should have a public key, so this shouldnt be an option (needs to be fixed in db)
fn public_key(&self) -> Option<String>;
/// For a given community, returns the inboxes of all followers.
async fn get_follower_inboxes(&self, pool: &DbPool) -> Result<Vec<Url>, LemmyError>;
- fn actor_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.actor_id_str())
- }
-
// TODO move these to the db rows
fn get_inbox_url(&self) -> Result<Url, ParseError> {
- Url::parse(&format!("{}/inbox", &self.actor_id_str()))
+ Url::parse(&format!("{}/inbox", &self.actor_id()))
}
fn get_shared_inbox_url(&self) -> Result<Url, LemmyError> {
- let actor_id = self.actor_id()?;
+ let actor_id = self.actor_id();
let url = format!(
"{}://{}{}/inbox",
&actor_id.scheme(),
}
fn get_outbox_url(&self) -> Result<Url, ParseError> {
- Url::parse(&format!("{}/outbox", &self.actor_id_str()))
+ Url::parse(&format!("{}/outbox", &self.actor_id()))
}
fn get_followers_url(&self) -> Result<Url, ParseError> {
- Url::parse(&format!("{}/followers", &self.actor_id_str()))
+ Url::parse(&format!("{}/followers", &self.actor_id()))
}
fn get_public_key_ext(&self) -> Result<PublicKeyExtension, LemmyError> {
Ok(
PublicKey {
- id: format!("{}#main-key", self.actor_id_str()),
- owner: self.actor_id_str(),
+ id: format!("{}#main-key", self.actor_id()),
+ owner: self.actor_id(),
public_key_pem: self.public_key().context(location_info!())?,
}
.to_ext(),
context: &LemmyContext,
apub_id: Url,
) -> Result<PostOrComment, LemmyError> {
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.clone();
let post = blocking(context.pool(), move |conn| {
- Post::read_from_apub_id(conn, &ap_id)
+ Post::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(p) = post {
return Ok(PostOrComment::Post(p));
}
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.clone();
let comment = blocking(context.pool(), move |conn| {
- Comment::read_from_apub_id(conn, &ap_id)
+ Comment::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(c) = comment {
context: &LemmyContext,
apub_id: Url,
) -> Result<Object, LemmyError> {
- if let Ok(pc) = find_post_or_comment_by_id(context, apub_id.to_owned()).await {
+ let ap_id = apub_id.clone();
+ if let Ok(pc) = find_post_or_comment_by_id(context, ap_id.to_owned()).await {
return Ok(match pc {
PostOrComment::Post(p) => Object::Post(p),
PostOrComment::Comment(c) => Object::Comment(c),
});
}
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.clone();
let user = blocking(context.pool(), move |conn| {
- User_::read_from_apub_id(conn, &ap_id)
+ User_::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(u) = user {
return Ok(Object::User(u));
}
- let ap_id = apub_id.to_string();
+ let ap_id = apub_id.clone();
let community = blocking(context.pool(), move |conn| {
- Community::read_from_apub_id(conn, &ap_id)
+ Community::read_from_apub_id(conn, &ap_id.into())
})
.await?;
if let Ok(c) = community {
return Ok(Object::Community(c));
}
- let ap_id = apub_id.to_string();
let private_message = blocking(context.pool(), move |conn| {
- PrivateMessage::read_from_apub_id(conn, &ap_id)
+ PrivateMessage::read_from_apub_id(conn, &apub_id.into())
})
.await?;
if let Ok(pm) = private_message {
// Add a vector containing some important info to the "in_reply_to" field
// [post_ap_id, Option(parent_comment_ap_id)]
- let mut in_reply_to_vec = vec![post.ap_id];
+ let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
if let Some(parent_id) = self.parent_id {
let parent_comment = blocking(pool, move |conn| Comment::read(conn, parent_id)).await??;
- in_reply_to_vec.push(parent_comment.ap_id);
+ in_reply_to_vec.push(parent_comment.ap_id.into_inner());
}
comment
// Not needed when the Post is embedded in a collection (like for community outbox)
.set_many_contexts(lemmy_context()?)
- .set_id(Url::parse(&self.ap_id)?)
+ .set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
- .set_to(community.actor_id)
+ .set_to(community.actor_id.into_inner())
.set_many_in_reply_tos(in_reply_to_vec)
- .set_attributed_to(creator.actor_id);
+ .set_attributed_to(creator.actor_id.into_inner());
set_content_and_source(&mut comment, &self.content)?;
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
+ create_tombstone(
+ self.deleted,
+ self.ap_id.to_owned().into(),
+ self.updated,
+ NoteType::Note,
+ )
}
}
CommunityModeratorView::for_community(&conn, id)
})
.await??;
- let moderators: Vec<String> = moderators
+ let moderators: Vec<Url> = moderators
.into_iter()
- .map(|m| m.moderator.actor_id)
+ .map(|m| m.moderator.actor_id.into_inner())
.collect();
let mut group = ApObject::new(Group::new());
group
.set_many_contexts(lemmy_context()?)
- .set_id(Url::parse(&self.actor_id)?)
+ .set_id(self.actor_id.to_owned().into())
.set_name(self.title.to_owned())
.set_published(convert_datetime(self.published))
.set_many_attributed_tos(moderators);
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(self.deleted, &self.actor_id, self.updated, GroupType::Group)
+ create_tombstone(
+ self.deleted,
+ self.actor_id.to_owned().into(),
+ self.updated,
+ GroupType::Group,
+ )
}
}
/// Updated is actually the deletion time
fn create_tombstone<T>(
deleted: bool,
- object_id: &str,
+ object_id: Url,
updated: Option<NaiveDateTime>,
former_type: T,
) -> Result<Tombstone, LemmyError>
if deleted {
if let Some(updated) = updated {
let mut tombstone = Tombstone::new();
- tombstone.set_id(object_id.parse()?);
+ tombstone.set_id(object_id);
tombstone.set_former_type(former_type.to_string());
tombstone.set_deleted(convert_datetime(updated));
Ok(tombstone)
pub(in crate::objects) fn check_object_domain<T, Kind>(
apub: &T,
expected_domain: Url,
-) -> Result<String, LemmyError>
+) -> Result<lemmy_db_schema::Url, LemmyError>
where
T: Base + AsBase<Kind>,
{
let domain = expected_domain.domain().context(location_info!())?;
let object_id = apub.id(domain)?.context(location_info!())?;
- check_is_apub_id_valid(&object_id)?;
- Ok(object_id.to_string())
+ check_is_apub_id_valid(object_id)?;
+ Ok(object_id.to_owned().into())
}
pub(in crate::objects) fn set_content_and_source<T, Kind1, Kind2>(
// if its a local object, return it directly from the database
if Settings::get().hostname == domain {
let object = blocking(context.pool(), move |conn| {
- To::read_from_apub_id(conn, object_id.as_str())
+ To::read_from_apub_id(conn, &object_id.into())
})
.await??;
Ok(object)
// TODO: need to set proper context defining sensitive/commentsEnabled fields
// https://git.asonix.dog/Aardwolf/activitystreams/issues/5
.set_many_contexts(lemmy_context()?)
- .set_id(self.ap_id.parse::<Url>()?)
+ .set_id(self.ap_id.to_owned().into_inner())
// Use summary field to be consistent with mastodon content warning.
// https://mastodon.xyz/@Louisa/103987265222901387.json
.set_summary(self.name.to_owned())
.set_published(convert_datetime(self.published))
- .set_to(community.actor_id)
- .set_attributed_to(creator.actor_id);
+ .set_to(community.actor_id.into_inner())
+ .set_attributed_to(creator.actor_id.into_inner());
if let Some(body) = &self.body {
set_content_and_source(&mut page, &body)?;
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(self.deleted, &self.ap_id, self.updated, PageType::Page)
+ create_tombstone(
+ self.deleted,
+ self.ap_id.to_owned().into(),
+ self.updated,
+ PageType::Page,
+ )
}
}
private_message
.set_many_contexts(lemmy_context()?)
- .set_id(Url::parse(&self.ap_id.to_owned())?)
+ .set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
- .set_to(recipient.actor_id)
- .set_attributed_to(creator.actor_id);
+ .set_to(recipient.actor_id.into_inner())
+ .set_attributed_to(creator.actor_id.into_inner());
set_content_and_source(&mut private_message, &self.content)?;
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
+ create_tombstone(
+ self.deleted,
+ self.ap_id.to_owned().into(),
+ self.updated,
+ NoteType::Note,
+ )
}
}
let mut person = ApObject::new(Person::new());
person
.set_many_contexts(lemmy_context()?)
- .set_id(Url::parse(&self.actor_id)?)
+ .set_id(self.actor_id.to_owned().into_inner())
.set_published(convert_datetime(self.published));
if let Some(u) = self.updated {
let domain = user_id.domain().context(location_info!())?;
if domain == Settings::get().hostname {
let user = blocking(context.pool(), move |conn| {
- User_::read_from_apub_id(conn, user_id.as_str())
+ User_::read_from_apub_id(conn, &user_id.into())
})
.await??;
Ok(user)
extern crate diesel_migrations;
use diesel::{result::Error, *};
+use lemmy_db_schema::Url;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::{env, env::VarError};
}
pub trait ApubObject<T> {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error>
+ fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error>
where
Self: Sized;
fn upsert(conn: &PgConnection, user_form: &T) -> Result<Self, Error>
CommentSaved,
CommentSavedForm,
},
+ Url,
};
pub trait Comment_ {
}
impl ApubObject<CommentForm> for Comment {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error> {
use lemmy_db_schema::schema::comment::dsl::*;
comment.filter(ap_id.eq(object_id)).first::<Self>(conn)
}
CommunityUserBan,
CommunityUserBanForm,
},
+ Url,
};
mod safe_type {
}
impl ApubObject<CommunityForm> for Community {
- fn read_from_apub_id(conn: &PgConnection, for_actor_id: &str) -> Result<Self, Error> {
+ fn read_from_apub_id(conn: &PgConnection, for_actor_id: &Url) -> Result<Self, Error> {
use lemmy_db_schema::schema::community::dsl::*;
community
.filter(actor_id.eq(for_actor_id))
PostSaved,
PostSavedForm,
},
+ Url,
};
impl Crud<PostForm> for Post {
}
impl ApubObject<PostForm> for Post {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error> {
use lemmy_db_schema::schema::post::dsl::*;
post.filter(ap_id.eq(object_id)).first::<Self>(conn)
}
use crate::{ApubObject, Crud};
use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::{naive_now, source::private_message::*};
+use lemmy_db_schema::{naive_now, source::private_message::*, Url};
impl Crud<PrivateMessageForm> for PrivateMessage {
fn read(conn: &PgConnection, private_message_id: i32) -> Result<Self, Error> {
}
impl ApubObject<PrivateMessageForm> for PrivateMessage {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error>
+ fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error>
where
Self: Sized,
{
naive_now,
schema::user_::dsl::*,
source::user::{UserForm, UserSafeSettings, User_},
+ Url,
};
use lemmy_utils::settings::Settings;
}
impl ApubObject<UserForm> for User_ {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
+ fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error> {
use lemmy_db_schema::schema::user_::dsl::*;
user_
.filter(deleted.eq(false))
extern crate diesel;
use chrono::NaiveDateTime;
+use diesel::{
+ backend::Backend,
+ deserialize::FromSql,
+ serialize::{Output, ToSql},
+ sql_types::Text,
+};
+use serde::Serialize;
+use std::{
+ fmt::{Display, Formatter},
+ io::Write,
+};
pub mod schema;
pub mod source;
+#[repr(transparent)]
+#[derive(Clone, PartialEq, Serialize, Debug, AsExpression, FromSqlRow)]
+#[sql_type = "Text"]
+pub struct Url(url::Url);
+
+impl<DB: Backend> ToSql<Text, DB> for Url
+where
+ String: ToSql<Text, DB>,
+{
+ fn to_sql<W: Write>(&self, out: &mut Output<W, DB>) -> diesel::serialize::Result {
+ self.0.to_string().to_sql(out)
+ }
+}
+
+impl<DB: Backend> FromSql<Text, DB> for Url
+where
+ String: FromSql<Text, DB>,
+{
+ fn from_sql(bytes: Option<&DB::RawValue>) -> diesel::deserialize::Result<Self> {
+ let str = String::from_sql(bytes)?;
+ Ok(Url(url::Url::parse(&str)?))
+ }
+}
+
+impl Url {
+ pub fn into_inner(self) -> url::Url {
+ self.0
+ }
+}
+
+impl Display for Url {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ self.to_owned().into_inner().fmt(f)
+ }
+}
+
+impl From<Url> for url::Url {
+ fn from(url: Url) -> Self {
+ url.0
+ }
+}
+
+impl From<url::Url> for Url {
+ fn from(url: url::Url) -> Self {
+ Url(url)
+ }
+}
+
// TODO: can probably move this back to lemmy_db_queries
pub fn naive_now() -> NaiveDateTime {
chrono::prelude::Utc::now().naive_utc()
use crate::{
schema::{comment, comment_alias_1, comment_like, comment_saved},
source::post::Post,
+ Url,
};
use serde::Serialize;
-use url::{ParseError, Url};
// WITH RECURSIVE MyTree AS (
// SELECT * FROM comment WHERE parent_id IS NULL
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
- pub ap_id: String,
+ pub ap_id: Url,
pub local: bool,
}
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
- pub ap_id: String,
+ pub ap_id: Url,
pub local: bool,
}
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
- pub ap_id: Option<String>,
+ pub ap_id: Option<Url>,
pub local: bool,
}
-impl CommentForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
-
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
#[belongs_to(Comment)]
#[table_name = "comment_like"]
-use crate::schema::{community, community_follower, community_moderator, community_user_ban};
+use crate::{
+ schema::{community, community_follower, community_moderator, community_user_ban},
+ Url,
+};
use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
pub nsfw: bool,
- pub actor_id: String,
+ pub actor_id: Url,
pub local: bool,
pub private_key: Option<String>,
pub public_key: Option<String>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
pub nsfw: bool,
- pub actor_id: String,
+ pub actor_id: Url,
pub local: bool,
pub icon: Option<String>,
pub banner: Option<String>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
pub nsfw: bool,
- pub actor_id: Option<String>,
+ pub actor_id: Option<Url>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: Option<String>,
-use crate::schema::{post, post_like, post_read, post_saved};
+use crate::{
+ schema::{post, post_like, post_read, post_saved},
+ Url,
+};
use serde::Serialize;
-use url::{ParseError, Url};
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "post"]
pub embed_description: Option<String>,
pub embed_html: Option<String>,
pub thumbnail_url: Option<String>,
- pub ap_id: String,
+ pub ap_id: Url,
pub local: bool,
}
pub embed_description: Option<String>,
pub embed_html: Option<String>,
pub thumbnail_url: Option<String>,
- pub ap_id: Option<String>,
+ pub ap_id: Option<Url>,
pub local: bool,
}
-impl PostForm {
- pub fn get_ap_id(&self) -> Result<Url, ParseError> {
- Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
- }
-}
-
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Post)]
#[table_name = "post_like"]
-use crate::schema::private_message;
+use crate::{schema::private_message, Url};
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
pub read: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
- pub ap_id: String,
+ pub ap_id: Url,
pub local: bool,
}
pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>,
pub updated: Option<chrono::NaiveDateTime>,
- pub ap_id: Option<String>,
+ pub ap_id: Option<Url>,
pub local: bool,
}
-use crate::schema::{user_, user_alias_1, user_alias_2};
+use crate::{
+ schema::{user_, user_alias_1, user_alias_2},
+ Url,
+};
use serde::Serialize;
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<String>,
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub last_refreshed_at: chrono::NaiveDateTime,
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<String>,
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub matrix_user_id: Option<String>,
- pub actor_id: String,
+ pub actor_id: Url,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<String>,
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<Option<String>>,
- pub actor_id: Option<String>,
+ pub actor_id: Option<Url>,
pub bio: Option<Option<String>>,
pub local: bool,
pub private_key: Option<String>,
actix-web = "3.3.2"
chrono = { version = "0.4.19", features = ["serde"] }
serde_json = { version = "1.0.60", features = ["preserve_order"] }
+url = "2.2.0"
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error;
use serde::{Deserialize, Serialize};
+use url::Url;
#[derive(Serialize, Deserialize, Debug)]
pub struct WebFingerLink {
pub rel: Option<String>,
#[serde(rename(serialize = "type", deserialize = "type"))]
pub type_: Option<String>,
- pub href: Option<String>,
+ pub href: Option<Url>,
#[serde(skip_serializing_if = "Option::is_none")]
pub template: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct WebFingerResponse {
pub subject: String,
- pub aliases: Vec<String>,
+ pub aliases: Vec<Url>,
pub links: Vec<WebFingerLink>,
}
--- /dev/null
+create or replace function generate_unique_changeme()
+returns text language sql
+as $$
+ select 'changeme_' || string_agg (substr('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789', ceil (random() * 62)::integer, 1), '')
+ from generate_series(1, 20)
+$$;
\ No newline at end of file
--- /dev/null
+create or replace function generate_unique_changeme()
+returns text language sql
+as $$
+ select 'http://changeme_' || string_agg (substr('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789', ceil (random() * 62)::integer, 1), '')
+ from generate_series(1, 20)
+$$;
\ No newline at end of file
// Update the actor_id, private_key, and public_key, last_refreshed_at
let incorrect_users = user_
- .filter(actor_id.like("changeme_%"))
+ .filter(actor_id.like("http://changeme_%"))
.filter(local.eq(true))
.load::<User_>(conn)?;
lang: cuser.lang.to_owned(),
show_avatars: cuser.show_avatars,
send_notifications_to_email: cuser.send_notifications_to_email,
- actor_id: Some(make_apub_endpoint(EndpointType::User, &cuser.name).to_string()),
+ actor_id: Some(make_apub_endpoint(EndpointType::User, &cuser.name).into()),
bio: Some(cuser.bio.to_owned()),
local: cuser.local,
private_key: Some(keypair.private_key),
// Update the actor_id, private_key, and public_key, last_refreshed_at
let incorrect_communities = community
- .filter(actor_id.like("changeme_%"))
+ .filter(actor_id.like("http://changeme_%"))
.filter(local.eq(true))
.load::<Community>(conn)?;
deleted: None,
nsfw: ccommunity.nsfw,
updated: None,
- actor_id: Some(make_apub_endpoint(EndpointType::Community, &ccommunity.name).to_string()),
+ actor_id: Some(make_apub_endpoint(EndpointType::Community, &ccommunity.name).into()),
local: ccommunity.local,
private_key: Some(keypair.private_key),
public_key: Some(keypair.public_key),
// Update the ap_id
let incorrect_posts = post
- .filter(ap_id.eq("changeme_%"))
+ .filter(ap_id.eq("http://changeme_%"))
.filter(local.eq(true))
.load::<Post>(conn)?;
// Update the ap_id
let incorrect_comments = comment
- .filter(ap_id.eq("changeme_%"))
+ .filter(ap_id.eq("http://changeme_%"))
.filter(local.eq(true))
.load::<Comment>(conn)?;
// Update the ap_id
let incorrect_pms = private_message
- .filter(ap_id.eq("changeme_%"))
+ .filter(ap_id.eq("http://changeme_%"))
.filter(local.eq(true))
.load::<PrivateMessage>(conn)?;
channel_builder
.namespaces(RSS_NAMESPACE.to_owned())
.title(&format!("{} - {}", site_view.site.name, community.name))
- .link(community.actor_id)
+ .link(community.actor_id.to_string())
.items(items);
if let Some(community_desc) = community.description {
i.title(p.post.name);
- dc_extension.creators(vec![p.creator.actor_id.to_owned()]);
+ dc_extension.creators(vec![p.creator.actor_id.to_string()]);
let dt = DateTime::<Utc>::from_utc(p.post.published, Utc);
i.pub_date(dt.to_rfc2822());
let json = WebFingerResponse {
subject: info.resource.to_owned(),
- aliases: vec![url.to_owned()],
+ aliases: vec![url.to_owned().into()],
links: vec![
WebFingerLink {
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
type_: Some("text/html".to_string()),
- href: Some(url.to_owned()),
+ href: Some(url.to_owned().into()),
template: None,
},
WebFingerLink {
rel: Some("self".to_string()),
type_: Some("application/activity+json".to_string()),
- href: Some(url),
+ href: Some(url.into()),
template: None,
}, // TODO: this also needs to return the subscribe link once that's implemented
//{
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
- actor_id: Some(format!("http://localhost:8536/u/{}", name)),
+ actor_id: Some(
+ Url::parse(&format!("http://localhost:8536/u/{}", name))
+ .unwrap()
+ .into(),
+ ),
bio: None,
local: true,
private_key: Some(user_keypair.private_key),
};
Community::create(&conn, &new_community).unwrap()
}
-fn create_activity<'a, Activity, Return>(user_id: String) -> web::Json<Return>
+fn create_activity<'a, Activity, Return>(user_id: Url) -> web::Json<Return>
where
for<'de> Return: Deserialize<'de> + 'a,
Activity: std::default::Default + Serialize,
let connection = &context.pool().get().unwrap();
let user = create_user(connection, "shared_inbox_rvgfd");
let activity =
- create_activity::<CreateType, ActorAndObject<shared_inbox::ValidTypes>>(user.actor_id);
+ create_activity::<CreateType, ActorAndObject<shared_inbox::ValidTypes>>(user.actor_id.into());
let response = shared_inbox(request, activity, web::Data::new(context)).await;
assert_eq!(
format!("{}", response.err().unwrap()),
let connection = &context.pool().get().unwrap();
let user = create_user(connection, "user_inbox_cgsax");
let activity =
- create_activity::<CreateType, ActorAndObject<user_inbox::UserValidTypes>>(user.actor_id);
+ create_activity::<CreateType, ActorAndObject<user_inbox::UserValidTypes>>(user.actor_id.into());
let path = Path::<String> {
0: "username".to_string(),
};
let community = create_community(connection, user.id);
let request = create_http_request();
let activity = create_activity::<FollowType, ActorAndObject<community_inbox::CommunityValidTypes>>(
- user.actor_id,
+ user.actor_id.into(),
);
let path = Path::<String> { 0: community.name };
let response = community_inbox(request, activity, path, web::Data::new(context)).await;