Implement remote follow
This commit is contained in:
@ -1,50 +0,0 @@
|
||||
import * as mongo from 'mongodb';
|
||||
import Notification from '../../../models/notification';
|
||||
import Mute from '../../../models/mute';
|
||||
import event from '../../../common/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);
|
||||
});
|
@ -2,10 +2,9 @@
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import User, { pack as packUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import notify from '../../common/notify';
|
||||
import event from '../../../../common/event';
|
||||
import queue from '../../../../queue';
|
||||
|
||||
/**
|
||||
* Follow a user
|
||||
@ -52,33 +51,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
// Create following
|
||||
await Following.insert({
|
||||
const { _id } = await Following.insert({
|
||||
createdAt: new Date(),
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id
|
||||
});
|
||||
|
||||
queue.create('http', { type: 'follow', following: _id }).save();
|
||||
|
||||
// Send response
|
||||
res();
|
||||
|
||||
// Increment following count
|
||||
User.update(follower._id, {
|
||||
$inc: {
|
||||
followingCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Increment followers count
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
followersCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Publish follow event
|
||||
event(follower._id, 'follow', await packUser(followee, follower));
|
||||
event(followee._id, 'followed', await packUser(follower, followee));
|
||||
|
||||
// Notify
|
||||
notify(followee._id, follower._id, 'follow');
|
||||
});
|
||||
|
@ -14,9 +14,9 @@ import DriveFile from '../../../../models/drive-file';
|
||||
import Watching from '../../../../models/post-watching';
|
||||
import ChannelWatching from '../../../../models/channel-watching';
|
||||
import { pack } from '../../../../models/post';
|
||||
import notify from '../../common/notify';
|
||||
import watch from '../../common/watch-post';
|
||||
import event, { pushSw, publishChannelStream } from '../../../../common/event';
|
||||
import notify from '../../../../common/notify';
|
||||
import getAcct from '../../../../common/user/get-acct';
|
||||
import parseAcct from '../../../../common/user/parse-acct';
|
||||
import config from '../../../../conf';
|
||||
|
@ -5,9 +5,9 @@ import $ from 'cafy';
|
||||
import Vote from '../../../../../models/poll-vote';
|
||||
import Post from '../../../../../models/post';
|
||||
import Watching from '../../../../../models/post-watching';
|
||||
import notify from '../../../common/notify';
|
||||
import watch from '../../../common/watch-post';
|
||||
import { publishPostStream } from '../../../../../common/event';
|
||||
import notify from '../../../../../common/notify';
|
||||
|
||||
/**
|
||||
* Vote poll of a post
|
||||
|
@ -6,9 +6,9 @@ import Reaction from '../../../../../models/post-reaction';
|
||||
import Post, { pack as packPost } from '../../../../../models/post';
|
||||
import { pack as packUser } from '../../../../../models/user';
|
||||
import Watching from '../../../../../models/post-watching';
|
||||
import notify from '../../../common/notify';
|
||||
import watch from '../../../common/watch-post';
|
||||
import { publishPostStream, pushSw } from '../../../../../common/event';
|
||||
import notify from '../../../../../common/notify';
|
||||
|
||||
/**
|
||||
* React to a post
|
||||
|
Reference in New Issue
Block a user