Clean up
This commit is contained in:
		
							parent
							
								
									7c5b9ba1d1
								
							
						
					
					
						commit
						50d56bdc25
					
				|  | @ -47,7 +47,6 @@ type IUserBase = { | |||
| 	bannerId: mongo.ObjectID; | ||||
| 	data: any; | ||||
| 	description: string; | ||||
| 	latestNote: INote; | ||||
| 	pinnedNoteId: mongo.ObjectID; | ||||
| 	isSuspended: boolean; | ||||
| 	keywords: string[]; | ||||
|  | @ -332,9 +331,6 @@ export const pack = ( | |||
| 	_user.id = _user._id; | ||||
| 	delete _user._id; | ||||
| 
 | ||||
| 	// Remove needless properties
 | ||||
| 	delete _user.latestNote; | ||||
| 
 | ||||
| 	if (_user.host == null) { | ||||
| 		// Remove private properties
 | ||||
| 		delete _user.keypair; | ||||
|  |  | |||
|  | @ -97,31 +97,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res | |||
| 			return rej('cannot renote to renote'); | ||||
| 		} | ||||
| 
 | ||||
| 		// Fetch recently note
 | ||||
| 		const latestNote = await Note.findOne({ | ||||
| 			userId: user._id | ||||
| 		}, { | ||||
| 			sort: { | ||||
| 				_id: -1 | ||||
| 			} | ||||
| 		}); | ||||
| 
 | ||||
| 		isQuote = text != null || files != null; | ||||
| 
 | ||||
| 		// 直近と同じRenote対象かつ引用じゃなかったらエラー
 | ||||
| 		if (latestNote && | ||||
| 			latestNote.renoteId && | ||||
| 			latestNote.renoteId.equals(renote._id) && | ||||
| 			!isQuote) { | ||||
| 			return rej('cannot renote same note that already reposted in your latest note'); | ||||
| 		} | ||||
| 
 | ||||
| 		// 直近がRenote対象かつ引用じゃなかったらエラー
 | ||||
| 		if (latestNote && | ||||
| 			latestNote._id.equals(renote._id) && | ||||
| 			!isQuote) { | ||||
| 			return rej('cannot renote your latest note'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// Get 'replyId' parameter
 | ||||
|  | @ -208,24 +184,6 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res | |||
| 		return rej('text, mediaIds, renoteId or poll is required'); | ||||
| 	} | ||||
| 
 | ||||
| 	// 直近の投稿と重複してたらエラー
 | ||||
| 	// TODO: 直近の投稿が一日前くらいなら重複とは見なさない
 | ||||
| 	if (user.latestNote) { | ||||
| 		if (deepEqual({ | ||||
| 			text: user.latestNote.text, | ||||
| 			reply: user.latestNote.replyId ? user.latestNote.replyId.toString() : null, | ||||
| 			renote: user.latestNote.renoteId ? user.latestNote.renoteId.toString() : null, | ||||
| 			mediaIds: (user.latestNote.mediaIds || []).map(id => id.toString()) | ||||
| 		}, { | ||||
| 			text: text, | ||||
| 			reply: reply ? reply._id.toString() : null, | ||||
| 			renote: renote ? renote._id.toString() : null, | ||||
| 			mediaIds: (files || []).map(file => file._id.toString()) | ||||
| 		})) { | ||||
| 			return rej('duplicate'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// 投稿を作成
 | ||||
| 	const note = await create(user, { | ||||
| 		createdAt: new Date(), | ||||
|  |  | |||
|  | @ -89,14 +89,10 @@ export default async (user: IUser, data: { | |||
| 
 | ||||
| 	res(note); | ||||
| 
 | ||||
| 	// Increment notes count
 | ||||
| 	User.update({ _id: user._id }, { | ||||
| 		// Increment notes count
 | ||||
| 		$inc: { | ||||
| 			notesCount: 1 | ||||
| 		}, | ||||
| 		// Update latest note
 | ||||
| 		$set: { | ||||
| 			latestNote: note | ||||
| 		} | ||||
| 	}); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue