refactor: resolve #7139
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import config from '../../../config';
|
||||
import { Users } from '../../../models';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
/**
|
||||
* Convert (local|remote)(Follower|Followee)ID to URL
|
||||
* @param id Follower|Followee ID
|
||||
*/
|
||||
export default async function renderFollowUser(id: User['id']): Promise<any> {
|
||||
const user = await Users.findOne(id).then(ensure);
|
||||
const user = await Users.findOneOrFail(id);
|
||||
return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri;
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ import { IActivity } from '../type';
|
||||
import { LdSignature } from '../misc/ld-signature';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { UserKeypairs } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export const renderActivity = (x: any): IActivity | null => {
|
||||
if (x == null) return null;
|
||||
@@ -24,9 +23,9 @@ export const renderActivity = (x: any): IActivity | null => {
|
||||
export const attachLdSignature = async (activity: any, user: ILocalUser): Promise<IActivity | null> => {
|
||||
if (activity == null) return null;
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
const keypair = await UserKeypairs.findOneOrFail({
|
||||
userId: user.id
|
||||
}).then(ensure);
|
||||
});
|
||||
|
||||
const obj = {
|
||||
// as non-standards
|
||||
|
@@ -10,7 +10,6 @@ import { DriveFiles, Notes, Users, Emojis, Polls } from '../../../models';
|
||||
import { In } from 'typeorm';
|
||||
import { Emoji } from '../../../models/entities/emoji';
|
||||
import { Poll } from '../../../models/entities/poll';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export default async function renderNote(note: Note, dive = true, isTalk = false): Promise<any> {
|
||||
const getPromisedFiles = async (ids: string[]) => {
|
||||
@@ -54,7 +53,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false
|
||||
}
|
||||
}
|
||||
|
||||
const user = await Users.findOne(note.userId).then(ensure);
|
||||
const user = await Users.findOneOrFail(note.userId);
|
||||
|
||||
const attributedTo = `${config.url}/users/${user.id}`;
|
||||
|
||||
|
@@ -9,7 +9,6 @@ import renderEmoji from './emoji';
|
||||
import { IIdentifier } from '../models/identifier';
|
||||
import renderHashtag from './hashtag';
|
||||
import { DriveFiles, UserProfiles, UserKeypairs } from '../../../models';
|
||||
import { ensure } from '../../../prelude/ensure';
|
||||
|
||||
export async function renderPerson(user: ILocalUser) {
|
||||
const id = `${config.url}/users/${user.id}`;
|
||||
@@ -18,7 +17,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
const [avatar, banner, profile] = await Promise.all([
|
||||
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
||||
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
||||
UserProfiles.findOne(user.id).then(ensure)
|
||||
UserProfiles.findOneOrFail(user.id)
|
||||
]);
|
||||
|
||||
const attachment: {
|
||||
@@ -50,7 +49,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
...hashtagTags,
|
||||
];
|
||||
|
||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
||||
const keypair = await UserKeypairs.findOneOrFail(user.id);
|
||||
|
||||
const person = {
|
||||
type: isSystem ? 'Application' : user.isBot ? 'Service' : 'Person',
|
||||
|
Reference in New Issue
Block a user