From 4feff8835cfa80529c14fcbb7a138eeb0a951650 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 2 Jun 2018 16:01:32 +0900 Subject: [PATCH] wip --- src/client/app/common/scripts/streaming/home.ts | 8 +------- src/server/api/endpoints/i/update.ts | 2 +- src/server/api/service/twitter.ts | 4 ++-- src/services/following/requests/accept.ts | 14 ++++++++++---- src/services/following/requests/cancel.ts | 9 +++++++-- src/services/following/requests/create.ts | 8 ++++++-- 6 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/client/app/common/scripts/streaming/home.ts b/src/client/app/common/scripts/streaming/home.ts index c5189ddc7a..f07d0289f6 100644 --- a/src/client/app/common/scripts/streaming/home.ts +++ b/src/client/app/common/scripts/streaming/home.ts @@ -20,7 +20,7 @@ export class HomeStream extends Stream { }, 1000 * 60); // 自分の情報が更新されたとき - this.on('i_updated', i => { + this.on('meUpdated', i => { if (os.debug) { console.log('I updated:', i); } @@ -28,12 +28,6 @@ export class HomeStream extends Stream { os.store.dispatch('mergeMe', i); }); - this.on('reciveFollowRequest', () => { - os.store.dispatch('mergeMe', { - pendingReceivedFollowRequestsCount: (os.store.state.i.pendingReceivedFollowRequestsCount || 0) + 1 - }); - }); - this.on('read_all_notifications', () => { os.store.dispatch('mergeMe', { hasUnreadNotification: false diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 8ee3c84861..5aff6da103 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -99,7 +99,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => { res(iObj); // Publish i updated event - event(user._id, 'i_updated', iObj); + event(user._id, 'meUpdated', iObj); // 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認 if (user.isLocked && isLocked === false) { diff --git a/src/server/api/service/twitter.ts b/src/server/api/service/twitter.ts index 284ae7ee22..8c35509cce 100644 --- a/src/server/api/service/twitter.ts +++ b/src/server/api/service/twitter.ts @@ -49,7 +49,7 @@ router.get('/disconnect/twitter', async ctx => { ctx.body = `Twitterの連携を解除しました :v:`; // Publish i updated event - event(user._id, 'i_updated', await pack(user, user, { + event(user._id, 'meUpdated', await pack(user, user, { detail: true, includeSecrets: true })); @@ -174,7 +174,7 @@ if (config.twitter == null) { ctx.body = `Twitter: @${result.screenName} を、Misskey: @${user.username} に接続しました!`; // Publish i updated event - event(user._id, 'i_updated', await pack(user, user, { + event(user._id, 'meUpdated', await pack(user, user, { detail: true, includeSecrets: true })); diff --git a/src/services/following/requests/accept.ts b/src/services/following/requests/accept.ts index 2dff9b01fe..1b89cdb981 100644 --- a/src/services/following/requests/accept.ts +++ b/src/services/following/requests/accept.ts @@ -1,4 +1,4 @@ -import User, { IUser, isRemoteUser, ILocalUser } from "../../../models/user"; +import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user"; import FollowRequest from "../../../models/follow-request"; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; @@ -7,6 +7,7 @@ import { deliver } from '../../../queue'; import Following from "../../../models/following"; import FollowingLog from "../../../models/following-log"; import FollowedLog from "../../../models/followed-log"; +import event from '../../../publishers/stream'; export default async function(followee: IUser, follower: IUser) { const following = await Following.insert({ @@ -30,13 +31,13 @@ export default async function(followee: IUser, follower: IUser) { deliver(followee as ILocalUser, content, follower.inbox); } - FollowRequest.remove({ + await FollowRequest.remove({ followeeId: followee._id, followerId: follower._id }); //#region Increment following count - User.update({ _id: follower._id }, { + await User.update({ _id: follower._id }, { $inc: { followingCount: 1 } @@ -50,15 +51,20 @@ export default async function(followee: IUser, follower: IUser) { //#endregion //#region Increment followers count - User.update({ _id: followee._id }, { + await User.update({ _id: followee._id }, { $inc: { followersCount: 1 } }); + FollowedLog.insert({ createdAt: following.createdAt, userId: followee._id, count: followee.followersCount + 1 }); //#endregion + + packUser(followee, followee, { + detail: true + }).then(packed => event(followee._id, 'meUpdated', packed)); } diff --git a/src/services/following/requests/cancel.ts b/src/services/following/requests/cancel.ts index 840f70264c..50c95de0eb 100644 --- a/src/services/following/requests/cancel.ts +++ b/src/services/following/requests/cancel.ts @@ -1,9 +1,10 @@ -import User, { IUser, isRemoteUser, ILocalUser } from "../../../models/user"; +import User, { IUser, isRemoteUser, ILocalUser, pack as packUser } from "../../../models/user"; import FollowRequest from "../../../models/follow-request"; import pack from '../../../remote/activitypub/renderer'; import renderFollow from '../../../remote/activitypub/renderer/follow'; import renderUndo from '../../../remote/activitypub/renderer/undo'; import { deliver } from '../../../queue'; +import event from '../../../publishers/stream'; export default async function(followee: IUser, follower: IUser) { if (isRemoteUser(followee)) { @@ -16,9 +17,13 @@ export default async function(followee: IUser, follower: IUser) { followerId: follower._id }); - User.update({ _id: followee._id }, { + await User.update({ _id: followee._id }, { $inc: { pendingReceivedFollowRequestsCount: -1 } }); + + packUser(followee, followee, { + detail: true + }).then(packed => event(followee._id, 'meUpdated', packed)); } diff --git a/src/services/following/requests/create.ts b/src/services/following/requests/create.ts index b69eb5acb0..836d85090d 100644 --- a/src/services/following/requests/create.ts +++ b/src/services/following/requests/create.ts @@ -25,7 +25,7 @@ export default async function(follower: IUser, followee: IUser) { } }); - User.update({ _id: followee._id }, { + await User.update({ _id: followee._id }, { $inc: { pendingReceivedFollowRequestsCount: 1 } @@ -33,7 +33,11 @@ export default async function(follower: IUser, followee: IUser) { // Publish reciveRequest event if (isLocalUser(followee)) { - packUser(follower, followee).then(packed => event(followee._id, 'reciveFollowRequest', packed)), + packUser(follower, followee).then(packed => event(followee._id, 'reciveFollowRequest', packed)); + + packUser(followee, followee, { + detail: true + }).then(packed => event(followee._id, 'meUpdated', packed)); // 通知を作成 notify(followee._id, follower._id, 'reciveFollowRequest');