* 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 2e691f4ec4
commit 4d341c5918
109 changed files with 252 additions and 201 deletions

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import config from '@/config';
import { toASCII } from 'punycode';

View file

@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as stream from 'stream';
import * as util from 'util';
import { URL } from 'url';
import fetch from 'node-fetch';
import { getAgentByUrl } from './fetch';
import { AbortController } from 'abort-controller';

View file

@ -9,7 +9,7 @@ export type PackedApp = SchemaType<typeof packedAppSchema>;
export class AppRepository extends Repository<App> {
public async pack(
src: App['id'] | App,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecret?: boolean,

View file

@ -2,12 +2,13 @@ import { EntityRepository, Repository } from 'typeorm';
import { Apps } from '..';
import { AuthSession } from '../entities/auth-session';
import { awaitAll } from '../../prelude/await-all';
import { User } from '../entities/user';
@EntityRepository(AuthSession)
export class AuthSessionRepository extends Repository<AuthSession> {
public async pack(
src: AuthSession['id'] | AuthSession,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const session = typeof src === 'object' ? src : await this.findOneOrFail(src);

View file

@ -3,6 +3,7 @@ import { Users } from '..';
import { Blocking } from '../entities/blocking';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedBlocking = SchemaType<typeof packedBlockingSchema>;
@ -10,7 +11,7 @@ export type PackedBlocking = SchemaType<typeof packedBlockingSchema>;
export class BlockingRepository extends Repository<Blocking> {
public async pack(
src: Blocking['id'] | Blocking,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedBlocking> {
const blocking = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -26,7 +27,7 @@ export class BlockingRepository extends Repository<Blocking> {
public packMany(
blockings: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(blockings.map(x => this.pack(x, me)));
}

View file

@ -10,19 +10,19 @@ export type PackedChannel = SchemaType<typeof packedChannelSchema>;
export class ChannelRepository extends Repository<Channel> {
public async pack(
src: Channel['id'] | Channel,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
): Promise<PackedChannel> {
const channel = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const banner = channel.bannerId ? await DriveFiles.findOne(channel.bannerId) : null;
const hasUnreadNote = me ? (await NoteUnreads.findOne({ noteChannelId: channel.id, userId: meId })) != null : undefined;
const hasUnreadNote = meId ? (await NoteUnreads.findOne({ noteChannelId: channel.id, userId: meId })) != null : undefined;
const following = await ChannelFollowings.findOne({
const following = meId ? await ChannelFollowings.findOne({
followerId: meId,
followeeId: channel.id,
});
}) : null;
return {
id: channel.id,

View file

@ -53,7 +53,7 @@ export class DriveFileRepository extends Repository<DriveFile> {
return thumbnail ? (file.thumbnailUrl || (isImage ? (file.webpublicUrl || file.url) : null)) : (file.webpublicUrl || file.url);
}
public async calcDriveUsageOf(user: User['id'] | User): Promise<number> {
public async calcDriveUsageOf(user: User['id'] | { id: User['id'] }): Promise<number> {
const id = typeof user === 'object' ? user.id : user;
const { sum } = await this

View file

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { FollowRequest } from '../entities/follow-request';
import { Users } from '..';
import { User } from '../entities/user';
@EntityRepository(FollowRequest)
export class FollowRequestRepository extends Repository<FollowRequest> {
public async pack(
src: FollowRequest['id'] | FollowRequest,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const request = typeof src === 'object' ? src : await this.findOneOrFail(src);

View file

@ -3,6 +3,7 @@ import { Users } from '..';
import { Following } from '../entities/following';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
type LocalFollowerFollowing = Following & {
followerHost: null;
@ -50,7 +51,7 @@ export class FollowingRepository extends Repository<Following> {
public async pack(
src: Following['id'] | Following,
me?: any,
me?: { id: User['id'] } | null | undefined,
opts?: {
populateFollowee?: boolean;
populateFollower?: boolean;
@ -76,7 +77,7 @@ export class FollowingRepository extends Repository<Following> {
public packMany(
followings: any[],
me?: any,
me?: { id: User['id'] } | null | undefined,
opts?: {
populateFollowee?: boolean;
populateFollower?: boolean;

View file

@ -1,3 +1,4 @@
import { User } from '@/models/entities/user';
import { EntityRepository, Repository } from 'typeorm';
import { Users } from '../../..';
import { ReversiGame } from '../../../entities/games/reversi/game';
@ -6,7 +7,7 @@ import { ReversiGame } from '../../../entities/games/reversi/game';
export class ReversiGameRepository extends Repository<ReversiGame> {
public async pack(
src: ReversiGame['id'] | ReversiGame,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean
}
@ -16,7 +17,6 @@ export class ReversiGameRepository extends Repository<ReversiGame> {
}, options);
const game = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
return {
id: game.id,
@ -30,10 +30,10 @@ export class ReversiGameRepository extends Repository<ReversiGame> {
user2Accepted: game.user2Accepted,
user1Id: game.user1Id,
user2Id: game.user2Id,
user1: await Users.pack(game.user1Id, meId),
user2: await Users.pack(game.user2Id, meId),
user1: await Users.pack(game.user1Id, me),
user2: await Users.pack(game.user2Id, me),
winnerId: game.winnerId,
winner: game.winnerId ? await Users.pack(game.winnerId, meId) : null,
winner: game.winnerId ? await Users.pack(game.winnerId, me) : null,
surrendered: game.surrendered,
black: game.black,
bw: game.bw,

View file

@ -2,12 +2,13 @@ import { EntityRepository, Repository } from 'typeorm';
import { ReversiMatching } from '../../../entities/games/reversi/matching';
import { Users } from '../../..';
import { awaitAll } from '../../../../prelude/await-all';
import { User } from '@/models/entities/user';
@EntityRepository(ReversiMatching)
export class ReversiMatchingRepository extends Repository<ReversiMatching> {
public async pack(
src: ReversiMatching['id'] | ReversiMatching,
me: any
me: { id: User['id'] }
) {
const matching = typeof src === 'object' ? src : await this.findOneOrFail(src);

View file

@ -2,6 +2,7 @@ import { EntityRepository, Repository } from 'typeorm';
import { MessagingMessage } from '../entities/messaging-message';
import { Users, DriveFiles, UserGroups } from '..';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedMessagingMessage = SchemaType<typeof packedMessagingMessageSchema>;
@ -13,7 +14,7 @@ export class MessagingMessageRepository extends Repository<MessagingMessage> {
public async pack(
src: MessagingMessage['id'] | MessagingMessage,
me?: any,
me?: { id: User['id'] } | null | undefined,
options?: {
populateRecipient?: boolean,
populateGroup?: boolean,

View file

@ -3,6 +3,7 @@ import { Users } from '..';
import { Muting } from '../entities/muting';
import { awaitAll } from '../../prelude/await-all';
import { SchemaType } from '@/misc/schema';
import { User } from '../entities/user';
export type PackedMuting = SchemaType<typeof packedMutingSchema>;
@ -10,7 +11,7 @@ export type PackedMuting = SchemaType<typeof packedMutingSchema>;
export class MutingRepository extends Repository<Muting> {
public async pack(
src: Muting['id'] | Muting,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedMuting> {
const muting = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -26,7 +27,7 @@ export class MutingRepository extends Repository<Muting> {
public packMany(
mutings: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(mutings.map(x => this.pack(x, me)));
}

View file

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { NoteFavorite } from '../entities/note-favorite';
import { Notes } from '..';
import { User } from '../entities/user';
@EntityRepository(NoteFavorite)
export class NoteFavoriteRepository extends Repository<NoteFavorite> {
public async pack(
src: NoteFavorite['id'] | NoteFavorite,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const favorite = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -20,7 +21,7 @@ export class NoteFavoriteRepository extends Repository<NoteFavorite> {
public packMany(
favorites: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(favorites.map(x => this.pack(x, me)));
}

View file

@ -3,6 +3,7 @@ import { NoteReaction } from '../entities/note-reaction';
import { Users } from '..';
import { SchemaType } from '@/misc/schema';
import { convertLegacyReaction } from '@/misc/reaction-lib';
import { User } from '../entities/user';
export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
@ -10,7 +11,7 @@ export type PackedNoteReaction = SchemaType<typeof packedNoteReactionSchema>;
export class NoteReactionRepository extends Repository<NoteReaction> {
public async pack(
src: NoteReaction['id'] | NoteReaction,
me?: any
me?: { id: User['id'] } | null | undefined
): Promise<PackedNoteReaction> {
const reaction = typeof src === 'object' ? src : await this.findOneOrFail(src);

View file

@ -79,7 +79,7 @@ export class NoteRepository extends Repository<Note> {
public async pack(
src: Note['id'] | Note,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean;
skipHide?: boolean;
@ -93,7 +93,7 @@ export class NoteRepository extends Repository<Note> {
skipHide: false
}, options);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const note = typeof src === 'object' ? src : await this.findOneOrFail(src);
const host = note.userHost;
@ -174,7 +174,7 @@ export class NoteRepository extends Repository<Note> {
id: note.id,
createdAt: note.createdAt.toISOString(),
userId: note.userId,
user: Users.pack(note.user || note.userId, meId, {
user: Users.pack(note.user || note.userId, me, {
detail: false,
}),
text: text,
@ -204,12 +204,12 @@ export class NoteRepository extends Repository<Note> {
_prId_: (note as any)._prId_ || undefined,
...(opts.detail ? {
reply: note.replyId ? this.pack(note.reply || note.replyId, meId, {
reply: note.replyId ? this.pack(note.reply || note.replyId, me, {
detail: false,
_hint_: options?._hint_
}) : undefined,
renote: note.renoteId ? this.pack(note.renote || note.renoteId, meId, {
renote: note.renoteId ? this.pack(note.renote || note.renoteId, me, {
detail: true,
_hint_: options?._hint_
}) : undefined,
@ -236,7 +236,7 @@ export class NoteRepository extends Repository<Note> {
public async packMany(
notes: Note[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean;
skipHide?: boolean;
@ -244,7 +244,7 @@ export class NoteRepository extends Repository<Note> {
) {
if (notes.length === 0) return [];
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const myReactionsMap = new Map<Note['id'], NoteReaction | null>();
if (meId) {
const renoteIds = notes.filter(n => n.renoteId != null).map(n => n.renoteId!);

View file

@ -31,38 +31,38 @@ export class NotificationRepository extends Repository<Notification> {
userId: notification.notifierId,
user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null,
...(notification.type === 'mention' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'reply' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'renote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'quote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
} : {}),
...(notification.type === 'reaction' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),
reaction: notification.reaction
} : {}),
...(notification.type === 'pollVote' ? {
note: Notes.pack(notification.note || notification.noteId!, notification.notifieeId, {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_
}),

View file

@ -1,12 +1,13 @@
import { EntityRepository, Repository } from 'typeorm';
import { PageLike } from '../entities/page-like';
import { Pages } from '..';
import { User } from '../entities/user';
@EntityRepository(PageLike)
export class PageLikeRepository extends Repository<PageLike> {
public async pack(
src: PageLike['id'] | PageLike,
me?: any
me?: { id: User['id'] } | null | undefined
) {
const like = typeof src === 'object' ? src : await this.findOneOrFail(src);
@ -18,7 +19,7 @@ export class PageLikeRepository extends Repository<PageLike> {
public packMany(
likes: any[],
me: any
me: { id: User['id'] }
) {
return Promise.all(likes.map(x => this.pack(x, me)));
}

View file

@ -12,9 +12,9 @@ export type PackedPage = SchemaType<typeof packedPageSchema>;
export class PageRepository extends Repository<Page> {
public async pack(
src: Page['id'] | Page,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
): Promise<PackedPage> {
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const page = typeof src === 'object' ? src : await this.findOneOrFail(src);
const attachedFiles: Promise<DriveFile | undefined>[] = [];
@ -84,7 +84,7 @@ export class PageRepository extends Repository<Page> {
public packMany(
pages: Page[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
) {
return Promise.all(pages.map(x => this.pack(x, me)));
}

View file

@ -147,7 +147,7 @@ export class UserRepository extends Repository<User> {
public async pack(
src: User['id'] | User,
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecrets?: boolean,
@ -159,7 +159,7 @@ export class UserRepository extends Repository<User> {
}, options);
const user = typeof src === 'object' ? src : await this.findOneOrFail(src);
const meId = me ? typeof me === 'string' ? me : me.id : null;
const meId = me ? me.id : null;
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
const pins = opts.detail ? await UserNotePinings.createQueryBuilder('pin')
@ -213,11 +213,11 @@ export class UserRepository extends Repository<User> {
followingCount: user.followingCount,
notesCount: user.notesCount,
pinnedNoteIds: pins.map(pin => pin.noteId),
pinnedNotes: Notes.packMany(pins.map(pin => pin.note!), meId, {
pinnedNotes: Notes.packMany(pins.map(pin => pin.note!), me, {
detail: true
}),
pinnedPageId: profile!.pinnedPageId,
pinnedPage: profile!.pinnedPageId ? Pages.pack(profile!.pinnedPageId, meId) : null,
pinnedPage: profile!.pinnedPageId ? Pages.pack(profile!.pinnedPageId, me) : null,
twoFactorEnabled: profile!.twoFactorEnabled,
usePasswordLessLogin: profile!.usePasswordLessLogin,
securityKeys: profile!.twoFactorEnabled
@ -286,7 +286,7 @@ export class UserRepository extends Repository<User> {
public packMany(
users: (User['id'] | User)[],
me?: User['id'] | User | null | undefined,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecrets?: boolean,
@ -295,11 +295,15 @@ export class UserRepository extends Repository<User> {
return Promise.all(users.map(u => this.pack(u, me, options)));
}
public isLocalUser(user: User): user is ILocalUser {
public isLocalUser(user: User): user is ILocalUser;
public isLocalUser<T extends { host: User['host'] }>(user: T): user is T & { host: null; };
public isLocalUser(user: User | { host: User['host'] }): boolean {
return user.host == null;
}
public isRemoteUser(user: User): user is IRemoteUser {
public isRemoteUser(user: User): user is IRemoteUser;
public isRemoteUser<T extends { host: User['host'] }>(user: T): user is T & { host: string; };
public isRemoteUser(user: User | { host: User['host'] }): boolean {
return !this.isLocalUser(user);
}

View file

@ -1,7 +1,7 @@
import * as httpSignature from 'http-signature';
import config from '@/config';
import { ILocalUser } from '../models/entities/user';
import { User } from '../models/entities/user';
import { program } from '../argv';
import processDeliver from './processors/deliver';
@ -65,7 +65,7 @@ objectStorageQueue
.on('error', (job: any, err: Error) => objectStorageLogger.error(`error ${err}`, { job, e: renderError(err) }))
.on('stalled', (job) => objectStorageLogger.warn(`stalled id=${job.id}`));
export function deliver(user: ILocalUser, content: any, to: any) {
export function deliver(user: { id: User['id']; host: null; }, content: any, to: any) {
if (content == null) return null;
const data = {
@ -102,7 +102,7 @@ export function inbox(activity: any, signature: httpSignature.IParsedSignature)
});
}
export function createDeleteDriveFilesJob(user: ILocalUser) {
export function createDeleteDriveFilesJob(user: { id: User['id'] }) {
return dbQueue.add('deleteDriveFiles', {
user: user
}, {
@ -111,7 +111,7 @@ export function createDeleteDriveFilesJob(user: ILocalUser) {
});
}
export function createExportNotesJob(user: ILocalUser) {
export function createExportNotesJob(user: { id: User['id'] }) {
return dbQueue.add('exportNotes', {
user: user
}, {
@ -120,7 +120,7 @@ export function createExportNotesJob(user: ILocalUser) {
});
}
export function createExportFollowingJob(user: ILocalUser) {
export function createExportFollowingJob(user: { id: User['id'] }) {
return dbQueue.add('exportFollowing', {
user: user
}, {
@ -129,7 +129,7 @@ export function createExportFollowingJob(user: ILocalUser) {
});
}
export function createExportMuteJob(user: ILocalUser) {
export function createExportMuteJob(user: { id: User['id'] }) {
return dbQueue.add('exportMute', {
user: user
}, {
@ -138,7 +138,7 @@ export function createExportMuteJob(user: ILocalUser) {
});
}
export function createExportBlockingJob(user: ILocalUser) {
export function createExportBlockingJob(user: { id: User['id'] }) {
return dbQueue.add('exportBlocking', {
user: user
}, {
@ -147,7 +147,7 @@ export function createExportBlockingJob(user: ILocalUser) {
});
}
export function createExportUserListsJob(user: ILocalUser) {
export function createExportUserListsJob(user: { id: User['id'] }) {
return dbQueue.add('exportUserLists', {
user: user
}, {
@ -156,7 +156,7 @@ export function createExportUserListsJob(user: ILocalUser) {
});
}
export function createImportFollowingJob(user: ILocalUser, fileId: DriveFile['id']) {
export function createImportFollowingJob(user: { id: User['id'] }, fileId: DriveFile['id']) {
return dbQueue.add('importFollowing', {
user: user,
fileId: fileId
@ -166,7 +166,7 @@ export function createImportFollowingJob(user: ILocalUser, fileId: DriveFile['id
});
}
export function createImportUserListsJob(user: ILocalUser, fileId: DriveFile['id']) {
export function createImportUserListsJob(user: { id: User['id'] }, fileId: DriveFile['id']) {
return dbQueue.add('importUserLists', {
user: user,
fileId: fileId

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import * as Bull from 'bull';
import request from '../../remote/activitypub/request';
import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc';

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import * as Bull from 'bull';
import * as httpSignature from 'http-signature';
import perform from '../../remote/activitypub/perform';

View file

@ -1,5 +1,5 @@
import { Users, Followings } from '../../models';
import { ILocalUser, IRemoteUser } from '../../models/entities/user';
import { ILocalUser, IRemoteUser, User } from '../../models/entities/user';
import { deliver } from '../../queue';
//#region types
@ -24,7 +24,7 @@ const isDirect = (recipe: any): recipe is IDirectRecipe =>
//#endregion
export default class DeliverManager {
private actor: ILocalUser;
private actor: { id: User['id']; host: null; };
private activity: any;
private recipes: IRecipe[] = [];
@ -33,7 +33,7 @@ export default class DeliverManager {
* @param actor Actor
* @param activity Activity to deliver
*/
constructor(actor: ILocalUser, activity: any) {
constructor(actor: { id: User['id']; host: null; }, activity: any) {
this.actor = actor;
this.activity = activity;
}

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import * as promiseLimit from 'promise-limit';
import config from '@/config';

View file

@ -1,7 +1,7 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '../../../models/entities/user';
export default (object: any, user: ILocalUser) => ({
export default (object: any, user: { id: User['id']; host: null }) => ({
type: 'Delete',
actor: `${config.url}/users/${user.id}`,
object

View file

@ -2,7 +2,7 @@ import config from '@/config';
import { User } from '../../../models/entities/user';
import { Users } from '../../../models';
export default (follower: User, followee: User, requestId?: string) => {
export default (follower: { id: User['id']; host: User['host']; uri: User['host'] }, followee: { id: User['id']; host: User['host']; uri: User['host'] }, requestId?: string) => {
const follow = {
type: 'Follow',
actor: Users.isLocalUser(follower) ? `${config.url}/users/${follower.id}` : follower.uri,

View file

@ -2,8 +2,8 @@ import config from '@/config';
import { v4 as uuid } from 'uuid';
import { IActivity } from '../type';
import { LdSignature } from '../misc/ld-signature';
import { ILocalUser } from '../../../models/entities/user';
import { getUserKeypair } from '@/misc/keypair-store';
import { User } from '@/models/entities/user';
export const renderActivity = (x: any): IActivity | null => {
if (x == null) return null;
@ -20,7 +20,7 @@ export const renderActivity = (x: any): IActivity | null => {
}, x);
};
export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => {
export const attachLdSignature = async (activity: any, user: { id: User['id']; host: null; }): Promise<IActivity | null> => {
if (activity == null) return null;
const keypair = await getUserKeypair(user.id);

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import renderImage from './image';
import renderKey from './key';
import config from '@/config';

View file

@ -1,9 +1,9 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '@/models/entities/user';
import { Note } from '../../../models/entities/note';
import { Poll } from '../../../models/entities/poll';
export default async function renderQuestion(user: ILocalUser, note: Note, poll: Poll) {
export default async function renderQuestion(user: { id: User['id'] }, note: Note, poll: Poll) {
const question = {
type: 'Question',
id: `${config.url}/questions/${note.id}`,

View file

@ -1,8 +1,8 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '@/models/entities/user';
import { MessagingMessage } from '../../../models/entities/messaging-message';
export const renderReadActivity = (user: ILocalUser, message: MessagingMessage) => ({
export const renderReadActivity = (user: { id: User['id'] }, message: MessagingMessage) => ({
type: 'Read',
actor: `${config.url}/users/${user.id}`,
object: message.uri

View file

@ -1,7 +1,7 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '@/models/entities/user';
export default (object: any, user: ILocalUser) => ({
export default (object: any, user: { id: User['id'] }) => ({
type: 'Reject',
actor: `${config.url}/users/${user.id}`,
object

View file

@ -1,7 +1,7 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '@/models/entities/user';
export default (user: ILocalUser, target: any, object: any) => ({
export default (user: { id: User['id'] }, target: any, object: any) => ({
type: 'Remove',
actor: `${config.url}/users/${user.id}`,
target,

View file

@ -1,7 +1,7 @@
import config from '@/config';
import { ILocalUser, User } from '../../../models/entities/user';
export default (object: any, user: ILocalUser | User) => ({
export default (object: any, user: { id: User['id'] }) => ({
type: 'Undo',
actor: `${config.url}/users/${user.id}`,
object

View file

@ -1,7 +1,7 @@
import config from '@/config';
import { ILocalUser } from '../../../models/entities/user';
import { User } from '@/models/entities/user';
export default (object: any, user: ILocalUser) => {
export default (object: any, user: { id: User['id'] }) => {
const activity = {
id: `${config.url}/users/${user.id}#updates/${new Date().getTime()}`,
actor: `${config.url}/users/${user.id}`,

View file

@ -1,10 +1,10 @@
import config from '@/config';
import { Note } from '../../../models/entities/note';
import { IRemoteUser, ILocalUser } from '../../../models/entities/user';
import { IRemoteUser, User } from '../../../models/entities/user';
import { PollVote } from '../../../models/entities/poll-vote';
import { Poll } from '../../../models/entities/poll';
export default async function renderVote(user: ILocalUser, vote: PollVote, note: Note, poll: Poll, pollOwner: IRemoteUser): Promise<any> {
export default async function renderVote(user: { id: User['id'] }, vote: PollVote, note: Note, poll: Poll, pollOwner: IRemoteUser): Promise<any> {
return {
id: `${config.url}/users/${user.id}#votes/${vote.id}/activity`,
actor: `${config.url}/users/${user.id}`,

View file

@ -4,14 +4,14 @@ import { sign } from 'http-signature';
import * as crypto from 'crypto';
import config from '@/config';
import { ILocalUser } from '../../models/entities/user';
import { User } from '@/models/entities/user';
import { getAgentByUrl } from '@/misc/fetch';
import { URL } from 'url';
import got from 'got';
import * as Got from 'got';
import { getUserKeypair } from '@/misc/keypair-store';
export default async (user: ILocalUser, url: string, object: any) => {
export default async (user: { id: User['id'] }, url: string, object: any) => {
const timeout = 10 * 1000;
const { protocol, hostname, port, pathname, search } = new URL(url);
@ -24,7 +24,7 @@ export default async (user: ILocalUser, url: string, object: any) => {
const keypair = await getUserKeypair(user.id);
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
const req = https.request({
agent: getAgentByUrl(new URL(`https://example.net`)),
protocol,
@ -69,7 +69,7 @@ export default async (user: ILocalUser, url: string, object: any) => {
* @param user http-signature user
* @param url URL to fetch
*/
export async function signedGet(url: string, user: ILocalUser) {
export async function signedGet(url: string, user: { id: User['id'] }) {
const timeout = 10 * 1000;
const keypair = await getUserKeypair(user.id);

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import webFinger from './webfinger';
import config from '@/config';
import { createPerson, updatePerson } from './activitypub/models/person';

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import { getJson } from '@/misc/fetch';
import { query as urlQuery } from '../prelude/url';

View file

@ -2,7 +2,7 @@ import { User } from '../../../models/entities/user';
import { Blockings } from '../../../models';
import { SelectQueryBuilder } from 'typeorm';
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: User) {
export function generateBlockQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const blockingQuery = Blockings.createQueryBuilder('blocking')
.select('blocking.blockeeId')
.where('blocking.blockerId = :blockerId', { blockerId: me.id });

View file

@ -2,7 +2,7 @@ import { User } from '../../../models/entities/user';
import { ChannelFollowings } from '../../../models';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export function generateChannelQuery(q: SelectQueryBuilder<any>, me?: User | null) {
export function generateChannelQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null) {
if (me == null) {
q.andWhere('note.channelId IS NULL');
} else {

View file

@ -2,7 +2,7 @@ import { User } from '../../../models/entities/user';
import { MutedNotes } from '../../../models';
import { SelectQueryBuilder } from 'typeorm';
export function generateMutedNoteQuery(q: SelectQueryBuilder<any>, me: User) {
export function generateMutedNoteQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const mutedQuery = MutedNotes.createQueryBuilder('muted')
.select('muted.noteId')
.where('muted.userId = :userId', { userId: me.id });

View file

@ -2,7 +2,7 @@ import { User } from '../../../models/entities/user';
import { Mutings } from '../../../models';
import { SelectQueryBuilder, Brackets } from 'typeorm';
export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: User, exclude?: User) {
export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: User['id'] }, exclude?: User) {
const mutingQuery = Mutings.createQueryBuilder('muting')
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });
@ -28,7 +28,7 @@ export function generateMutedUserQuery(q: SelectQueryBuilder<any>, me: User, exc
q.setParameters(mutingQuery.getParameters());
}
export function generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: User) {
export function generateMutedUserQueryForUsers(q: SelectQueryBuilder<any>, me: { id: User['id'] }) {
const mutingQuery = Mutings.createQueryBuilder('muting')
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });

View file

@ -1,7 +1,7 @@
import { User } from '../../../models/entities/user';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export function generateRepliesQuery(q: SelectQueryBuilder<any>, me?: User | null) {
export function generateRepliesQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null) {
if (me == null) {
q.andWhere(new Brackets(qb => { qb
.where(`note.replyId IS NULL`) // 返信ではない

View file

@ -2,7 +2,7 @@ import { User } from '../../../models/entities/user';
import { Followings } from '../../../models';
import { Brackets, SelectQueryBuilder } from 'typeorm';
export function generateVisibilityQuery(q: SelectQueryBuilder<any>, me?: User | null) {
export function generateVisibilityQuery(q: SelectQueryBuilder<any>, me?: { id: User['id'] } | null) {
if (me == null) {
q.andWhere(new Brackets(qb => { qb
.where(`note.visibility = 'public'`)

View file

@ -1,7 +1,7 @@
import { publishMainStream, publishGroupMessagingStream } from '../../../services/stream';
import { publishMessagingStream } from '../../../services/stream';
import { publishMessagingIndexStream } from '../../../services/stream';
import { User, ILocalUser, IRemoteUser } from '../../../models/entities/user';
import { User, IRemoteUser } from '../../../models/entities/user';
import { MessagingMessage } from '../../../models/entities/messaging-message';
import { MessagingMessages, UserGroupJoinings, Users } from '../../../models';
import { In } from 'typeorm';
@ -107,7 +107,7 @@ export async function readGroupMessagingMessage(
}
}
export async function deliverReadActivity(user: ILocalUser, recipient: IRemoteUser, messages: MessagingMessage | MessagingMessage[]) {
export async function deliverReadActivity(user: { id: User['id']; host: null; }, recipient: IRemoteUser, messages: MessagingMessage | MessagingMessage[]) {
messages = toArray(messages).filter(x => x.uri);
const contents = messages.map(x => renderReadActivity(user, x));

View file

@ -5,6 +5,18 @@ import { ApiError } from './error';
import { SchemaType } from '@/misc/schema';
import { AccessToken } from '../../models/entities/access-token';
type SimpleUserInfo = {
id: ILocalUser['id'];
host: ILocalUser['host'];
username: ILocalUser['username'];
uri: ILocalUser['uri'];
inbox: ILocalUser['inbox'];
sharedInbox: ILocalUser['sharedInbox'];
isAdmin: ILocalUser['isAdmin'];
isModerator: ILocalUser['isModerator'];
isSilenced: ILocalUser['isSilenced'];
};
// TODO: defaultが設定されている場合はその型も考慮する
type Params<T extends IEndpointMeta> = {
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends Function
@ -15,13 +27,12 @@ type Params<T extends IEndpointMeta> = {
export type Response = Record<string, any> | void;
type executor<T extends IEndpointMeta> =
(params: Params<T>, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any, cleanup?: Function) =>
(params: Params<T>, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any, cleanup?: Function) =>
Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
// TODO: API関数に user まるごと渡すのではなくユーザーIDなどの最小限のプロパティだけ渡すようにしたい(キャッシュとか考えないでよくなるため)
export default function <T extends IEndpointMeta>(meta: T, cb: executor<T>)
: (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => Promise<any> {
return (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => {
: (params: any, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any) => Promise<any> {
return (params: any, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any) => {
function cleanup() {
fs.unlink(file.path, () => {});
}

View file

@ -34,7 +34,8 @@ export const meta = {
}
};
export default define(meta, async (ps, me) => {
export default define(meta, async (ps, _me) => {
const me = _me ? await Users.findOneOrFail(_me.id) : null;
const noUsers = (await Users.count({
host: null,
})) === 0;

View file

@ -96,9 +96,9 @@ export default define(meta, async (ps) => {
emojis = await q.getMany();
emojis = emojis.filter(emoji =>
emoji.name.includes(ps.query) ||
emoji.aliases.some(a => a.includes(ps.query)) ||
emoji.category?.includes(ps.query));
emoji.name.includes(ps.query!) ||
emoji.aliases.some(a => a.includes(ps.query!)) ||
emoji.category?.includes(ps.query!));
emojis.splice(ps.limit! + 1);
} else {

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import define from '../../../define';
import { deliverQueue } from '../../../../../queue';

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import define from '../../../define';
import { inboxQueue } from '../../../../../queue';

View file

@ -1,3 +1,4 @@
import { URL } from 'url';
import $ from 'cafy';
import define from '../../../define';
import { addRelay } from '../../../../../services/relay';

View file

@ -89,7 +89,7 @@ export default define(meta, async (ps, user) => {
let userList;
let userGroupJoining;
if (ps.src === 'list') {
if (ps.src === 'list' && ps.userListId) {
userList = await UserLists.findOne({
id: ps.userListId,
userId: user.id,
@ -98,7 +98,7 @@ export default define(meta, async (ps, user) => {
if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList);
}
} else if (ps.src === 'group') {
} else if (ps.src === 'group' && ps.userGroupId) {
userGroupJoining = await UserGroupJoinings.findOne({
userGroupId: ps.userGroupId,
userId: user.id,

View file

@ -108,7 +108,7 @@ export default define(meta, async (ps, user) => {
let userList;
let userGroupJoining;
if (ps.src === 'list') {
if (ps.src === 'list' && ps.userListId) {
userList = await UserLists.findOne({
id: ps.userListId,
userId: user.id,
@ -117,7 +117,7 @@ export default define(meta, async (ps, user) => {
if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList);
}
} else if (ps.src === 'group') {
} else if (ps.src === 'group' && ps.userGroupId) {
userGroupJoining = await UserGroupJoinings.findOne({
userGroupId: ps.userGroupId,
userId: user.id,

View file

@ -46,6 +46,6 @@ export default define(meta, async (ps, user, token) => {
return await Apps.pack(ap, user, {
detail: true,
includeSecret: isSecure && (ap.userId === user.id)
includeSecret: isSecure && (ap.userId === user!.id)
});
});

View file

@ -62,7 +62,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const blocker = user;
const blocker = await Users.findOneOrFail(user.id);
// 自分自身
if (user.id === ps.userId) {
@ -93,7 +93,7 @@ export default define(meta, async (ps, user) => {
noteUserId: blockee.id
});
return await Users.pack(blockee.id, user, {
return await Users.pack(blockee.id, blocker, {
detail: true
});
});

View file

@ -126,7 +126,7 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const blocker = user;
const blocker = await Users.findOneOrFail(user.id);
// Check if the blockee is yourself
if (user.id === ps.userId) {
@ -152,7 +152,7 @@ export default define(meta, async (ps, user) => {
// Delete blocking
await deleteBlocking(blocker, blockee);
return await Users.pack(blockee.id, user, {
return await Users.pack(blockee.id, blocker, {
detail: true
});
});

View file

@ -97,7 +97,7 @@ export default define(meta, async (ps, user) => {
const timeline = await query.take(ps.limit!).getMany();
activeUsersChart.update(user);
if (user) activeUsersChart.update(user);
return await Notes.packMany(timeline, user);
});

View file

@ -32,14 +32,14 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const clip = await Clips.save({
const clip = await Clips.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.name,
isPublic: ps.isPublic,
description: ps.description,
});
}).then(x => Clips.findOneOrFail(x.identifiers[0]));
return await Clips.pack(clip);
});

View file

@ -34,7 +34,7 @@ export default define(meta, async (ps, user) => {
const instance = await fetchMeta(true);
// Calculate drive usage
const usage = await DriveFiles.calcDriveUsageOf(user);
const usage = await DriveFiles.calcDriveUsageOf(user.id);
return {
capacity: 1024 * 1024 * instance.localDriveCapacityMb,

View file

@ -68,13 +68,13 @@ export default define(meta, async (ps, user) => {
}
// Create folder
const folder = await DriveFolders.save({
const folder = await DriveFolders.insert({
id: genId(),
createdAt: new Date(),
name: ps.name,
parentId: parent !== null ? parent.id : null,
userId: user.id
});
}).then(x => DriveFolders.findOneOrFail(x.identifiers[0]));
const folderObj = await DriveFolders.pack(folder);

View file

@ -2,7 +2,6 @@ import $ from 'cafy';
import define from '../../define';
import { Instances } from '../../../../models';
import { toPuny } from '@/misc/convert-host';
import config from '@/config';
export const meta = {
tags: ['federation'],

View file

@ -140,7 +140,7 @@ export default define(meta, async (ps, user) => {
const query = makePaginationQuery(ReversiGames.createQueryBuilder('game'), ps.sinceId, ps.untilId)
.andWhere('game.isStarted = TRUE');
if (ps.my) {
if (ps.my && user) {
query.andWhere(new Brackets(qb => { qb
.where('game.user1Id = :userId', { userId: user.id })
.orWhere('game.user2Id = :userId', { userId: user.id });

View file

@ -72,7 +72,7 @@ export default define(meta, async (ps, user) => {
isLlotheo: false
} as Partial<ReversiGame>);
publishReversiStream(exist.parentId, 'matched', await ReversiGames.pack(game, exist.parentId));
publishReversiStream(exist.parentId, 'matched', await ReversiGames.pack(game, { id: exist.parentId }));
const other = await ReversiMatchings.count({
childId: user.id

View file

@ -61,7 +61,7 @@ export default define(meta, async (ps, user) => {
throw e;
});
return await Users.pack(user, user, {
return await Users.pack(user.id, user, {
detail: true
});
});

View file

@ -1,4 +1,3 @@
import $ from 'cafy';
import define from '../../../define';
import { RegistryItems } from '../../../../../models';

View file

@ -47,7 +47,7 @@ export default define(meta, async (ps, user) => {
throw e;
});
return await Users.pack(user, user, {
return await Users.pack(user.id, user, {
detail: true
});
});

View file

@ -205,7 +205,8 @@ export const meta = {
}
};
export default define(meta, async (ps, user, token) => {
export default define(meta, async (ps, _user, token) => {
const user = await Users.findOneOrFail(_user.id);
const isSecure = token == null;
const updates = {} as Partial<User>;

View file

@ -5,7 +5,7 @@ import define from '../../define';
import * as ms from 'ms';
import { getNote } from '../../common/getters';
import { ApiError } from '../../error';
import { Notes } from '../../../../models';
import { Notes, Users } from '../../../../models';
export const meta = {
desc: {
@ -55,6 +55,6 @@ export default define(meta, async (ps, user) => {
});
for (const note of renotes) {
deleteNote(user, note);
deleteNote(await Users.findOneOrFail(user.id), note);
}
});

View file

@ -43,7 +43,7 @@ export default define(meta, async (ps, user) => {
event: ps.event,
var: ps.var,
userId: user.id,
user: await Users.pack(user, page.userId, {
user: await Users.pack(user.id, { id: page.userId }, {
detail: true
})
});

View file

@ -31,12 +31,12 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const userGroup = await UserGroups.save({
const userGroup = await UserGroups.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.name,
} as UserGroup);
} as UserGroup).then(x => UserGroups.findOneOrFail(x.identifiers[0]));
// Push the owner
await UserGroupJoinings.insert({

View file

@ -96,12 +96,12 @@ export default define(meta, async (ps, me) => {
throw new ApiError(meta.errors.alreadyInvited);
}
const invitation = await UserGroupInvitations.save({
const invitation = await UserGroupInvitations.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
userGroupId: userGroup.id
} as UserGroupInvitation);
} as UserGroupInvitation).then(x => UserGroupInvitations.findOneOrFail(x.identifiers[0]));
// 通知を作成
createNotification(user.id, 'groupInvited', {

View file

@ -30,12 +30,12 @@ export const meta = {
};
export default define(meta, async (ps, user) => {
const userList = await UserLists.save({
const userList = await UserLists.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.name,
} as UserList);
} as UserList).then(x => UserLists.findOneOrFail(x.identifiers[0]));
return await UserLists.pack(userList);
});

View file

@ -6,6 +6,7 @@ import { ApiError } from '../../error';
import { ID } from '@/misc/cafy-id';
import { Users } from '../../../../models';
import { In } from 'typeorm';
import { User } from '@/models/entities/user';
export const meta = {
desc: {
@ -81,9 +82,9 @@ export default define(meta, async (ps, me) => {
});
// リクエストされた通りに並べ替え
const _users = [];
const _users: User[] = [];
for (const id of ps.userIds) {
_users.push(users.find(x => x.id === id));
_users.push(users.find(x => x.id === id)!);
}
return await Promise.all(_users.map(u => Users.pack(u, me, {

View file

@ -7,7 +7,7 @@ import Logger from '../../services/logger';
const logger = new Logger('limiter');
export default (endpoint: IEndpoint, user: User) => new Promise((ok, reject) => {
export default (endpoint: IEndpoint, user: User) => new Promise<void>((ok, reject) => {
const limitation = endpoint.meta.limit!;
const key = limitation.hasOwnProperty('key')

View file

@ -26,7 +26,7 @@ export default class extends Channel {
childId: body.id
});
if (matching == null) return;
publishMainStream(matching.childId, 'reversiInvited', await ReversiMatchings.pack(matching, matching.childId));
publishMainStream(matching.childId, 'reversiInvited', await ReversiMatchings.pack(matching, { id: matching.childId }));
break;
}
}

View file

@ -42,8 +42,9 @@ export default class extends Channel {
// 関係ない返信は除外
if (note.reply) {
const reply = note.reply as PackedNote;
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (note.reply.userId !== this.user!.id && note.userId !== this.user!.id && note.reply.userId !== note.userId) return;
if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
}
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する

View file

@ -50,8 +50,9 @@ export default class extends Channel {
// 関係ない返信は除外
if (note.reply) {
const reply = note.reply as PackedNote;
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (note.reply.userId !== this.user!.id && note.userId !== this.user!.id && note.reply.userId !== note.userId) return;
if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
}
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する

View file

@ -59,8 +59,9 @@ export default class extends Channel {
// 関係ない返信は除外
if (note.reply) {
const reply = note.reply as PackedNote;
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (note.reply.userId !== this.user!.id && note.userId !== this.user!.id && note.reply.userId !== note.userId) return;
if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
}
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する

View file

@ -44,8 +44,9 @@ export default class extends Channel {
// 関係ない返信は除外
if (note.reply) {
const reply = note.reply as PackedNote;
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (note.reply.userId !== this.user!.id && note.userId !== this.user!.id && note.reply.userId !== note.userId) return;
if (reply.userId !== this.user!.id && note.userId !== this.user!.id && reply.userId !== note.userId) return;
}
// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する

View file

@ -156,8 +156,8 @@ export default class Connection {
};
add(note);
if (note.reply) add(note.reply);
if (note.renote) add(note.renote);
if (note.reply) add(note.reply as PackedNote);
if (note.renote) add(note.renote as PackedNote);
}
@autobind

View file

@ -89,7 +89,7 @@ router.get('/verify-email/:code', async ctx => {
emailVerifyCode: null
});
publishMainStream(profile.userId, 'meUpdated', await Users.pack(profile.userId, profile.userId, {
publishMainStream(profile.userId, 'meUpdated', await Users.pack(profile.userId, { id: profile.userId }, {
detail: true,
includeSecrets: true
}));

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,

Some files were not shown because too many files have changed in this diff Show more