add: achievement toggle

Closes #16
This commit is contained in:
Mar0xy 2023-09-29 00:57:38 +02:00
parent 0c7011bd02
commit fc00f08d5b
No known key found for this signature in database
GPG Key ID: 56569BBE47D2C828
9 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,11 @@
export class EnableAchievements1695937489995 {
name = 'EnableAchievements1695937489995'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "enableAchievements" boolean NOT NULL DEFAULT true`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableAchievements"`);
}
}

View File

@ -449,6 +449,11 @@ export class MiMeta {
})
public enableIdenticonGeneration: boolean;
@Column('boolean', {
default: true,
})
public enableAchievements: boolean;
@Column('jsonb', {
default: { },
})

View File

@ -282,6 +282,10 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
enableAchievements: {
type: 'boolean',
optional: false, nullable: false,
},
enableIdenticonGeneration: {
type: 'boolean',
optional: false, nullable: false,
@ -396,6 +400,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableChartsForRemoteUser: instance.enableChartsForRemoteUser,
enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances,
enableServerMachineStats: instance.enableServerMachineStats,
enableAchievements: instance.enableAchievements,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
manifestJsonOverride: instance.manifestJsonOverride,

View File

@ -104,6 +104,7 @@ export const paramDef = {
enableChartsForRemoteUser: { type: 'boolean' },
enableChartsForFederatedInstances: { type: 'boolean' },
enableServerMachineStats: { type: 'boolean' },
enableAchievements: { type: 'boolean' },
enableIdenticonGeneration: { type: 'boolean' },
serverRules: { type: 'array', items: { type: 'string' } },
preservedUsernames: { type: 'array', items: { type: 'string' } },
@ -425,6 +426,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.enableServerMachineStats = ps.enableServerMachineStats;
}
if (ps.enableAchievements !== undefined) {
set.enableAchievements = ps.enableAchievements;
}
if (ps.enableIdenticonGeneration !== undefined) {
set.enableIdenticonGeneration = ps.enableIdenticonGeneration;
}

View File

@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { AchievementService, ACHIEVEMENT_TYPES } from '@/core/AchievementService.js';
import { MetaService } from '@/core/MetaService.js';
export const meta = {
requireCredential: true,
@ -24,8 +25,12 @@ export const paramDef = {
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
private achievementService: AchievementService,
private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
const meta = await this.metaService.fetch();
if (!meta.enableAchievements) return;
await this.achievementService.create(me.id, ps.name);
});
}

View File

@ -304,6 +304,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey,
enableRecaptcha: instance.enableRecaptcha,
enableAchievements: instance.enableAchievements,
recaptchaSiteKey: instance.recaptchaSiteKey,
enableTurnstile: instance.enableTurnstile,
turnstileSiteKey: instance.turnstileSiteKey,

View File

@ -12,6 +12,7 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { ui } from '@/config.js';
import { unisonReload } from '@/scripts/unison-reload.js';
import { instance } from './instance.js';
export const navbarItemDef = reactive({
notifications: {
@ -104,7 +105,7 @@ export const navbarItemDef = reactive({
achievements: {
title: i18n.ts.achievements,
icon: 'ti ti-medal',
show: computed(() => $i != null),
show: computed(() => $i != null && instance.enableAchievements),
to: '/my/achievements',
},
ui: {

View File

@ -16,6 +16,13 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch>
</div>
<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableAchievements">
<template #label>Enable Achievements</template>
<template #caption>Turning this off will disable the achievement system</template>
</MkSwitch>
</div>
<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableIdenticonGeneration">
<template #label>{{ i18n.ts.enableIdenticonGeneration }}</template>
@ -53,6 +60,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkSwitch from '@/components/MkSwitch.vue';
let enableServerMachineStats: boolean = $ref(false);
let enableAchievements: boolean = $ref(false);
let enableIdenticonGeneration: boolean = $ref(false);
let enableChartsForRemoteUser: boolean = $ref(false);
let enableChartsForFederatedInstances: boolean = $ref(false);
@ -60,6 +68,7 @@ let enableChartsForFederatedInstances: boolean = $ref(false);
async function init() {
const meta = await os.api('admin/meta');
enableServerMachineStats = meta.enableServerMachineStats;
enableAchievements = meta.enableAchievements;
enableIdenticonGeneration = meta.enableIdenticonGeneration;
enableChartsForRemoteUser = meta.enableChartsForRemoteUser;
enableChartsForFederatedInstances = meta.enableChartsForFederatedInstances;
@ -68,6 +77,7 @@ async function init() {
function save() {
os.apiWithDialog('admin/update-meta', {
enableServerMachineStats,
enableAchievements,
enableIdenticonGeneration,
enableChartsForRemoteUser,
enableChartsForFederatedInstances,

View File

@ -344,6 +344,7 @@ export type LiteInstanceMetadata = {
enableTwitterIntegration: boolean;
enableGithubIntegration: boolean;
enableDiscordIntegration: boolean;
enableAchievements: boolean;
enableServiceWorker: boolean;
emojis: CustomEmoji[];
defaultDarkTheme: string | null;