Skip to content
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 combined person content and person saved tables. #5251

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
39b3ec2
Combined tables try 2
dessalines Nov 26, 2024
1ff8ae0
Finishing up combined report table.
dessalines Nov 26, 2024
2351c7a
Fix ts optionals.
dessalines Nov 26, 2024
0ba961f
Adding tests, triggers, and history updates for report_combined.
dessalines Nov 27, 2024
d8dda44
Adding profile.
dessalines Nov 27, 2024
d68c0a6
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 28, 2024
a9f28af
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 28, 2024
3adadf9
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Nov 30, 2024
588e1f6
Add cursor pagination to report_combined view (#5244)
dullbananas Dec 2, 2024
f25d346
Merge branch 'combined_tables_2' of https://github.com/LemmyNet/lemmy…
dessalines Dec 2, 2024
7fdbb58
Fixing migration and paged API.
dessalines Dec 2, 2024
00beccd
Using dullbananas trigger procedure
dessalines Dec 2, 2024
1776de2
Removing pointless list routes, reorganizing tests.
dessalines Dec 2, 2024
612c2e9
Fixing column XOR check.
dessalines Dec 2, 2024
5a8b9de
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 2, 2024
0c854d2
Forgot to remove list report actions.
dessalines Dec 2, 2024
802a8a6
Cleanup.
dessalines Dec 2, 2024
4674821
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 2, 2024
91ca6d3
Merge branch 'main' into combined_tables_2
dessalines Dec 2, 2024
4cac67c
Use internal tagging.
dessalines Dec 2, 2024
83988cd
Merge branch 'combined_tables_2' of https://github.com/LemmyNet/lemmy…
dessalines Dec 2, 2024
82a14fc
Fixing api tests.
dessalines Dec 2, 2024
1f28407
Adding a few indexes.
dessalines Dec 2, 2024
34a440a
Fixing migration name.
dessalines Dec 2, 2024
1a739a1
Fixing unique constraints.
dessalines Dec 3, 2024
e1affa8
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 4, 2024
921d532
Addressing PR comments.
dessalines Dec 4, 2024
724856d
Start working on profile combined
dessalines Dec 6, 2024
1053df1
Adding views and replaceable schema.
dessalines Dec 6, 2024
32b5411
A few changes to profile view.
dessalines Dec 7, 2024
3abc46f
Finishing up combined person_saved and person_content.
dessalines Dec 7, 2024
a940ce3
Merge remote-tracking branch 'origin/main' into combined_tables_2
dessalines Dec 7, 2024
67d72e3
Fixing api tests.
dessalines Dec 8, 2024
a4de41d
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
5d2b611
Moving to api-v4 routes.
dessalines Dec 8, 2024
a0f2966
Fixing imports.
dessalines Dec 8, 2024
165c7f4
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
dc0ec15
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
22d8697
Update crates/db_views/src/report_combined_view.rs
dessalines Dec 8, 2024
fa31fc3
Update migrations/2024-12-02-181601_add_report_combined_table/up.sql
dessalines Dec 8, 2024
10f5e37
Update migrations/2024-12-02-181601_add_report_combined_table/up.sql
dessalines Dec 8, 2024
02bd2f6
Fixing import and fmt.
dessalines Dec 8, 2024
40fead2
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
2d482b3
Fixing null types in postgres.
dessalines Dec 8, 2024
3e31e1c
Comment out err.
dessalines Dec 8, 2024
cf2b00e
Merge branch 'combined_tables_2' into combined_profile
dessalines Dec 8, 2024
58e62d5
Fixing TS issues.
dessalines Dec 8, 2024
a320f5a
Merge remote-tracking branch 'origin/main' into combined_profile
dessalines Dec 9, 2024
63b7f72
Using dullbananas trigger procedure
dessalines Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint": "^9.14.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.5.0",
"lemmy-js-client": "0.20.0-reports-combined.2",
"lemmy-js-client": "0.20.0-reports-combined.3",
"prettier": "^3.2.5",
"ts-jest": "^29.1.0",
"typescript": "^5.5.4",
Expand Down
10 changes: 5 additions & 5 deletions api_tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions api_tests/src/community.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
followCommunity,
banPersonFromCommunity,
resolvePerson,
getSite,
createPost,
getPost,
resolvePost,
Expand All @@ -36,7 +35,7 @@ import {
userBlockInstance,
} from "./shared";
import { AdminAllowInstanceParams } from "lemmy-js-client/dist/types/AdminAllowInstanceParams";
import { EditCommunity, EditSite, GetPosts } from "lemmy-js-client";
import { EditCommunity, GetPosts } from "lemmy-js-client";

beforeAll(setupLogins);
afterAll(unfollows);
Expand Down Expand Up @@ -573,7 +572,7 @@ test("Remote mods can edit communities", async () => {
communityRes.community_view.community.id,
);

await expect(alphaCommunity.community_view.community.description).toBe(
expect(alphaCommunity.community_view.community.description).toBe(
"Example description",
);
});
Expand Down
1 change: 0 additions & 1 deletion api_tests/src/follow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
setupLogins,
resolveBetaCommunity,
followCommunity,
getSite,
waitUntil,
beta,
betaUrl,
Expand Down
1 change: 0 additions & 1 deletion api_tests/src/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
epsilon,
followCommunity,
gamma,
getSite,
imageFetchLimit,
registerUser,
resolveBetaCommunity,
Expand Down
2 changes: 1 addition & 1 deletion api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
reportPost,
randomString,
registerUser,
getSite,
unfollows,
resolveCommunity,
waitUntil,
Expand All @@ -38,6 +37,7 @@ import {
loginUser,
createCommunity,
listReports,
getMyUser,
} from "./shared";
import { PostView } from "lemmy-js-client/dist/types/PostView";
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams";
Expand Down
5 changes: 4 additions & 1 deletion api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ListCommunityPendingFollowsResponse,
ListReports,
ListReportsResponse,
MyUserInfo,
PersonId,
PostView,
PrivateMessageReportResponse,
Expand Down Expand Up @@ -206,7 +207,9 @@ async function allowInstance(api: LemmyHttp, instance: string) {
// Ignore errors from duplicate allows (because setup gets called for each test file)
try {
await api.adminAllowInstance(params);
} catch {}
} catch (error) {
// console.error(error);
}
}

