共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視するように
This commit is contained in:
		
							parent
							
								
									ad67886f96
								
							
						
					
					
						commit
						e85f9f4aa5
					
				
					 17 changed files with 59 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -7,6 +7,8 @@ import Connection from '.';
 | 
			
		|||
export default abstract class Channel {
 | 
			
		||||
	protected connection: Connection;
 | 
			
		||||
	public id: string;
 | 
			
		||||
	public abstract readonly chName: string;
 | 
			
		||||
	public abstract readonly shouldShare: boolean;
 | 
			
		||||
 | 
			
		||||
	protected get user() {
 | 
			
		||||
		return this.connection.user;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,9 @@ import autobind from 'autobind-decorator';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'drive';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		// Subscribe drive stream
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,9 @@ import * as maps from '../../../../../games/reversi/maps';
 | 
			
		|||
import Channel from '../../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'gamesReversiGame';
 | 
			
		||||
	public readonly shouldShare = false;
 | 
			
		||||
 | 
			
		||||
	private gameId: mongo.ObjectID;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import { publishMainStream } from '../../../../../stream';
 | 
			
		|||
import Channel from '../../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'gamesReversi';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		// Subscribe reversi stream
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'globalTimeline';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	private mutedUserIds: string[] = [];
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'hashtag';
 | 
			
		||||
	public readonly shouldShare = false;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		const mute = this.user ? await Mute.find({ muterId: this.user._id }) : null;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'homeTimeline';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	private mutedUserIds: string[] = [];
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'hybridTimeline';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	private mutedUserIds: string[] = [];
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'localTimeline';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	private mutedUserIds: string[] = [];
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,9 @@ import Mute from '../../../../models/mute';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'main';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		const mute = await Mute.find({ muterId: this.user._id });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,9 @@ import autobind from 'autobind-decorator';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'messagingIndex';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		// Subscribe messaging index stream
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,9 @@ import read from '../../common/read-messaging-message';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'messaging';
 | 
			
		||||
	public readonly shouldShare = false;
 | 
			
		||||
 | 
			
		||||
	private otherpartyId: string;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import Channel from '../channel';
 | 
			
		|||
const ev = new Xev();
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'notesStats';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		ev.addListener('notesStats', this.onStats);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,9 @@ import Channel from '../channel';
 | 
			
		|||
const ev = new Xev();
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'serverStats';
 | 
			
		||||
	public readonly shouldShare = true;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		ev.addListener('serverStats', this.onStats);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,9 @@ import autobind from 'autobind-decorator';
 | 
			
		|||
import Channel from '../channel';
 | 
			
		||||
 | 
			
		||||
export default class extends Channel {
 | 
			
		||||
	public readonly chName = 'userList';
 | 
			
		||||
	public readonly shouldShare = false;
 | 
			
		||||
 | 
			
		||||
	@autobind
 | 
			
		||||
	public async init(params: any) {
 | 
			
		||||
		const listId = params.listId as string;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -148,7 +148,7 @@ export default class Connection {
 | 
			
		|||
	private onChannelConnectRequested(payload: any) {
 | 
			
		||||
		const { channel, id, params } = payload;
 | 
			
		||||
		log(`CH CONNECT: ${id} ${channel} by @${this.user.username}`);
 | 
			
		||||
		this.connectChannel(id, params, (channels as any)[channel]);
 | 
			
		||||
		this.connectChannel(id, params, channel);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			@ -177,10 +177,15 @@ export default class Connection {
 | 
			
		|||
	 * チャンネルに接続
 | 
			
		||||
	 */
 | 
			
		||||
	@autobind
 | 
			
		||||
	public connectChannel(id: string, params: any, channelClass: { new(id: string, connection: Connection): Channel }) {
 | 
			
		||||
		const channel = new channelClass(id, this);
 | 
			
		||||
		this.channels.push(channel);
 | 
			
		||||
		channel.init(params);
 | 
			
		||||
	public connectChannel(id: string, params: any, channel: string) {
 | 
			
		||||
		// 共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視
 | 
			
		||||
		if ((channels as any)[channel].shouldShare && this.channels.some(c => c.chName === channel)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		const ch: Channel = new (channels as any)[channel](id, this);
 | 
			
		||||
		this.channels.push(ch);
 | 
			
		||||
		ch.init(params);
 | 
			
		||||
		this.sendMessageToWs('connected', {
 | 
			
		||||
			id: id
 | 
			
		||||
		});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,6 @@ import Xev from 'xev';
 | 
			
		|||
import MainStreamConnection from './stream';
 | 
			
		||||
import { ParsedUrlQuery } from 'querystring';
 | 
			
		||||
import authenticate from './authenticate';
 | 
			
		||||
import channels from './stream/channels';
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
import config from '../../config';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -66,13 +65,13 @@ module.exports = (server: http.Server) => {
 | 
			
		|||
			};
 | 
			
		||||
 | 
			
		||||
			main.connectChannel(Math.random().toString(), null,
 | 
			
		||||
				request.resourceURL.pathname === '/' ? channels.homeTimeline :
 | 
			
		||||
				request.resourceURL.pathname === '/local-timeline' ? channels.localTimeline :
 | 
			
		||||
				request.resourceURL.pathname === '/hybrid-timeline' ? channels.hybridTimeline :
 | 
			
		||||
				request.resourceURL.pathname === '/global-timeline' ? channels.globalTimeline : null);
 | 
			
		||||
				request.resourceURL.pathname === '/' ? 'homeTimeline' :
 | 
			
		||||
				request.resourceURL.pathname === '/local-timeline' ? 'localTimeline' :
 | 
			
		||||
				request.resourceURL.pathname === '/hybrid-timeline' ? 'hybridTimeline' :
 | 
			
		||||
				request.resourceURL.pathname === '/global-timeline' ? 'globalTimeline' : null);
 | 
			
		||||
 | 
			
		||||
			if (request.resourceURL.pathname === '/') {
 | 
			
		||||
				main.connectChannel(Math.random().toString(), null, channels.main);
 | 
			
		||||
				main.connectChannel(Math.random().toString(), null, 'main');
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue