mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 15:51:14 +00:00
Fix posts pushed from blocked users/comms. Fixes #697
This commit is contained in:
parent
d14db474bf
commit
0450511996
3 changed files with 55 additions and 16 deletions
|
@ -49,7 +49,9 @@ import {
|
||||||
getDataTypeFromProps,
|
getDataTypeFromProps,
|
||||||
getPageFromProps,
|
getPageFromProps,
|
||||||
getSortTypeFromProps,
|
getSortTypeFromProps,
|
||||||
|
isPostBlocked,
|
||||||
notifyPost,
|
notifyPost,
|
||||||
|
nsfwCheck,
|
||||||
postToCommentSortType,
|
postToCommentSortType,
|
||||||
relTags,
|
relTags,
|
||||||
restoreScrollPosition,
|
restoreScrollPosition,
|
||||||
|
@ -594,15 +596,24 @@ export class Community extends Component<any, State> {
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
} else if (op == UserOperation.CreatePost) {
|
} else if (op == UserOperation.CreatePost) {
|
||||||
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
||||||
this.state.posts.unshift(data.post_view);
|
|
||||||
if (
|
let showPostNotifs = UserService.Instance.myUserInfo
|
||||||
UserService.Instance.myUserInfo
|
|
||||||
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
||||||
.unwrapOr(false)
|
.unwrapOr(false);
|
||||||
|
|
||||||
|
// Only push these if you're on the first page, you pass the nsfw check, and it isn't blocked
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
this.state.page == 1 &&
|
||||||
|
nsfwCheck(data.post_view) &&
|
||||||
|
!isPostBlocked(data.post_view)
|
||||||
) {
|
) {
|
||||||
|
this.state.posts.unshift(data.post_view);
|
||||||
|
if (showPostNotifs) {
|
||||||
notifyPost(data.post_view, this.context.router);
|
notifyPost(data.post_view, this.context.router);
|
||||||
}
|
}
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
|
}
|
||||||
} else if (op == UserOperation.CreatePostLike) {
|
} else if (op == UserOperation.CreatePostLike) {
|
||||||
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
||||||
createPostLikeFindRes(data.post_view, this.state.posts);
|
createPostLikeFindRes(data.post_view, this.state.posts);
|
||||||
|
|
|
@ -52,7 +52,9 @@ import {
|
||||||
getPageFromProps,
|
getPageFromProps,
|
||||||
getSortTypeFromProps,
|
getSortTypeFromProps,
|
||||||
isBrowser,
|
isBrowser,
|
||||||
|
isPostBlocked,
|
||||||
notifyPost,
|
notifyPost,
|
||||||
|
nsfwCheck,
|
||||||
postToCommentSortType,
|
postToCommentSortType,
|
||||||
relTags,
|
relTags,
|
||||||
restoreScrollPosition,
|
restoreScrollPosition,
|
||||||
|
@ -756,21 +758,17 @@ export class Home extends Component<any, HomeState> {
|
||||||
setupTippy();
|
setupTippy();
|
||||||
} else if (op == UserOperation.CreatePost) {
|
} else if (op == UserOperation.CreatePost) {
|
||||||
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
let data = wsJsonToRes<PostResponse>(msg, PostResponse);
|
||||||
// NSFW check
|
|
||||||
let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw;
|
|
||||||
let nsfwCheck =
|
|
||||||
!nsfw ||
|
|
||||||
(nsfw &&
|
|
||||||
UserService.Instance.myUserInfo
|
|
||||||
.map(m => m.local_user_view.local_user.show_nsfw)
|
|
||||||
.unwrapOr(false));
|
|
||||||
|
|
||||||
let showPostNotifs = UserService.Instance.myUserInfo
|
let showPostNotifs = UserService.Instance.myUserInfo
|
||||||
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
.map(m => m.local_user_view.local_user.show_new_post_notifs)
|
||||||
.unwrapOr(false);
|
.unwrapOr(false);
|
||||||
|
|
||||||
// Only push these if you're on the first page, and you pass the nsfw check
|
// Only push these if you're on the first page, you pass the nsfw check, and it isn't blocked
|
||||||
if (this.state.page == 1 && nsfwCheck) {
|
if (
|
||||||
|
this.state.page == 1 &&
|
||||||
|
nsfwCheck(data.post_view) &&
|
||||||
|
!isPostBlocked(data.post_view)
|
||||||
|
) {
|
||||||
// If you're on subscribed, only push it if you're subscribed.
|
// If you're on subscribed, only push it if you're subscribed.
|
||||||
if (this.state.listingType == ListingType.Subscribed) {
|
if (this.state.listingType == ListingType.Subscribed) {
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -1487,3 +1487,33 @@ export function canCreateCommunity(siteRes: GetSiteResponse): boolean {
|
||||||
.unwrapOr(false);
|
.unwrapOr(false);
|
||||||
return !adminOnly || amAdmin(Some(siteRes.admins));
|
return !adminOnly || amAdmin(Some(siteRes.admins));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPostBlocked(
|
||||||
|
pv: PostView,
|
||||||
|
myUserInfo = UserService.Instance.myUserInfo
|
||||||
|
): boolean {
|
||||||
|
return myUserInfo
|
||||||
|
.map(
|
||||||
|
mui =>
|
||||||
|
mui.community_blocks
|
||||||
|
.map(c => c.community.id)
|
||||||
|
.includes(pv.community.id) ||
|
||||||
|
mui.person_blocks.map(p => p.target.id).includes(pv.creator.id)
|
||||||
|
)
|
||||||
|
.unwrapOr(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks to make sure you can view NSFW posts. Returns true if you can.
|
||||||
|
export function nsfwCheck(
|
||||||
|
pv: PostView,
|
||||||
|
myUserInfo = UserService.Instance.myUserInfo
|
||||||
|
): boolean {
|
||||||
|
let nsfw = pv.post.nsfw || pv.community.nsfw;
|
||||||
|
return (
|
||||||
|
!nsfw ||
|
||||||
|
(nsfw &&
|
||||||
|
myUserInfo
|
||||||
|
.map(m => m.local_user_view.local_user.show_nsfw)
|
||||||
|
.unwrapOr(false))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue