mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	safer typings for userNeedsPublishing and profileNeedsPublishing
				
					
				
			This commit is contained in:
		
							parent
							
								
									02b600c9da
								
							
						
					
					
						commit
						1c65f23445
					
				
					 1 changed files with 12 additions and 6 deletions
				
			
		| 
						 | 
					@ -589,12 +589,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
	// these two methods need to be kept in sync with
 | 
						// these two methods need to be kept in sync with
 | 
				
			||||||
	// `ApRendererService.renderPerson`
 | 
						// `ApRendererService.renderPerson`
 | 
				
			||||||
	private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial<MiUser>): boolean {
 | 
						private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial<MiUser>): boolean {
 | 
				
			||||||
		for (const field of ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss'] as (keyof MiUser)[]) {
 | 
							const basicFields: (keyof MiUser)[] = ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss'];
 | 
				
			||||||
 | 
							for (const field of basicFields) {
 | 
				
			||||||
			if ((field in newUser) && oldUser[field] !== newUser[field]) {
 | 
								if ((field in newUser) && oldUser[field] !== newUser[field]) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for (const arrayField of ['emojis', 'tags'] as (keyof MiUser)[]) {
 | 
					
 | 
				
			||||||
 | 
							const arrayFields: (keyof MiUser)[] = ['emojis', 'tags'];
 | 
				
			||||||
 | 
							for (const arrayField of arrayFields) {
 | 
				
			||||||
			if ((arrayField in newUser) !== (arrayField in oldUser)) {
 | 
								if ((arrayField in newUser) !== (arrayField in oldUser)) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -604,7 +607,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
			if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
 | 
								if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (oldArray.join("\0") !== newArray.join("\0")) {
 | 
								if (oldArray.join('\0') !== newArray.join('\0')) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -612,12 +615,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial<MiUserProfile>): boolean {
 | 
						private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial<MiUserProfile>): boolean {
 | 
				
			||||||
		for (const field of ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'] as (keyof MiUserProfile)[]) {
 | 
							const basicFields: (keyof MiUserProfile)[] = ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'];
 | 
				
			||||||
 | 
							for (const field of basicFields) {
 | 
				
			||||||
			if ((field in newProfile) && oldProfile[field] !== newProfile[field]) {
 | 
								if ((field in newProfile) && oldProfile[field] !== newProfile[field]) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for (const arrayField of ['fields'] as (keyof MiUserProfile)[]) {
 | 
					
 | 
				
			||||||
 | 
							const arrayFields: (keyof MiUserProfile)[] = ['fields'];
 | 
				
			||||||
 | 
							for (const arrayField of arrayFields) {
 | 
				
			||||||
			if ((arrayField in newProfile) !== (arrayField in oldProfile)) {
 | 
								if ((arrayField in newProfile) !== (arrayField in oldProfile)) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -627,7 +633,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
			if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
 | 
								if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (oldArray.join("\0") !== newArray.join("\0")) {
 | 
								if (oldArray.join('\0') !== newArray.join('\0')) {
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue