2023-07-27 07:31:52 +02:00
|
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
|
import { bindThis } from '@/decorators.js';
|
2024-04-17 07:23:41 +02:00
|
|
|
|
import { isInstanceMuted } from '@/misc/is-instance-muted.js';
|
|
|
|
|
|
import { isUserRelated } from '@/misc/is-user-related.js';
|
2024-06-10 13:36:30 +02:00
|
|
|
|
import { isQuotePacked, isRenotePacked } from '@/misc/is-renote.js';
|
2024-07-02 01:19:04 +02:00
|
|
|
|
import { isChannelRelated } from '@/misc/is-channel-related.js';
|
2024-04-17 07:23:41 +02:00
|
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2024-07-18 13:04:23 +02:00
|
|
|
|
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
|
2023-09-15 07:28:29 +02:00
|
|
|
|
import type Connection from './Connection.js';
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Stream channel
|
|
|
|
|
|
*/
|
2023-08-17 14:20:58 +02:00
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
2018-10-07 04:06:17 +02:00
|
|
|
|
export default abstract class Channel {
|
|
|
|
|
|
protected connection: Connection;
|
|
|
|
|
|
public id: string;
|
2018-10-11 16:01:57 +02:00
|
|
|
|
public abstract readonly chName: string;
|
2018-10-11 16:07:20 +02:00
|
|
|
|
public static readonly shouldShare: boolean;
|
2018-11-10 18:22:34 +01:00
|
|
|
|
public static readonly requireCredential: boolean;
|
2023-12-27 07:08:59 +01:00
|
|
|
|
public static readonly kind?: string | null;
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
|
|
|
protected get user() {
|
|
|
|
|
|
return this.connection.user;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-27 06:34:20 +02:00
|
|
|
|
protected get userProfile() {
|
|
|
|
|
|
return this.connection.userProfile;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
|
protected get following() {
|
|
|
|
|
|
return this.connection.following;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-05 03:21:10 +02:00
|
|
|
|
protected get userIdsWhoMeMuting() {
|
|
|
|
|
|
return this.connection.userIdsWhoMeMuting;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-05 03:21:10 +02:00
|
|
|
|
protected get userIdsWhoMeMutingRenotes() {
|
|
|
|
|
|
return this.connection.userIdsWhoMeMutingRenotes;
|
2023-03-08 00:56:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-05 03:21:10 +02:00
|
|
|
|
protected get userIdsWhoBlockingMe() {
|
|
|
|
|
|
return this.connection.userIdsWhoBlockingMe;
|
2021-08-17 14:48:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-03 02:19:37 +01:00
|
|
|
|
protected get userMutedInstances() {
|
|
|
|
|
|
return this.connection.userMutedInstances;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-18 15:44:21 +02:00
|
|
|
|
protected get followingChannels() {
|
|
|
|
|
|
return this.connection.followingChannels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-10 13:36:30 +02:00
|
|
|
|
protected get mutingChannels() {
|
|
|
|
|
|
return this.connection.mutingChannels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
|
protected get subscriber() {
|
|
|
|
|
|
return this.connection.subscriber;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-17 07:23:41 +02:00
|
|
|
|
/*
|
|
|
|
|
|
* ミュートとブロックされてるを処理する
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected isNoteMutedOrBlocked(note: Packed<'Note'>): boolean {
|
|
|
|
|
|
// 流れてきたNoteがインスタンスミュートしたインスタンスが関わる
|
|
|
|
|
|
if (isInstanceMuted(note, new Set<string>(this.userProfile?.mutedInstances ?? []))) return true;
|
|
|
|
|
|
|
|
|
|
|
|
// 流れてきたNoteがミュートしているユーザーが関わる
|
|
|
|
|
|
if (isUserRelated(note, this.userIdsWhoMeMuting)) return true;
|
|
|
|
|
|
// 流れてきたNoteがブロックされているユーザーが関わる
|
|
|
|
|
|
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
// 流れてきたNoteがリノートをミュートしてるユーザが行ったもの
|
|
|
|
|
|
if (isRenotePacked(note) && !isQuotePacked(note) && this.userIdsWhoMeMutingRenotes.has(note.user.id)) return true;
|
|
|
|
|
|
|
2024-07-02 01:19:04 +02:00
|
|
|
|
// 流れてきたNoteがミュートしているチャンネルと関わる
|
|
|
|
|
|
if (isChannelRelated(note, this.mutingChannels)) return true;
|
|
|
|
|
|
|
2024-04-17 07:23:41 +02:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
|
constructor(id: string, connection: Connection) {
|
|
|
|
|
|
this.id = id;
|
|
|
|
|
|
this.connection = connection;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-18 13:04:23 +02:00
|
|
|
|
public send(payload: { type: string, body: JsonValue }): void
|
|
|
|
|
|
public send(type: string, payload: JsonValue): void
|
2022-12-04 07:03:09 +01:00
|
|
|
|
@bindThis
|
2024-07-18 13:04:23 +02:00
|
|
|
|
public send(typeOrPayload: { type: string, body: JsonValue } | string, payload?: JsonValue) {
|
|
|
|
|
|
const type = payload === undefined ? (typeOrPayload as { type: string, body: JsonValue }).type : (typeOrPayload as string);
|
|
|
|
|
|
const body = payload === undefined ? (typeOrPayload as { type: string, body: JsonValue }).body : payload;
|
2018-10-07 04:06:17 +02:00
|
|
|
|
|
|
|
|
|
|
this.connection.sendMessageToWs('channel', {
|
|
|
|
|
|
id: this.id,
|
|
|
|
|
|
type: type,
|
2021-12-09 15:58:30 +01:00
|
|
|
|
body: body,
|
2018-10-07 04:06:17 +02:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-18 13:04:23 +02:00
|
|
|
|
public abstract init(params: JsonObject): void;
|
2023-10-30 09:36:32 +01:00
|
|
|
|
|
2018-10-07 04:06:17 +02:00
|
|
|
|
public dispose?(): void;
|
2023-10-30 09:36:32 +01:00
|
|
|
|
|
2024-07-18 13:04:23 +02:00
|
|
|
|
public onMessage?(type: string, body: JsonValue): void;
|
2018-10-07 04:06:17 +02:00
|
|
|
|
}
|
2023-12-27 07:08:59 +01:00
|
|
|
|
|
|
|
|
|
|
export type MiChannelService<T extends boolean> = {
|
|
|
|
|
|
shouldShare: boolean;
|
|
|
|
|
|
requireCredential: T;
|
|
|
|
|
|
kind: T extends true ? string : string | null | undefined;
|
|
|
|
|
|
create: (id: string, connection: Connection) => Channel;
|
|
|
|
|
|
}
|