mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	新形式に移行
This commit is contained in:
		
							parent
							
								
									118db9b267
								
							
						
					
					
						commit
						a81a34cd76
					
				
					 1 changed files with 77 additions and 44 deletions
				
			
		| 
						 | 
					@ -4,48 +4,81 @@ import Mute from '../../../../models/mute';
 | 
				
			||||||
import { getFriends } from '../../common/get-friends';
 | 
					import { getFriends } from '../../common/get-friends';
 | 
				
			||||||
import { pack } from '../../../../models/note';
 | 
					import { pack } from '../../../../models/note';
 | 
				
			||||||
import { ILocalUser } from '../../../../models/user';
 | 
					import { ILocalUser } from '../../../../models/user';
 | 
				
			||||||
 | 
					import getParams from '../../get-params';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const meta = {
 | 
				
			||||||
 | 
						name: 'notes/timeline',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						desc: {
 | 
				
			||||||
 | 
							ja: 'タイムラインを取得します。'
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						params: {
 | 
				
			||||||
 | 
							limit: $.num.optional.range(1, 100).note({
 | 
				
			||||||
 | 
								default: 10,
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '最大数'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							sinceId: $.type(ID).optional.note({
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '指定すると、この投稿を基点としてより新しい投稿を取得します'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							untilId: $.type(ID).optional.note({
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '指定すると、この投稿を基点としてより古い投稿を取得します'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							sinceDate: $.num.optional.note({
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							untilDate: $.num.optional.note({
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							includeMyRenotes: $.bool.optional.note({
 | 
				
			||||||
 | 
								default: true,
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: '自分の行ったRenoteを含めるかどうか'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							includeRenotedMyNotes: $.bool.optional.note({
 | 
				
			||||||
 | 
								default: true,
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: 'Renoteされた自分の投稿を含めるかどうか'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							mediaOnly: $.bool.optional.note({
 | 
				
			||||||
 | 
								desc: {
 | 
				
			||||||
 | 
									ja: 'true にすると、メディアが添付された投稿だけ取得します'
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Get timeline of myself
 | 
					 * Get timeline of myself
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export default async (params: any, user: ILocalUser) => {
 | 
					export default async (params: any, user: ILocalUser) => {
 | 
				
			||||||
	// Get 'limit' parameter
 | 
						const [ps, psErr] = getParams(meta, params);
 | 
				
			||||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
						if (psErr) throw psErr;
 | 
				
			||||||
	if (limitErr) throw 'invalid limit param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'sinceId' parameter
 | 
					 | 
				
			||||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
					 | 
				
			||||||
	if (sinceIdErr) throw 'invalid sinceId param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'untilId' parameter
 | 
					 | 
				
			||||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
					 | 
				
			||||||
	if (untilIdErr) throw 'invalid untilId param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'sinceDate' parameter
 | 
					 | 
				
			||||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
					 | 
				
			||||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'untilDate' parameter
 | 
					 | 
				
			||||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
					 | 
				
			||||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
						// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
				
			||||||
	if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
 | 
						if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
 | 
				
			||||||
		throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
 | 
							throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get 'includeMyRenotes' parameter
 | 
					 | 
				
			||||||
	const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes);
 | 
					 | 
				
			||||||
	if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'includeRenotedMyNotes' parameter
 | 
					 | 
				
			||||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes);
 | 
					 | 
				
			||||||
	if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Get 'mediaOnly' parameter
 | 
					 | 
				
			||||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
 | 
					 | 
				
			||||||
	if (mediaOnlyErr) throw 'invalid mediaOnly param';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	const [followings, mutedUserIds] = await Promise.all([
 | 
						const [followings, mutedUserIds] = await Promise.all([
 | 
				
			||||||
		// フォローを取得
 | 
							// フォローを取得
 | 
				
			||||||
		// Fetch following
 | 
							// Fetch following
 | 
				
			||||||
| 
						 | 
					@ -107,7 +140,7 @@ export default async (params: any, user: ILocalUser) => {
 | 
				
			||||||
	// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
 | 
						// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
 | 
				
			||||||
	// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
 | 
						// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (includeMyRenotes === false) {
 | 
						if (ps.includeMyRenotes === false) {
 | 
				
			||||||
		query.$and.push({
 | 
							query.$and.push({
 | 
				
			||||||
			$or: [{
 | 
								$or: [{
 | 
				
			||||||
				userId: { $ne: user._id }
 | 
									userId: { $ne: user._id }
 | 
				
			||||||
| 
						 | 
					@ -123,7 +156,7 @@ export default async (params: any, user: ILocalUser) => {
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (includeRenotedMyNotes === false) {
 | 
						if (ps.includeRenotedMyNotes === false) {
 | 
				
			||||||
		query.$and.push({
 | 
							query.$and.push({
 | 
				
			||||||
			$or: [{
 | 
								$or: [{
 | 
				
			||||||
				'_renote.userId': { $ne: user._id }
 | 
									'_renote.userId': { $ne: user._id }
 | 
				
			||||||
| 
						 | 
					@ -139,29 +172,29 @@ export default async (params: any, user: ILocalUser) => {
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (mediaOnly) {
 | 
						if (ps.mediaOnly) {
 | 
				
			||||||
		query.$and.push({
 | 
							query.$and.push({
 | 
				
			||||||
			mediaIds: { $exists: true, $ne: [] }
 | 
								mediaIds: { $exists: true, $ne: [] }
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (sinceId) {
 | 
						if (ps.sinceId) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
		query._id = {
 | 
							query._id = {
 | 
				
			||||||
			$gt: sinceId
 | 
								$gt: ps.sinceId
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (untilId) {
 | 
						} else if (ps.untilId) {
 | 
				
			||||||
		query._id = {
 | 
							query._id = {
 | 
				
			||||||
			$lt: untilId
 | 
								$lt: ps.untilId
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (sinceDate) {
 | 
						} else if (ps.sinceDate) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort._id = 1;
 | 
				
			||||||
		query.createdAt = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$gt: new Date(sinceDate)
 | 
								$gt: new Date(ps.sinceDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (untilDate) {
 | 
						} else if (ps.untilDate) {
 | 
				
			||||||
		query.createdAt = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$lt: new Date(untilDate)
 | 
								$lt: new Date(ps.untilDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//#endregion
 | 
						//#endregion
 | 
				
			||||||
| 
						 | 
					@ -169,7 +202,7 @@ export default async (params: any, user: ILocalUser) => {
 | 
				
			||||||
	// Issue query
 | 
						// Issue query
 | 
				
			||||||
	const timeline = await Note
 | 
						const timeline = await Note
 | 
				
			||||||
		.find(query, {
 | 
							.find(query, {
 | 
				
			||||||
			limit: limit,
 | 
								limit: ps.limit,
 | 
				
			||||||
			sort: sort
 | 
								sort: sort
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue