wip
This commit is contained in:
parent
21d6aacea8
commit
9dbe7bfbcb
@ -1,5 +1,6 @@
|
||||
import define from '../../../define.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { publishInternalEvent } from '@/services/stream.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -31,4 +32,6 @@ export default define(meta, paramDef, async (ps) => {
|
||||
await Users.update(user.id, {
|
||||
isModerator: true,
|
||||
});
|
||||
|
||||
publishInternalEvent('userChangeModeratorState', { id: user.id, isModerator: true });
|
||||
});
|
||||
|
@ -27,4 +27,6 @@ export default define(meta, paramDef, async (ps) => {
|
||||
await Users.update(user.id, {
|
||||
isModerator: false,
|
||||
});
|
||||
|
||||
publishInternalEvent('userChangeModeratorState', { id: user.id, isModerator: false });
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import define from '../../define.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { publishInternalEvent } from '@/services/stream.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -33,6 +34,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
isSilenced: true,
|
||||
});
|
||||
|
||||
publishInternalEvent('userChangeSilencedState', { id: user.id, isSilenced: true });
|
||||
|
||||
insertModerationLog(me, 'silence', {
|
||||
targetId: user.id,
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import define from '../../define.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||
import { publishInternalEvent } from '@/services/stream.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
@ -29,6 +30,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||
isSilenced: false,
|
||||
});
|
||||
|
||||
publishInternalEvent('userChangeSilencedState', { id: user.id, isSilenced: false });
|
||||
|
||||
insertModerationLog(me, 'unsilence', {
|
||||
targetId: user.id,
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { publishMainStream, publishUserEvent } from '@/services/stream.js';
|
||||
import { publishInternalEvent, publishMainStream, publishUserEvent } from '@/services/stream.js';
|
||||
import generateUserToken from '../../common/generate-native-user-token.js';
|
||||
import define from '../../define.js';
|
||||
import { Users, UserProfiles } from '@/models/index.js';
|
||||
@ -20,6 +20,9 @@ export const paramDef = {
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
const freshUser = await Users.findOneOrFail(user.id);
|
||||
const oldToken = freshUser.token;
|
||||
|
||||
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||
|
||||
// Compare password
|
||||
@ -29,14 +32,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||
throw new Error('incorrect password');
|
||||
}
|
||||
|
||||
// Generate secret
|
||||
const secret = generateUserToken();
|
||||
const newToken = generateUserToken();
|
||||
|
||||
await Users.update(user.id, {
|
||||
token: secret,
|
||||
token: newToken,
|
||||
});
|
||||
|
||||
// Publish event
|
||||
publishInternalEvent('userTokenRegenerated', { id: user.id, oldToken, newToken });
|
||||
publishMainStream(user.id, 'myTokenRegenerated');
|
||||
|
||||
// Terminate streaming
|
||||
|
@ -18,6 +18,10 @@ import { Packed } from '@/misc/schema.js';
|
||||
|
||||
//#region Stream type-body definitions
|
||||
export interface InternalStreamTypes {
|
||||
userChangeSuspendedState: { id: User['id']; isSuspended: User['isSuspended']; };
|
||||
userChangeSilencedState: { id: User['id']; isSilenced: User['isSilenced']; };
|
||||
userChangeModeratorState: { id: User['id']; isModerator: User['isModerator']; };
|
||||
userTokenRegenerated: { id: User['id']; oldToken: User['token']; newToken: User['token']; };
|
||||
antennaCreated: Antenna;
|
||||
antennaDeleted: Antenna;
|
||||
antennaUpdated: Antenna;
|
||||
|
@ -125,7 +125,7 @@ type Option = {
|
||||
app?: App | null;
|
||||
};
|
||||
|
||||
export default async (user: { id: User['id']; username: User['username']; host: User['host']; createdAt: User['createdAt']; }, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
|
||||
export default async (user: { id: User['id']; username: User['username']; host: User['host']; isSilenced: User['isSilenced']; createdAt: User['createdAt']; }, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
|
||||
// チャンネル外にリプライしたら対象のスコープに合わせる
|
||||
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
|
||||
if (data.reply && data.channel && data.reply.channelId !== data.channel.id) {
|
||||
|
@ -5,8 +5,11 @@ import config from '@/config/index.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Users, Followings } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { publishInternalEvent } from './stream';
|
||||
|
||||
export async function doPostSuspend(user: { id: User['id']; host: User['host'] }) {
|
||||
publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: true });
|
||||
|
||||
if (Users.isLocalUser(user)) {
|
||||
// 知り得る全SharedInboxにDelete配信
|
||||
const content = renderActivity(renderDelete(`${config.url}/users/${user.id}`, user));
|
||||
|
@ -6,8 +6,11 @@ import config from '@/config/index.js';
|
||||
import { User } from '@/models/entities/user.js';
|
||||
import { Users, Followings } from '@/models/index.js';
|
||||
import { Not, IsNull } from 'typeorm';
|
||||
import { publishInternalEvent } from './stream';
|
||||
|
||||
export async function doPostUnsuspend(user: User) {
|
||||
publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
|
||||
|
||||
if (Users.isLocalUser(user)) {
|
||||
// 知り得る全SharedInboxにUndo Delete配信
|
||||
const content = renderActivity(renderUndo(renderDelete(`${config.url}/users/${user.id}`, user), user));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CacheableLocalUser, CacheableUser, User } from '@/models/entities/user.js';
|
||||
import { CacheableLocalUser, CacheableUser, ILocalUser, User } from '@/models/entities/user.js';
|
||||
import { Users } from '@/models/index.js';
|
||||
import { Cache } from '@/misc/cache.js';
|
||||
import { subsdcriber } from '@/db/redis.js';
|
||||
@ -16,7 +16,7 @@ subsdcriber.on('message', async (_, data) => {
|
||||
switch (type) {
|
||||
case 'userChangeSuspendedState':
|
||||
case 'userChangeSilencedState':
|
||||
case 'userChangeModeratorState':
|
||||
case 'userChangeModeratorState': {
|
||||
const user = await Users.findOneOrFail(body.id);
|
||||
userByIdCache.set(user.id, user);
|
||||
for (const [k, v] of uriPersonCache.cache.entries()) {
|
||||
@ -29,9 +29,13 @@ subsdcriber.on('message', async (_, data) => {
|
||||
localUserByIdCache.set(user.id, user);
|
||||
}
|
||||
break;
|
||||
case 'userTokenRegenerated':
|
||||
|
||||
}
|
||||
case 'userTokenRegenerated': {
|
||||
const user = await Users.findOneOrFail(body.id) as ILocalUser;
|
||||
localUserByNativeTokenCache.delete(body.oldToken);
|
||||
localUserByNativeTokenCache.set(body.newToken, user);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user