Add setting for an autofollowed account on signup

This commit is contained in:
PrivateGER 2023-11-22 23:23:46 +01:00 committed by Laura Hausmann
parent 4f9b5d9f72
commit b814ebcdfb
6 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddAutofollowedAccount1700686908916 implements MigrationInterface {
name = "AddAutofollowedAccount1700686908916";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "meta" ADD "autofollowedAccount" character varying(128)`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "meta" DROP COLUMN "autofollowedAccount"`,
);
}
}

View file

@ -518,4 +518,10 @@ export class Meta {
nullable: true,
})
public donationLink: string | null;
@Column("varchar", {
length: 64,
nullable: true,
})
public autofollowedAccount: string | null;
}

View file

@ -12,6 +12,8 @@ import { UsedUsername } from "@/models/entities/used-username.js";
import { db } from "@/db/postgre.js";
import config from "@/config/index.js";
import { hashPassword } from "@/misc/password.js";
import { fetchMeta } from "@/misc/fetch-meta.js";
import follow from "@/services/following/create.js";
export async function signup(opts: {
username: User["username"];
@ -133,6 +135,20 @@ export async function signup(opts: {
const account = await Users.findOneByOrFail({ id: user.id });
const meta = await fetchMeta();
// If an autofollow account exists, follow it
if (meta.autofollowedAccount) {
const autofollowedAccount = await Users.findOneByOrFail({
usernameLower: meta.autofollowedAccount.toLowerCase(),
host: IsNull(),
});
if (autofollowedAccount) {
await follow(account, autofollowedAccount)
}
}
usersChart.update(account, true);
return { account, secret };
}

View file

@ -430,6 +430,11 @@ export const meta = {
optional: true,
nullable: true,
},
autofollowedAccount: {
type: "string",
optional: true,
nullable: true,
},
},
},
} as const;
@ -536,5 +541,6 @@ export default define(meta, paramDef, async (ps, me) => {
enableServerMachineStats: instance.enableServerMachineStats,
enableIdenticonGeneration: instance.enableIdenticonGeneration,
donationLink: instance.donationLink,
autofollowedAccount: instance.autofollowedAccount,
};
});

View file

@ -3,6 +3,8 @@ import { insertModerationLog } from "@/services/insert-moderation-log.js";
import { db } from "@/db/postgre.js";
import define from "../../define.js";
import { Metas } from "@/models/index.js";
import { Users } from "@/models/index.js";
export const meta = {
tags: ["admin"],
@ -166,6 +168,7 @@ export const paramDef = {
enableServerMachineStats: { type: "boolean" },
enableIdenticonGeneration: { type: "boolean" },
donationLink: { type: "string", nullable: true },
autofollowedAccount: { type: "string", nullable: true },
},
required: [],
} as const;
@ -547,6 +550,14 @@ export default define(meta, paramDef, async (ps, me) => {
}
}
if (ps.autofollowedAccount !== undefined) {
// Verify account exists and is a local account
const user = await Users.findOneBy({ username: ps.autofollowedAccount, host: null });
if (user) {
set.autofollowedAccount = user.username;
}
}
const meta = await Metas.findOne({
where: {},
order: {

View file

@ -382,6 +382,22 @@
>
</FormInput>
</FormSection>
<FormSection>
<template #label>Auto-followed account</template>
<FormInput
v-model="autofollowedAccount"
class="_formBlock"
>
<template #prefix
><i class="ph-at ph-bold ph-lg"></i
></template>
<template #label
>Username</template
>
</FormInput>
</FormSection>
</div>
</FormSuspense>
</MkSpacer>
@ -437,6 +453,7 @@ let defaultReaction: string = $ref("");
let defaultReactionCustom: string = $ref("");
let enableServerMachineStats: boolean = $ref(false);
let enableIdenticonGeneration: boolean = $ref(false);
let autofollowedAccount: string | null = $ref(null);
async function init() {
const meta = await os.api("admin/meta");
@ -478,6 +495,7 @@ async function init() {
: meta.defaultReaction;
enableServerMachineStats = meta.enableServerMachineStats;
enableIdenticonGeneration = meta.enableIdenticonGeneration;
autofollowedAccount = meta.autofollowedAccount;
}
function save() {
@ -517,6 +535,7 @@ function save() {
defaultReaction,
enableServerMachineStats,
enableIdenticonGeneration,
autofollowedAccount,
}).then(() => {
fetchInstance();
});