2023-07-27 14:31:52 +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';
|
2024-01-08 17:43:52 +09:00
|
|
|
import { api, connectStream, post, signup } from '../utils.js';
|
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', () => {
|
2024-01-03 13:41:28 +09:00
|
|
|
let alice: misskey.entities.SignupResponse;
|
|
|
|
let bob: misskey.entities.SignupResponse;
|
|
|
|
let carol: misskey.entities.SignupResponse;
|
2021-10-31 15:30:22 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
beforeAll(async () => {
|
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
|
|
|
|
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
|
|
|
});
|