Add totalItems property to followers, following and subscribers collections
This commit is contained in:
parent
ed9b724895
commit
ce28c2e9fb
2 changed files with 35 additions and 7 deletions
|
@ -17,18 +17,23 @@ pub struct OrderedCollection {
|
||||||
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
first: Option<String>,
|
first: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
total_items: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OrderedCollection {
|
impl OrderedCollection {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
collection_id: String,
|
collection_id: String,
|
||||||
first_page_id: Option<String>,
|
first_page_id: Option<String>,
|
||||||
|
total_items: Option<i32>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
context: json!(AP_CONTEXT),
|
context: json!(AP_CONTEXT),
|
||||||
id: collection_id,
|
id: collection_id,
|
||||||
object_type: ORDERED_COLLECTION.to_string(),
|
object_type: ORDERED_COLLECTION.to_string(),
|
||||||
first: first_page_id,
|
first: first_page_id,
|
||||||
|
total_items,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,7 @@ async fn outbox(
|
||||||
let collection = OrderedCollection::new(
|
let collection = OrderedCollection::new(
|
||||||
collection_id,
|
collection_id,
|
||||||
Some(first_page_id),
|
Some(first_page_id),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let response = HttpResponse::Ok()
|
let response = HttpResponse::Ok()
|
||||||
.content_type(ACTIVITY_CONTENT_TYPE)
|
.content_type(ACTIVITY_CONTENT_TYPE)
|
||||||
|
@ -134,7 +135,8 @@ async fn outbox(
|
||||||
None, // include only public posts
|
None, // include only public posts
|
||||||
false, // exclude replies
|
false, // exclude replies
|
||||||
false, // exclude reposts
|
false, // exclude reposts
|
||||||
None, COLLECTION_PAGE_SIZE,
|
None,
|
||||||
|
COLLECTION_PAGE_SIZE,
|
||||||
).await?;
|
).await?;
|
||||||
let activities: Vec<_> = posts.iter().filter_map(|post| {
|
let activities: Vec<_> = posts.iter().filter_map(|post| {
|
||||||
if post.in_reply_to_id.is_some() || post.repost_of_id.is_some() {
|
if post.in_reply_to_id.is_some() || post.repost_of_id.is_some() {
|
||||||
|
@ -162,18 +164,25 @@ async fn outbox(
|
||||||
#[get("/followers")]
|
#[get("/followers")]
|
||||||
async fn followers_collection(
|
async fn followers_collection(
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
username: web::Path<String>,
|
username: web::Path<String>,
|
||||||
query_params: web::Query<CollectionQueryParams>,
|
query_params: web::Query<CollectionQueryParams>,
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
if query_params.page.is_some() {
|
if query_params.page.is_some() {
|
||||||
// Social graph is not available
|
// Social graph is not available
|
||||||
return Err(HttpError::PermissionError);
|
return Err(HttpError::PermissionError);
|
||||||
}
|
};
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let user = get_user_by_name(db_client, &username).await?;
|
||||||
let collection_id = local_actor_followers(
|
let collection_id = local_actor_followers(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
&username,
|
&username,
|
||||||
);
|
);
|
||||||
let collection = OrderedCollection::new(collection_id, None);
|
let collection = OrderedCollection::new(
|
||||||
|
collection_id,
|
||||||
|
None,
|
||||||
|
Some(user.profile.follower_count),
|
||||||
|
);
|
||||||
let response = HttpResponse::Ok()
|
let response = HttpResponse::Ok()
|
||||||
.content_type(ACTIVITY_CONTENT_TYPE)
|
.content_type(ACTIVITY_CONTENT_TYPE)
|
||||||
.json(collection);
|
.json(collection);
|
||||||
|
@ -183,18 +192,25 @@ async fn followers_collection(
|
||||||
#[get("/following")]
|
#[get("/following")]
|
||||||
async fn following_collection(
|
async fn following_collection(
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
username: web::Path<String>,
|
username: web::Path<String>,
|
||||||
query_params: web::Query<CollectionQueryParams>,
|
query_params: web::Query<CollectionQueryParams>,
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
if query_params.page.is_some() {
|
if query_params.page.is_some() {
|
||||||
// Social graph is not available
|
// Social graph is not available
|
||||||
return Err(HttpError::PermissionError);
|
return Err(HttpError::PermissionError);
|
||||||
}
|
};
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let user = get_user_by_name(db_client, &username).await?;
|
||||||
let collection_id = local_actor_following(
|
let collection_id = local_actor_following(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
&username,
|
&username,
|
||||||
);
|
);
|
||||||
let collection = OrderedCollection::new(collection_id, None);
|
let collection = OrderedCollection::new(
|
||||||
|
collection_id,
|
||||||
|
None,
|
||||||
|
Some(user.profile.following_count),
|
||||||
|
);
|
||||||
let response = HttpResponse::Ok()
|
let response = HttpResponse::Ok()
|
||||||
.content_type(ACTIVITY_CONTENT_TYPE)
|
.content_type(ACTIVITY_CONTENT_TYPE)
|
||||||
.json(collection);
|
.json(collection);
|
||||||
|
@ -204,18 +220,25 @@ async fn following_collection(
|
||||||
#[get("/subscribers")]
|
#[get("/subscribers")]
|
||||||
async fn subscribers_collection(
|
async fn subscribers_collection(
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
username: web::Path<String>,
|
username: web::Path<String>,
|
||||||
query_params: web::Query<CollectionQueryParams>,
|
query_params: web::Query<CollectionQueryParams>,
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
if query_params.page.is_some() {
|
if query_params.page.is_some() {
|
||||||
// Subscriber list is hidden
|
// Subscriber list is hidden
|
||||||
return Err(HttpError::PermissionError);
|
return Err(HttpError::PermissionError);
|
||||||
}
|
};
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let user = get_user_by_name(db_client, &username).await?;
|
||||||
let collection_id = local_actor_subscribers(
|
let collection_id = local_actor_subscribers(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
&username,
|
&username,
|
||||||
);
|
);
|
||||||
let collection = OrderedCollection::new(collection_id, None);
|
let collection = OrderedCollection::new(
|
||||||
|
collection_id,
|
||||||
|
None,
|
||||||
|
Some(user.profile.subscriber_count),
|
||||||
|
);
|
||||||
let response = HttpResponse::Ok()
|
let response = HttpResponse::Ok()
|
||||||
.content_type(ACTIVITY_CONTENT_TYPE)
|
.content_type(ACTIVITY_CONTENT_TYPE)
|
||||||
.json(collection);
|
.json(collection);
|
||||||
|
|
Loading…
Reference in a new issue