This commit is contained in:
syuilo 2018-06-02 16:01:32 +09:00
parent 8dfd892b71
commit 4feff8835c
6 changed files with 27 additions and 18 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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
}));

View file

@ -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));
}

View file

@ -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));
}

View file

@ -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');