Merge branch 'develop' into swn
This commit is contained in:
commit
2cbee47c73
20 changed files with 412 additions and 60 deletions
|
@ -19,9 +19,13 @@
|
||||||
- クライアント: 新しいライトテーマを追加
|
- クライアント: 新しいライトテーマを追加
|
||||||
- API: ユーザーのリアクション一覧を取得する users/reactions を追加
|
- API: ユーザーのリアクション一覧を取得する users/reactions を追加
|
||||||
- API: users/search および users/search-by-username-and-host を強化
|
- API: users/search および users/search-by-username-and-host を強化
|
||||||
|
- ミュート及びブロックのインポートを行えるように
|
||||||
|
- クライアント: /share のクエリでリプライやファイル等の情報を渡せるように
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
- クライアント: テーマの管理が行えない問題を修正
|
- クライアント: テーマの管理が行えない問題を修正
|
||||||
|
- API: アプリケーション通知が取得できない問題を修正
|
||||||
|
- ActivityPub: not reacted な Undo.Like がinboxに滞留するのを修正
|
||||||
|
|
||||||
## 12.92.0 (2021/10/16)
|
## 12.92.0 (2021/10/16)
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,9 @@ const users = userIds.length > 0 ? await Users.find({
|
||||||
SQLでは配列のインデックスは**1始まり**。
|
SQLでは配列のインデックスは**1始まり**。
|
||||||
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
|
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
|
||||||
|
|
||||||
|
### null IN
|
||||||
|
nullが含まれる可能性のあるカラムにINするときは、そのままだとおかしくなるのでORなどでnullのハンドリングをしよう。
|
||||||
|
|
||||||
### `undefined`にご用心
|
### `undefined`にご用心
|
||||||
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
||||||
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
||||||
|
|
|
@ -203,6 +203,12 @@ export default defineComponent({
|
||||||
|
|
||||||
&.thin {
|
&.thin {
|
||||||
--height: 50px;
|
--height: 50px;
|
||||||
|
|
||||||
|
> .buttons {
|
||||||
|
> .button {
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.slim {
|
&.slim {
|
||||||
|
|
|
@ -185,7 +185,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (style == null) {
|
if (style == null) {
|
||||||
return h('span', {}, ['[', token.props.name, ' ', ...genEl(token.children), ']']);
|
return h('span', {}, ['$[', token.props.name, ' ', ...genEl(token.children), ']']);
|
||||||
} else {
|
} else {
|
||||||
return h('span', {
|
return h('span', {
|
||||||
style: 'display: inline-block;' + style,
|
style: 'display: inline-block;' + style,
|
||||||
|
|
|
@ -16,11 +16,13 @@
|
||||||
</FormSection>
|
</FormSection>
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ $ts._exportOrImport.muteList }}</template>
|
<template #label>{{ $ts._exportOrImport.muteList }}</template>
|
||||||
<MkButton :class="$style.button" inline @click="doExport('mute')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
|
<MkButton :class="$style.button" inline @click="doExport('muting')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
|
||||||
|
<MkButton :class="$style.button" inline @click="doImport('muting', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
<FormSection>
|
<FormSection>
|
||||||
<template #label>{{ $ts._exportOrImport.blockingList }}</template>
|
<template #label>{{ $ts._exportOrImport.blockingList }}</template>
|
||||||
<MkButton :class="$style.button" inline @click="doExport('blocking')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
|
<MkButton :class="$style.button" inline @click="doExport('blocking')"><i class="fas fa-download"></i> {{ $ts.export }}</MkButton>
|
||||||
|
<MkButton :class="$style.button" inline @click="doImport('blocking', $event)"><i class="fas fa-upload"></i> {{ $ts.import }}</MkButton>
|
||||||
</FormSection>
|
</FormSection>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -58,11 +60,11 @@ export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
doExport(target) {
|
doExport(target) {
|
||||||
os.api(
|
os.api(
|
||||||
target == 'notes' ? 'i/export-notes' :
|
target === 'notes' ? 'i/export-notes' :
|
||||||
target == 'following' ? 'i/export-following' :
|
target === 'following' ? 'i/export-following' :
|
||||||
target == 'blocking' ? 'i/export-blocking' :
|
target === 'blocking' ? 'i/export-blocking' :
|
||||||
target == 'user-lists' ? 'i/export-user-lists' :
|
target === 'user-lists' ? 'i/export-user-lists' :
|
||||||
target == 'mute' ? 'i/export-mute' :
|
target === 'muting' ? 'i/export-mute' :
|
||||||
null, {})
|
null, {})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
os.dialog({
|
os.dialog({
|
||||||
|
@ -81,8 +83,10 @@ export default defineComponent({
|
||||||
const file = await selectFile(e.currentTarget || e.target);
|
const file = await selectFile(e.currentTarget || e.target);
|
||||||
|
|
||||||
os.api(
|
os.api(
|
||||||
target == 'following' ? 'i/import-following' :
|
target === 'following' ? 'i/import-following' :
|
||||||
target == 'user-lists' ? 'i/import-user-lists' :
|
target === 'user-lists' ? 'i/import-user-lists' :
|
||||||
|
target === 'muting' ? 'i/import-muting' :
|
||||||
|
target === 'blocking' ? 'i/import-blocking' :
|
||||||
null, {
|
null, {
|
||||||
fileId: file.id
|
fileId: file.id
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
|
@ -163,6 +163,26 @@ export function createImportFollowingJob(user: ThinUser, fileId: DriveFile['id']
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createImportMutingJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||||
|
return dbQueue.add('importMuting', {
|
||||||
|
user: user,
|
||||||
|
fileId: fileId
|
||||||
|
}, {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createImportBlockingJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||||
|
return dbQueue.add('importBlocking', {
|
||||||
|
user: user,
|
||||||
|
fileId: fileId
|
||||||
|
}, {
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function createImportUserListsJob(user: ThinUser, fileId: DriveFile['id']) {
|
export function createImportUserListsJob(user: ThinUser, fileId: DriveFile['id']) {
|
||||||
return dbQueue.add('importUserLists', {
|
return dbQueue.add('importUserLists', {
|
||||||
user: user,
|
user: user,
|
||||||
|
|
74
src/queue/processors/db/import-blocking.ts
Normal file
74
src/queue/processors/db/import-blocking.ts
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
import * as Bull from 'bull';
|
||||||
|
|
||||||
|
import { queueLogger } from '../../logger';
|
||||||
|
import { parseAcct } from '@/misc/acct';
|
||||||
|
import { resolveUser } from '@/remote/resolve-user';
|
||||||
|
import { downloadTextFile } from '@/misc/download-text-file';
|
||||||
|
import { isSelfHost, toPuny } from '@/misc/convert-host';
|
||||||
|
import { Users, DriveFiles, Blockings } from '@/models/index';
|
||||||
|
import { DbUserImportJobData } from '@/queue/types';
|
||||||
|
import block from '@/services/blocking/create';
|
||||||
|
|
||||||
|
const logger = queueLogger.createSubLogger('import-blocking');
|
||||||
|
|
||||||
|
export async function importBlocking(job: Bull.Job<DbUserImportJobData>, done: any): Promise<void> {
|
||||||
|
logger.info(`Importing blocking of ${job.data.user.id} ...`);
|
||||||
|
|
||||||
|
const user = await Users.findOne(job.data.user.id);
|
||||||
|
if (user == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await DriveFiles.findOne({
|
||||||
|
id: job.data.fileId
|
||||||
|
});
|
||||||
|
if (file == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = await downloadTextFile(file.url);
|
||||||
|
|
||||||
|
let linenum = 0;
|
||||||
|
|
||||||
|
for (const line of csv.trim().split('\n')) {
|
||||||
|
linenum++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const acct = line.split(',')[0].trim();
|
||||||
|
const { username, host } = parseAcct(acct);
|
||||||
|
|
||||||
|
let target = isSelfHost(host!) ? await Users.findOne({
|
||||||
|
host: null,
|
||||||
|
usernameLower: username.toLowerCase()
|
||||||
|
}) : await Users.findOne({
|
||||||
|
host: toPuny(host!),
|
||||||
|
usernameLower: username.toLowerCase()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (host == null && target == null) continue;
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
target = await resolveUser(username, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
throw `cannot resolve user: @${username}@${host}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip myself
|
||||||
|
if (target.id === job.data.user.id) continue;
|
||||||
|
|
||||||
|
logger.info(`Block[${linenum}] ${target.id} ...`);
|
||||||
|
|
||||||
|
await block(user, target);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`Error in line:${linenum} ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.succ('Imported');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
83
src/queue/processors/db/import-muting.ts
Normal file
83
src/queue/processors/db/import-muting.ts
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
import * as Bull from 'bull';
|
||||||
|
|
||||||
|
import { queueLogger } from '../../logger';
|
||||||
|
import { parseAcct } from '@/misc/acct';
|
||||||
|
import { resolveUser } from '@/remote/resolve-user';
|
||||||
|
import { downloadTextFile } from '@/misc/download-text-file';
|
||||||
|
import { isSelfHost, toPuny } from '@/misc/convert-host';
|
||||||
|
import { Users, DriveFiles, Mutings } from '@/models/index';
|
||||||
|
import { DbUserImportJobData } from '@/queue/types';
|
||||||
|
import { User } from '@/models/entities/user';
|
||||||
|
import { genId } from '@/misc/gen-id';
|
||||||
|
|
||||||
|
const logger = queueLogger.createSubLogger('import-muting');
|
||||||
|
|
||||||
|
export async function importMuting(job: Bull.Job<DbUserImportJobData>, done: any): Promise<void> {
|
||||||
|
logger.info(`Importing muting of ${job.data.user.id} ...`);
|
||||||
|
|
||||||
|
const user = await Users.findOne(job.data.user.id);
|
||||||
|
if (user == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await DriveFiles.findOne({
|
||||||
|
id: job.data.fileId
|
||||||
|
});
|
||||||
|
if (file == null) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const csv = await downloadTextFile(file.url);
|
||||||
|
|
||||||
|
let linenum = 0;
|
||||||
|
|
||||||
|
for (const line of csv.trim().split('\n')) {
|
||||||
|
linenum++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const acct = line.split(',')[0].trim();
|
||||||
|
const { username, host } = parseAcct(acct);
|
||||||
|
|
||||||
|
let target = isSelfHost(host!) ? await Users.findOne({
|
||||||
|
host: null,
|
||||||
|
usernameLower: username.toLowerCase()
|
||||||
|
}) : await Users.findOne({
|
||||||
|
host: toPuny(host!),
|
||||||
|
usernameLower: username.toLowerCase()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (host == null && target == null) continue;
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
target = await resolveUser(username, host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
throw `cannot resolve user: @${username}@${host}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip myself
|
||||||
|
if (target.id === job.data.user.id) continue;
|
||||||
|
|
||||||
|
logger.info(`Mute[${linenum}] ${target.id} ...`);
|
||||||
|
|
||||||
|
await mute(user, target);
|
||||||
|
} catch (e) {
|
||||||
|
logger.warn(`Error in line:${linenum} ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.succ('Imported');
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function mute(user: User, target: User) {
|
||||||
|
await Mutings.insert({
|
||||||
|
id: genId(),
|
||||||
|
createdAt: new Date(),
|
||||||
|
muterId: user.id,
|
||||||
|
muteeId: target.id,
|
||||||
|
});
|
||||||
|
}
|
|
@ -9,6 +9,8 @@ import { exportUserLists } from './export-user-lists';
|
||||||
import { importFollowing } from './import-following';
|
import { importFollowing } from './import-following';
|
||||||
import { importUserLists } from './import-user-lists';
|
import { importUserLists } from './import-user-lists';
|
||||||
import { deleteAccount } from './delete-account';
|
import { deleteAccount } from './delete-account';
|
||||||
|
import { importMuting } from './import-muting';
|
||||||
|
import { importBlocking } from './import-blocking';
|
||||||
|
|
||||||
const jobs = {
|
const jobs = {
|
||||||
deleteDriveFiles,
|
deleteDriveFiles,
|
||||||
|
@ -18,6 +20,8 @@ const jobs = {
|
||||||
exportBlocking,
|
exportBlocking,
|
||||||
exportUserLists,
|
exportUserLists,
|
||||||
importFollowing,
|
importFollowing,
|
||||||
|
importMuting,
|
||||||
|
importBlocking,
|
||||||
importUserLists,
|
importUserLists,
|
||||||
deleteAccount,
|
deleteAccount,
|
||||||
} as Record<string, Bull.ProcessCallbackFunction<DbJobData> | Bull.ProcessPromiseFunction<DbJobData>>;
|
} as Record<string, Bull.ProcessCallbackFunction<DbJobData> | Bull.ProcessPromiseFunction<DbJobData>>;
|
||||||
|
|
|
@ -12,6 +12,10 @@ export default async (actor: IRemoteUser, activity: ILike) => {
|
||||||
const note = await fetchNote(targetUri);
|
const note = await fetchNote(targetUri);
|
||||||
if (!note) return `skip: target note not found ${targetUri}`;
|
if (!note) return `skip: target note not found ${targetUri}`;
|
||||||
|
|
||||||
await deleteReaction(actor, note);
|
await deleteReaction(actor, note).catch(e => {
|
||||||
|
if (e.id === '60527ec9-b4cb-4a88-a6bd-32d3ad26817d') return;
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
|
||||||
return `ok`;
|
return `ok`;
|
||||||
};
|
};
|
||||||
|
|
60
src/server/api/endpoints/i/import-blocking.ts
Normal file
60
src/server/api/endpoints/i/import-blocking.ts
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import $ from 'cafy';
|
||||||
|
import { ID } from '@/misc/cafy-id';
|
||||||
|
import define from '../../define';
|
||||||
|
import { createImportBlockingJob } from '@/queue/index';
|
||||||
|
import * as ms from 'ms';
|
||||||
|
import { ApiError } from '../../error';
|
||||||
|
import { DriveFiles } from '@/models/index';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
secure: true,
|
||||||
|
requireCredential: true as const,
|
||||||
|
|
||||||
|
limit: {
|
||||||
|
duration: ms('1hour'),
|
||||||
|
max: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
params: {
|
||||||
|
fileId: {
|
||||||
|
validator: $.type(ID),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchFile: {
|
||||||
|
message: 'No such file.',
|
||||||
|
code: 'NO_SUCH_FILE',
|
||||||
|
id: 'ebb53e5f-6574-9c0c-0b92-7ca6def56d7e'
|
||||||
|
},
|
||||||
|
|
||||||
|
unexpectedFileType: {
|
||||||
|
message: 'We need csv file.',
|
||||||
|
code: 'UNEXPECTED_FILE_TYPE',
|
||||||
|
id: 'b6fab7d6-d945-d67c-dfdb-32da1cd12cfe'
|
||||||
|
},
|
||||||
|
|
||||||
|
tooBigFile: {
|
||||||
|
message: 'That file is too big.',
|
||||||
|
code: 'TOO_BIG_FILE',
|
||||||
|
id: 'b7fbf0b1-aeef-3b21-29ef-fadd4cb72ccf'
|
||||||
|
},
|
||||||
|
|
||||||
|
emptyFile: {
|
||||||
|
message: 'That file is empty.',
|
||||||
|
code: 'EMPTY_FILE',
|
||||||
|
id: '6f3a4dcc-f060-a707-4950-806fbdbe60d6'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, async (ps, user) => {
|
||||||
|
const file = await DriveFiles.findOne(ps.fileId);
|
||||||
|
|
||||||
|
if (file == null) throw new ApiError(meta.errors.noSuchFile);
|
||||||
|
//if (!file.type.endsWith('/csv')) throw new ApiError(meta.errors.unexpectedFileType);
|
||||||
|
if (file.size > 50000) throw new ApiError(meta.errors.tooBigFile);
|
||||||
|
if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
|
||||||
|
|
||||||
|
createImportBlockingJob(user, file.id);
|
||||||
|
});
|
60
src/server/api/endpoints/i/import-muting.ts
Normal file
60
src/server/api/endpoints/i/import-muting.ts
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
import $ from 'cafy';
|
||||||
|
import { ID } from '@/misc/cafy-id';
|
||||||
|
import define from '../../define';
|
||||||
|
import { createImportMutingJob } from '@/queue/index';
|
||||||
|
import * as ms from 'ms';
|
||||||
|
import { ApiError } from '../../error';
|
||||||
|
import { DriveFiles } from '@/models/index';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
secure: true,
|
||||||
|
requireCredential: true as const,
|
||||||
|
|
||||||
|
limit: {
|
||||||
|
duration: ms('1hour'),
|
||||||
|
max: 1,
|
||||||
|
},
|
||||||
|
|
||||||
|
params: {
|
||||||
|
fileId: {
|
||||||
|
validator: $.type(ID),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchFile: {
|
||||||
|
message: 'No such file.',
|
||||||
|
code: 'NO_SUCH_FILE',
|
||||||
|
id: 'e674141e-bd2a-ba85-e616-aefb187c9c2a'
|
||||||
|
},
|
||||||
|
|
||||||
|
unexpectedFileType: {
|
||||||
|
message: 'We need csv file.',
|
||||||
|
code: 'UNEXPECTED_FILE_TYPE',
|
||||||
|
id: '568c6e42-c86c-ba09-c004-517f83f9f1a8'
|
||||||
|
},
|
||||||
|
|
||||||
|
tooBigFile: {
|
||||||
|
message: 'That file is too big.',
|
||||||
|
code: 'TOO_BIG_FILE',
|
||||||
|
id: '9b4ada6d-d7f7-0472-0713-4f558bd1ec9c'
|
||||||
|
},
|
||||||
|
|
||||||
|
emptyFile: {
|
||||||
|
message: 'That file is empty.',
|
||||||
|
code: 'EMPTY_FILE',
|
||||||
|
id: 'd2f12af1-e7b4-feac-86a3-519548f2728e'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default define(meta, async (ps, user) => {
|
||||||
|
const file = await DriveFiles.findOne(ps.fileId);
|
||||||
|
|
||||||
|
if (file == null) throw new ApiError(meta.errors.noSuchFile);
|
||||||
|
//if (!file.type.endsWith('/csv')) throw new ApiError(meta.errors.unexpectedFileType);
|
||||||
|
if (file.size > 50000) throw new ApiError(meta.errors.tooBigFile);
|
||||||
|
if (file.size === 0) throw new ApiError(meta.errors.emptyFile);
|
||||||
|
|
||||||
|
createImportMutingJob(user, file.id);
|
||||||
|
});
|
|
@ -6,6 +6,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||||
import { Notifications, Followings, Mutings, Users } from '@/models/index';
|
import { Notifications, Followings, Mutings, Users } from '@/models/index';
|
||||||
import { notificationTypes } from '@/types';
|
import { notificationTypes } from '@/types';
|
||||||
import read from '@/services/note/read';
|
import read from '@/services/note/read';
|
||||||
|
import { Brackets } from 'typeorm';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['account', 'notifications'],
|
tags: ['account', 'notifications'],
|
||||||
|
@ -94,10 +95,16 @@ export default define(meta, async (ps, user) => {
|
||||||
.leftJoinAndSelect('reply.user', 'replyUser')
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
||||||
.leftJoinAndSelect('renote.user', 'renoteUser');
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
||||||
|
|
||||||
query.andWhere(`notification.notifierId NOT IN (${ mutingQuery.getQuery() })`);
|
query.andWhere(new Brackets(qb => { qb
|
||||||
|
.where(`notification.notifierId NOT IN (${ mutingQuery.getQuery() })`)
|
||||||
|
.orWhere('notification.notifierId IS NULL');
|
||||||
|
}));
|
||||||
query.setParameters(mutingQuery.getParameters());
|
query.setParameters(mutingQuery.getParameters());
|
||||||
|
|
||||||
query.andWhere(`notification.notifierId NOT IN (${ suspendedQuery.getQuery() })`);
|
query.andWhere(new Brackets(qb => { qb
|
||||||
|
.where(`notification.notifierId NOT IN (${ suspendedQuery.getQuery() })`)
|
||||||
|
.orWhere('notification.notifierId IS NULL');
|
||||||
|
}));
|
||||||
|
|
||||||
if (ps.following) {
|
if (ps.following) {
|
||||||
query.andWhere(`((notification.notifierId IN (${ followingQuery.getQuery() })) OR (notification.notifierId = :meId))`, { meId: user.id });
|
query.andWhere(`((notification.notifierId IN (${ followingQuery.getQuery() })) OR (notification.notifierId = :meId))`, { meId: user.id });
|
||||||
|
|
|
@ -67,7 +67,7 @@ export default define(meta, async (ps, user) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create mute
|
// Create mute
|
||||||
await Mutings.save({
|
await Mutings.insert({
|
||||||
id: genId(),
|
id: genId(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
muterId: muter.id,
|
muterId: muter.id,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import { Users } from '@/models/index';
|
import { Followings, Users } from '@/models/index';
|
||||||
import { Brackets } from 'typeorm';
|
import { Brackets } from 'typeorm';
|
||||||
import { USER_ACTIVE_THRESHOLD } from '@/const';
|
import { USER_ACTIVE_THRESHOLD } from '@/const';
|
||||||
|
import { User } from '@/models/entities/user';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['users'],
|
tags: ['users'],
|
||||||
|
@ -18,11 +19,6 @@ export const meta = {
|
||||||
validator: $.optional.nullable.str,
|
validator: $.optional.nullable.str,
|
||||||
},
|
},
|
||||||
|
|
||||||
offset: {
|
|
||||||
validator: $.optional.num.min(0),
|
|
||||||
default: 0,
|
|
||||||
},
|
|
||||||
|
|
||||||
limit: {
|
limit: {
|
||||||
validator: $.optional.num.range(1, 100),
|
validator: $.optional.num.range(1, 100),
|
||||||
default: 10,
|
default: 10,
|
||||||
|
@ -60,34 +56,59 @@ export default define(meta, async (ps, me) => {
|
||||||
q.andWhere('user.updatedAt IS NOT NULL');
|
q.andWhere('user.updatedAt IS NOT NULL');
|
||||||
q.orderBy('user.updatedAt', 'DESC');
|
q.orderBy('user.updatedAt', 'DESC');
|
||||||
|
|
||||||
const users = await q.take(ps.limit!).skip(ps.offset).getMany();
|
const users = await q.take(ps.limit!).getMany();
|
||||||
|
|
||||||
return await Users.packMany(users, me, { detail: ps.detail });
|
return await Users.packMany(users, me, { detail: ps.detail });
|
||||||
} else if (ps.username) {
|
} else if (ps.username) {
|
||||||
let users = await Users.createQueryBuilder('user')
|
let users: User[] = [];
|
||||||
.where('user.host IS NULL')
|
|
||||||
.andWhere('user.isSuspended = FALSE')
|
|
||||||
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
|
||||||
.andWhere(new Brackets(qb => { qb
|
|
||||||
.where('user.updatedAt IS NULL')
|
|
||||||
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
|
|
||||||
}))
|
|
||||||
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
|
|
||||||
.take(ps.limit!)
|
|
||||||
.skip(ps.offset)
|
|
||||||
.getMany();
|
|
||||||
|
|
||||||
if (users.length < ps.limit!) {
|
if (me) {
|
||||||
const otherUsers = await Users.createQueryBuilder('user')
|
const followingQuery = Followings.createQueryBuilder('following')
|
||||||
.where('user.host IS NOT NULL')
|
.select('following.followeeId')
|
||||||
|
.where('following.followerId = :followerId', { followerId: me.id });
|
||||||
|
|
||||||
|
const query = Users.createQueryBuilder('user')
|
||||||
|
.where(`user.id IN (${ followingQuery.getQuery() })`)
|
||||||
|
.andWhere(`user.id != :meId`, { meId: me.id })
|
||||||
.andWhere('user.isSuspended = FALSE')
|
.andWhere('user.isSuspended = FALSE')
|
||||||
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
||||||
|
.andWhere(new Brackets(qb => { qb
|
||||||
|
.where('user.updatedAt IS NULL')
|
||||||
|
.orWhere('user.updatedAt > :activeThreshold', { activeThreshold: activeThreshold });
|
||||||
|
}));
|
||||||
|
|
||||||
|
query.setParameters(followingQuery.getParameters());
|
||||||
|
|
||||||
|
users = await query
|
||||||
|
.orderBy('user.usernameLower', 'ASC')
|
||||||
|
.take(ps.limit!)
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
if (users.length < ps.limit!) {
|
||||||
|
const otherQuery = await Users.createQueryBuilder('user')
|
||||||
|
.where(`user.id NOT IN (${ followingQuery.getQuery() })`)
|
||||||
|
.andWhere(`user.id != :meId`, { meId: me.id })
|
||||||
|
.andWhere('user.isSuspended = FALSE')
|
||||||
|
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
||||||
|
.andWhere('user.updatedAt IS NOT NULL');
|
||||||
|
|
||||||
|
otherQuery.setParameters(followingQuery.getParameters());
|
||||||
|
|
||||||
|
const otherUsers = await otherQuery
|
||||||
|
.orderBy('user.updatedAt', 'DESC')
|
||||||
|
.take(ps.limit! - users.length)
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
users = users.concat(otherUsers);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
users = await Users.createQueryBuilder('user')
|
||||||
|
.where('user.isSuspended = FALSE')
|
||||||
|
.andWhere('user.usernameLower LIKE :username', { username: ps.username.toLowerCase() + '%' })
|
||||||
.andWhere('user.updatedAt IS NOT NULL')
|
.andWhere('user.updatedAt IS NOT NULL')
|
||||||
.orderBy('user.updatedAt', 'DESC')
|
.orderBy('user.updatedAt', 'DESC')
|
||||||
.take(ps.limit! - users.length)
|
.take(ps.limit! - users.length)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
users = users.concat(otherUsers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await Users.packMany(users, me, { detail: ps.detail });
|
return await Users.packMany(users, me, { detail: ps.detail });
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default class extends Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private async onEvent(data: StreamMessages['antenna']['spec']) {
|
private async onEvent(data: StreamMessages['antenna']['payload']) {
|
||||||
if (data.type === 'note') {
|
if (data.type === 'note') {
|
||||||
const note = await Notes.pack(data.body.id, this.user, { detail: true });
|
const note = await Notes.pack(data.body.id, this.user, { detail: true });
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ export default class extends Channel {
|
||||||
this.connection.cacheNote(note);
|
this.connection.cacheNote(note);
|
||||||
|
|
||||||
this.send('note', note);
|
this.send('note', note);
|
||||||
|
} else {
|
||||||
|
this.send(data.type, data.body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default class extends Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private onEvent(data: StreamMessages['channel']['spec']) {
|
private onEvent(data: StreamMessages['channel']['payload']) {
|
||||||
if (data.type === 'typing') {
|
if (data.type === 'typing') {
|
||||||
const id = data.body;
|
const id = data.body;
|
||||||
const begin = this.typers[id] == null;
|
const begin = this.typers[id] == null;
|
||||||
|
|
|
@ -47,7 +47,7 @@ export default class extends Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private onEvent(data: StreamMessages['messaging']['spec'] | StreamMessages['groupMessaging']['spec']) {
|
private onEvent(data: StreamMessages['messaging']['payload'] | StreamMessages['groupMessaging']['payload']) {
|
||||||
if (data.type === 'typing') {
|
if (data.type === 'typing') {
|
||||||
const id = data.body;
|
const id = data.body;
|
||||||
const begin = this.typers[id] == null;
|
const begin = this.typers[id] == null;
|
||||||
|
|
|
@ -63,7 +63,7 @@ export default class Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private onUserEvent(data: StreamMessages['user']['spec']) { // { type, body }と展開すると型も展開されてしまう
|
private onUserEvent(data: StreamMessages['user']['payload']) { // { type, body }と展開するとそれぞれ型が分離してしまう
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case 'follow':
|
case 'follow':
|
||||||
this.following.add(data.body.id);
|
this.following.add(data.body.id);
|
||||||
|
@ -144,7 +144,7 @@ export default class Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private onBroadcastMessage(data: StreamMessages['broadcast']['spec']) {
|
private onBroadcastMessage(data: StreamMessages['broadcast']['payload']) {
|
||||||
this.sendMessageToWs(data.type, data.body);
|
this.sendMessageToWs(data.type, data.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ export default class Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private async onNoteStreamMessage(data: StreamMessages['note']['spec']) {
|
private async onNoteStreamMessage(data: StreamMessages['note']['payload']) {
|
||||||
this.sendMessageToWs('noteUpdated', {
|
this.sendMessageToWs('noteUpdated', {
|
||||||
id: data.body.id,
|
id: data.body.id,
|
||||||
type: data.type,
|
type: data.type,
|
||||||
|
|
|
@ -222,73 +222,73 @@ type EventUnionFromDictionary<
|
||||||
export type StreamMessages = {
|
export type StreamMessages = {
|
||||||
internal: {
|
internal: {
|
||||||
name: 'internal';
|
name: 'internal';
|
||||||
spec: EventUnionFromDictionary<InternalStreamTypes>;
|
payload: EventUnionFromDictionary<InternalStreamTypes>;
|
||||||
};
|
};
|
||||||
broadcast: {
|
broadcast: {
|
||||||
name: 'broadcast';
|
name: 'broadcast';
|
||||||
spec: EventUnionFromDictionary<BroadcastTypes>;
|
payload: EventUnionFromDictionary<BroadcastTypes>;
|
||||||
};
|
};
|
||||||
user: {
|
user: {
|
||||||
name: `user:${User['id']}`;
|
name: `user:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<UserStreamTypes>;
|
payload: EventUnionFromDictionary<UserStreamTypes>;
|
||||||
};
|
};
|
||||||
main: {
|
main: {
|
||||||
name: `mainStream:${User['id']}`;
|
name: `mainStream:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<MainStreamTypes>;
|
payload: EventUnionFromDictionary<MainStreamTypes>;
|
||||||
};
|
};
|
||||||
drive: {
|
drive: {
|
||||||
name: `driveStream:${User['id']}`;
|
name: `driveStream:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<DriveStreamTypes>;
|
payload: EventUnionFromDictionary<DriveStreamTypes>;
|
||||||
};
|
};
|
||||||
note: {
|
note: {
|
||||||
name: `noteStream:${Note['id']}`;
|
name: `noteStream:${Note['id']}`;
|
||||||
spec: EventUnionFromDictionary<NoteStreamEventTypes>;
|
payload: EventUnionFromDictionary<NoteStreamEventTypes>;
|
||||||
};
|
};
|
||||||
channel: {
|
channel: {
|
||||||
name: `channelStream:${Channel['id']}`;
|
name: `channelStream:${Channel['id']}`;
|
||||||
spec: EventUnionFromDictionary<ChannelStreamTypes>;
|
payload: EventUnionFromDictionary<ChannelStreamTypes>;
|
||||||
};
|
};
|
||||||
userList: {
|
userList: {
|
||||||
name: `userListStream:${UserList['id']}`;
|
name: `userListStream:${UserList['id']}`;
|
||||||
spec: EventUnionFromDictionary<UserListStreamTypes>;
|
payload: EventUnionFromDictionary<UserListStreamTypes>;
|
||||||
};
|
};
|
||||||
antenna: {
|
antenna: {
|
||||||
name: `antennaStream:${Antenna['id']}`;
|
name: `antennaStream:${Antenna['id']}`;
|
||||||
spec: EventUnionFromDictionary<AntennaStreamTypes>;
|
payload: EventUnionFromDictionary<AntennaStreamTypes>;
|
||||||
};
|
};
|
||||||
messaging: {
|
messaging: {
|
||||||
name: `messagingStream:${User['id']}-${User['id']}`;
|
name: `messagingStream:${User['id']}-${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<MessagingStreamTypes>;
|
payload: EventUnionFromDictionary<MessagingStreamTypes>;
|
||||||
};
|
};
|
||||||
groupMessaging: {
|
groupMessaging: {
|
||||||
name: `messagingStream:${UserGroup['id']}`;
|
name: `messagingStream:${UserGroup['id']}`;
|
||||||
spec: EventUnionFromDictionary<GroupMessagingStreamTypes>;
|
payload: EventUnionFromDictionary<GroupMessagingStreamTypes>;
|
||||||
};
|
};
|
||||||
messagingIndex: {
|
messagingIndex: {
|
||||||
name: `messagingIndexStream:${User['id']}`;
|
name: `messagingIndexStream:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<MessagingIndexStreamTypes>;
|
payload: EventUnionFromDictionary<MessagingIndexStreamTypes>;
|
||||||
};
|
};
|
||||||
reversi: {
|
reversi: {
|
||||||
name: `reversiStream:${User['id']}`;
|
name: `reversiStream:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<ReversiStreamTypes>;
|
payload: EventUnionFromDictionary<ReversiStreamTypes>;
|
||||||
};
|
};
|
||||||
reversiGame: {
|
reversiGame: {
|
||||||
name: `reversiGameStream:${ReversiGame['id']}`;
|
name: `reversiGameStream:${ReversiGame['id']}`;
|
||||||
spec: EventUnionFromDictionary<ReversiGameStreamTypes>;
|
payload: EventUnionFromDictionary<ReversiGameStreamTypes>;
|
||||||
};
|
};
|
||||||
admin: {
|
admin: {
|
||||||
name: `adminStream:${User['id']}`;
|
name: `adminStream:${User['id']}`;
|
||||||
spec: EventUnionFromDictionary<AdminStreamTypes>;
|
payload: EventUnionFromDictionary<AdminStreamTypes>;
|
||||||
};
|
};
|
||||||
notes: {
|
notes: {
|
||||||
name: 'notesStream';
|
name: 'notesStream';
|
||||||
spec: Packed<'Note'>;
|
payload: Packed<'Note'>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// API event definitions
|
// API event definitions
|
||||||
// ストリームごとのEmitterの辞書を用意
|
// ストリームごとのEmitterの辞書を用意
|
||||||
type EventEmitterDictionary = { [x in keyof StreamMessages]: Emitter<EventEmitter, { [y in StreamMessages[x]['name']]: (e: StreamMessages[x]['spec']) => void }> };
|
type EventEmitterDictionary = { [x in keyof StreamMessages]: Emitter<EventEmitter, { [y in StreamMessages[x]['name']]: (e: StreamMessages[x]['payload']) => void }> };
|
||||||
// 共用体型を交差型にする型 https://stackoverflow.com/questions/54938141/typescript-convert-union-to-intersection
|
// 共用体型を交差型にする型 https://stackoverflow.com/questions/54938141/typescript-convert-union-to-intersection
|
||||||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
||||||
// Emitter辞書から共用体型を作り、UnionToIntersectionで交差型にする
|
// Emitter辞書から共用体型を作り、UnionToIntersectionで交差型にする
|
||||||
|
|
Loading…
Reference in a new issue