summaryrefslogtreecommitdiff
path: root/src/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api')
-rw-r--r--src/server/api/common/read-messaging-message.ts8
-rw-r--r--src/server/api/common/read-notification.ts8
-rw-r--r--src/server/api/endpoints.ts50
-rw-r--r--src/server/api/endpoints/following/create.ts4
-rw-r--r--src/server/api/endpoints/following/delete.ts4
-rw-r--r--src/server/api/endpoints/following/requests/accept.ts26
-rw-r--r--src/server/api/endpoints/following/requests/cancel.ts26
-rw-r--r--src/server/api/endpoints/following/requests/list.ts14
-rw-r--r--src/server/api/endpoints/following/requests/reject.ts26
-rw-r--r--src/server/api/endpoints/hashtags/trend.ts86
-rw-r--r--src/server/api/endpoints/i/update.ts73
-rw-r--r--src/server/api/endpoints/i/update_home.ts51
-rw-r--r--src/server/api/endpoints/i/update_mobile_home.ts52
-rw-r--r--src/server/api/endpoints/i/update_widget.ts79
-rw-r--r--src/server/api/endpoints/messaging/messages.ts7
-rw-r--r--src/server/api/endpoints/messaging/messages/create.ts7
-rw-r--r--src/server/api/endpoints/messaging/unread.ts29
-rw-r--r--src/server/api/endpoints/notes.ts4
-rw-r--r--src/server/api/endpoints/notes/create.ts2
-rw-r--r--src/server/api/endpoints/notes/delete.ts26
-rw-r--r--src/server/api/endpoints/notes/global-timeline.ts36
-rw-r--r--src/server/api/endpoints/notes/local-timeline.ts40
-rw-r--r--src/server/api/endpoints/notes/replies.ts26
-rw-r--r--src/server/api/endpoints/notes/search_by_tag.ts329
-rw-r--r--src/server/api/endpoints/notes/timeline.ts10
-rw-r--r--src/server/api/endpoints/notes/user-list-timeline.ts10
-rw-r--r--src/server/api/endpoints/notifications/get_unread_count.ts28
-rw-r--r--src/server/api/endpoints/notifications/mark_as_read_all.ts11
-rw-r--r--src/server/api/endpoints/users/recommendation.ts1
-rw-r--r--src/server/api/private/signup.ts48
-rw-r--r--src/server/api/service/github.ts2
-rw-r--r--src/server/api/service/twitter.ts4
-rw-r--r--src/server/api/stream/notes-stats.ts35
-rw-r--r--src/server/api/stream/server-stats.ts35
-rw-r--r--src/server/api/stream/server.ts19
-rw-r--r--src/server/api/streaming.ts12
36 files changed, 907 insertions, 321 deletions
diff --git a/src/server/api/common/read-messaging-message.ts b/src/server/api/common/read-messaging-message.ts
index 28854e186e..fd5e9f242c 100644
--- a/src/server/api/common/read-messaging-message.ts
+++ b/src/server/api/common/read-messaging-message.ts
@@ -4,6 +4,7 @@ import { IMessagingMessage as IMessage } from '../../../models/messaging-message
import publishUserStream from '../../../publishers/stream';
import { publishMessagingStream } from '../../../publishers/stream';
import { publishMessagingIndexStream } from '../../../publishers/stream';
+import User from '../../../models/user';
/**
* Mark as read message(s)
@@ -62,6 +63,13 @@ export default (
});
if (count == 0) {
+ // Update flag
+ User.update({ _id: userId }, {
+ $set: {
+ hasUnreadMessagingMessage: false
+ }
+ });
+
// 全ての(いままで未読だった)自分宛てのメッセージを(これで)読みましたよというイベントを発行
publishUserStream(userId, 'read_all_messaging_messages');
}
diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts
index cdb87a4114..6505c58c39 100644
--- a/src/server/api/common/read-notification.ts
+++ b/src/server/api/common/read-notification.ts
@@ -2,6 +2,7 @@ import * as mongo from 'mongodb';
import { default as Notification, INotification } from '../../../models/notification';
import publishUserStream from '../../../publishers/stream';
import Mute from '../../../models/mute';
+import User from '../../../models/user';
/**
* Mark as read notification(s)
@@ -57,6 +58,13 @@ export default (
});
if (count == 0) {
+ // Update flag
+ User.update({ _id: userId }, {
+ $set: {
+ hasUnreadNotification: false
+ }
+ });
+
// 全ての(いままで未読だった)通知を(これで)読みましたよというイベントを発行
publishUserStream(userId, 'read_all_notifications');
}
diff --git a/src/server/api/endpoints.ts b/src/server/api/endpoints.ts
index 892da3540f..5f0a020d6f 100644
--- a/src/server/api/endpoints.ts
+++ b/src/server/api/endpoints.ts
@@ -190,6 +190,11 @@ const endpoints: Endpoint[] = [
secure: true
},
{
+ name: 'i/update_widget',
+ withCredential: true,
+ secure: true
+ },
+ {
name: 'i/change_password',
withCredential: true,
secure: true
@@ -280,11 +285,6 @@ const endpoints: Endpoint[] = [
},
{
- name: 'notifications/get_unread_count',
- withCredential: true,
- kind: 'notification-read'
- },
- {
name: 'notifications/delete',
withCredential: true,
kind: 'notification-write'
@@ -454,6 +454,26 @@ const endpoints: Endpoint[] = [
kind: 'following-write'
},
{
+ name: 'following/requests/accept',
+ withCredential: true,
+ kind: 'following-write'
+ },
+ {
+ name: 'following/requests/reject',
+ withCredential: true,
+ kind: 'following-write'
+ },
+ {
+ name: 'following/requests/cancel',
+ withCredential: true,
+ kind: 'following-write'
+ },
+ {
+ name: 'following/requests/list',
+ withCredential: true,
+ kind: 'following-read'
+ },
+ {
name: 'following/stalk',
withCredential: true,
limit: {
@@ -495,12 +515,20 @@ const endpoints: Endpoint[] = [
kind: 'note-write'
},
{
+ name: 'notes/delete',
+ withCredential: true,
+ kind: 'note-write'
+ },
+ {
name: 'notes/renotes'
},
{
name: 'notes/search'
},
{
+ name: 'notes/search_by_tag'
+ },
+ {
name: 'notes/timeline',
withCredential: true,
limit: {
@@ -510,7 +538,6 @@ const endpoints: Endpoint[] = [
},
{
name: 'notes/local-timeline',
- withCredential: true,
limit: {
duration: ms('10minutes'),
max: 100
@@ -518,7 +545,6 @@ const endpoints: Endpoint[] = [
},
{
name: 'notes/global-timeline',
- withCredential: true,
limit: {
duration: ms('10minutes'),
max: 100
@@ -557,7 +583,7 @@ const endpoints: Endpoint[] = [
withCredential: true,
limit: {
duration: ms('1hour'),
- max: 100
+ max: 300
},
kind: 'reaction-write'
},
@@ -603,12 +629,12 @@ const endpoints: Endpoint[] = [
},
{
- name: 'messaging/history',
- withCredential: true,
- kind: 'messaging-read'
+ name: 'hashtags/trend',
+ withCredential: true
},
+
{
- name: 'messaging/unread',
+ name: 'messaging/history',
withCredential: true,
kind: 'messaging-read'
},
diff --git a/src/server/api/endpoints/following/create.ts b/src/server/api/endpoints/following/create.ts
index 766a8c03d0..b9610658d1 100644
--- a/src/server/api/endpoints/following/create.ts
+++ b/src/server/api/endpoints/following/create.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../cafy-id';
-import User from '../../../../models/user';
+import User, { pack } from '../../../../models/user';
import Following from '../../../../models/following';
import create from '../../../../services/following/create';
@@ -49,5 +49,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
create(follower, followee);
// Send response
- res();
+ res(await pack(followee._id, user));
});
diff --git a/src/server/api/endpoints/following/delete.ts b/src/server/api/endpoints/following/delete.ts
index 396b19a6f6..4fcdaf5a82 100644
--- a/src/server/api/endpoints/following/delete.ts
+++ b/src/server/api/endpoints/following/delete.ts
@@ -2,7 +2,7 @@
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../cafy-id';
-import User from '../../../../models/user';
+import User, { pack } from '../../../../models/user';
import Following from '../../../../models/following';
import deleteFollowing from '../../../../services/following/delete';
@@ -49,5 +49,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
deleteFollowing(follower, followee);
// Send response
- res();
+ res(await pack(followee._id, user));
});
diff --git a/src/server/api/endpoints/following/requests/accept.ts b/src/server/api/endpoints/following/requests/accept.ts
new file mode 100644
index 0000000000..705d3b161a
--- /dev/null
+++ b/src/server/api/endpoints/following/requests/accept.ts
@@ -0,0 +1,26 @@
+import $ from 'cafy'; import ID from '../../../../../cafy-id';
+import acceptFollowRequest from '../../../../../services/following/requests/accept';
+import User from '../../../../../models/user';
+
+/**
+ * Accept a follow request
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'userId' parameter
+ const [followerId, followerIdErr] = $.type(ID).get(params.userId);
+ if (followerIdErr) return rej('invalid userId param');
+
+ // Fetch follower
+ const follower = await User.findOne({
+ _id: followerId
+ });
+
+ if (follower === null) {
+ return rej('follower not found');
+ }
+
+ await acceptFollowRequest(user, follower);
+
+ // Send response
+ res();
+});
diff --git a/src/server/api/endpoints/following/requests/cancel.ts b/src/server/api/endpoints/following/requests/cancel.ts
new file mode 100644
index 0000000000..388a54890b
--- /dev/null
+++ b/src/server/api/endpoints/following/requests/cancel.ts
@@ -0,0 +1,26 @@
+import $ from 'cafy'; import ID from '../../../../../cafy-id';
+import cancelFollowRequest from '../../../../../services/following/requests/cancel';
+import User, { pack } from '../../../../../models/user';
+
+/**
+ * Cancel a follow request
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'userId' parameter
+ const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
+ if (followeeIdErr) return rej('invalid userId param');
+
+ // Fetch followee
+ const followee = await User.findOne({
+ _id: followeeId
+ });
+
+ if (followee === null) {
+ return rej('followee not found');
+ }
+
+ await cancelFollowRequest(followee, user);
+
+ // Send response
+ res(await pack(followee._id, user));
+});
diff --git a/src/server/api/endpoints/following/requests/list.ts b/src/server/api/endpoints/following/requests/list.ts
new file mode 100644
index 0000000000..e8364335d1
--- /dev/null
+++ b/src/server/api/endpoints/following/requests/list.ts
@@ -0,0 +1,14 @@
+//import $ from 'cafy'; import ID from '../../../../../cafy-id';
+import FollowRequest, { pack } from '../../../../../models/follow-request';
+
+/**
+ * Get all pending received follow requests
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ const reqs = await FollowRequest.find({
+ followeeId: user._id
+ });
+
+ // Send response
+ res(await Promise.all(reqs.map(req => pack(req))));
+});
diff --git a/src/server/api/endpoints/following/requests/reject.ts b/src/server/api/endpoints/following/requests/reject.ts
new file mode 100644
index 0000000000..1cfb562b55
--- /dev/null
+++ b/src/server/api/endpoints/following/requests/reject.ts
@@ -0,0 +1,26 @@
+import $ from 'cafy'; import ID from '../../../../../cafy-id';
+import rejectFollowRequest from '../../../../../services/following/requests/reject';
+import User from '../../../../../models/user';
+
+/**
+ * Reject a follow request
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'userId' parameter
+ const [followerId, followerIdErr] = $.type(ID).get(params.userId);
+ if (followerIdErr) return rej('invalid userId param');
+
+ // Fetch follower
+ const follower = await User.findOne({
+ _id: followerId
+ });
+
+ if (follower === null) {
+ return rej('follower not found');
+ }
+
+ await rejectFollowRequest(user, follower);
+
+ // Send response
+ res();
+});
diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts
new file mode 100644
index 0000000000..faf4e582fa
--- /dev/null
+++ b/src/server/api/endpoints/hashtags/trend.ts
@@ -0,0 +1,86 @@
+import Note from '../../../../models/note';
+
+/**
+ * Get trends of hashtags
+ */
+module.exports = () => new Promise(async (res, rej) => {
+ const data = await Note.aggregate([{
+ $match: {
+ createdAt: {
+ $gt: new Date(Date.now() - 1000 * 60 * 60)
+ },
+ tags: {
+ $exists: true,
+ $ne: []
+ }
+ }
+ }, {
+ $unwind: '$tags'
+ }, {
+ $group: {
+ _id: { tags: '$tags', userId: '$userId' }
+ }
+ }]) as Array<{
+ _id: {
+ tags: string;
+ userId: any;
+ }
+ }>;
+
+ if (data.length == 0) {
+ return res([]);
+ }
+
+ const tags = [];
+
+ data.map(x => x._id).forEach(x => {
+ const i = tags.findIndex(tag => tag.name == x.tags);
+ if (i != -1) {
+ tags[i].count++;
+ } else {
+ tags.push({
+ name: x.tags,
+ count: 1
+ });
+ }
+ });
+
+ const hots = tags
+ .sort((a, b) => b.count - a.count)
+ .map(tag => tag.name)
+ .slice(0, 5);
+
+ const countPromises: Array<Promise<any[]>> = [];
+
+ const range = 20;
+
+ // 10分
+ const interval = 1000 * 60 * 10;
+
+ for (let i = 0; i < range; i++) {
+ countPromises.push(Promise.all(hots.map(tag => Note.distinct('userId', {
+ tags: tag,
+ createdAt: {
+ $lt: new Date(Date.now() - (interval * i)),
+ $gt: new Date(Date.now() - (interval * (i + 1)))
+ }
+ }))));
+ }
+
+ const countsLog = await Promise.all(countPromises);
+
+ const totalCounts: any = await Promise.all(hots.map(tag => Note.distinct('userId', {
+ tags: tag,
+ createdAt: {
+ $gt: new Date(Date.now() - (interval * range))
+ }
+ })));
+
+ const stats = hots.map((tag, i) => ({
+ tag,
+ chart: countsLog.map(counts => counts[i].length),
+ usersCount: totalCounts[i].length
+ }));
+
+ res(stats);
+});
diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts
index 6e0c5b8515..1a1da997c9 100644
--- a/src/server/api/endpoints/i/update.ts
+++ b/src/server/api/endpoints/i/update.ts
@@ -5,6 +5,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id';
import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../../../models/user';
import event from '../../../../publishers/stream';
import DriveFile from '../../../../models/drive-file';
+import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
/**
* Update myself
@@ -12,50 +13,62 @@ import DriveFile from '../../../../models/drive-file';
module.exports = async (params, user, app) => new Promise(async (res, rej) => {
const isSecure = user != null && app == null;
+ const updates = {} as any;
+
// Get 'name' parameter
const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name);
if (nameErr) return rej('invalid name param');
- if (name) user.name = name;
+ if (name) updates.name = name;
// Get 'description' parameter
const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description);
if (descriptionErr) return rej('invalid description param');
- if (description !== undefined) user.description = description;
+ if (description !== undefined) updates.description = description;
// Get 'location' parameter
const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location);
if (locationErr) return rej('invalid location param');
- if (location !== undefined) user.profile.location = location;
+ if (location !== undefined) updates['profile.location'] = location;
// Get 'birthday' parameter
const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday);
if (birthdayErr) return rej('invalid birthday param');
- if (birthday !== undefined) user.profile.birthday = birthday;
+ if (birthday !== undefined) updates['profile.birthday'] = birthday;
// Get 'avatarId' parameter
- const [avatarId, avatarIdErr] = $.type(ID).optional().get(params.avatarId);
+ const [avatarId, avatarIdErr] = $.type(ID).optional().nullable().get(params.avatarId);
if (avatarIdErr) return rej('invalid avatarId param');
- if (avatarId) user.avatarId = avatarId;
+ if (avatarId !== undefined) updates.avatarId = avatarId;
// Get 'bannerId' parameter
- const [bannerId, bannerIdErr] = $.type(ID).optional().get(params.bannerId);
+ const [bannerId, bannerIdErr] = $.type(ID).optional().nullable().get(params.bannerId);
if (bannerIdErr) return rej('invalid bannerId param');
- if (bannerId) user.bannerId = bannerId;
+ if (bannerId !== undefined) updates.bannerId = bannerId;
+
+ // Get 'wallpaperId' parameter
+ const [wallpaperId, wallpaperIdErr] = $.type(ID).optional().nullable().get(params.wallpaperId);
+ if (wallpaperIdErr) return rej('invalid wallpaperId param');
+ if (wallpaperId !== undefined) updates.wallpaperId = wallpaperId;
+
+ // Get 'isLocked' parameter
+ const [isLocked, isLockedErr] = $.bool.optional().get(params.isLocked);
+ if (isLockedErr) return rej('invalid isLocked param');
+ if (isLocked != null) updates.isLocked = isLocked;
// Get 'isBot' parameter
const [isBot, isBotErr] = $.bool.optional().get(params.isBot);
if (isBotErr) return rej('invalid isBot param');
- if (isBot != null) user.isBot = isBot;
+ if (isBot != null) updates.isBot = isBot;
// Get 'isCat' parameter
const [isCat, isCatErr] = $.bool.optional().get(params.isCat);
if (isCatErr) return rej('invalid isCat param');
- if (isCat != null) user.isCat = isCat;
+ if (isCat != null) updates.isCat = isCat;
// Get 'autoWatch' parameter
const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
if (autoWatchErr) return rej('invalid autoWatch param');
- if (autoWatch != null) user.settings.autoWatch = autoWatch;
+ if (autoWatch != null) updates['settings.autoWatch'] = autoWatch;
if (avatarId) {
const avatar = await DriveFile.findOne({
@@ -63,7 +76,7 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
});
if (avatar != null && avatar.metadata.properties.avgColor) {
- user.avatarColor = avatar.metadata.properties.avgColor;
+ updates.avatarColor = avatar.metadata.properties.avgColor;
}
}
@@ -73,27 +86,26 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
});
if (banner != null && banner.metadata.properties.avgColor) {
- user.bannerColor = banner.metadata.properties.avgColor;
+ updates.bannerColor = banner.metadata.properties.avgColor;
}
}
- await User.update(user._id, {
- $set: {
- name: user.name,
- description: user.description,
- avatarId: user.avatarId,
- avatarColor: user.avatarColor,
- bannerId: user.bannerId,
- bannerColor: user.bannerColor,
- profile: user.profile,
- isBot: user.isBot,
- isCat: user.isCat,
- settings: user.settings
+ if (wallpaperId) {
+ const wallpaper = await DriveFile.findOne({
+ _id: wallpaperId
+ });
+
+ if (wallpaper != null && wallpaper.metadata.properties.avgColor) {
+ updates.wallpaperColor = wallpaper.metadata.properties.avgColor;
}
+ }
+
+ await User.update(user._id, {
+ $set: updates
});
// Serialize
- const iObj = await pack(user, user, {
+ const iObj = await pack(user._id, user, {
detail: true,
includeSecrets: isSecure
});
@@ -101,6 +113,11 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
// Send response
res(iObj);
- // Publish i updated event
- event(user._id, 'i_updated', iObj);
+ // Publish meUpdated event
+ event(user._id, 'meUpdated', iObj);
+
+ // 鍵垢を解除したとき、溜まっていたフォローリクエストがあるならすべて承認
+ if (user.isLocked && isLocked === false) {
+ acceptAllFollowRequests(user);
+ }
});
diff --git a/src/server/api/endpoints/i/update_home.ts b/src/server/api/endpoints/i/update_home.ts
index 8ce551957e..48f6dbbb7a 100644
--- a/src/server/api/endpoints/i/update_home.ts
+++ b/src/server/api/endpoints/i/update_home.ts
@@ -1,6 +1,3 @@
-/**
- * Module dependencies
- */
import $ from 'cafy';
import User from '../../../../models/user';
import event from '../../../../publishers/stream';
@@ -13,50 +10,16 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
.have('id', $.str)
.have('place', $.str)
.have('data', $.obj))
- .optional()
.get(params.home);
if (homeErr) return rej('invalid home param');
- // Get 'id' parameter
- const [id, idErr] = $.str.optional().get(params.id);
- if (idErr) return rej('invalid id param');
+ await User.update(user._id, {
+ $set: {
+ 'clientSettings.home': home
+ }
+ });
- // Get 'data' parameter
- const [data, dataErr] = $.obj.optional().get(params.data);
- if (dataErr) return rej('invalid data param');
+ res();
- if (home) {
- await User.update(user._id, {
- $set: {
- 'clientSettings.home': home
- }
- });
-
- res();
-
- event(user._id, 'home_updated', {
- home
- });
- } else {
- if (id == null && data == null) return rej('you need to set id and data params if home param unset');
-
- const _home = user.clientSettings.home;
- const widget = _home.find(w => w.id == id);
-
- if (widget == null) return rej('widget not found');
-
- widget.data = data;
-
- await User.update(user._id, {
- $set: {
- 'clientSettings.home': _home
- }
- });
-
- res();
-
- event(user._id, 'home_updated', {
- id, data
- });
- }
+ event(user._id, 'home_updated', home);
});
diff --git a/src/server/api/endpoints/i/update_mobile_home.ts b/src/server/api/endpoints/i/update_mobile_home.ts
index d79a77072b..d285a0a72d 100644
--- a/src/server/api/endpoints/i/update_mobile_home.ts
+++ b/src/server/api/endpoints/i/update_mobile_home.ts
@@ -1,6 +1,3 @@
-/**
- * Module dependencies
- */
import $ from 'cafy';
import User from '../../../../models/user';
import event from '../../../../publishers/stream';
@@ -12,49 +9,16 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
.have('name', $.str)
.have('id', $.str)
.have('data', $.obj))
- .optional().get(params.home);
+ .get(params.home);
if (homeErr) return rej('invalid home param');
- // Get 'id' parameter
- const [id, idErr] = $.str.optional().get(params.id);
- if (idErr) return rej('invalid id param');
+ await User.update(user._id, {
+ $set: {
+ 'clientSettings.mobileHome': home
+ }
+ });
- // Get 'data' parameter
- const [data, dataErr] = $.obj.optional().get(params.data);
- if (dataErr) return rej('invalid data param');
+ res();
- if (home) {
- await User.update(user._id, {
- $set: {
- 'clientSettings.mobileHome': home
- }
- });
-
- res();
-
- event(user._id, 'mobile_home_updated', {
- home
- });
- } else {
- if (id == null && data == null) return rej('you need to set id and data params if home param unset');
-
- const _home = user.clientSettings.mobileHome || [];
- const widget = _home.find(w => w.id == id);
-
- if (widget == null) return rej('widget not found');
-
- widget.data = data;
-
- await User.update(user._id, {
- $set: {
- 'clientSettings.mobileHome': _home
- }
- });
-
- res();
-
- event(user._id, 'mobile_home_updated', {
- id, data
- });
- }
+ event(user._id, 'mobile_home_updated', home);
});
diff --git a/src/server/api/endpoints/i/update_widget.ts b/src/server/api/endpoints/i/update_widget.ts
new file mode 100644
index 0000000000..b37761bde1
--- /dev/null
+++ b/src/server/api/endpoints/i/update_widget.ts
@@ -0,0 +1,79 @@
+import $ from 'cafy';
+import User from '../../../../models/user';
+import event from '../../../../publishers/stream';
+
+module.exports = async (params, user) => new Promise(async (res, rej) => {
+ // Get 'id' parameter
+ const [id, idErr] = $.str.get(params.id);
+ if (idErr) return rej('invalid id param');
+
+ // Get 'data' parameter
+ const [data, dataErr] = $.obj.get(params.data);
+ if (dataErr) return rej('invalid data param');
+
+ if (id == null && data == null) return rej('you need to set id and data params if home param unset');
+
+ let widget;
+
+ //#region Desktop home
+ if (widget == null && user.clientSettings.home) {
+ const desktopHome = user.clientSettings.home;
+ widget = desktopHome.find(w => w.id == id);
+ if (widget) {
+ widget.data = data;
+
+ await User.update(user._id, {
+ $set: {
+ 'clientSettings.home': desktopHome
+ }
+ });
+ }
+ }
+ //#endregion
+
+ //#region Mobile home
+ if (widget == null && user.clientSettings.mobileHome) {
+ const mobileHome = user.clientSettings.mobileHome;
+ widget = mobileHome.find(w => w.id == id);
+ if (widget) {
+ widget.data = data;
+
+ await User.update(user._id, {
+ $set: {
+ 'clientSettings.mobileHome': mobileHome
+ }
+ });
+ }
+ }
+ //#endregion
+
+ //#region Deck
+ if (widget == null && user.clientSettings.deck && user.clientSettings.deck.columns) {
+ const deck = user.clientSettings.deck;
+ deck.columns.filter(c => c.type == 'widgets').forEach(c => {
+ c.widgets.forEach(w => {
+ if (w.id == id) widget = w;
+ });
+ });
+ if (widget) {
+ widget.data = data;
+
+ await User.update(user._id, {
+ $set: {
+ 'clientSettings.deck': deck
+ }
+ });
+ }
+ }
+ //#endregion
+
+ if (widget) {
+ event(user._id, 'widgetUpdated', {
+ id, data
+ });
+
+ res();
+ } else {
+ rej('widget not found');
+ }
+});
diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts
index 0338aba68a..9c3a48334b 100644
--- a/src/server/api/endpoints/messaging/messages.ts
+++ b/src/server/api/endpoints/messaging/messages.ts
@@ -1,6 +1,3 @@
-/**
- * Module dependencies
- */
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Message from '../../../../models/messaging-message';
import User from '../../../../models/user';
@@ -9,10 +6,6 @@ import read from '../../common/read-messaging-message';
/**
* Get messages
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'userId' parameter
diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts
index db471839e7..41238de1e1 100644
--- a/src/server/api/endpoints/messaging/messages/create.ts
+++ b/src/server/api/endpoints/messaging/messages/create.ts
@@ -91,6 +91,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
publishUserStream(message.recipientId, 'messaging_message', messageObj);
+ // Update flag
+ User.update({ _id: recipient._id }, {
+ $set: {
+ hasUnreadMessagingMessage: true
+ }
+ });
+
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
setTimeout(async () => {
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
diff --git a/src/server/api/endpoints/messaging/unread.ts b/src/server/api/endpoints/messaging/unread.ts
deleted file mode 100644
index 1d83af501d..0000000000
--- a/src/server/api/endpoints/messaging/unread.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Module dependencies
- */
-import Message from '../../../../models/messaging-message';
-import Mute from '../../../../models/mute';
-
-/**
- * Get count of unread messages
- */
-module.exports = (params, user) => new Promise(async (res, rej) => {
- const mute = await Mute.find({
- muterId: user._id,
- deletedAt: { $exists: false }
- });
- const mutedUserIds = mute.map(m => m.muteeId);
-
- const count = await Message
- .count({
- userId: {
- $nin: mutedUserIds
- },
- recipientId: user._id,
- isRead: false
- });
-
- res({
- count: count
- });
-});
diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts
index 21946d1bd3..e6fe80ac8a 100644
--- a/src/server/api/endpoints/notes.ts
+++ b/src/server/api/endpoints/notes.ts
@@ -53,7 +53,9 @@ module.exports = (params) => new Promise(async (res, rej) => {
const sort = {
_id: -1
};
- const query = {} as any;
+ const query = {
+ visibility: 'public'
+ } as any;
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts
index 182359f637..446764e1d6 100644
--- a/src/server/api/endpoints/notes/create.ts
+++ b/src/server/api/endpoints/notes/create.ts
@@ -140,7 +140,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
}
// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
- if (text === undefined && files === null && renote === null && poll === undefined) {
+ if ((text === undefined || text === null) && files === null && renote === null && poll === undefined) {
return rej('text, mediaIds, renoteId or poll is required');
}
diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts
new file mode 100644
index 0000000000..9bbb1541d6
--- /dev/null
+++ b/src/server/api/endpoints/notes/delete.ts
@@ -0,0 +1,26 @@
+import $ from 'cafy'; import ID from '../../../../cafy-id';
+import Note from '../../../../models/note';
+import deleteNote from '../../../../services/note/delete';
+
+/**
+ * Delete a note
+ */
+module.exports = (params, user) => new Promise(async (res, rej) => {
+ // Get 'noteId' parameter
+ const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
+ if (noteIdErr) return rej('invalid noteId param');
+
+ // Fetch note
+ const note = await Note.findOne({
+ _id: noteId,
+ userId: user._id
+ });
+
+ if (note === null) {
+ return rej('note not found');
+ }
+
+ await deleteNote(user, note);
+
+ res();
+});
diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts
index d22a1763de..2d4f2b6368 100644
--- a/src/server/api/endpoints/notes/global-timeline.ts
+++ b/src/server/api/endpoints/notes/global-timeline.ts
@@ -9,7 +9,7 @@ import { pack } from '../../../../models/note';
/**
* Get timeline of global
*/
-module.exports = async (params, user, app) => {
+module.exports = async (params, user) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
@@ -35,10 +35,14 @@ module.exports = async (params, user, app) => {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
+ // Get 'mediaOnly' parameter
+ const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
+ if (mediaOnlyErr) throw 'invalid mediaOnly param';
+
// ミュートしているユーザーを取得
- const mutedUserIds = (await Mute.find({
+ const mutedUserIds = user ? (await Mute.find({
muterId: user._id
- })).map(m => m.muteeId);
+ })).map(m => m.muteeId) : null;
//#region Construct query
const sort = {
@@ -46,17 +50,27 @@ module.exports = async (params, user, app) => {
};
const query = {
- // mute
- userId: {
+ // public only
+ visibility: 'public'
+ } as any;
+
+ if (mutedUserIds && mutedUserIds.length > 0) {
+ query.userId = {
$nin: mutedUserIds
- },
- '_reply.userId': {
+ };
+
+ query['_reply.userId'] = {
$nin: mutedUserIds
- },
- '_renote.userId': {
+ };
+
+ query['_renote.userId'] = {
$nin: mutedUserIds
- }
- } as any;
+ };
+ }
+
+ if (mediaOnly) {
+ query.mediaIds = { $exists: true, $ne: [] };
+ }
if (sinceId) {
sort._id = 1;
diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts
index e7ebe5d960..734cc9af0a 100644
--- a/src/server/api/endpoints/notes/local-timeline.ts
+++ b/src/server/api/endpoints/notes/local-timeline.ts
@@ -9,7 +9,7 @@ import { pack } from '../../../../models/note';
/**
* Get timeline of local
*/
-module.exports = async (params, user, app) => {
+module.exports = async (params, user) => {
// Get 'limit' parameter
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
if (limitErr) throw 'invalid limit param';
@@ -35,10 +35,14 @@ module.exports = async (params, user, app) => {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
+ // Get 'mediaOnly' parameter
+ const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
+ if (mediaOnlyErr) throw 'invalid mediaOnly param';
+
// ミュートしているユーザーを取得
- const mutedUserIds = (await Mute.find({
+ const mutedUserIds = user ? (await Mute.find({
muterId: user._id
- })).map(m => m.muteeId);
+ })).map(m => m.muteeId) : null;
//#region Construct query
const sort = {
@@ -46,21 +50,31 @@ module.exports = async (params, user, app) => {
};
const query = {
- // mute
- userId: {
- $nin: mutedUserIds
- },
- '_reply.userId': {
- $nin: mutedUserIds
- },
- '_renote.userId': {
- $nin: mutedUserIds
- },
+ // public only
+ visibility: 'public',
// local
'_user.host': null
} as any;
+ if (mutedUserIds && mutedUserIds.length > 0) {
+ query.userId = {
+ $nin: mutedUserIds
+ };
+
+ query['_reply.userId'] = {
+ $nin: mutedUserIds
+ };
+
+ query['_renote.userId'] = {
+ $nin: mutedUserIds
+ };
+ }
+
+ if (mediaOnly) {
+ query.mediaIds = { $exists: true, $ne: [] };
+ }
+
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts
index 11d221d8f7..608027f6b1 100644
--- a/src/server/api/endpoints/notes/replies.ts
+++ b/src/server/api/endpoints/notes/replies.ts
@@ -1,15 +1,8 @@
-/**
- * Module dependencies
- */
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
/**
- * Show a replies of a note
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
+ * Get replies of a note
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
@@ -24,10 +17,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
- // Get 'sort' parameter
- const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
- if (sortError) return rej('invalid sort param');
-
// Lookup note
const note = await Note.findOne({
_id: noteId
@@ -37,17 +26,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('note not found');
}
- // Issue query
- const replies = await Note
- .find({ replyId: note._id }, {
- limit: limit,
- skip: offset,
- sort: {
- _id: sort == 'asc' ? 1 : -1
- }
- });
+ const ids = (note._replyIds || []).slice(offset, offset + limit);
// Serialize
- res(await Promise.all(replies.map(async note =>
- await pack(note, user))));
+ res(await Promise.all(ids.map(id => pack(id, user))));
});
diff --git a/src/server/api/endpoints/notes/search_by_tag.ts b/src/server/api/endpoints/notes/search_by_tag.ts
new file mode 100644
index 0000000000..4cf070f4ce
--- /dev/null
+++ b/src/server/api/endpoints/notes/search_by_tag.ts
@@ -0,0 +1,329 @@
+import $ from 'cafy'; import ID from '../../../../cafy-id';
+import Note from '../../../../models/note';
+import User from '../../../../models/user';
+import Mute from '../../../../models/mute';
+import { getFriendIds } from '../../common/get-friends';
+import { pack } from '../../../../models/note';
+
+/**
+ * Search notes by tag
+ */
+module.exports = (params, me) => new Promise(async (res, rej) => {
+ // Get 'tag' parameter
+ const [tag, tagError] = $.str.get(params.tag);
+ if (tagError) return rej('invalid tag param');
+
+ // Get 'includeUserIds' parameter
+ const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional().get(params.includeUserIds);
+ if (includeUserIdsErr) return rej('invalid includeUserIds param');
+
+ // Get 'excludeUserIds' parameter
+ const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional().get(params.excludeUserIds);
+ if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
+
+ // Get 'includeUserUsernames' parameter
+ const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional().get(params.includeUserUsernames);
+ if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
+
+ // Get 'excludeUserUsernames' parameter
+ const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional().get(params.excludeUserUsernames);
+ if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
+
+ // Get 'following' parameter
+ const [following = null, followingErr] = $.bool.optional().nullable().get(params.following);
+ if (followingErr) return rej('invalid following param');
+
+ // Get 'mute' parameter
+ const [mute = 'mute_all', muteErr] = $.str.optional().get(params.mute);
+ if (muteErr) return rej('invalid mute param');
+
+ // Get 'reply' parameter
+ const [reply = null, replyErr] = $.bool.optional().nullable().get(params.reply);
+ if (replyErr) return rej('invalid reply param');
+
+ // Get 'renote' parameter
+ const [renote = null, renoteErr] = $.bool.optional().nullable().get(params.renote);
+ if (renoteErr) return rej('invalid renote param');
+
+ // Get 'media' parameter
+ const [media = null, mediaErr] = $.bool.optional().nullable().get(params.media);
+ if (mediaErr) return rej('invalid media param');
+
+ // Get 'poll' parameter
+ const [poll = null, pollErr] = $.bool.optional().nullable().get(params.poll);
+ if (pollErr) return rej('invalid poll param');
+
+ // Get 'sinceDate' parameter
+ const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
+ if (sinceDateErr) throw 'invalid sinceDate param';
+
+ // Get 'untilDate' parameter
+ const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
+ if (untilDateErr) throw 'invalid untilDate param';
+
+ // Get 'offset' parameter
+ const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
+ if (offsetErr) return rej('invalid offset param');
+
+ // Get 'limit' parameter
+ const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
+ if (limitErr) return rej('invalid limit param');
+
+ let includeUsers = includeUserIds;
+ if (includeUserUsernames != null) {
+ const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
+ const _user = await User.findOne({
+ usernameLower: username.toLowerCase()
+ });
+ return _user ? _user._id : null;
+ }))).filter(id => id != null);
+ includeUsers = includeUsers.concat(ids);
+ }
+
+ let excludeUsers = excludeUserIds;
+ if (excludeUserUsernames != null) {
+ const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
+ const _user = await User.findOne({
+ usernameLower: username.toLowerCase()
+ });
+ return _user ? _user._id : null;
+ }))).filter(id => id != null);
+ excludeUsers = excludeUsers.concat(ids);
+ }
+
+ search(res, rej, me, tag, includeUsers, excludeUsers, following,
+ mute, reply, renote, media, poll, sinceDate, untilDate, offset, limit);
+});
+
+async function search(
+ res, rej, me, tag, includeUserIds, excludeUserIds, following,
+ mute, reply, renote, media, poll, sinceDate, untilDate, offset, max) {
+
+ let q: any = {
+ $and: [{
+ tags: tag
+ }]
+ };
+
+ const push = x => q.$and.push(x);
+
+ if (includeUserIds && includeUserIds.length != 0) {
+ push({
+ userId: {
+ $in: includeUserIds
+ }
+ });
+ } else if (excludeUserIds && excludeUserIds.length != 0) {
+ push({
+ userId: {
+ $nin: excludeUserIds
+ }
+ });
+ }
+
+ if (following != null && me != null) {
+ const ids = await getFriendIds(me._id, false);
+ push({
+ userId: following ? {
+ $in: ids
+ } : {
+ $nin: ids.concat(me._id)
+ }
+ });
+ }
+
+ if (me != null) {
+ const mutes = await Mute.find({
+ muterId: me._id,
+ deletedAt: { $exists: false }
+ });
+ const mutedUserIds = mutes.map(m => m.muteeId);
+
+ switch (mute) {
+ case 'mute_all':
+ push({
+ userId: {
+ $nin: mutedUserIds
+ },
+ '_reply.userId': {
+ $nin: mutedUserIds
+ },
+ '_renote.userId': {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'mute_related':
+ push({
+ '_reply.userId': {
+ $nin: mutedUserIds
+ },
+ '_renote.userId': {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'mute_direct':
+ push({
+ userId: {
+ $nin: mutedUserIds
+ }
+ });
+ break;
+ case 'direct_only':
+ push({
+ userId: {
+ $in: mutedUserIds
+ }
+ });
+ break;
+ case 'related_only':
+ push({
+ $or: [{
+ '_reply.userId': {
+ $in: mutedUserIds
+ }
+ }, {
+ '_renote.userId': {
+ $in: mutedUserIds
+ }
+ }]
+ });
+ break;
+ case 'all_only':
+ push({
+ $or: [{
+ userId: {
+ $in: mutedUserIds
+ }
+ }, {
+ '_reply.userId': {
+ $in: mutedUserIds
+ }
+ }, {
+ '_renote.userId': {
+ $in: mutedUserIds
+ }
+ }]
+ });
+ break;
+ }
+ }
+
+ if (reply != null) {
+ if (reply) {
+ push({
+ replyId: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ replyId: {
+ $exists: false
+ }
+ }, {
+ replyId: null
+ }]
+ });
+ }
+ }
+
+ if (renote != null) {
+ if (renote) {
+ push({
+ renoteId: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ renoteId: {
+ $exists: false
+ }
+ }, {
+ renoteId: null
+ }]
+ });
+ }
+ }
+
+ if (media != null) {
+ if (media) {
+ push({
+ mediaIds: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ mediaIds: {
+ $exists: false
+ }
+ }, {
+ mediaIds: null
+ }]
+ });
+ }
+ }
+
+ if (poll != null) {
+ if (poll) {
+ push({
+ poll: {
+ $exists: true,
+ $ne: null
+ }
+ });
+ } else {
+ push({
+ $or: [{
+ poll: {
+ $exists: false
+ }
+ }, {
+ poll: null
+ }]
+ });
+ }
+ }
+
+ if (sinceDate) {
+ push({
+ createdAt: {
+ $gt: new Date(sinceDate)
+ }
+ });
+ }
+
+ if (untilDate) {
+ push({
+ createdAt: {
+ $lt: new Date(untilDate)
+ }
+ });
+ }
+
+ if (q.$and.length == 0) {
+ q = {};
+ }
+
+ // Search notes
+ const notes = await Note
+ .find(q, {
+ sort: {
+ _id: -1
+ },
+ limit: max,
+ skip: offset
+ });
+
+ // Serialize
+ res(await Promise.all(notes.map(note => pack(note, me))));
+}
diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts
index 9f32555649..f1d741d5ee 100644
--- a/src/server/api/endpoints/notes/timeline.ts
+++ b/src/server/api/endpoints/notes/timeline.ts
@@ -44,6 +44,10 @@ module.exports = async (params, user, app) => {
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
+ // Get 'mediaOnly' parameter
+ const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
+ if (mediaOnlyErr) throw 'invalid mediaOnly param';
+
const [followings, mutedUserIds] = await Promise.all([
// フォローを取得
// Fetch following
@@ -137,6 +141,12 @@ module.exports = async (params, user, app) => {
});
}
+ if (mediaOnly) {
+ query.$and.push({
+ mediaIds: { $exists: true, $ne: [] }
+ });
+ }
+
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts
index 9f8397d679..a74a5141f9 100644
--- a/src/server/api/endpoints/notes/user-list-timeline.ts
+++ b/src/server/api/endpoints/notes/user-list-timeline.ts
@@ -44,6 +44,10 @@ module.exports = async (params, user, app) => {
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
+ // Get 'mediaOnly' parameter
+ const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
+ if (mediaOnlyErr) throw 'invalid mediaOnly param';
+
// Get 'listId' parameter
const [listId, listIdErr] = $.type(ID).get(params.listId);
if (listIdErr) throw 'invalid listId param';
@@ -146,6 +150,12 @@ module.exports = async (params, user, app) => {
});
}
+ if (mediaOnly) {
+ query.$and.push({
+ mediaIds: { $exists: true, $ne: [] }
+ });
+ }
+
if (sinceId) {
sort._id = 1;
query._id = {
diff --git a/src/server/api/endpoints/notifications/get_unread_count.ts b/src/server/api/endpoints/notifications/get_unread_count.ts
deleted file mode 100644
index 9766366ff1..0000000000
--- a/src/server/api/endpoints/notifications/get_unread_count.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Module dependencies
- */
-import Notification from '../../../../models/notification';
-import Mute from '../../../../models/mute';
-
-/**
- * Get count of unread notifications
- */
-module.exports = (params, user) => new Promise(async (res, rej) => {
- const mute = await Mute.find({
- muterId: user._id
- });
- const mutedUserIds = mute.map(m => m.muteeId);
-
- const count = await Notification
- .count({
- notifieeId: user._id,
- notifierId: {
- $nin: mutedUserIds
- },
- isRead: false
- });
-
- res({
- count: count
- });
-});
diff --git a/src/server/api/endpoints/notifications/mark_as_read_all.ts b/src/server/api/endpoints/notifications/mark_as_read_all.ts
index dce3cb4663..7a48ca3e62 100644
--- a/src/server/api/endpoints/notifications/mark_as_read_all.ts
+++ b/src/server/api/endpoints/notifications/mark_as_read_all.ts
@@ -1,8 +1,6 @@
-/**
- * Module dependencies
- */
import Notification from '../../../../models/notification';
import event from '../../../../publishers/stream';
+import User from '../../../../models/user';
/**
* Mark as read all notifications
@@ -23,6 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Response
res();
+ // Update flag
+ User.update({ _id: user._id }, {
+ $set: {
+ hasUnreadNotification: false
+ }
+ });
+
// 全ての通知を読みましたよというイベントを発行
event(user._id, 'read_all_notifications');
});
diff --git a/src/server/api/endpoints/users/recommendation.ts b/src/server/api/endpoints/users/recommendation.ts
index 620ae17ca2..23821a552f 100644
--- a/src/server/api/endpoints/users/recommendation.ts
+++ b/src/server/api/endpoints/users/recommendation.ts
@@ -36,6 +36,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
_id: {
$nin: followingIds.concat(mutedUserIds)
},
+ isLocked: false,
$or: [{
lastUsedAt: {
$gte: new Date(Date.now() - ms('7days'))
diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts
index cf51dec4d2..14d4b8a3fc 100644
--- a/src/server/api/private/signup.ts
+++ b/src/server/api/private/signup.ts
@@ -1,4 +1,3 @@
-import * as uuid from 'uuid';
import * as Koa from 'koa';
import * as bcrypt from 'bcryptjs';
import { generate as generateKeypair } from '../../../crypto_key';
@@ -11,28 +10,6 @@ recaptcha.init({
secret_key: config.recaptcha.secret_key
});
-const home = {
- left: [
- 'profile',
- 'calendar',
- 'activity',
- 'rss',
- 'trends',
- 'photo-stream',
- 'version'
- ],
- right: [
- 'broadcast',
- 'notifications',
- 'users',
- 'polls',
- 'server',
- 'donation',
- 'nav',
- 'tips'
- ]
-};
-
export default async (ctx: Koa.Context) => {
// Verify recaptcha
// ただしテスト時はこの機構は障害となるため無効にする
@@ -82,28 +59,6 @@ export default async (ctx: Koa.Context) => {
// Generate secret
const secret = generateUserToken();
- //#region Construct home data
- const homeData = [];
-
- home.left.forEach(widget => {
- homeData.push({
- name: widget,
- id: uuid(),
- place: 'left',
- data: {}
- });
- });
-
- home.right.forEach(widget => {
- homeData.push({
- name: widget,
- id: uuid(),
- place: 'right',
- data: {}
- });
- });
- //#endregion
-
// Create account
const account: IUser = await User.insert({
avatarId: null,
@@ -135,9 +90,6 @@ export default async (ctx: Koa.Context) => {
},
settings: {
autoWatch: true
- },
- clientSettings: {
- home: homeData
}
});
diff --git a/src/server/api/service/github.ts b/src/server/api/service/github.ts
index cd9760a36d..da33648a16 100644
--- a/src/server/api/service/github.ts
+++ b/src/server/api/service/github.ts
@@ -25,7 +25,7 @@ const post = async text => {
}
}
- createNote(bot, { text });
+ createNote(bot, { text, visibility: 'home' });
};
// Init router
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/server/api/stream/notes-stats.ts b/src/server/api/stream/notes-stats.ts
new file mode 100644
index 0000000000..739b325848
--- /dev/null
+++ b/src/server/api/stream/notes-stats.ts
@@ -0,0 +1,35 @@
+import * as websocket from 'websocket';
+import Xev from 'xev';
+
+const ev = new Xev();
+
+export default function(request: websocket.request, connection: websocket.connection): void {
+ const onStats = stats => {
+ connection.send(JSON.stringify({
+ type: 'stats',
+ body: stats
+ }));
+ };
+
+ connection.on('message', async data => {
+ const msg = JSON.parse(data.utf8Data);
+
+ switch (msg.type) {
+ case 'requestLog':
+ ev.once('notesStatsLog:' + msg.id, statsLog => {
+ connection.send(JSON.stringify({
+ type: 'statsLog',
+ body: statsLog
+ }));
+ });
+ ev.emit('requestNotesStatsLog', msg.id);
+ break;
+ }
+ });
+
+ ev.addListener('notesStats', onStats);
+
+ connection.on('close', () => {
+ ev.removeListener('notesStats', onStats);
+ });
+}
diff --git a/src/server/api/stream/server-stats.ts b/src/server/api/stream/server-stats.ts
new file mode 100644
index 0000000000..342170a21e
--- /dev/null
+++ b/src/server/api/stream/server-stats.ts
@@ -0,0 +1,35 @@
+import * as websocket from 'websocket';
+import Xev from 'xev';
+
+const ev = new Xev();
+
+export default function(request: websocket.request, connection: websocket.connection): void {
+ const onStats = stats => {
+ connection.send(JSON.stringify({
+ type: 'stats',
+ body: stats
+ }));
+ };
+
+ connection.on('message', async data => {
+ const msg = JSON.parse(data.utf8Data);
+
+ switch (msg.type) {
+ case 'requestLog':
+ ev.once('serverStatsLog:' + msg.id, statsLog => {
+ connection.send(JSON.stringify({
+ type: 'statsLog',
+ body: statsLog
+ }));
+ });
+ ev.emit('requestServerStatsLog', msg.id);
+ break;
+ }
+ });
+
+ ev.addListener('serverStats', onStats);
+
+ connection.on('close', () => {
+ ev.removeListener('serverStats', onStats);
+ });
+}
diff --git a/src/server/api/stream/server.ts b/src/server/api/stream/server.ts
deleted file mode 100644
index 4ca2ad1b10..0000000000
--- a/src/server/api/stream/server.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import * as websocket from 'websocket';
-import Xev from 'xev';
-
-const ev = new Xev();
-
-export default function(request: websocket.request, connection: websocket.connection): void {
- const onStats = stats => {
- connection.send(JSON.stringify({
- type: 'stats',
- body: stats
- }));
- };
-
- ev.addListener('stats', onStats);
-
- connection.on('close', () => {
- ev.removeListener('stats', onStats);
- });
-}
diff --git a/src/server/api/streaming.ts b/src/server/api/streaming.ts
index 6825b6336a..2d4cfc108f 100644
--- a/src/server/api/streaming.ts
+++ b/src/server/api/streaming.ts
@@ -12,7 +12,8 @@ import messagingStream from './stream/messaging';
import messagingIndexStream from './stream/messaging-index';
import othelloGameStream from './stream/othello-game';
import othelloStream from './stream/othello';
-import serverStream from './stream/server';
+import serverStatsStream from './stream/server-stats';
+import notesStatsStream from './stream/notes-stats';
import requestsStream from './stream/requests';
import { ParsedUrlQuery } from 'querystring';
import authenticate from './authenticate';
@@ -28,8 +29,13 @@ module.exports = (server: http.Server) => {
ws.on('request', async (request) => {
const connection = request.accept();
- if (request.resourceURL.pathname === '/server') {
- serverStream(request, connection);
+ if (request.resourceURL.pathname === '/server-stats') {
+ serverStatsStream(request, connection);
+ return;
+ }
+
+ if (request.resourceURL.pathname === '/notes-stats') {
+ notesStatsStream(request, connection);
return;
}