2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
|
|
|
|
import * as assert from 'assert';
|
2024-01-08 08:43:52 +00:00
|
|
|
import { api, post, react, signup, waitFire } from '../utils.js';
|
2023-06-24 23:34:18 +00:00
|
|
|
import type * as misskey from 'misskey-js';
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
describe('Mute', () => {
|
|
|
|
// alice mutes carol
|
2024-01-03 04:41:28 +00:00
|
|
|
let alice: misskey.entities.SignupResponse;
|
|
|
|
let bob: misskey.entities.SignupResponse;
|
|
|
|
let carol: misskey.entities.SignupResponse;
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
beforeAll(async () => {
|
2020-01-09 05:35:04 +00:00
|
|
|
alice = await signup({ username: 'alice' });
|
|
|
|
bob = await signup({ username: 'bob' });
|
|
|
|
carol = await signup({ username: 'carol' });
|
2023-03-03 02:13:12 +00:00
|
|
|
}, 1000 * 60 * 2);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('ミュート作成', async () => {
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/mute/create', {
|
2022-05-21 13:21:41 +00:00
|
|
|
userId: carol.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
}, alice);
|
|
|
|
|
|
|
|
assert.strictEqual(res.status, 204);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('「自分宛ての投稿」にミュートしているユーザーの投稿が含まれない', async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const bobNote = await post(bob, { text: '@alice hi' });
|
|
|
|
const carolNote = await post(carol, { text: '@alice hi' });
|
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/notes/mentions', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2020-01-09 05:35:04 +00:00
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('ミュートしているユーザーからメンションされても、hasUnreadMentions が true にならない', async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
// 状態リセット
|
2023-03-03 02:13:12 +00:00
|
|
|
await api('/i/read-all-unread-notes', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
await post(carol, { text: '@alice hi' });
|
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/i', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(res.body.hasUnreadMentions, false);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('ミュートしているユーザーからメンションされても、ストリームに unreadMention イベントが流れてこない', async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
// 状態リセット
|
2023-03-03 02:13:12 +00:00
|
|
|
await api('/i/read-all-unread-notes', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-06-26 10:16:32 +00:00
|
|
|
const fired = await waitFire(alice, 'main', () => post(carol, { text: '@alice hi' }), msg => msg.type === 'unreadMention');
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-06-26 10:16:32 +00:00
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('ミュートしているユーザーからメンションされても、ストリームに unreadNotification イベントが流れてこない', async () => {
|
2019-04-07 12:50:36 +00:00
|
|
|
// 状態リセット
|
2023-03-03 02:13:12 +00:00
|
|
|
await api('/i/read-all-unread-notes', {}, alice);
|
|
|
|
await api('/notifications/mark-all-as-read', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-06-26 10:16:32 +00:00
|
|
|
const fired = await waitFire(alice, 'main', () => post(carol, { text: '@alice hi' }), msg => msg.type === 'unreadNotification');
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2022-06-26 10:16:32 +00:00
|
|
|
assert.strictEqual(fired, false);
|
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
describe('Timeline', () => {
|
2023-02-02 09:18:25 +00:00
|
|
|
test('タイムラインにミュートしているユーザーの投稿が含まれない', async () => {
|
2023-03-07 23:56:09 +00:00
|
|
|
const aliceNote = await post(alice, { text: 'hi' });
|
|
|
|
const bobNote = await post(bob, { text: 'hi' });
|
|
|
|
const carolNote = await post(carol, { text: 'hi' });
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/notes/local-timeline', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2020-01-09 05:35:04 +00:00
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === aliceNote.id), true);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2023-02-02 09:18:25 +00:00
|
|
|
test('タイムラインにミュートしているユーザーの投稿のRenoteが含まれない', async () => {
|
2023-03-07 23:56:09 +00:00
|
|
|
const aliceNote = await post(alice, { text: 'hi' });
|
|
|
|
const carolNote = await post(carol, { text: 'hi' });
|
2019-04-07 12:50:36 +00:00
|
|
|
const bobNote = await post(bob, {
|
2022-05-21 13:21:41 +00:00
|
|
|
renoteId: carolNote.id,
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/notes/local-timeline', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2020-01-09 05:35:04 +00:00
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === aliceNote.id), true);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false);
|
|
|
|
assert.strictEqual(res.body.some((note: any) => note.id === carolNote.id), false);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Notification', () => {
|
2023-02-02 09:18:25 +00:00
|
|
|
test('通知にミュートしているユーザーの通知が含まれない(リアクション)', async () => {
|
2023-03-07 23:56:09 +00:00
|
|
|
const aliceNote = await post(alice, { text: 'hi' });
|
2019-04-07 12:50:36 +00:00
|
|
|
await react(bob, aliceNote, 'like');
|
|
|
|
await react(carol, aliceNote, 'like');
|
|
|
|
|
2023-03-03 02:13:12 +00:00
|
|
|
const res = await api('/i/notifications', {}, alice);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
assert.strictEqual(res.status, 200);
|
|
|
|
assert.strictEqual(Array.isArray(res.body), true);
|
2020-01-09 05:35:04 +00:00
|
|
|
assert.strictEqual(res.body.some((notification: any) => notification.userId === bob.id), true);
|
|
|
|
assert.strictEqual(res.body.some((notification: any) => notification.userId === carol.id), false);
|
2022-09-17 18:27:08 +00:00
|
|
|
});
|
2019-04-07 12:50:36 +00:00
|
|
|
});
|
|
|
|
});
|