From: Dessalines Date: Sun, 24 Jan 2021 05:56:00 +0000 (-0500) Subject: Only push notifs if on first page, and right local context. Fixes #131 X-Git-Url: http://these/git/%22https:/nerdica.net/readmes/README.ru.md?a=commitdiff_plain;h=a4e207bde776fcd208c09d497912e066a70a862b;p=lemmy-ui.git Only push notifs if on first page, and right local context. Fixes #131 --- diff --git a/src/shared/components/main.tsx b/src/shared/components/main.tsx index 4f0587b..dbe0130 100644 --- a/src/shared/components/main.tsx +++ b/src/shared/components/main.tsx @@ -716,32 +716,38 @@ export class Main extends Component { } else if (op == UserOperation.CreatePost) { let data = wsJsonToRes(msg).data; - // If you're on subscribed, only push it if you're subscribed. - if (this.state.listingType == ListingType.Subscribed) { - if ( - this.state.subscribedCommunities - .map(c => c.community.id) - .includes(data.post_view.community.id) - ) { - this.state.posts.unshift(data.post_view); - notifyPost(data.post_view, this.context.router); - } - } else { - // NSFW posts - let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw; - - // Don't push the post if its nsfw, and don't have that setting on - if ( - !nsfw || - (nsfw && - UserService.Instance.user && - UserService.Instance.user.show_nsfw) - ) { + // NSFW check + let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw; + let nsfwCheck = + !nsfw || + (nsfw && + UserService.Instance.user && + UserService.Instance.user.show_nsfw); + + // Only push these if you're on the first page, and you pass the nsfw check + if (this.state.page == 1 && nsfwCheck) { + // If you're on subscribed, only push it if you're subscribed. + if (this.state.listingType == ListingType.Subscribed) { + if ( + this.state.subscribedCommunities + .map(c => c.community.id) + .includes(data.post_view.community.id) + ) { + this.state.posts.unshift(data.post_view); + notifyPost(data.post_view, this.context.router); + } + } else if (this.state.listingType == ListingType.Local) { + // If you're on the local view, only push it if its local + if (data.post_view.post.local) { + this.state.posts.unshift(data.post_view); + notifyPost(data.post_view, this.context.router); + } + } else { this.state.posts.unshift(data.post_view); notifyPost(data.post_view, this.context.router); } + this.setState(this.state); } - this.setState(this.state); } else if ( op == UserOperation.EditPost || op == UserOperation.DeletePost ||