Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/juxtaposition-ui/src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function verifyConnected() {
}
}

export function notBanned() {
return { account_status: { $in: [0, 1] } };
}

async function getCommunities(numberOfCommunities, offset) {
verifyConnected();
if (!offset) {
Expand Down Expand Up @@ -288,7 +292,8 @@ async function getUserContent(pid) {
async function getFollowingUsers(content) {
verifyConnected();
return SETTINGS.find({
pid: content.following_users
pid: content.following_users,
...notBanned()
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from 'zod';
import { database } from '@/database';
import { POST } from '@/models/post';
import { config } from '@/config';
import { parseReq } from '@/services/juxt-web/routes/routeUtils';
import { ifNotMod, parseReq } from '@/services/juxt-web/routes/routeUtils';
import { WebGlobalFeedView, WebPersonalFeedView } from '@/services/juxt-web/views/web/feed';
import { buildContext } from '@/services/juxt-web/views/context';
import { WebPostListView } from '@/services/juxt-web/views/web/postList';
Expand Down Expand Up @@ -54,10 +54,13 @@ feedRouter.get('/all', async function (req, res) {
if (!userContent) {
return res.redirect('/404');
}

const posts = await POST.find({
parent: null,
message_to_pid: null,
removed: false
...ifNotMod(res, {
parent: null,
removed: false
}),
message_to_pid: null
}).limit(config.postLimit).sort({ created_at: -1 });

const nextLink = `/feed/all/more?offset=${posts.length}&pjax=true`;
Expand Down Expand Up @@ -117,9 +120,11 @@ feedRouter.get('/all/more', async function (req, res) {
}

const posts = await POST.find({
parent: null,
message_to_pid: null,
removed: false
...ifNotMod(res, {
parent: null,
removed: false
}),
message_to_pid: null
}).skip(query.offset).limit(config.postLimit).sort({ created_at: -1 });

const nextLink = `/feed/all/more?offset=${query.offset + posts.length}&pjax=true`;
Expand Down
12 changes: 11 additions & 1 deletion apps/juxtaposition-ui/src/services/juxt-web/routes/routeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GetUserDataResponse as AccountGetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc';
import type { Request } from 'express';
import type { Request, Response } from 'express';
import type { z } from 'zod';
import type { UserTokens } from '@/types/juxt/tokens';
import type { ParamPack } from '@/types/common/param-pack';
Expand Down Expand Up @@ -107,3 +107,13 @@ export function parseReq<TBody extends AnySchema = undefined, TQuery extends Any
hasAuth
} as ParsedRequest<TBody, TQuery, TParams, TFiles>;
}

/**
* Returns a Mongoose filter if the account isn't a moderator.
*/
export function ifNotMod<T>(res: Response, filter: T): T | {} {
if (res.locals.moderator) {
return {};
}
return filter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function WebPostView(props: PostViewProps): ReactNode {
: null}

<h4>
{moment(post.created_at).fromNow()}
<a href={`/posts/${post.id}`}>{moment(post.created_at).fromNow()}</a>
{' - '}
<a href={`/titles/${post.community_id}`}>{props.ctx.communityMap.get(post.community_id ?? '')}</a>
</h4>
Expand Down