2023-08-15 02:52:38 +09:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2021-10-31 15:30:22 +09:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2023-03-03 11:13:12 +09:00
|
|
|
import { signup, api, post, connectStream, startServer } from '../utils.js';
|
|
|
|
import type { INestApplicationContext } from '@nestjs/common';
|
2023-06-25 08:34:18 +09:00
|
|
|
import type * as misskey from 'misskey-js';
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
describe('Note thread mute', () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
let app: INestApplicationContext;
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2023-06-25 08:34:18 +09:00
|
|
|
let alice: misskey.entities.MeSignup;
|
|
|
|
let bob: misskey.entities.MeSignup;
|
|
|
|
let carol: misskey.entities.MeSignup;
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
beforeAll(async () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
app = await startServer();
|
2021-10-31 15:30:22 +09:00
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
|
|
|
carol = await signup({ username: 'carol' });
|
2023-03-03 11:13:12 +09:00
|
|
|
}, 1000 * 60 * 2);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
afterAll(async () => {
|
2023-03-12 20:57:01 +09:00
|
|
|
await app.close();
|
2021-10-31 15:30:22 +09:00
|
|
|
});
|
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('notes/mentions にミュートしているスレッドの投稿が含まれない', async () => {
|
2021-10-31 15:30:22 +09:00
|
|
|
const bobNote = await post(bob, { text: '@alice @carol root note' });
|
|
|
|
const aliceReply = await post(alice, { replyId: bobNote.id, text: '@bob @carol child note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/notes/thread-muting/create', { noteId: bobNote.id }, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
const carolReply = await post(carol, { replyId: bobNote.id, text: '@bob @alice child note' });
|
|
|
|
const carolReplyWithoutMention = await post(carol, { replyId: aliceReply.id, text: 'child note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const res = await api('/notes/mentions', {}, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === carolReply.id), false);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === carolReplyWithoutMention.id), false);
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('ミュートしているスレッドからメンションされても、hasUnreadMentions が true にならない', async () => {
|
2021-10-31 15:30:22 +09:00
|
|
|
// 状態リセット
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/read-all-unread-notes', {}, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
const bobNote = await post(bob, { text: '@alice @carol root note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/notes/thread-muting/create', { noteId: bobNote.id }, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
const carolReply = await post(carol, { replyId: bobNote.id, text: '@bob @alice child note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const res = await api('/i', {}, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(res.body.hasUnreadMentions, false);
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
test('ミュートしているスレッドからメンションされても、ストリームに unreadMention イベントが流れてこない', () => new Promise<void>(async done => {
|
2021-10-31 15:30:22 +09:00
|
|
|
// 状態リセット
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/i/read-all-unread-notes', {}, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
const bobNote = await post(bob, { text: '@alice @carol root note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/notes/thread-muting/create', { noteId: bobNote.id }, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
let fired = false;
|
|
|
|
|
|
|
|
const ws = await connectStream(alice, 'main', async ({ type, body }) => {
|
|
|
|
if (type === 'unreadMention') {
|
|
|
|
if (body === bobNote.id) return;
|
|
|
|
fired = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const carolReply = await post(carol, { replyId: bobNote.id, text: '@bob @alice child note' });
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
ws.close();
|
|
|
|
done();
|
|
|
|
}, 5000);
|
|
|
|
}));
|
|
|
|
|
2023-02-02 18:18:25 +09:00
|
|
|
test('i/notifications にミュートしているスレッドの通知が含まれない', async () => {
|
2021-10-31 15:30:22 +09:00
|
|
|
const bobNote = await post(bob, { text: '@alice @carol root note' });
|
|
|
|
const aliceReply = await post(alice, { replyId: bobNote.id, text: '@bob @carol child note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
await api('/notes/thread-muting/create', { noteId: bobNote.id }, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
const carolReply = await post(carol, { replyId: bobNote.id, text: '@bob @alice child note' });
|
|
|
|
const carolReplyWithoutMention = await post(carol, { replyId: aliceReply.id, text: 'child note' });
|
|
|
|
|
2023-03-03 11:13:12 +09:00
|
|
|
const res = await api('/i/notifications', {}, alice);
|
2021-10-31 15:30:22 +09:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
|
|
|
assert.strictEqual(res.body.some((notification: any) => notification.note.id === carolReply.id), false);
|
|
|
|
assert.strictEqual(res.body.some((notification: any) => notification.note.id === carolReplyWithoutMention.id), false);
|
|
|
|
|
|
|
|
// NOTE: bobの投稿はスレッドミュート前に行われたため通知に含まれていてもよい
|
2022-09-18 03:27:08 +09:00
|
|
|
});
|
2021-10-31 15:30:22 +09:00
|
|
|
});
|