summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/messaging/history.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-05-18 20:36:33 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-05-18 20:36:33 +0900
commitc7cc3dcdfd2c0962a39e7186852a17dbd09b6a5b (patch)
treec2e1671787c00daa8963c879dba6fbdab6f02d66 /src/server/api/endpoints/messaging/history.ts
parentFix bug (diff)
downloadsharkey-c7cc3dcdfd2c0962a39e7186852a17dbd09b6a5b.tar.gz
sharkey-c7cc3dcdfd2c0962a39e7186852a17dbd09b6a5b.tar.bz2
sharkey-c7cc3dcdfd2c0962a39e7186852a17dbd09b6a5b.zip
ユーザーグループ
Resolve #3218
Diffstat (limited to 'src/server/api/endpoints/messaging/history.ts')
-rw-r--r--src/server/api/endpoints/messaging/history.ts51
1 files changed, 38 insertions, 13 deletions
diff --git a/src/server/api/endpoints/messaging/history.ts b/src/server/api/endpoints/messaging/history.ts
index 27e38bbdec..833ec37e4c 100644
--- a/src/server/api/endpoints/messaging/history.ts
+++ b/src/server/api/endpoints/messaging/history.ts
@@ -1,13 +1,13 @@
import $ from 'cafy';
import define from '../../define';
import { MessagingMessage } from '../../../../models/entities/messaging-message';
-import { MessagingMessages, Mutings } from '../../../../models';
+import { MessagingMessages, Mutings, UserGroupJoinings } from '../../../../models';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
- 'ja-JP': 'Messagingの履歴を取得します。',
+ 'ja-JP': 'トークの履歴を取得します。',
'en-US': 'Show messaging history.'
},
@@ -21,6 +21,11 @@ export const meta = {
limit: {
validator: $.optional.num.range(1, 100),
default: 10
+ },
+
+ group: {
+ validator: $.optional.bool,
+ default: false
}
},
@@ -40,26 +45,46 @@ export default define(meta, async (ps, user) => {
muterId: user.id,
});
+ const groups = ps.group ? await UserGroupJoinings.find({
+ userId: user.id,
+ }).then(xs => xs.map(x => x.userGroupId)) : [];
+
+ if (ps.group && groups.length === 0) {
+ return [];
+ }
+
const history: MessagingMessage[] = [];
for (let i = 0; i < ps.limit!; i++) {
- const found = history.map(m => (m.userId === user.id) ? m.recipientId : m.userId);
+ const found = ps.group
+ ? history.map(m => m.groupId!)
+ : history.map(m => (m.userId === user.id) ? m.recipientId! : m.userId!);
const query = MessagingMessages.createQueryBuilder('message')
- .where(new Brackets(qb => { qb
+ .orderBy('message.createdAt', 'DESC');
+
+ if (ps.group) {
+ query.where(`message.groupId IN (:...groups)`, { groups: groups });
+
+ if (found.length > 0) {
+ query.andWhere(`message.groupId NOT IN (:...found)`, { found: found });
+ }
+ } else {
+ query.where(new Brackets(qb => { qb
.where(`message.userId = :userId`, { userId: user.id })
.orWhere(`message.recipientId = :userId`, { userId: user.id });
- }))
- .orderBy('message.createdAt', 'DESC');
+ }));
+ query.andWhere(`message.groupId IS NULL`);
- if (found.length > 0) {
- query.andWhere(`message.userId NOT IN (:...found)`, { found: found });
- query.andWhere(`message.recipientId NOT IN (:...found)`, { found: found });
- }
+ if (found.length > 0) {
+ query.andWhere(`message.userId NOT IN (:...found)`, { found: found });
+ query.andWhere(`message.recipientId NOT IN (:...found)`, { found: found });
+ }
- if (mute.length > 0) {
- query.andWhere(`message.userId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
- query.andWhere(`message.recipientId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
+ if (mute.length > 0) {
+ query.andWhere(`message.userId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
+ query.andWhere(`message.recipientId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
+ }
}
const message = await query.getOne();