Refactor: Extract shouldMuteThisNote function
This commit is contained in:
		
							parent
							
								
									311b4e90ca
								
							
						
					
					
						commit
						44f6fe6f1f
					
				
					 6 changed files with 29 additions and 53 deletions
				
			
		
							
								
								
									
										15
									
								
								src/misc/should-mute-this-note.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/misc/should-mute-this-note.ts
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,15 @@
 | 
				
			||||||
 | 
					export default function(note: any, mutedUserIds: string[]): boolean {
 | 
				
			||||||
 | 
						if (mutedUserIds.indexOf(note.userId) != -1) {
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ import Xev from 'xev';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { IUser } from '../../../models/user';
 | 
					import { IUser } from '../../../models/user';
 | 
				
			||||||
import Mute from '../../../models/mute';
 | 
					import Mute from '../../../models/mute';
 | 
				
			||||||
 | 
					import shouldMuteThisNote from '../../../misc/should-mute-this-note';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(
 | 
					export default async function(
 | 
				
			||||||
	request: websocket.request,
 | 
						request: websocket.request,
 | 
				
			||||||
| 
						 | 
					@ -15,17 +16,8 @@ export default async function(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Subscribe stream
 | 
						// Subscribe stream
 | 
				
			||||||
	subscriber.on('global-timeline', async note => {
 | 
						subscriber.on('global-timeline', async note => {
 | 
				
			||||||
		//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
							// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
				
			||||||
		if (mutedUserIds.indexOf(note.userId) != -1) {
 | 
							if (shouldMuteThisNote(note, mutedUserIds)) return;
 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		//#endregion
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		connection.send(JSON.stringify({
 | 
							connection.send(JSON.stringify({
 | 
				
			||||||
			type: 'note',
 | 
								type: 'note',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import Xev from 'xev';
 | 
				
			||||||
import { IUser } from '../../../models/user';
 | 
					import { IUser } from '../../../models/user';
 | 
				
			||||||
import Mute from '../../../models/mute';
 | 
					import Mute from '../../../models/mute';
 | 
				
			||||||
import { pack } from '../../../models/note';
 | 
					import { pack } from '../../../models/note';
 | 
				
			||||||
 | 
					import shouldMuteThisNote from '../../../misc/should-mute-this-note';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(
 | 
					export default async function(
 | 
				
			||||||
	request: websocket.request,
 | 
						request: websocket.request,
 | 
				
			||||||
| 
						 | 
					@ -28,17 +29,8 @@ export default async function(
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
							// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
				
			||||||
		if (mutedUserIds.indexOf(note.userId) != -1) {
 | 
							if (shouldMuteThisNote(note, mutedUserIds)) return;
 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		//#endregion
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		connection.send(JSON.stringify({
 | 
							connection.send(JSON.stringify({
 | 
				
			||||||
			type: 'note',
 | 
								type: 'note',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import { pack as packNote, pack } from '../../../models/note';
 | 
				
			||||||
import readNotification from '../common/read-notification';
 | 
					import readNotification from '../common/read-notification';
 | 
				
			||||||
import call from '../call';
 | 
					import call from '../call';
 | 
				
			||||||
import { IApp } from '../../../models/app';
 | 
					import { IApp } from '../../../models/app';
 | 
				
			||||||
 | 
					import shouldMuteThisNote from '../../../misc/should-mute-this-note';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const log = debug('misskey');
 | 
					const log = debug('misskey');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,15 +46,7 @@ export default async function(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//#region 流れてきたメッセージがミュートしているユーザーが関わるものだったら無視する
 | 
							//#region 流れてきたメッセージがミュートしているユーザーが関わるものだったら無視する
 | 
				
			||||||
		if (x.type == 'note') {
 | 
							if (x.type == 'note') {
 | 
				
			||||||
			if (mutedUserIds.includes(x.body.userId)) {
 | 
								if (shouldMuteThisNote(x.body, mutedUserIds)) return;
 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if (x.body.reply != null && mutedUserIds.includes(x.body.reply.userId)) {
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if (x.body.renote != null && mutedUserIds.includes(x.body.renote.userId)) {
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		} else if (x.type == 'notification') {
 | 
							} else if (x.type == 'notification') {
 | 
				
			||||||
			if (mutedUserIds.includes(x.body.userId)) {
 | 
								if (mutedUserIds.includes(x.body.userId)) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import Xev from 'xev';
 | 
				
			||||||
import { IUser } from '../../../models/user';
 | 
					import { IUser } from '../../../models/user';
 | 
				
			||||||
import Mute from '../../../models/mute';
 | 
					import Mute from '../../../models/mute';
 | 
				
			||||||
import { pack } from '../../../models/note';
 | 
					import { pack } from '../../../models/note';
 | 
				
			||||||
 | 
					import shouldMuteThisNote from '../../../misc/should-mute-this-note';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(
 | 
					export default async function(
 | 
				
			||||||
	request: websocket.request,
 | 
						request: websocket.request,
 | 
				
			||||||
| 
						 | 
					@ -26,17 +27,8 @@ export default async function(
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
							// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
				
			||||||
		if (mutedUserIds.indexOf(note.userId) != -1) {
 | 
							if (shouldMuteThisNote(note, mutedUserIds)) return;
 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		//#endregion
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		connection.send(JSON.stringify({
 | 
							connection.send(JSON.stringify({
 | 
				
			||||||
			type: 'note',
 | 
								type: 'note',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import Xev from 'xev';
 | 
				
			||||||
import { IUser } from '../../../models/user';
 | 
					import { IUser } from '../../../models/user';
 | 
				
			||||||
import Mute from '../../../models/mute';
 | 
					import Mute from '../../../models/mute';
 | 
				
			||||||
import { pack } from '../../../models/note';
 | 
					import { pack } from '../../../models/note';
 | 
				
			||||||
 | 
					import shouldMuteThisNote from '../../../misc/should-mute-this-note';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function(
 | 
					export default async function(
 | 
				
			||||||
	request: websocket.request,
 | 
						request: websocket.request,
 | 
				
			||||||
| 
						 | 
					@ -23,17 +24,8 @@ export default async function(
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
							// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | 
				
			||||||
		if (mutedUserIds.indexOf(note.userId) != -1) {
 | 
							if (shouldMuteThisNote(note, mutedUserIds)) return;
 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		//#endregion
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		connection.send(JSON.stringify({
 | 
							connection.send(JSON.stringify({
 | 
				
			||||||
			type: 'note',
 | 
								type: 'note',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue