Merge pull request #1356 from akihikodaki/publickey

Implement remote follow
This commit is contained in:
syuilo
2018-04-01 23:32:46 +09:00
committed by GitHub
11 changed files with 114 additions and 32 deletions

50
src/common/notify.ts Normal file
View File

@@ -0,0 +1,50 @@
import * as mongo from 'mongodb';
import Notification from '../models/notification';
import Mute from '../models/mute';
import event from './event';
import { pack } from '../models/notification';
export default (
notifiee: mongo.ObjectID,
notifier: mongo.ObjectID,
type: string,
content?: any
) => new Promise<any>(async (resolve, reject) => {
if (notifiee.equals(notifier)) {
return resolve();
}
// Create notification
const notification = await Notification.insert(Object.assign({
createdAt: new Date(),
notifieeId: notifiee,
notifierId: notifier,
type: type,
isRead: false
}, content));
resolve(notification);
// Publish notification event
event(notifiee, 'notification',
await pack(notification));
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
setTimeout(async () => {
const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
if (!fresh.isRead) {
//#region ただしミュートしているユーザーからの通知なら無視
const mute = await Mute.find({
muterId: notifiee,
deletedAt: { $exists: false }
});
const mutedUserIds = mute.map(m => m.muteeId.toString());
if (mutedUserIds.indexOf(notifier.toString()) != -1) {
return;
}
//#endregion
event(notifiee, 'unread_notification', await pack(notification));
}
}, 3000);
});

View File

@@ -0,0 +1,8 @@
import config from '../../../../conf';
import { IRemoteAccount } from '../../../../models/user';
export default ({ username }, { account }) => ({
type: 'Follow',
actor: `${config.url}/@${username}`,
object: (account as IRemoteAccount).uri
});

View File

@@ -66,6 +66,7 @@ export default async (value, usernameLower, hostLower, acctLower) => {
id: object.publicKey.id,
publicKeyPem: object.publicKey.publicKeyPem
},
inbox: object.inbox,
uri: object.id,
},
});

View File

@@ -1,6 +1,6 @@
const WebFinger = require('webfinger.js');
const webFinger = new WebFinger({});
const webFinger = new WebFinger({ tls_only: false });
type ILink = {
href: string;