mirror of
https://github.com/LemmyNet/lemmy.git
synced 2026-02-11 16:51:20 -06:00
Add support for Featured Posts (#2585)
* Add support for Featured Posts * Fix rebase * More fixes
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
"eslint": "^8.25.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "^27.0.6",
|
||||
"lemmy-js-client": "0.17.0-rc.48",
|
||||
"lemmy-js-client": "0.17.0-rc.56",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prettier": "^2.7.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
setupLogins,
|
||||
createPost,
|
||||
editPost,
|
||||
stickyPost,
|
||||
featurePost,
|
||||
lockPost,
|
||||
resolvePost,
|
||||
likePost,
|
||||
@@ -157,8 +157,8 @@ test("Sticky a post", async () => {
|
||||
let betaPost1 = (
|
||||
await resolvePost(beta, postRes.post_view.post)
|
||||
).post.unwrap();
|
||||
let stickiedPostRes = await stickyPost(beta, true, betaPost1.post);
|
||||
expect(stickiedPostRes.post_view.post.stickied).toBe(true);
|
||||
let stickiedPostRes = await featurePost(beta, true, betaPost1.post);
|
||||
expect(stickiedPostRes.post_view.post.featured_community).toBe(true);
|
||||
|
||||
// Make sure that post is stickied on beta
|
||||
let betaPost = (
|
||||
@@ -166,11 +166,11 @@ test("Sticky a post", async () => {
|
||||
).post.unwrap();
|
||||
expect(betaPost.community.local).toBe(true);
|
||||
expect(betaPost.creator.local).toBe(false);
|
||||
expect(betaPost.post.stickied).toBe(true);
|
||||
expect(betaPost.post.featured_community).toBe(true);
|
||||
|
||||
// Unsticky a post
|
||||
let unstickiedPost = await stickyPost(beta, false, betaPost1.post);
|
||||
expect(unstickiedPost.post_view.post.stickied).toBe(false);
|
||||
let unstickiedPost = await featurePost(beta, false, betaPost1.post);
|
||||
expect(unstickiedPost.post_view.post.featured_community).toBe(false);
|
||||
|
||||
// Make sure that post is unstickied on beta
|
||||
let betaPost2 = (
|
||||
@@ -178,18 +178,18 @@ test("Sticky a post", async () => {
|
||||
).post.unwrap();
|
||||
expect(betaPost2.community.local).toBe(true);
|
||||
expect(betaPost2.creator.local).toBe(false);
|
||||
expect(betaPost2.post.stickied).toBe(false);
|
||||
expect(betaPost2.post.featured_community).toBe(false);
|
||||
|
||||
// Make sure that gamma cannot sticky the post on beta
|
||||
let gammaPost = (
|
||||
await resolvePost(gamma, postRes.post_view.post)
|
||||
).post.unwrap();
|
||||
let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post);
|
||||
let gammaTrySticky = await featurePost(gamma, true, gammaPost.post);
|
||||
let betaPost3 = (
|
||||
await resolvePost(beta, postRes.post_view.post)
|
||||
).post.unwrap();
|
||||
expect(gammaTrySticky.post_view.post.stickied).toBe(true);
|
||||
expect(betaPost3.post.stickied).toBe(false);
|
||||
expect(gammaTrySticky.post_view.post.featured_community).toBe(true);
|
||||
expect(betaPost3.post.featured_community).toBe(false);
|
||||
});
|
||||
|
||||
test("Lock a post", async () => {
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
CreateComment,
|
||||
DeletePost,
|
||||
RemovePost,
|
||||
StickyPost,
|
||||
LockPost,
|
||||
PostResponse,
|
||||
SearchResponse,
|
||||
@@ -64,6 +63,8 @@ import {
|
||||
CommentSortType,
|
||||
GetComments,
|
||||
GetCommentsResponse,
|
||||
FeaturePost,
|
||||
PostFeatureType,
|
||||
} from "lemmy-js-client";
|
||||
|
||||
export interface API {
|
||||
@@ -180,14 +181,13 @@ export async function setupLogins() {
|
||||
rate_limit_search: Some(999),
|
||||
rate_limit_search_per_second: None,
|
||||
federation_enabled: None,
|
||||
federation_strict_allowlist: None,
|
||||
federation_http_fetch_retry_limit: None,
|
||||
federation_worker_count: None,
|
||||
captcha_enabled: None,
|
||||
captcha_difficulty: None,
|
||||
allowed_instances: None,
|
||||
blocked_instances: None,
|
||||
auth: "",
|
||||
taglines: None,
|
||||
});
|
||||
|
||||
// Set the blocks and auths for each
|
||||
@@ -293,17 +293,18 @@ export async function removePost(
|
||||
return api.client.removePost(form);
|
||||
}
|
||||
|
||||
export async function stickyPost(
|
||||
export async function featurePost(
|
||||
api: API,
|
||||
stickied: boolean,
|
||||
featured: boolean,
|
||||
post: Post
|
||||
): Promise<PostResponse> {
|
||||
let form = new StickyPost({
|
||||
let form = new FeaturePost({
|
||||
post_id: post.id,
|
||||
stickied,
|
||||
featured,
|
||||
feature_type: PostFeatureType.Community,
|
||||
auth: api.auth.unwrap(),
|
||||
});
|
||||
return api.client.stickyPost(form);
|
||||
return api.client.featurePost(form);
|
||||
}
|
||||
|
||||
export async function lockPost(
|
||||
|
||||
@@ -2373,10 +2373,15 @@ kleur@^3.0.3:
|
||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||
|
||||
lemmy-js-client@0.17.0-rc.48:
|
||||
version "0.17.0-rc.48"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.48.tgz#6085812d4901b7d12b3fca237d8aced7f5210eac"
|
||||
integrity sha512-Lz8Nzq/kczQtDj6STlbhxoEarFHtTCoWcWBabyPs6X6em/pfK/cnZqx1mMn7EaBSDUVQ+WL8UNFjQiqjhR4kww==
|
||||
lemmy-js-client@0.17.0-rc.56:
|
||||
version "0.17.0-rc.56"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.56.tgz#2c7abba9b8195826eb36401e7c5c2cb75609bcf2"
|
||||
integrity sha512-7MM5xV8H9fIr1TbM/4e9PFKJpwlD2t135pSiH92TFgdkTzOMf0mtLO2BWLAQ7Rq+XVoVgj/WSBR4BofJka8XRQ==
|
||||
dependencies:
|
||||
"@sniptt/monads" "^0.5.10"
|
||||
class-transformer "^0.5.1"
|
||||
node-fetch "2.6.6"
|
||||
reflect-metadata "^0.1.13"
|
||||
|
||||
leven@^3.1.0:
|
||||
version "3.1.0"
|
||||
@@ -2511,6 +2516,13 @@ natural-compare@^1.4.0:
|
||||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==
|
||||
|
||||
node-fetch@2.6.6:
|
||||
version "2.6.6"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89"
|
||||
integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
|
||||
dependencies:
|
||||
whatwg-url "^5.0.0"
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
version "2.6.7"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
||||
|
||||
Reference in New Issue
Block a user