1
0
Fork 0
forked from alemi/upub

feat: add streams and move feed to its own field

This commit is contained in:
əlemi 2024-06-11 05:51:12 +02:00
parent 20e5a3c104
commit 40392aef56
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 50 additions and 4 deletions

View file

@ -43,6 +43,8 @@ pub trait Actor : Object {
fn following_me(&self) -> Field<bool> { Err(FieldErr("followingMe")) } fn following_me(&self) -> Field<bool> { Err(FieldErr("followingMe")) }
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
fn followed_by_me(&self) -> Field<bool> { Err(FieldErr("followedByMe")) } fn followed_by_me(&self) -> Field<bool> { Err(FieldErr("followedByMe")) }
#[cfg(feature = "activitypub-fe")]
fn feed(&self) -> Node<Self::Collection> { Node::Empty }
#[cfg(feature = "activitypub-counters")] #[cfg(feature = "activitypub-counters")]
fn followers_count(&self) -> Field<u64> { Err(FieldErr("followersCount")) } fn followers_count(&self) -> Field<u64> { Err(FieldErr("followersCount")) }
@ -96,6 +98,8 @@ pub trait ActorMut : ObjectMut {
fn set_following_me(self, val: Option<bool>) -> Self; fn set_following_me(self, val: Option<bool>) -> Self;
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
fn set_followed_by_me(self, val: Option<bool>) -> Self; fn set_followed_by_me(self, val: Option<bool>) -> Self;
#[cfg(feature = "activitypub-fe")]
fn set_feed(self, val: Node<Self::Collection>) -> Self;
#[cfg(feature = "activitypub-counters")] #[cfg(feature = "activitypub-counters")]
fn set_followers_count(self, val: Option<u64>) -> Self; fn set_followers_count(self, val: Option<u64>) -> Self;
@ -150,6 +154,8 @@ impl Actor for serde_json::Value {
crate::getter! { followingMe -> bool } crate::getter! { followingMe -> bool }
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
crate::getter! { followedByMe -> bool } crate::getter! { followedByMe -> bool }
#[cfg(feature = "activitypub-fe")]
crate::getter! { feed -> node Self::Collection }
#[cfg(feature = "activitypub-counters")] #[cfg(feature = "activitypub-counters")]
crate::getter! { followingCount -> u64 } crate::getter! { followingCount -> u64 }
@ -199,6 +205,8 @@ impl ActorMut for serde_json::Value {
crate::setter! { followingMe -> bool } crate::setter! { followingMe -> bool }
#[cfg(feature = "activitypub-fe")] #[cfg(feature = "activitypub-fe")]
crate::setter! { followedByMe -> bool } crate::setter! { followedByMe -> bool }
#[cfg(feature = "activitypub-fe")]
crate::setter! { feed -> node Self::Collection }
#[cfg(feature = "activitypub-counters")] #[cfg(feature = "activitypub-counters")]
crate::setter! { followingCount -> u64 } crate::setter! { followingCount -> u64 }

View file

@ -1,10 +1,8 @@
pub mod inbox; pub mod inbox;
pub mod outbox; pub mod outbox;
pub mod following; pub mod following;
pub mod feed; pub mod feed;
pub mod streams;
use axum::extract::{Path, Query, State}; use axum::extract::{Path, Query, State};
@ -60,7 +58,7 @@ pub async fn view(
let mut user = user_model.ap() let mut user = user_model.ap()
.set_inbox(Node::link(upub::url!(ctx, "/actors/{id}/inbox"))) .set_inbox(Node::link(upub::url!(ctx, "/actors/{id}/inbox")))
.set_outbox(Node::link(upub::url!(ctx, "/actors/{id}/outbox"))) .set_outbox(Node::link(upub::url!(ctx, "/actors/{id}/outbox")))
.set_streams(Node::link(upub::url!(ctx, "/actors/{id}/feed"))) .set_streams(Node::link(upub::url!(ctx, "/actors/{id}/streams")))
.set_following(Node::link(upub::url!(ctx, "/actors/{id}/following"))) .set_following(Node::link(upub::url!(ctx, "/actors/{id}/following")))
.set_followers(Node::link(upub::url!(ctx, "/actors/{id}/followers"))) .set_followers(Node::link(upub::url!(ctx, "/actors/{id}/followers")))
.set_following_me(following_me) .set_following_me(following_me)
@ -72,6 +70,10 @@ pub async fn view(
.set_proxy_url(Some(&upub::url!(ctx, "/proxy"))) .set_proxy_url(Some(&upub::url!(ctx, "/proxy")))
)); ));
if auth.is(&uid) {
user = user.set_feed(Node::link(upub::url!(ctx, "/actors/{id}/feed")));
}
if !auth.is(&uid) && !cfg.show_followers_count { if !auth.is(&uid) && !cfg.show_followers_count {
user = user.set_followers_count(None); user = user.set_followers_count(None);
} }
@ -91,6 +93,8 @@ pub async fn view(
user_model.ap() user_model.ap()
.set_following_me(following_me) .set_following_me(following_me)
.set_followed_by_me(followed_by_me) .set_followed_by_me(followed_by_me)
// TODO should we set streams?? we offer this collection but actor is remote
.set_streams(Node::link(upub::url!(ctx, "/actors/{id}/streams")))
.ld_context() .ld_context()
)), )),
None => Err(crate::ApiError::not_found()), None => Err(crate::ApiError::not_found()),

View file

@ -0,0 +1,32 @@
use axum::extract::{Path, Query, State};
use sea_orm::{ColumnTrait, Condition};
use upub::Context;
use crate::{activitypub::Pagination, builders::JsonLD, AuthIdentity};
pub async fn get(
State(ctx): State<Context>,
Path(id): Path<String>,
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
crate::builders::collection(&upub::url!(ctx, "/actors/{id}/streams"), None)
}
pub async fn page(
State(ctx): State<Context>,
Path(id): Path<String>,
AuthIdentity(auth): AuthIdentity,
Query(page): Query<Pagination>,
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
crate::builders::paginate_objects(
upub::url!(ctx, "/actors/{id}/streams/page"),
Condition::all()
.add(auth.filter_objects())
.add(upub::model::object::Column::AttributedTo.eq(ctx.uid(&id))),
ctx.db(),
page,
auth.my_id(),
false,
)
.await
}

View file

@ -51,6 +51,8 @@ impl ActivityPubRouter for Router<upub::Context> {
.route("/actors/:id/outbox", post(ap::actor::outbox::post)) .route("/actors/:id/outbox", post(ap::actor::outbox::post))
.route("/actors/:id/outbox", get(ap::actor::outbox::get)) .route("/actors/:id/outbox", get(ap::actor::outbox::get))
.route("/actors/:id/outbox/page", get(ap::actor::outbox::page)) .route("/actors/:id/outbox/page", get(ap::actor::outbox::page))
.route("/actors/:id/streams", get(ap::actor::streams::get))
.route("/actors/:id/streams/page", get(ap::actor::streams::page))
.route("/actors/:id/feed", get(ap::actor::feed::get)) .route("/actors/:id/feed", get(ap::actor::feed::get))
.route("/actors/:id/feed/page", get(ap::actor::feed::page)) .route("/actors/:id/feed/page", get(ap::actor::feed::page))
.route("/actors/:id/followers", get(ap::actor::following::get::<false>)) .route("/actors/:id/followers", get(ap::actor::following::get::<false>))