misskey/src/server/api/common/get-friends.ts

27 lines
623 B
TypeScript
Raw Normal View History

2016-12-29 07:49:51 +09:00
import * as mongodb from 'mongodb';
import Following from '../models/following';
export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
// Fetch relation to other users who the I follows
// SELECT followee
const myfollowing = await Following
.find({
2018-03-29 14:48:47 +09:00
followerId: me,
2016-12-29 07:49:51 +09:00
// 削除されたドキュメントは除く
2018-03-29 14:48:47 +09:00
deletedAt: { $exists: false }
2016-12-29 07:49:51 +09:00
}, {
2017-01-18 06:10:56 +09:00
fields: {
2018-03-29 14:48:47 +09:00
followeeId: true
2017-01-18 06:10:56 +09:00
}
2017-01-17 11:11:22 +09:00
});
2016-12-29 07:49:51 +09:00
// ID list of other users who the I follows
2018-03-29 14:48:47 +09:00
const myfollowingIds = myfollowing.map(follow => follow.followeeId);
2016-12-29 07:49:51 +09:00
if (includeMe) {
myfollowingIds.push(me);
}
return myfollowingIds;
};