pub struct PageExtension {
pub comments_enabled: bool,
pub sensitive: bool,
+ pub stickied: bool,
}
impl<U> UnparsedExtension<U> for PageExtension
Ok(PageExtension {
comments_enabled: unparsed_mut.remove("commentsEnabled")?,
sensitive: unparsed_mut.remove("sensitive")?,
+ stickied: unparsed_mut.remove("stickied")?,
})
}
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
unparsed_mut.insert("commentsEnabled", self.comments_enabled)?;
unparsed_mut.insert("sensitive", self.sensitive)?;
+ unparsed_mut.insert("stickied", self.stickied)?;
Ok(())
}
}
use crate::{
apub::{
activities::send_activity_to_community,
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
+ create_apub_response, create_apub_tombstone_response, create_tombstone,
extensions::page_extension::PageExtension,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
- ActorType,
- ApubLikeableType,
- ApubObjectType,
- FromApub,
- PageExt,
- ToApub,
+ ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::Ext1;
use activitystreams_new::{
let ext = PageExtension {
comments_enabled: !self.locked,
sensitive: self.nsfw,
+ stickied: self.stickied,
};
Ok(Ext1::new(page, ext))
}
.map(|u| u.to_owned().naive_local()),
deleted: None,
nsfw: ext.sensitive,
- stickied: None, // -> put it in "featured" collection of the community
+ stickied: Some(ext.stickied),
embed_title,
embed_description,
embed_html,
PostForm,
DeletePostForm,
RemovePostForm,
- // TODO need to test LockPost and StickyPost federated
+ StickyPostForm,
+ LockPostForm,
PostResponse,
SearchResponse,
FollowCommunityForm,
expect(updateResponse.post.community_local).toBe(false);
expect(updateResponse.post.creator_local).toBe(true);
+ let stickyPostForm: StickyPostForm = {
+ edit_id: 2,
+ stickied: true,
+ auth: lemmyAlphaAuth,
+ };
+
+ let stickyRes: PostResponse = await fetch(
+ `${lemmyAlphaApiUrl}/post/sticky`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(stickyPostForm),
+ }
+ ).then(d => d.json());
+
+ expect(stickyRes.post.name).toBe(name);
+ expect(stickyRes.post.stickied).toBe(true);
+
+ // Fetch from B
let getPostUrl = `${lemmyBetaApiUrl}/post?id=2`;
let getPostRes: GetPostResponse = await fetch(getPostUrl, {
method: 'GET',
expect(getPostRes.post.name).toBe(name);
expect(getPostRes.post.community_local).toBe(true);
expect(getPostRes.post.creator_local).toBe(false);
+ expect(getPostRes.post.stickied).toBe(true);
+
+ let lockPostForm: LockPostForm = {
+ edit_id: 2,
+ locked: true,
+ auth: lemmyAlphaAuth,
+ };
+
+ let lockedRes: PostResponse = await fetch(
+ `${lemmyAlphaApiUrl}/post/lock`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(lockPostForm),
+ }
+ ).then(d => d.json());
+
+ expect(lockedRes.post.name).toBe(name);
+ expect(lockedRes.post.locked).toBe(true);
+
+ // Fetch from B to make sure its locked
+ getPostRes = await fetch(getPostUrl, {
+ method: 'GET',
+ }).then(d => d.json());
+ expect(getPostRes.post.locked).toBe(true);
+
+ // Create a test comment on a locked post, it should be undefined
+ // since it shouldn't get created.
+ let content = 'A rejected comment on a locked post';
+ let commentForm: CommentForm = {
+ content,
+ post_id: 2,
+ auth: lemmyAlphaAuth,
+ };
+
+ let createResponse: CommentResponse = await fetch(
+ `${lemmyAlphaApiUrl}/comment`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(commentForm),
+ }
+ ).then(d => d.json());
+
+ expect(createResponse['error']).toBe('locked');
+
+ // Unlock the post for later actions
+ let unlockPostForm: LockPostForm = {
+ edit_id: 2,
+ locked: false,
+ auth: lemmyAlphaAuth,
+ };
+
+ let unlockedRes: PostResponse = await fetch(
+ `${lemmyAlphaApiUrl}/post/lock`,
+ {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: wrapper(unlockPostForm),
+ }
+ ).then(d => d.json());
+
+ expect(unlockedRes.post.name).toBe(name);
+ expect(unlockedRes.post.locked).toBe(false);
});
});