Only push notifs if on first page, and right local context. Fixes #131

This commit is contained in:
Dessalines 2021-01-24 00:56:00 -05:00
parent 829b617b17
commit a4e207bde7

View file

@ -716,32 +716,38 @@ export class Main extends Component<any, MainState> {
} else if (op == UserOperation.CreatePost) { } else if (op == UserOperation.CreatePost) {
let data = wsJsonToRes<PostResponse>(msg).data; let data = wsJsonToRes<PostResponse>(msg).data;
// If you're on subscribed, only push it if you're subscribed. // NSFW check
if (this.state.listingType == ListingType.Subscribed) { let nsfw = data.post_view.post.nsfw || data.post_view.community.nsfw;
if ( let nsfwCheck =
this.state.subscribedCommunities !nsfw ||
.map(c => c.community.id) (nsfw &&
.includes(data.post_view.community.id) UserService.Instance.user &&
) { UserService.Instance.user.show_nsfw);
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 // Only push these if you're on the first page, and you pass the nsfw check
if ( if (this.state.page == 1 && nsfwCheck) {
!nsfw || // If you're on subscribed, only push it if you're subscribed.
(nsfw && if (this.state.listingType == ListingType.Subscribed) {
UserService.Instance.user && if (
UserService.Instance.user.show_nsfw) 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); this.state.posts.unshift(data.post_view);
notifyPost(data.post_view, this.context.router); notifyPost(data.post_view, this.context.router);
} }
this.setState(this.state);
} }
this.setState(this.state);
} else if ( } else if (
op == UserOperation.EditPost || op == UserOperation.EditPost ||
op == UserOperation.DeletePost || op == UserOperation.DeletePost ||