export async function createPost(
Expand Down
5 changes: 1 addition & 4 deletions crates/api/src/comment/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub async fn save_comment(
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<CommentResponse>> {
let comment_saved_form = CommentSavedForm {
comment_id: data.comment_id,
person_id: local_user_view.person.id,
};
let comment_saved_form = CommentSavedForm::new(data.comment_id, local_user_view.person.id);

if data.save {
CommentSaved::save(&mut context.pool(), &comment_saved_form)
Expand Down
40 changes: 40 additions & 0 deletions crates/api/src/local_user/list_saved.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use activitypub_federation::config::Data;
use actix_web::web::{Json, Query};
use lemmy_api_common::{
context::LemmyContext,
person::{ListPersonSaved, ListPersonSavedResponse},
utils::check_private_instance,
};
use lemmy_db_views::{
person_saved_combined_view::PersonSavedCombinedQuery,
structs::{LocalUserView, SiteView},
};
use lemmy_utils::error::LemmyResult;

#[tracing::instrument(skip(context))]
pub async fn list_person_saved(
data: Query<ListPersonSaved>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<ListPersonSavedResponse>> {
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&Some(local_user_view.clone()), &local_site.local_site)?;

// parse pagination token
let page_after = if let Some(pa) = &data.page_cursor {
Some(pa.read(&mut context.pool()).await?)
} else {
None
};
let page_back = data.page_back;

let saved = PersonSavedCombinedQuery {
page_after,
page_back,
}
.list(&mut context.pool(), &local_user_view)
.await?;

Ok(Json(ListPersonSavedResponse { saved }))
}
1 change: 1 addition & 0 deletions crates/api/src/local_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod get_captcha;
pub mod list_banned;
pub mod list_logins;
pub mod list_media;
pub mod list_saved;
pub mod login;
pub mod logout;
pub mod notifications;
Expand Down
2 changes: 0 additions & 2 deletions crates/api_common/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ pub struct GetComments {
#[cfg_attr(feature = "full", ts(optional))]
pub parent_id: Option<CommentId>,
#[cfg_attr(feature = "full", ts(optional))]
pub saved_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub liked_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub disliked_only: Option<bool>,
Expand Down
68 changes: 55 additions & 13 deletions crates/api_common/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use lemmy_db_schema::{
PostListingMode,
PostSortType,
};
use lemmy_db_views::structs::{CommentView, LocalImageView, PostView};
use lemmy_db_views::structs::{
LocalImageView,
PersonContentCombinedPaginationCursor,
PersonContentCombinedView,
PersonSavedCombinedPaginationCursor,
};
use lemmy_db_views_actor::structs::{
CommentReplyView,
CommunityModeratorView,
Expand Down Expand Up @@ -222,16 +227,6 @@ pub struct GetPersonDetails {
/// Example: dessalines , or [email protected]
#[cfg_attr(feature = "full", ts(optional))]
pub username: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub sort: Option<PostSortType>,
#[cfg_attr(feature = "full", ts(optional))]
pub page: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub limit: Option<i64>,
#[cfg_attr(feature = "full", ts(optional))]
pub community_id: Option<CommunityId>,
#[cfg_attr(feature = "full", ts(optional))]
pub saved_only: Option<bool>,
}

#[skip_serializing_none]
Expand All @@ -243,11 +238,58 @@ pub struct GetPersonDetailsResponse {
pub person_view: PersonView,
#[cfg_attr(feature = "full", ts(optional))]
pub site: Option<Site>,
pub comments: Vec<CommentView>,
pub posts: Vec<PostView>,
pub moderates: Vec<CommunityModeratorView>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Gets a person's content (posts and comments)
///
/// Either person_id, or username are required.
pub struct ListPersonContent {
#[cfg_attr(feature = "full", ts(optional))]
pub person_id: Option<PersonId>,
/// Example: dessalines , or [email protected]
#[cfg_attr(feature = "full", ts(optional))]
pub username: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub page_cursor: Option<PersonContentCombinedPaginationCursor>,
#[cfg_attr(feature = "full", ts(optional))]
pub page_back: Option<bool>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A person's content response.
pub struct ListPersonContentResponse {
pub content: Vec<PersonContentCombinedView>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// Gets your saved posts and comments
pub struct ListPersonSaved {
#[cfg_attr(feature = "full", ts(optional))]
pub page_cursor: Option<PersonSavedCombinedPaginationCursor>,
#[cfg_attr(feature = "full", ts(optional))]
pub page_back: Option<bool>,
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// A person's saved content response.
pub struct ListPersonSavedResponse {
pub saved: Vec<PersonContentCombinedView>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
Expand Down
2 changes: 0 additions & 2 deletions crates/api_common/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ pub struct GetPosts {
#[cfg_attr(feature = "full", ts(optional))]
pub community_name: Option<String>,
#[cfg_attr(feature = "full", ts(optional))]
pub saved_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub liked_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub disliked_only: Option<bool>,
Expand Down
2 changes: 0 additions & 2 deletions crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ pub struct Search {
#[cfg_attr(feature = "full", ts(optional))]
pub post_url_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub saved_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub liked_only: Option<bool>,
#[cfg_attr(feature = "full", ts(optional))]
pub disliked_only: Option<bool>,
Expand Down
2 changes: 0 additions & 2 deletions crates/apub/src/api/list_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub async fn list_comments(
&site_view.local_site,
));
let max_depth = data.max_depth;
let saved_only = data.saved_only;

let liked_only = data.liked_only;
let disliked_only = data.disliked_only;
Expand Down Expand Up @@ -80,7 +79,6 @@ pub async fn list_comments(
listing_type,
sort,
max_depth,
saved_only,
liked_only,
disliked_only,
community_id,
Expand Down
50 changes: 50 additions & 0 deletions crates/apub/src/api/list_person_content.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::resolve_person_id_from_id_or_username;
use activitypub_federation::config::Data;
use actix_web::web::{Json, Query};
use lemmy_api_common::{
context::LemmyContext,
person::{ListPersonContent, ListPersonContentResponse},
utils::check_private_instance,
};
use lemmy_db_views::{
person_content_combined_view::PersonContentCombinedQuery,
structs::{LocalUserView, SiteView},
};
use lemmy_utils::error::LemmyResult;

#[tracing::instrument(skip(context))]
pub async fn list_person_content(
data: Query<ListPersonContent>,
context: Data<LemmyContext>,
local_user_view: Option<LocalUserView>,
) -> LemmyResult<Json<ListPersonContentResponse>> {
let local_site = SiteView::read_local(&mut context.pool()).await?;

check_private_instance(&local_user_view, &local_site.local_site)?;

let person_details_id = resolve_person_id_from_id_or_username(
&data.person_id,
&data.username,
&context,
&local_user_view,
)
.await?;

// parse pagination token
let page_after = if let Some(pa) = &data.page_cursor {
Some(pa.read(&mut context.pool()).await?)
} else {
None
};
let page_back = data.page_back;

let content = PersonContentCombinedQuery {
creator_id: person_details_id,
page_after,
page_back,
}
.list(&mut context.pool(), &local_user_view)
.await?;

Ok(Json(ListPersonContentResponse { content }))
}
2 changes: 0 additions & 2 deletions crates/apub/src/api/list_posts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub async fn list_posts(
} else {
data.community_id
};
let saved_only = data.saved_only;
let show_hidden = data.show_hidden;
let show_read = data.show_read;
let show_nsfw = data.show_nsfw;
Expand Down Expand Up @@ -77,7 +76,6 @@ pub async fn list_posts(
listing_type,
sort,
community_id,
saved_only,
liked_only,
disliked_only,
page,
Expand Down
Loading