mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-17 19:35:29 +02:00
Merge commit from fork
* Tighten security on channels * Fix main channel * add comments, improve typing * fix indent * fix: missing membership checks in chat-room * remove unnecessary check in chat-user * fix * refactor: use exists * fix --------- Co-authored-by: Julia Johannesen <julia@insertdomain.name>
This commit is contained in:
@@ -52,7 +52,7 @@ export default class Connection {
|
||||
public token?: MiAccessToken;
|
||||
private wsConnection: WebSocket.WebSocket;
|
||||
public subscriber: StreamEventEmitter;
|
||||
private channels: Channel[] = [];
|
||||
private channels: Map<string, Channel> = new Map();
|
||||
private subscribingNotes: Partial<Record<string, number>> = {};
|
||||
public userProfile: MiUserProfile | null = null;
|
||||
public following: Record<string, Pick<MiFollowing, 'withReplies'> | undefined> = {};
|
||||
@@ -262,7 +262,11 @@ export default class Connection {
|
||||
*/
|
||||
@bindThis
|
||||
public async connectChannel(id: string, params: JsonObject | undefined, channel: string, pong = false) {
|
||||
if (this.channels.length >= MAX_CHANNELS_PER_CONNECTION) {
|
||||
if (this.channels.has(id)) {
|
||||
this.disconnectChannel(id);
|
||||
}
|
||||
|
||||
if (this.channels.size >= MAX_CHANNELS_PER_CONNECTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -278,8 +282,12 @@ export default class Connection {
|
||||
}
|
||||
|
||||
// 共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視
|
||||
if (channelConstructor.shouldShare && this.channels.some(c => c.chName === channel)) {
|
||||
return;
|
||||
if (channelConstructor.shouldShare) {
|
||||
for (const c of this.channels.values()) {
|
||||
if (c.chName === channel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const contextId = ContextIdFactory.create();
|
||||
@@ -289,8 +297,13 @@ export default class Connection {
|
||||
}, contextId);
|
||||
const ch: Channel = await this.moduleRef.create<Channel>(channelConstructor, contextId);
|
||||
|
||||
this.channels.push(ch);
|
||||
ch.init(params ?? {});
|
||||
this.channels.set(ch.id, ch);
|
||||
const valid = await ch.init(params ?? {});
|
||||
if (typeof valid === 'boolean' && !valid) {
|
||||
// 初期化処理の結果、接続拒否されたので切断
|
||||
this.disconnectChannel(id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pong) {
|
||||
this.sendMessageToWs('connected', {
|
||||
@@ -332,11 +345,11 @@ export default class Connection {
|
||||
*/
|
||||
@bindThis
|
||||
public disconnectChannel(id: string) {
|
||||
const channel = this.channels.find(c => c.id === id);
|
||||
const channel = this.channels.get(id);
|
||||
|
||||
if (channel) {
|
||||
if (channel.dispose) channel.dispose();
|
||||
this.channels = this.channels.filter(c => c.id !== id);
|
||||
this.channels.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +364,7 @@ export default class Connection {
|
||||
if (typeof data.type !== 'string') return;
|
||||
if (typeof data.body === 'undefined') return;
|
||||
|
||||
const channel = this.channels.find(c => c.id === data.id);
|
||||
const channel = this.channels.get(data.id);
|
||||
if (channel != null && channel.onMessage != null) {
|
||||
channel.onMessage(data.type, data.body);
|
||||
}
|
||||
@@ -363,7 +376,7 @@ export default class Connection {
|
||||
@bindThis
|
||||
public dispose() {
|
||||
if (this.fetchIntervalId) clearInterval(this.fetchIntervalId);
|
||||
for (const c of this.channels.filter(c => c.dispose)) {
|
||||
for (const c of this.channels.values()) {
|
||||
if (c.dispose) c.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user