2018-04-08 06:55:26 +09:00
|
|
|
|
import * as debug from 'debug';
|
|
|
|
|
|
|
|
|
|
import Resolver from '../../resolver';
|
|
|
|
|
import post from '../../../../services/note/create';
|
2018-06-18 14:28:43 +09:00
|
|
|
|
import { IRemoteUser, IUser } from '../../../../models/user';
|
2018-04-08 06:55:26 +09:00
|
|
|
|
import { IAnnounce, INote } from '../../type';
|
2018-04-17 16:05:50 +09:00
|
|
|
|
import { fetchNote, resolveNote } from '../../models/note';
|
2018-04-29 04:44:58 +09:00
|
|
|
|
import { resolvePerson } from '../../models/person';
|
2018-04-08 06:55:26 +09:00
|
|
|
|
|
|
|
|
|
const log = debug('misskey:activitypub');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* アナウンスアクティビティを捌きます
|
|
|
|
|
*/
|
|
|
|
|
export default async function(resolver: Resolver, actor: IRemoteUser, activity: IAnnounce, note: INote): Promise<void> {
|
|
|
|
|
const uri = activity.id || activity;
|
|
|
|
|
|
2018-06-13 05:15:26 +09:00
|
|
|
|
// アナウンサーが凍結されていたらスキップ
|
|
|
|
|
if (actor.isSuspended) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-08 06:55:26 +09:00
|
|
|
|
if (typeof uri !== 'string') {
|
|
|
|
|
throw new Error('invalid announce');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 既に同じURIを持つものが登録されていないかチェック
|
2018-04-09 04:08:56 +09:00
|
|
|
|
const exist = await fetchNote(uri);
|
2018-04-08 06:55:26 +09:00
|
|
|
|
if (exist) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 04:08:56 +09:00
|
|
|
|
const renote = await resolveNote(note);
|
2018-04-08 06:55:26 +09:00
|
|
|
|
|
|
|
|
|
log(`Creating the (Re)Note: ${uri}`);
|
|
|
|
|
|
|
|
|
|
//#region Visibility
|
|
|
|
|
let visibility = 'public';
|
2018-06-18 14:28:43 +09:00
|
|
|
|
let visibleUsers: IUser[] = [];
|
2018-04-29 04:44:58 +09:00
|
|
|
|
if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
|
|
|
|
if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) {
|
|
|
|
|
visibility = 'home';
|
2018-08-17 06:40:08 +09:00
|
|
|
|
} else if (note.to.includes(`${actor.uri}/followers`)) { // TODO: person.followerと照合するべき?
|
|
|
|
|
visibility = 'followers';
|
2018-04-29 04:44:58 +09:00
|
|
|
|
} else {
|
|
|
|
|
visibility = 'specified';
|
|
|
|
|
visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri)));
|
|
|
|
|
}
|
2018-08-17 06:40:08 +09:00
|
|
|
|
}
|
2018-04-08 06:55:26 +09:00
|
|
|
|
//#endergion
|
|
|
|
|
|
|
|
|
|
await post(actor, {
|
|
|
|
|
createdAt: new Date(activity.published),
|
|
|
|
|
renote,
|
|
|
|
|
visibility,
|
2018-04-29 04:44:58 +09:00
|
|
|
|
visibleUsers,
|
2018-04-08 06:55:26 +09:00
|
|
|
|
uri
|
|
|
|
|
});
|
|
|
|
|
}
|