mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-30 16:05:41 +00:00
Add discovery filtering
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -44,31 +44,21 @@ router.get(
|
||||
select: { guild_id: true },
|
||||
}).then((members) => members.map((member) => member.guild_id))
|
||||
: [];
|
||||
let guilds;
|
||||
if (categories == undefined) {
|
||||
guilds = showAllGuilds
|
||||
? await Guild.find({
|
||||
take: Math.abs(Number(limit || configLimit)),
|
||||
})
|
||||
: await Guild.find({
|
||||
where: { features: Like(`%DISCOVERABLE%`) },
|
||||
take: Math.abs(Number(limit || configLimit)),
|
||||
});
|
||||
} else {
|
||||
guilds = showAllGuilds
|
||||
? await Guild.find({
|
||||
where: { primary_category_id: categories.toString(), id: Not(In(hiddenGuildIds)) },
|
||||
take: Math.abs(Number(limit || configLimit)),
|
||||
})
|
||||
: await Guild.find({
|
||||
where: {
|
||||
primary_category_id: categories.toString(),
|
||||
features: Like("%DISCOVERABLE%"),
|
||||
id: Not(In(hiddenGuildIds)),
|
||||
},
|
||||
take: Math.abs(Number(limit || configLimit)),
|
||||
});
|
||||
}
|
||||
|
||||
const guilds = await Guild.find({
|
||||
where: {
|
||||
id: Not(In(hiddenGuildIds)),
|
||||
discovery_excluded: false,
|
||||
...(categories == undefined ? {} : { primary_category_id: categories.toString() }), // TODO: isnt this an array?
|
||||
...(showAllGuilds ? {} : { features: Like("%DISCOVERABLE%") }),
|
||||
},
|
||||
order: {
|
||||
discovery_weight: "DESC",
|
||||
member_count: "DESC",
|
||||
},
|
||||
skip: Math.abs(Number(offset || Config.get().guild.discovery.offset)),
|
||||
take: Math.abs(Number(limit || configLimit)),
|
||||
});
|
||||
|
||||
const total = guilds ? guilds.length : undefined;
|
||||
|
||||
|
||||
@@ -298,6 +298,12 @@ export class Guild extends BaseClass {
|
||||
@Column({ select: false, type: "simple-array" })
|
||||
channel_ordering: string[];
|
||||
|
||||
@Column()
|
||||
discovery_weight: number = 0;
|
||||
|
||||
@Column()
|
||||
discovery_excluded: boolean = false;
|
||||
|
||||
static async createGuild(body: {
|
||||
name?: string;
|
||||
icon?: string | null;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class GuildDiscoveryHoisting1770748070808 implements MigrationInterface {
|
||||
name = "GuildDiscoveryHoisting1770748070808";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "guilds" ADD "discovery_weight" integer NOT NULL`);
|
||||
await queryRunner.query(`ALTER TABLE "guilds" ADD "discovery_excluded" boolean NOT NULL`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "guilds" DROP COLUMN "discovery_excluded"`);
|
||||
await queryRunner.query(`ALTER TABLE "guilds" DROP COLUMN "discovery_weight"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user