Skip to content

Commit

Permalink
add: achievement toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Mar0xy committed Sep 28, 2023
1 parent 0c7011b commit fc00f08
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/backend/migration/1695937489995-enableAchievements.js
Original file line number Diff line number Diff line change
@@ -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"`);
}
}
5 changes: 5 additions & 0 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ export class MiMeta {
})
public enableIdenticonGeneration: boolean;

@Column('boolean', {
default: true,
})
public enableAchievements: boolean;

@Column('jsonb', {
default: { },
})
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/navbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions packages/frontend/src/pages/admin/other-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -53,13 +60,15 @@ 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);
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;
Expand All @@ -68,6 +77,7 @@ async function init() {
function save() {
os.apiWithDialog('admin/update-meta', {
enableServerMachineStats,
enableAchievements,
enableIdenticonGeneration,
enableChartsForRemoteUser,
enableChartsForFederatedInstances,
Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/src/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export type LiteInstanceMetadata = {
enableTwitterIntegration: boolean;
enableGithubIntegration: boolean;
enableDiscordIntegration: boolean;
enableAchievements: boolean;
enableServiceWorker: boolean;
emojis: CustomEmoji[];
defaultDarkTheme: string | null;
Expand Down

0 comments on commit fc00f08

Please sign in to comment.