summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-04-01 23:32:46 +0900
committerGitHub <noreply@github.com>2018-04-01 23:32:46 +0900
commit13c2de67a4e5aedc9e70726752c15ff232b7c9fd (patch)
tree3da38725843c01e0dddf9a044e8017018b735325 /src/common
parentAdd missing semicolon (diff)
parentImplement remote follow (diff)
downloadsharkey-13c2de67a4e5aedc9e70726752c15ff232b7c9fd.tar.gz
sharkey-13c2de67a4e5aedc9e70726752c15ff232b7c9fd.tar.bz2
sharkey-13c2de67a4e5aedc9e70726752c15ff232b7c9fd.zip
Merge pull request #1356 from akihikodaki/publickey
Implement remote follow
Diffstat (limited to 'src/common')
-rw-r--r--src/common/notify.ts50
-rw-r--r--src/common/remote/activitypub/renderer/follow.ts8
-rw-r--r--src/common/remote/activitypub/resolve-person.ts1
-rw-r--r--src/common/remote/webfinger.ts2
4 files changed, 60 insertions, 1 deletions
diff --git a/src/common/notify.ts b/src/common/notify.ts
new file mode 100644
index 0000000000..fc65820d3b
--- /dev/null
+++ b/src/common/notify.ts
@@ -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);
+});
diff --git a/src/common/remote/activitypub/renderer/follow.ts b/src/common/remote/activitypub/renderer/follow.ts
new file mode 100644
index 0000000000..05c0ecca06
--- /dev/null
+++ b/src/common/remote/activitypub/renderer/follow.ts
@@ -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
+});
diff --git a/src/common/remote/activitypub/resolve-person.ts b/src/common/remote/activitypub/resolve-person.ts
index b8c507d358..73584946e5 100644
--- a/src/common/remote/activitypub/resolve-person.ts
+++ b/src/common/remote/activitypub/resolve-person.ts
@@ -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,
},
});
diff --git a/src/common/remote/webfinger.ts b/src/common/remote/webfinger.ts
index 9f1b916c9f..039156d776 100644
--- a/src/common/remote/webfinger.ts
+++ b/src/common/remote/webfinger.ts
@@ -1,6 +1,6 @@
const WebFinger = require('webfinger.js');
-const webFinger = new WebFinger({});
+const webFinger = new WebFinger({ tls_only: false });
type ILink = {
href: string;