strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import config from '../../../config';
|
||||
import { ILocalUser, IRemoteUser } from '../../../models/entities/user';
|
||||
|
||||
export default (blocker?: ILocalUser, blockee?: IRemoteUser) => ({
|
||||
export default (blocker: ILocalUser, blockee: IRemoteUser) => ({
|
||||
type: 'Block',
|
||||
actor: `${config.url}/users/${blocker.id}`,
|
||||
object: blockee.uri
|
||||
|
@@ -1,12 +1,13 @@
|
||||
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);
|
||||
const user = await Users.findOne(id).then(ensure);
|
||||
return Users.isLocalUser(user) ? `${config.url}/users/${user.id}` : user.uri;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ 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): Promise<any> {
|
||||
const promisedFiles: Promise<DriveFile[]> = note.fileIds.length > 0
|
||||
@@ -17,15 +18,15 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
|
||||
: Promise.resolve([]);
|
||||
|
||||
let inReplyTo;
|
||||
let inReplyToNote: Note;
|
||||
let inReplyToNote: Note | undefined;
|
||||
|
||||
if (note.replyId) {
|
||||
inReplyToNote = await Notes.findOne(note.replyId);
|
||||
|
||||
if (inReplyToNote !== null) {
|
||||
if (inReplyToNote != null) {
|
||||
const inReplyToUser = await Users.findOne(inReplyToNote.userId);
|
||||
|
||||
if (inReplyToUser !== null) {
|
||||
if (inReplyToUser != null) {
|
||||
if (inReplyToNote.uri) {
|
||||
inReplyTo = inReplyToNote.uri;
|
||||
} else {
|
||||
@@ -51,9 +52,7 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
|
||||
}
|
||||
}
|
||||
|
||||
const user = await Users.findOne({
|
||||
id: note.userId
|
||||
});
|
||||
const user = await Users.findOne(note.userId).then(ensure);
|
||||
|
||||
const attributedTo = `${config.url}/users/${user.id}`;
|
||||
|
||||
@@ -85,13 +84,13 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
|
||||
const files = await promisedFiles;
|
||||
|
||||
let text = note.text;
|
||||
let poll: Poll;
|
||||
let poll: Poll | undefined;
|
||||
|
||||
if (note.hasPoll) {
|
||||
poll = await Polls.findOne({ noteId: note.id });
|
||||
}
|
||||
|
||||
let question: string;
|
||||
let question: string | undefined;
|
||||
if (poll) {
|
||||
if (text == null) text = '';
|
||||
const url = `${config.url}/notes/${note.id}`;
|
||||
@@ -144,7 +143,7 @@ export default async function renderNote(note: Note, dive = true): Promise<any>
|
||||
name: text,
|
||||
replies: {
|
||||
type: 'Collection',
|
||||
totalItems: poll.votes[i]
|
||||
totalItems: poll!.votes[i]
|
||||
}
|
||||
}))
|
||||
} : {};
|
||||
@@ -179,5 +178,5 @@ export async function getEmojis(names: string[]): Promise<Emoji[]> {
|
||||
}))
|
||||
);
|
||||
|
||||
return emojis.filter(emoji => emoji != null);
|
||||
return emojis.filter(emoji => emoji != null) as Emoji[];
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* @param prev URL of prev page (optional)
|
||||
* @param next URL of next page (optional)
|
||||
*/
|
||||
export default function(id: string, totalItems: any, orderedItems: any, partOf: string, prev: string, next: string) {
|
||||
export default function(id: string, totalItems: any, orderedItems: any, partOf: string, prev?: string, next?: string) {
|
||||
const page = {
|
||||
id,
|
||||
partOf,
|
||||
|
@@ -9,14 +9,15 @@ 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}`;
|
||||
|
||||
const [avatar, banner, profile] = await Promise.all([
|
||||
DriveFiles.findOne(user.avatarId),
|
||||
DriveFiles.findOne(user.bannerId),
|
||||
UserProfiles.findOne({ userId: user.id })
|
||||
user.avatarId ? DriveFiles.findOne(user.avatarId) : Promise.resolve(undefined),
|
||||
user.bannerId ? DriveFiles.findOne(user.bannerId) : Promise.resolve(undefined),
|
||||
UserProfiles.findOne({ userId: user.id }).then(ensure)
|
||||
]);
|
||||
|
||||
const attachment: {
|
||||
@@ -76,9 +77,7 @@ export async function renderPerson(user: ILocalUser) {
|
||||
...hashtagTags,
|
||||
];
|
||||
|
||||
const keypair = await UserKeypairs.findOne({
|
||||
userId: user.id
|
||||
});
|
||||
const keypair = await UserKeypairs.findOne(user.id).then(ensure);
|
||||
|
||||
return {
|
||||
type: user.isBot ? 'Service' : 'Person',
|
||||
@@ -94,8 +93,8 @@ export async function renderPerson(user: ILocalUser) {
|
||||
preferredUsername: user.username,
|
||||
name: user.name,
|
||||
summary: toHtml(parse(profile.description)),
|
||||
icon: user.avatarId && renderImage(avatar),
|
||||
image: user.bannerId && renderImage(banner),
|
||||
icon: avatar ? renderImage(avatar) : null,
|
||||
image: banner ? renderImage(banner) : null,
|
||||
tag,
|
||||
manuallyApprovesFollowers: user.isLocked,
|
||||
publicKey: renderKey(user, keypair),
|
||||
|
Reference in New Issue
Block a user