bye room
|  | @ -124,6 +124,7 @@ export class UserProfile { | |||
| 	}) | ||||
| 	public clientData: Record<string, any>; | ||||
| 
 | ||||
| 	// TODO: そのうち消す
 | ||||
| 	@Column('jsonb', { | ||||
| 		default: {}, | ||||
| 		comment: 'The room data of the User.', | ||||
|  |  | |||
|  | @ -1,160 +0,0 @@ | |||
| import $ from 'cafy'; | ||||
| import define from '../../define'; | ||||
| import { ApiError } from '../../error'; | ||||
| import { Users, UserProfiles } from '@/models/index'; | ||||
| import { ID } from '@/misc/cafy-id'; | ||||
| import { toPunyNullable } from '@/misc/convert-host'; | ||||
| 
 | ||||
| export const meta = { | ||||
| 	tags: ['room'], | ||||
| 
 | ||||
| 	requireCredential: false as const, | ||||
| 
 | ||||
| 	params: { | ||||
| 		userId: { | ||||
| 			validator: $.optional.type(ID), | ||||
| 		}, | ||||
| 
 | ||||
| 		username: { | ||||
| 			validator: $.optional.str, | ||||
| 		}, | ||||
| 
 | ||||
| 		host: { | ||||
| 			validator: $.optional.nullable.str, | ||||
| 		}, | ||||
| 	}, | ||||
| 
 | ||||
| 	errors: { | ||||
| 		noSuchUser: { | ||||
| 			message: 'No such user.', | ||||
| 			code: 'NO_SUCH_USER', | ||||
| 			id: '7ad3fa3e-5e12-42f0-b23a-f3d13f10ee4b', | ||||
| 		}, | ||||
| 	}, | ||||
| 
 | ||||
| 	res: { | ||||
| 		type: 'object' as const, | ||||
| 		optional: false as const, nullable: false as const, | ||||
| 		properties: { | ||||
| 			roomType: { | ||||
| 				type: 'string' as const, | ||||
| 				optional: false as const, nullable: false as const, | ||||
| 				enum: ['default', 'washitsu'], | ||||
| 			}, | ||||
| 			furnitures: { | ||||
| 				type: 'array' as const, | ||||
| 				optional: false as const, nullable: false as const, | ||||
| 				items: { | ||||
| 					type: 'object' as const, | ||||
| 					optional: false as const, nullable: false as const, | ||||
| 					properties: { | ||||
| 						id: { | ||||
| 							type: 'string' as const, | ||||
| 							optional: false as const, nullable: false as const, | ||||
| 						}, | ||||
| 						type: { | ||||
| 							type: 'string' as const, | ||||
| 							optional: false as const, nullable: false as const, | ||||
| 						}, | ||||
| 						props: { | ||||
| 							type: 'object' as const, | ||||
| 							optional: true as const, nullable: false as const, | ||||
| 						}, | ||||
| 						position: { | ||||
| 							type: 'object' as const, | ||||
| 							optional: false as const, nullable: false as const, | ||||
| 							properties: { | ||||
| 								x: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 								y: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 								z: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 						rotation: { | ||||
| 							type: 'object' as const, | ||||
| 							optional: false as const, nullable: false as const, | ||||
| 							properties: { | ||||
| 								x: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 								y: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 								z: { | ||||
| 									type: 'number' as const, | ||||
| 									optional: false as const, nullable: false as const, | ||||
| 								}, | ||||
| 							}, | ||||
| 						}, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			carpetColor: { | ||||
| 				type: 'string' as const, | ||||
| 				optional: false as const, nullable: false as const, | ||||
| 				format: 'hex', | ||||
| 				example: '#85CAF0', | ||||
| 			}, | ||||
| 		}, | ||||
| 	}, | ||||
| }; | ||||
| 
 | ||||
| // eslint-disable-next-line import/no-default-export
 | ||||
| export default define(meta, async (ps, me) => { | ||||
| 	const user = await Users.findOne(ps.userId != null | ||||
| 		? { id: ps.userId } | ||||
| 		: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) }); | ||||
| 
 | ||||
| 	if (user == null) { | ||||
| 		throw new ApiError(meta.errors.noSuchUser); | ||||
| 	} | ||||
| 
 | ||||
| 	const profile = await UserProfiles.findOneOrFail(user.id); | ||||
| 
 | ||||
| 	if (profile.room.furnitures == null) { | ||||
| 		await UserProfiles.update(user.id, { | ||||
| 			room: { | ||||
| 				furnitures: [], | ||||
| 				...profile.room, | ||||
| 			}, | ||||
| 		}); | ||||
| 
 | ||||
| 		profile.room.furnitures = []; | ||||
| 	} | ||||
| 
 | ||||
| 	if (profile.room.roomType == null) { | ||||
| 		const initialType = 'default'; | ||||
| 		await UserProfiles.update(user.id, { | ||||
| 			room: { | ||||
| 				roomType: initialType as any, | ||||
| 				...profile.room, | ||||
| 			}, | ||||
| 		}); | ||||
| 
 | ||||
| 		profile.room.roomType = initialType; | ||||
| 	} | ||||
| 
 | ||||
| 	if (profile.room.carpetColor == null) { | ||||
| 		const initialColor = '#85CAF0'; | ||||
| 		await UserProfiles.update(user.id, { | ||||
| 			room: { | ||||
| 				carpetColor: initialColor as any, | ||||
| 				...profile.room, | ||||
| 			}, | ||||
| 		}); | ||||
| 
 | ||||
| 		profile.room.carpetColor = initialColor; | ||||
| 	} | ||||
| 
 | ||||
| 	return profile.room; | ||||
| }); | ||||
|  | @ -1,52 +0,0 @@ | |||
| import $ from 'cafy'; | ||||
| import { publishMainStream } from '@/services/stream'; | ||||
| import define from '../../define'; | ||||
| import { Users, UserProfiles } from '@/models/index'; | ||||
| 
 | ||||
| export const meta = { | ||||
| 	tags: ['room'], | ||||
| 
 | ||||
| 	requireCredential: true as const, | ||||
| 
 | ||||
| 	params: { | ||||
| 		room: { | ||||
| 			validator: $.obj({ | ||||
| 				furnitures: $.arr($.obj({ | ||||
| 					id: $.str, | ||||
| 					type: $.str, | ||||
| 					position: $.obj({ | ||||
| 						x: $.num, | ||||
| 						y: $.num, | ||||
| 						z: $.num, | ||||
| 					}), | ||||
| 					rotation: $.obj({ | ||||
| 						x: $.num, | ||||
| 						y: $.num, | ||||
| 						z: $.num, | ||||
| 					}), | ||||
| 					props: $.optional.nullable.obj(), | ||||
| 				})), | ||||
| 				roomType: $.str, | ||||
| 				carpetColor: $.str, | ||||
| 			}), | ||||
| 		}, | ||||
| 	}, | ||||
| }; | ||||
| 
 | ||||
| // eslint-disable-next-line import/no-default-export
 | ||||
| export default define(meta, async (ps, user) => { | ||||
| 	await UserProfiles.update(user.id, { | ||||
| 		room: ps.room as any, | ||||
| 	}); | ||||
| 
 | ||||
| 	const iObj = await Users.pack(user.id, user, { | ||||
| 		detail: true, | ||||
| 		includeSecrets: true, | ||||
| 	}); | ||||
| 
 | ||||
| 	// Publish meUpdated event
 | ||||
| 	publishMainStream(user.id, 'meUpdated', iObj); | ||||
| 
 | ||||
| 	// TODO: レスポンスがおかしいと思う by YuzuRyo61
 | ||||
| 	return iObj; | ||||
| }); | ||||
| Before Width: | Height: | Size: 43 KiB | 
| Before Width: | Height: | Size: 3.4 KiB | 
| Before Width: | Height: | Size: 60 KiB | 
| Before Width: | Height: | Size: 8.4 KiB | 
| Before Width: | Height: | Size: 16 KiB | 
| Before Width: | Height: | Size: 4.5 KiB | 
| Before Width: | Height: | Size: 16 KiB | 
| Before Width: | Height: | Size: 3.5 KiB | 
| Before Width: | Height: | Size: 290 KiB | 
| Before Width: | Height: | Size: 10 KiB | 
| Before Width: | Height: | Size: 124 KiB | 
| Before Width: | Height: | Size: 22 KiB | 
| Before Width: | Height: | Size: 8.1 KiB | 
| Before Width: | Height: | Size: 11 KiB | 
| Before Width: | Height: | Size: 4.4 KiB | 
| Before Width: | Height: | Size: 688 B | 
| Before Width: | Height: | Size: 20 KiB | 
| Before Width: | Height: | Size: 102 KiB | 
| Before Width: | Height: | Size: 16 KiB | 
| Before Width: | Height: | Size: 658 B | 
| Before Width: | Height: | Size: 1.5 KiB | 
| Before Width: | Height: | Size: 24 KiB | 
| Before Width: | Height: | Size: 85 KiB | 
| Before Width: | Height: | Size: 2.9 KiB | 
| Before Width: | Height: | Size: 63 KiB | 
| Before Width: | Height: | Size: 2.6 KiB | 
| Before Width: | Height: | Size: 30 KiB |