-
-
Notifications
You must be signed in to change notification settings - Fork 883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a get_random_community endpoint. #5042
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95a6ed1
Adding a get_random_community endpoint.
dessalines a0c48ca
Merge remote-tracking branch 'origin/main' into random_community
dessalines 2956da0
Fixing issue from main.
dessalines f510696
Merge remote-tracking branch 'origin/main' into random_community
dessalines d0e57ed
Merge remote-tracking branch 'origin/main' into random_community
dessalines 0ccecb6
Adding ListingType to the query.
dessalines 22a2b1e
More concise query filter.
dessalines 3643699
Merge branch 'main' into random_community
dessalines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod ban; | |
pub mod block; | ||
pub mod follow; | ||
pub mod hide; | ||
pub mod random; | ||
pub mod transfer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use activitypub_federation::config::Data; | ||
use actix_web::web::Json; | ||
use lemmy_api_common::{ | ||
community::CommunityResponse, | ||
context::LemmyContext, | ||
utils::{check_private_instance, is_mod_or_admin_opt}, | ||
}; | ||
use lemmy_db_schema::source::{ | ||
actor_language::CommunityLanguage, | ||
community::Community, | ||
local_site::LocalSite, | ||
}; | ||
use lemmy_db_views::structs::LocalUserView; | ||
use lemmy_db_views_actor::structs::CommunityView; | ||
use lemmy_utils::error::{LemmyErrorType, LemmyResult}; | ||
|
||
#[tracing::instrument(skip(context))] | ||
pub async fn get_random_community( | ||
context: Data<LemmyContext>, | ||
local_user_view: Option<LocalUserView>, | ||
) -> LemmyResult<Json<CommunityResponse>> { | ||
let local_site = LocalSite::read(&mut context.pool()).await?; | ||
|
||
check_private_instance(&local_user_view, &local_site)?; | ||
|
||
let local_user = local_user_view.as_ref().map(|u| &u.local_user); | ||
|
||
let random_community_id = Community::get_random_local_community(&mut context.pool()) | ||
.await? | ||
.ok_or(LemmyErrorType::NotFound)? | ||
.id; | ||
|
||
let is_mod_or_admin = is_mod_or_admin_opt( | ||
&mut context.pool(), | ||
local_user_view.as_ref(), | ||
Some(random_community_id), | ||
) | ||
.await | ||
.is_ok(); | ||
|
||
let community_view = CommunityView::read( | ||
&mut context.pool(), | ||
random_community_id, | ||
local_user, | ||
is_mod_or_admin, | ||
) | ||
.await?; | ||
|
||
let discussion_languages = | ||
CommunityLanguage::read(&mut context.pool(), random_community_id).await?; | ||
|
||
Ok(Json(CommunityResponse { | ||
community_view, | ||
discussion_languages, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue doesnt mention that it should return only local communities, and thats not clear from the endpoint name either. Based on the issue it should take a type param (
GET /api/v3/community/random?type_=All
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K, added ListingType to the query.