refactor: remove duplicate code (#8895)
This commit is contained in:
		
							parent
							
								
									0ec266abf7
								
							
						
					
					
						commit
						bc3ae901cc
					
				
					 12 changed files with 41 additions and 64 deletions
				
			
		|  | @ -1,15 +0,0 @@ | |||
| export function isBlockerUserRelated(note: any, blockerUserIds: Set<string>): boolean { | ||||
| 	if (blockerUserIds.has(note.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.reply != null && blockerUserIds.has(note.reply.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.renote != null && blockerUserIds.has(note.renote.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
|  | @ -1,15 +0,0 @@ | |||
| export function isMutedUserRelated(note: any, mutedUserIds: Set<string>): boolean { | ||||
| 	if (mutedUserIds.has(note.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.reply != null && mutedUserIds.has(note.reply.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.renote != null && mutedUserIds.has(note.renote.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
							
								
								
									
										15
									
								
								packages/backend/src/misc/is-user-related.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								packages/backend/src/misc/is-user-related.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,15 @@ | |||
| export function isUserRelated(note: any, userIds: Set<string>): boolean { | ||||
| 	if (userIds.has(note.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.reply != null && userIds.has(note.reply.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	if (note.renote != null && userIds.has(note.renote.userId)) { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
|  | @ -1,7 +1,6 @@ | |||
| import Channel from '../channel.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { StreamMessages } from '../types.js'; | ||||
| 
 | ||||
| export default class extends Channel { | ||||
|  | @ -27,9 +26,9 @@ export default class extends Channel { | |||
| 			const note = await Notes.pack(data.body.id, this.user, { detail: true }); | ||||
| 
 | ||||
| 			// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 			if (isMutedUserRelated(note, this.muting)) return; | ||||
| 			if (isUserRelated(note, this.muting)) return; | ||||
| 			// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 			if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 			if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 			this.connection.cacheNote(note); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| import Channel from '../channel.js'; | ||||
| import { Notes, Users } from '@/models/index.js'; | ||||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { User } from '@/models/entities/user.js'; | ||||
| import { StreamMessages } from '../types.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
|  | @ -45,9 +44,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		this.connection.cacheNote(note); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,10 +1,9 @@ | |||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import Channel from '../channel.js'; | ||||
| import { fetchMeta } from '@/misc/fetch-meta.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { checkWordMute } from '@/misc/check-word-mute.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isInstanceMuted } from '@/misc/is-instance-muted.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
| export default class extends Channel { | ||||
|  | @ -55,9 +54,9 @@ export default class extends Channel { | |||
| 		if (isInstanceMuted(note, new Set<string>(this.userProfile?.mutedInstances ?? []))) return; | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートすべきNoteだったら無視する
 | ||||
| 		// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)
 | ||||
|  |  | |||
|  | @ -1,8 +1,7 @@ | |||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import Channel from '../channel.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { normalizeForSearch } from '@/misc/normalize-for-search.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
| export default class extends Channel { | ||||
|  | @ -38,9 +37,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		this.connection.cacheNote(note); | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,7 @@ | |||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import Channel from '../channel.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { checkWordMute } from '@/misc/check-word-mute.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { isInstanceMuted } from '@/misc/is-instance-muted.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
|  | @ -63,9 +62,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートすべきNoteだったら無視する
 | ||||
| 		// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)
 | ||||
|  |  | |||
|  | @ -1,9 +1,8 @@ | |||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import Channel from '../channel.js'; | ||||
| import { fetchMeta } from '@/misc/fetch-meta.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { checkWordMute } from '@/misc/check-word-mute.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { isInstanceMuted } from '@/misc/is-instance-muted.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
|  | @ -71,9 +70,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートすべきNoteだったら無視する
 | ||||
| 		// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)
 | ||||
|  |  | |||
|  | @ -1,9 +1,8 @@ | |||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import Channel from '../channel.js'; | ||||
| import { fetchMeta } from '@/misc/fetch-meta.js'; | ||||
| import { Notes } from '@/models/index.js'; | ||||
| import { checkWordMute } from '@/misc/check-word-mute.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
| export default class extends Channel { | ||||
|  | @ -52,9 +51,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (iUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートすべきNoteだったら無視する
 | ||||
| 		// TODO: 将来的には、単にMutedNoteテーブルにレコードがあるかどうかで判定したい(以下の理由により難しそうではある)
 | ||||
|  |  | |||
|  | @ -1,8 +1,7 @@ | |||
| import Channel from '../channel.js'; | ||||
| import { Notes, UserListJoinings, UserLists } from '@/models/index.js'; | ||||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import { User } from '@/models/entities/user.js'; | ||||
| import { isBlockerUserRelated } from '@/misc/is-blocker-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { Packed } from '@/misc/schema.js'; | ||||
| 
 | ||||
| export default class extends Channel { | ||||
|  | @ -76,9 +75,9 @@ export default class extends Channel { | |||
| 		} | ||||
| 
 | ||||
| 		// 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
 | ||||
| 		if (isMutedUserRelated(note, this.muting)) return; | ||||
| 		if (isUserRelated(note, this.muting)) return; | ||||
| 		// 流れてきたNoteがブロックされているユーザーが関わるものだったら無視する
 | ||||
| 		if (isBlockerUserRelated(note, this.blocking)) return; | ||||
| 		if (isUserRelated(note, this.blocking)) return; | ||||
| 
 | ||||
| 		this.send('note', note); | ||||
| 	} | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import { Antenna } from '@/models/entities/antenna.js'; | |||
| import { Note } from '@/models/entities/note.js'; | ||||
| import { AntennaNotes, Mutings, Notes } from '@/models/index.js'; | ||||
| import { genId } from '@/misc/gen-id.js'; | ||||
| import { isMutedUserRelated } from '@/misc/is-muted-user-related.js'; | ||||
| import { isUserRelated } from '@/misc/is-user-related.js'; | ||||
| import { publishAntennaStream, publishMainStream } from '@/services/stream.js'; | ||||
| import { User } from '@/models/entities/user.js'; | ||||
| 
 | ||||
|  | @ -39,7 +39,7 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: { | |||
| 			_note.renote = await Notes.findOneByOrFail({ id: note.renoteId }); | ||||
| 		} | ||||
| 
 | ||||
| 		if (isMutedUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) { | ||||
| 		if (isUserRelated(_note, new Set<string>(mutings.map(x => x.muteeId)))) { | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue