summaryrefslogtreecommitdiff
path: root/src/server/api/common
diff options
context:
space:
mode:
authorrinsuki <428rinsuki+git@gmail.com>2018-05-17 07:52:24 +0900
committerrinsuki <428rinsuki+git@gmail.com>2018-05-17 07:52:24 +0900
commit829b4012e6dc14eb64a3d8f60826fe9b6a41b40d (patch)
tree42ac37f323db349dca9316e6fdb39fc33b860686 /src/server/api/common
parentadd yarn.lock to gitignore (diff)
parentUpdate deliver.ts (diff)
downloadmisskey-829b4012e6dc14eb64a3d8f60826fe9b6a41b40d.tar.gz
misskey-829b4012e6dc14eb64a3d8f60826fe9b6a41b40d.tar.bz2
misskey-829b4012e6dc14eb64a3d8f60826fe9b6a41b40d.zip
Merge branch 'master' into fix/yarn-lock-ignore
Diffstat (limited to 'src/server/api/common')
-rw-r--r--src/server/api/common/get-friends.ts29
-rw-r--r--src/server/api/common/read-messaging-message.ts2
-rw-r--r--src/server/api/common/read-notification.ts2
3 files changed, 30 insertions, 3 deletions
diff --git a/src/server/api/common/get-friends.ts b/src/server/api/common/get-friends.ts
index c1cc3957d8..50ba71ea96 100644
--- a/src/server/api/common/get-friends.ts
+++ b/src/server/api/common/get-friends.ts
@@ -1,10 +1,10 @@
import * as mongodb from 'mongodb';
import Following from '../../../models/following';
-export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
+export const getFriendIds = async (me: mongodb.ObjectID, includeMe = true) => {
// Fetch relation to other users who the I follows
// SELECT followee
- const myfollowing = await Following
+ const followings = await Following
.find({
followerId: me
}, {
@@ -14,7 +14,7 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
});
// ID list of other users who the I follows
- const myfollowingIds = myfollowing.map(follow => follow.followeeId);
+ const myfollowingIds = followings.map(following => following.followeeId);
if (includeMe) {
myfollowingIds.push(me);
@@ -22,3 +22,26 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
return myfollowingIds;
};
+
+export const getFriends = async (me: mongodb.ObjectID, includeMe = true) => {
+ // Fetch relation to other users who the I follows
+ const followings = await Following
+ .find({
+ followerId: me
+ });
+
+ // ID list of other users who the I follows
+ const myfollowings = followings.map(following => ({
+ id: following.followeeId,
+ stalk: following.stalk
+ }));
+
+ if (includeMe) {
+ myfollowings.push({
+ id: me,
+ stalk: true
+ });
+ }
+
+ return myfollowings;
+};
diff --git a/src/server/api/common/read-messaging-message.ts b/src/server/api/common/read-messaging-message.ts
index c52f9363b5..28854e186e 100644
--- a/src/server/api/common/read-messaging-message.ts
+++ b/src/server/api/common/read-messaging-message.ts
@@ -57,6 +57,8 @@ export default (
.count({
recipientId: userId,
isRead: false
+ }, {
+ limit: 1
});
if (count == 0) {
diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts
index 9bd41519fb..7b9faf4cf4 100644
--- a/src/server/api/common/read-notification.ts
+++ b/src/server/api/common/read-notification.ts
@@ -43,6 +43,8 @@ export default (
.count({
notifieeId: userId,
isRead: false
+ }, {
+ limit: 1
});
if (count == 0) {