strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
This commit is contained in:
parent
4ee40c3345
commit
987168b863
214 changed files with 939 additions and 785 deletions
|
|
@ -6,9 +6,10 @@ import { Users } from '../../../../models';
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const follower = await Users.findOne({
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default async (actor: IRemoteUser, activity: IAdd): Promise<void> => {
|
|||
|
||||
if (activity.target === actor.featured) {
|
||||
const note = await resolveNote(activity.object);
|
||||
if (note == null) throw new Error('note not found');
|
||||
await addPinned(actor, note.id);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,16 +53,16 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
|
|||
logger.info(`Creating the (Re)Note: ${uri}`);
|
||||
|
||||
//#region Visibility
|
||||
const visibility = getVisibility(activity.to, activity.cc, actor);
|
||||
const visibility = getVisibility(activity.to || [], activity.cc || [], actor);
|
||||
|
||||
let visibleUsers: User[] = [];
|
||||
if (visibility == 'specified') {
|
||||
visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri)));
|
||||
visibleUsers = await Promise.all((note.to || []).map(uri => resolvePerson(uri)));
|
||||
}
|
||||
//#endergion
|
||||
|
||||
await post(actor, {
|
||||
createdAt: new Date(activity.published),
|
||||
createdAt: activity.published ? new Date(activity.published) : null,
|
||||
renote,
|
||||
visibility,
|
||||
visibleUsers,
|
||||
|
|
@ -75,9 +75,6 @@ type visibility = 'public' | 'home' | 'followers' | 'specified';
|
|||
function getVisibility(to: string[], cc: string[], actor: IRemoteUser): visibility {
|
||||
const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
|
||||
|
||||
to = to || [];
|
||||
cc = cc || [];
|
||||
|
||||
if (to.includes(PUBLIC)) {
|
||||
return 'public';
|
||||
} else if (cc.includes(PUBLIC)) {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ const logger = apLogger;
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
const uri = activity.id || activity;
|
||||
|
||||
logger.info(`Block: ${uri}`);
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const blockee = await Users.findOne(id.split('/').pop());
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ import { Users } from '../../../models';
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const followee = await Users.findOne(id.split('/').pop());
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
|||
|
||||
default:
|
||||
apLogger.warn(`unknown activity type: ${(activity as any).type}`);
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Notes } from '../../../models';
|
|||
|
||||
export default async (actor: IRemoteUser, activity: ILike) => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
// Transform:
|
||||
// https://misskey.ex/notes/xxxx to
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@ import { Users } from '../../../../models';
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const id = typeof activity.actor == 'string' ? activity.actor : activity.actor.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const follower = await Users.findOne(id.split('/').pop());
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export default async (actor: IRemoteUser, activity: IRemove): Promise<void> => {
|
|||
|
||||
if (activity.target === actor.featured) {
|
||||
const note = await resolveNote(activity.object);
|
||||
if (note == null) throw new Error('note not found');
|
||||
await removePinned(actor, note.id);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ const logger = apLogger;
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
const uri = activity.id || activity;
|
||||
|
||||
logger.info(`UnBlock: ${uri}`);
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const blockee = await Users.findOne(id.split('/').pop());
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@ import { Users, FollowRequests, Followings } from '../../../../models';
|
|||
|
||||
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
if (!id.startsWith(config.url + '/')) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
const followee = await Users.findOne(id.split('/').pop());
|
||||
|
|
|
|||
|
|
@ -39,6 +39,4 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
|
|||
undoLike(actor, object as ILike);
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { Notes } from '../../../../models';
|
|||
*/
|
||||
export default async (actor: IRemoteUser, activity: ILike): Promise<void> => {
|
||||
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
|
||||
if (id == null) throw 'missing id';
|
||||
|
||||
const noteId = id.split('/').pop();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue