wip
This commit is contained in:
parent
21d6aacea8
commit
9dbe7bfbcb
@ -1,5 +1,6 @@
|
|||||||
import define from '../../../define.js';
|
import define from '../../../define.js';
|
||||||
import { Users } from '@/models/index.js';
|
import { Users } from '@/models/index.js';
|
||||||
|
import { publishInternalEvent } from '@/services/stream.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['admin'],
|
tags: ['admin'],
|
||||||
@ -31,4 +32,6 @@ export default define(meta, paramDef, async (ps) => {
|
|||||||
await Users.update(user.id, {
|
await Users.update(user.id, {
|
||||||
isModerator: true,
|
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, {
|
await Users.update(user.id, {
|
||||||
isModerator: false,
|
isModerator: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
publishInternalEvent('userChangeModeratorState', { id: user.id, isModerator: false });
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import define from '../../define.js';
|
import define from '../../define.js';
|
||||||
import { Users } from '@/models/index.js';
|
import { Users } from '@/models/index.js';
|
||||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||||
|
import { publishInternalEvent } from '@/services/stream.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['admin'],
|
tags: ['admin'],
|
||||||
@ -33,6 +34,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||||||
isSilenced: true,
|
isSilenced: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
publishInternalEvent('userChangeSilencedState', { id: user.id, isSilenced: true });
|
||||||
|
|
||||||
insertModerationLog(me, 'silence', {
|
insertModerationLog(me, 'silence', {
|
||||||
targetId: user.id,
|
targetId: user.id,
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import define from '../../define.js';
|
import define from '../../define.js';
|
||||||
import { Users } from '@/models/index.js';
|
import { Users } from '@/models/index.js';
|
||||||
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
import { insertModerationLog } from '@/services/insert-moderation-log.js';
|
||||||
|
import { publishInternalEvent } from '@/services/stream.js';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['admin'],
|
tags: ['admin'],
|
||||||
@ -29,6 +30,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||||||
isSilenced: false,
|
isSilenced: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
publishInternalEvent('userChangeSilencedState', { id: user.id, isSilenced: false });
|
||||||
|
|
||||||
insertModerationLog(me, 'unsilence', {
|
insertModerationLog(me, 'unsilence', {
|
||||||
targetId: user.id,
|
targetId: user.id,
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import bcrypt from 'bcryptjs';
|
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 generateUserToken from '../../common/generate-native-user-token.js';
|
||||||
import define from '../../define.js';
|
import define from '../../define.js';
|
||||||
import { Users, UserProfiles } from '@/models/index.js';
|
import { Users, UserProfiles } from '@/models/index.js';
|
||||||
@ -20,6 +20,9 @@ export const paramDef = {
|
|||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
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);
|
const profile = await UserProfiles.findOneOrFail(user.id);
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
@ -29,14 +32,14 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||||||
throw new Error('incorrect password');
|
throw new Error('incorrect password');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate secret
|
const newToken = generateUserToken();
|
||||||
const secret = generateUserToken();
|
|
||||||
|
|
||||||
await Users.update(user.id, {
|
await Users.update(user.id, {
|
||||||
token: secret,
|
token: newToken,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Publish event
|
// Publish event
|
||||||
|
publishInternalEvent('userTokenRegenerated', { id: user.id, oldToken, newToken });
|
||||||
publishMainStream(user.id, 'myTokenRegenerated');
|
publishMainStream(user.id, 'myTokenRegenerated');
|
||||||
|
|
||||||
// Terminate streaming
|
// Terminate streaming
|
||||||
|
@ -18,6 +18,10 @@ import { Packed } from '@/misc/schema.js';
|
|||||||
|
|
||||||
//#region Stream type-body definitions
|
//#region Stream type-body definitions
|
||||||
export interface InternalStreamTypes {
|
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;
|
antennaCreated: Antenna;
|
||||||
antennaDeleted: Antenna;
|
antennaDeleted: Antenna;
|
||||||
antennaUpdated: Antenna;
|
antennaUpdated: Antenna;
|
||||||
|
@ -125,7 +125,7 @@ type Option = {
|
|||||||
app?: App | null;
|
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) {
|
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 { User } from '@/models/entities/user.js';
|
||||||
import { Users, Followings } from '@/models/index.js';
|
import { Users, Followings } from '@/models/index.js';
|
||||||
import { Not, IsNull } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
|
import { publishInternalEvent } from './stream';
|
||||||
|
|
||||||
export async function doPostSuspend(user: { id: User['id']; host: User['host'] }) {
|
export async function doPostSuspend(user: { id: User['id']; host: User['host'] }) {
|
||||||
|
publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: true });
|
||||||
|
|
||||||
if (Users.isLocalUser(user)) {
|
if (Users.isLocalUser(user)) {
|
||||||
// 知り得る全SharedInboxにDelete配信
|
// 知り得る全SharedInboxにDelete配信
|
||||||
const content = renderActivity(renderDelete(`${config.url}/users/${user.id}`, user));
|
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 { User } from '@/models/entities/user.js';
|
||||||
import { Users, Followings } from '@/models/index.js';
|
import { Users, Followings } from '@/models/index.js';
|
||||||
import { Not, IsNull } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
|
import { publishInternalEvent } from './stream';
|
||||||
|
|
||||||
export async function doPostUnsuspend(user: User) {
|
export async function doPostUnsuspend(user: User) {
|
||||||
|
publishInternalEvent('userChangeSuspendedState', { id: user.id, isSuspended: false });
|
||||||
|
|
||||||
if (Users.isLocalUser(user)) {
|
if (Users.isLocalUser(user)) {
|
||||||
// 知り得る全SharedInboxにUndo Delete配信
|
// 知り得る全SharedInboxにUndo Delete配信
|
||||||
const content = renderActivity(renderUndo(renderDelete(`${config.url}/users/${user.id}`, user), user));
|
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 { Users } from '@/models/index.js';
|
||||||
import { Cache } from '@/misc/cache.js';
|
import { Cache } from '@/misc/cache.js';
|
||||||
import { subsdcriber } from '@/db/redis.js';
|
import { subsdcriber } from '@/db/redis.js';
|
||||||
@ -16,7 +16,7 @@ subsdcriber.on('message', async (_, data) => {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case 'userChangeSuspendedState':
|
case 'userChangeSuspendedState':
|
||||||
case 'userChangeSilencedState':
|
case 'userChangeSilencedState':
|
||||||
case 'userChangeModeratorState':
|
case 'userChangeModeratorState': {
|
||||||
const user = await Users.findOneOrFail(body.id);
|
const user = await Users.findOneOrFail(body.id);
|
||||||
userByIdCache.set(user.id, user);
|
userByIdCache.set(user.id, user);
|
||||||
for (const [k, v] of uriPersonCache.cache.entries()) {
|
for (const [k, v] of uriPersonCache.cache.entries()) {
|
||||||
@ -29,9 +29,13 @@ subsdcriber.on('message', async (_, data) => {
|
|||||||
localUserByIdCache.set(user.id, user);
|
localUserByIdCache.set(user.id, user);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'userTokenRegenerated':
|
}
|
||||||
|
case 'userTokenRegenerated': {
|
||||||
|
const user = await Users.findOneOrFail(body.id) as ILocalUser;
|
||||||
|
localUserByNativeTokenCache.delete(body.oldToken);
|
||||||
|
localUserByNativeTokenCache.set(body.newToken, user);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user