* wip

* wip

* wip

* wip

* wip

* Update define.ts

* Update update.ts

* Update user.ts

* wip

* wip

* Update request.ts

* URL

* wip

* wip

* wip

* wip

* Update invite.ts

* Update create.ts
This commit is contained in:
syuilo
2021-03-24 11:05:37 +09:00
committed by GitHub
parent 62cc14c93b
commit ce340aba7a
109 changed files with 252 additions and 201 deletions

View File

@ -6,7 +6,7 @@ import { isMutedUserRelated } from '@/misc/is-muted-user-related';
import { publishAntennaStream, publishMainStream } from './stream';
import { User } from '../models/entities/user';
export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: User) {
export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { id: User['id']; }) {
// 通知しない設定になっているか、自分自身の投稿なら既読にする
const read = !antenna.notify || (antenna.userId === noteUser.id);

View File

@ -35,7 +35,7 @@ export default class ActiveUsersChart extends Chart<ActiveUsersLog> {
}
@autobind
public async update(user: User) {
public async update(user: { id: User['id'], host: User['host'] }) {
const update: Obj = {
users: [user.id]
};

View File

@ -35,7 +35,7 @@ export default class HashtagChart extends Chart<HashtagLog> {
}
@autobind
public async update(hashtag: string, user: User) {
public async update(hashtag: string, user: { id: User['id'], host: User['host'] }) {
const update: Obj = {
users: [user.id]
};

View File

@ -100,7 +100,7 @@ export default class PerUserFollowingChart extends Chart<PerUserFollowingLog> {
}
@autobind
public async update(follower: User, followee: User, isFollow: boolean) {
public async update(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }, isFollow: boolean) {
const update: Obj = {};
update.total = isFollow ? 1 : -1;

View File

@ -46,7 +46,7 @@ export default class PerUserNotesChart extends Chart<PerUserNotesLog> {
}
@autobind
public async update(user: User, note: Note, isAdditional: boolean) {
public async update(user: { id: User['id'] }, note: Note, isAdditional: boolean) {
const update: Obj = {
diffs: {}
};

View File

@ -36,7 +36,7 @@ export default class PerUserReactionsChart extends Chart<PerUserReactionsLog> {
}
@autobind
public async update(user: User, note: Note) {
public async update(user: { id: User['id'], host: User['host'] }, note: Note) {
this.inc({
[Users.isLocalUser(user) ? 'local' : 'remote']: { count: 1 }
}, note.userId);

View File

@ -59,7 +59,7 @@ export default class UsersChart extends Chart<UsersLog> {
}
@autobind
public async update(user: User, isAdditional: boolean) {
public async update(user: { id: User['id'], host: User['host'] }, isAdditional: boolean) {
const update: Obj = {};
update.total = isAdditional ? 1 : -1;

View File

@ -302,7 +302,7 @@ async function deleteOldFile(user: IRemoteUser) {
* @return Created drive file
*/
export default async function(
user: User | null,
user: { id: User['id']; host: User['host'] } | null,
path: string,
name: string | null = null,
comment: string | null = null,
@ -347,7 +347,7 @@ export default async function(
throw new Error('no-free-space');
} else {
// (アバターまたはバナーを含まず)最も古いファイルを削除する
deleteOldFile(user as IRemoteUser);
deleteOldFile(await Users.findOneOrFail(user.id) as IRemoteUser);
}
}
}

View File

@ -1,3 +1,4 @@
import { URL } from 'url';
import * as S3 from 'aws-sdk/clients/s3';
import { Meta } from '../../models/entities/meta';
import { getAgentByUrl } from '@/misc/fetch';

View File

@ -1,3 +1,4 @@
import { URL } from 'url';
import create from './add-file';
import { User } from '../../models/entities/user';
import { driveLogger } from './logger';
@ -11,7 +12,7 @@ const logger = driveLogger.createSubLogger('downloader');
export default async (
url: string,
user: User | null,
user: { id: User['id']; host: User['host'] } | null,
folderId: DriveFolder['id'] | null = null,
uri: string | null = null,
sensitive = false,

View File

@ -17,7 +17,7 @@ import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error';
const logger = new Logger('following/create');
export async function insertFollowingDoc(followee: User, follower: User) {
export async function insertFollowingDoc(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'] }, follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox'] }) {
if (follower.id === followee.id) return;
let alreadyFollowed = false;
@ -86,7 +86,7 @@ export async function insertFollowingDoc(followee: User, follower: User) {
// Publish follow event
if (Users.isLocalUser(follower)) {
Users.pack(followee, follower, {
Users.pack(followee.id, follower, {
detail: true
}).then(packed => {
publishUserEvent(follower.id, 'follow', packed);
@ -96,7 +96,7 @@ export async function insertFollowingDoc(followee: User, follower: User) {
// Publish followed event
if (Users.isLocalUser(followee)) {
Users.pack(follower, followee).then(packed => publishMainStream(followee.id, 'followed', packed));
Users.pack(follower.id, followee).then(packed => publishMainStream(followee.id, 'followed', packed));
// 通知を作成
createNotification(followee.id, 'follow', {
@ -105,7 +105,12 @@ export async function insertFollowingDoc(followee: User, follower: User) {
}
}
export default async function(follower: User, followee: User, requestId?: string) {
export default async function(_follower: { id: User['id'] }, _followee: { id: User['id'] }, requestId?: string) {
const [follower, followee] = await Promise.all([
Users.findOneOrFail(_follower.id),
Users.findOneOrFail(_followee.id)
]);
// check blocking
const [blocking, blocked] = await Promise.all([
Blockings.findOne({

View File

@ -11,7 +11,7 @@ import { instanceChart, perUserFollowingChart } from '../chart';
const logger = new Logger('following/delete');
export default async function(follower: User, followee: User, silent = false) {
export default async function(follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, silent = false) {
const following = await Followings.findOne({
followerId: follower.id,
followeeId: followee.id
@ -28,7 +28,7 @@ export default async function(follower: User, followee: User, silent = false) {
// Publish unfollow event
if (!silent && Users.isLocalUser(follower)) {
Users.pack(followee, follower, {
Users.pack(followee.id, follower, {
detail: true
}).then(packed => {
publishUserEvent(follower.id, 'unfollow', packed);
@ -42,7 +42,7 @@ export default async function(follower: User, followee: User, silent = false) {
}
}
export async function decrementFollowing(follower: User, followee: User) {
export async function decrementFollowing(follower: { id: User['id']; host: User['host']; }, followee: { id: User['id']; host: User['host']; }) {
//#region Decrement following count
Users.decrement({ id: follower.id }, 'followingCount', 1);
//#endregion

View File

@ -6,7 +6,7 @@ import { FollowRequests, Users } from '../../../models';
* 指定したユーザー宛てのフォローリクエストをすべて承認
* @param user ユーザー
*/
export default async function(user: User) {
export default async function(user: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }) {
const requests = await FollowRequests.find({
followeeId: user.id
});

View File

@ -8,7 +8,7 @@ import { User, ILocalUser } from '../../../models/entities/user';
import { FollowRequests, Users } from '../../../models';
import { IdentifiableError } from '@/misc/identifiable-error';
export default async function(followee: User, follower: User) {
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, follower: User) {
const request = await FollowRequests.findOne({
followeeId: followee.id,
followerId: follower.id
@ -20,12 +20,12 @@ export default async function(followee: User, follower: User) {
await insertFollowingDoc(followee, follower);
if (Users.isRemoteUser(follower)) {
const content = renderActivity(renderAccept(renderFollow(follower, followee, request.requestId!), followee as ILocalUser));
deliver(followee as ILocalUser, content, follower.inbox);
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
const content = renderActivity(renderAccept(renderFollow(follower, followee, request.requestId!), followee));
deliver(followee, content, follower.inbox);
}
Users.pack(followee, followee, {
Users.pack(followee.id, followee, {
detail: true
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));
}

View File

@ -7,10 +7,13 @@ import { IdentifiableError } from '@/misc/identifiable-error';
import { User, ILocalUser } from '../../../models/entities/user';
import { Users, FollowRequests } from '../../../models';
export default async function(followee: User, follower: User) {
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox'] }, follower: { id: User['id']; host: User['host']; uri: User['host'] }) {
if (Users.isRemoteUser(followee)) {
const content = renderActivity(renderUndo(renderFollow(follower, followee), follower));
deliver(follower as ILocalUser, content, followee.inbox);
if (Users.isLocalUser(follower)) { // 本来このチェックは不要だけどTSに怒られるので
deliver(follower, content, followee.inbox);
}
}
const request = await FollowRequests.findOne({
@ -27,7 +30,7 @@ export default async function(followee: User, follower: User) {
followerId: follower.id
});
Users.pack(followee, followee, {
Users.pack(followee.id, followee, {
detail: true
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));
}

View File

@ -7,7 +7,7 @@ import { Blockings, FollowRequests, Users } from '../../../models';
import { genId } from '@/misc/gen-id';
import { createNotification } from '../../create-notification';
export default async function(follower: User, followee: User, requestId?: string) {
export default async function(follower: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, followee: { id: User['id']; host: User['host']; uri: User['host']; inbox: User['inbox']; sharedInbox: User['sharedInbox']; }, requestId?: string) {
if (follower.id === followee.id) return;
// check blocking
@ -43,9 +43,9 @@ export default async function(follower: User, followee: User, requestId?: string
// Publish receiveRequest event
if (Users.isLocalUser(followee)) {
Users.pack(follower, followee).then(packed => publishMainStream(followee.id, 'receiveFollowRequest', packed));
Users.pack(follower.id, followee).then(packed => publishMainStream(followee.id, 'receiveFollowRequest', packed));
Users.pack(followee, followee, {
Users.pack(followee.id, followee, {
detail: true
}).then(packed => publishMainStream(followee.id, 'meUpdated', packed));

View File

@ -7,15 +7,15 @@ import { User, ILocalUser } from '../../../models/entities/user';
import { Users, FollowRequests, Followings } from '../../../models';
import { decrementFollowing } from '../delete';
export default async function(followee: User, follower: User) {
if (Users.isRemoteUser(follower)) {
export default async function(followee: { id: User['id']; host: User['host']; uri: User['host'] }, follower: User) {
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
const request = await FollowRequests.findOne({
followeeId: followee.id,
followerId: follower.id
});
const content = renderActivity(renderReject(renderFollow(follower, followee, request!.requestId!), followee as ILocalUser));
deliver(followee as ILocalUser, content, follower.inbox);
const content = renderActivity(renderReject(renderFollow(follower, followee, request!.requestId!), followee));
deliver(followee, content, follower.inbox);
}
const request = await FollowRequests.findOne({
@ -37,7 +37,7 @@ export default async function(followee: User, follower: User) {
}
}
Users.pack(followee, follower, {
Users.pack(followee.id, follower, {
detail: true
}).then(packed => {
publishUserEvent(follower.id, 'unfollow', packed);

View File

@ -16,7 +16,7 @@ import { deliverToRelays } from '../relay';
* @param user
* @param noteId
*/
export async function addPinned(user: User, noteId: Note['id']) {
export async function addPinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) {
// Fetch pinee
const note = await Notes.findOne({
id: noteId,
@ -55,7 +55,7 @@ export async function addPinned(user: User, noteId: Note['id']) {
* @param user
* @param noteId
*/
export async function removePinned(user: User, noteId: Note['id']) {
export async function removePinned(user: { id: User['id']; host: User['host']; }, noteId: Note['id']) {
// Fetch unpinee
const note = await Notes.findOne({
id: noteId,

View File

@ -1,8 +1,8 @@
import { ILocalUser } from '../models/entities/user';
import { ModerationLogs } from '../models';
import { genId } from '@/misc/gen-id';
import { User } from '@/models/entities/user';
export async function insertModerationLog(moderator: ILocalUser, type: string, info?: Record<string, any>) {
export async function insertModerationLog(moderator: { id: User['id'] }, type: string, info?: Record<string, any>) {
await ModerationLogs.insert({
id: genId(),
createdAt: new Date(),

View File

@ -13,7 +13,7 @@ import renderCreate from '../../remote/activitypub/renderer/create';
import { renderActivity } from '../../remote/activitypub/renderer';
import { deliver } from '../../queue';
export async function createMessage(user: User, recipientUser: User | undefined, recipientGroup: UserGroup | undefined, text: string | undefined, file: DriveFile | null, uri?: string) {
export async function createMessage(user: { id: User['id']; host: User['host']; }, recipientUser: User | undefined, recipientGroup: UserGroup | undefined, text: string | undefined, file: DriveFile | null, uri?: string) {
const message = {
id: genId(),
createdAt: new Date(),

View File

@ -38,14 +38,14 @@ import { getAntennas } from '@/misc/antenna-cache';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
class NotificationManager {
private notifier: User;
private notifier: { id: User['id']; };
private note: Note;
private queue: {
target: ILocalUser['id'];
reason: NotificationType;
}[];
constructor(notifier: User, note: Note) {
constructor(notifier: { id: User['id']; }, note: Note) {
this.notifier = notifier;
this.note = note;
this.queue = [];
@ -112,7 +112,7 @@ type Option = {
app?: App | null;
};
export default async (user: User, 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']; }, data: Option, silent = false) => new Promise<Note>(async (res, rej) => {
// チャンネル外にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
if (data.reply && data.channel && data.reply.channelId !== data.channel.id) {
@ -420,7 +420,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
// この処理が行われるのはノート作成後なので、ノートが一つしかなかったら最初の投稿だと判断できる
// TODO: とはいえノートを削除して何回も投稿すればその分だけインクリメントされる雑さもあるのでどうにかしたい
if (count === 1) {
Channels.increment({ id: data.channel.id }, 'usersCount', 1);
Channels.increment({ id: data.channel!.id }, 'usersCount', 1);
}
});
}
@ -449,7 +449,7 @@ function incRenoteCount(renote: Note) {
.execute();
}
async function insertNote(user: User, data: Option, tags: string[], emojis: string[], mentionedUsers: User[]) {
async function insertNote(user: { id: User['id']; host: User['host']; }, data: Option, tags: string[], emojis: string[], mentionedUsers: User[]) {
const insert = new Note({
id: genId(data.createdAt!),
createdAt: data.createdAt!,
@ -555,7 +555,7 @@ function index(note: Note) {
});
}
async function notifyToWatchersOfRenotee(renote: Note, user: User, nm: NotificationManager, type: NotificationType) {
async function notifyToWatchersOfRenotee(renote: Note, user: { id: User['id']; }, nm: NotificationManager, type: NotificationType) {
const watchers = await NoteWatchings.find({
noteId: renote.id,
userId: Not(user.id)
@ -566,7 +566,7 @@ async function notifyToWatchersOfRenotee(renote: Note, user: User, nm: Notificat
}
}
async function notifyToWatchersOfReplyee(reply: Note, user: User, nm: NotificationManager) {
async function notifyToWatchersOfReplyee(reply: Note, user: { id: User['id']; }, nm: NotificationManager) {
const watchers = await NoteWatchings.find({
noteId: reply.id,
userId: Not(user.id)
@ -594,7 +594,7 @@ function saveReply(reply: Note, note: Note) {
Notes.increment({ id: reply.id }, 'repliesCount', 1);
}
function incNotesCountOfUser(user: User) {
function incNotesCountOfUser(user: { id: User['id']; }) {
Users.createQueryBuilder().update()
.set({
updatedAt: new Date(),
@ -604,7 +604,7 @@ function incNotesCountOfUser(user: User) {
.execute();
}
async function extractMentionedUsers(user: User, tokens: ReturnType<typeof parse>): Promise<User[]> {
async function extractMentionedUsers(user: { host: User['host']; }, tokens: ReturnType<typeof parse>): Promise<User[]> {
if (tokens == null) return [];
const mentions = extractMentions(tokens);

View File

@ -14,7 +14,7 @@ import deleteReaction from './delete';
import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error';
import { NoteReaction } from '../../../models/entities/note-reaction';
export default async (user: User, note: Note, reaction?: string) => {
export default async (user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) => {
// TODO: cache
reaction = await toDbReaction(reaction, user.host);

View File

@ -9,7 +9,7 @@ import { Note } from '../../../models/entities/note';
import { NoteReactions, Users, Notes } from '../../../models';
import { decodeReaction } from '@/misc/reaction-lib';
export default async (user: User, note: Note) => {
export default async (user: { id: User['id']; host: User['host']; }, note: Note) => {
// if already unreacted
const exist = await NoteReactions.findOne({
noteId: note.id,

View File

@ -3,7 +3,7 @@ import { renderFollowRelay } from '../remote/activitypub/renderer/follow-relay';
import { renderActivity, attachLdSignature } from '../remote/activitypub/renderer';
import renderUndo from '../remote/activitypub/renderer/undo';
import { deliver } from '../queue';
import { ILocalUser } from '../models/entities/user';
import { ILocalUser, User } from '../models/entities/user';
import { Users, Relays } from '../models';
import { genId } from '@/misc/gen-id';
@ -75,7 +75,7 @@ export async function relayRejected(id: string) {
return JSON.stringify(result);
}
export async function deliverToRelays(user: ILocalUser, activity: any) {
export async function deliverToRelays(user: { id: User['id']; host: null; }, activity: any) {
if (activity == null) return;
const relays = await Relays.find({

View File

@ -6,7 +6,7 @@ import { User } from '../models/entities/user';
import { Users, Followings } from '../models';
import { Not, IsNull } from 'typeorm';
export async function doPostSuspend(user: User) {
export async function doPostSuspend(user: { id: User['id']; host: User['host'] }) {
if (Users.isLocalUser(user)) {
// 知り得る全SharedInboxにDelete配信
const content = renderActivity(renderDelete(`${config.url}/users/${user.id}`, user));
@ -28,7 +28,7 @@ export async function doPostSuspend(user: User) {
}
for (const inbox of queue) {
deliver(user as any, content, inbox);
deliver(user, content, inbox);
}
}
}

View File

@ -5,7 +5,7 @@ import { genId } from '@/misc/gen-id';
import { Hashtag } from '../models/entities/hashtag';
import { normalizeForSearch } from '@/misc/normalize-for-search';
export async function updateHashtags(user: User, tags: string[]) {
export async function updateHashtags(user: { id: User['id']; host: User['host']; }, tags: string[]) {
for (const tag of tags) {
await updateHashtag(user, tag);
}
@ -21,7 +21,7 @@ export async function updateUsertags(user: User, tags: string[]) {
}
}
export async function updateHashtag(user: User, tag: string, isUserAttached = false, inc = true) {
export async function updateHashtag(user: { id: User['id']; host: User['host']; }, tag: string, isUserAttached = false, inc = true) {
tag = normalizeForSearch(tag);
const index = await Hashtags.findOne({ name: tag });