sort user timeline by date (#3210)
This commit is contained in:
		
							parent
							
								
									50824a7245
								
							
						
					
					
						commit
						81805b01cc
					
				
					 7 changed files with 19 additions and 13 deletions
				
			
		| 
						 | 
					@ -155,7 +155,8 @@ export default Vue.extend({
 | 
				
			||||||
			this.$root.api('users/notes', {
 | 
								this.$root.api('users/notes', {
 | 
				
			||||||
				userId: this.user.id,
 | 
									userId: this.user.id,
 | 
				
			||||||
				fileType: image,
 | 
									fileType: image,
 | 
				
			||||||
				limit: 9
 | 
									limit: 9,
 | 
				
			||||||
 | 
									untilDate: new Date().getTime() + 1000 * 86400 * 365
 | 
				
			||||||
			}).then(notes => {
 | 
								}).then(notes => {
 | 
				
			||||||
				notes.forEach(note => {
 | 
									notes.forEach(note => {
 | 
				
			||||||
					note.files.forEach(file => {
 | 
										note.files.forEach(file => {
 | 
				
			||||||
| 
						 | 
					@ -254,6 +255,7 @@ export default Vue.extend({
 | 
				
			||||||
				this.$root.api('users/notes', {
 | 
									this.$root.api('users/notes', {
 | 
				
			||||||
					userId: this.user.id,
 | 
										userId: this.user.id,
 | 
				
			||||||
					limit: fetchLimit + 1,
 | 
										limit: fetchLimit + 1,
 | 
				
			||||||
 | 
										untilDate: new Date().getTime() + 1000 * 86400 * 365,
 | 
				
			||||||
					withFiles: this.withFiles,
 | 
										withFiles: this.withFiles,
 | 
				
			||||||
					includeMyRenotes: this.$store.state.settings.showMyRenotes,
 | 
										includeMyRenotes: this.$store.state.settings.showMyRenotes,
 | 
				
			||||||
					includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
 | 
										includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
 | 
				
			||||||
| 
						 | 
					@ -274,7 +276,7 @@ export default Vue.extend({
 | 
				
			||||||
			const promise = this.$root.api('users/notes', {
 | 
								const promise = this.$root.api('users/notes', {
 | 
				
			||||||
				userId: this.user.id,
 | 
									userId: this.user.id,
 | 
				
			||||||
				limit: fetchLimit + 1,
 | 
									limit: fetchLimit + 1,
 | 
				
			||||||
				untilId: (this.$refs.timeline as any).tail().id,
 | 
									untilDate: new Date((this.$refs.timeline as any).tail().createdAt).getTime(),
 | 
				
			||||||
				withFiles: this.withFiles,
 | 
									withFiles: this.withFiles,
 | 
				
			||||||
				includeMyRenotes: this.$store.state.settings.showMyRenotes,
 | 
									includeMyRenotes: this.$store.state.settings.showMyRenotes,
 | 
				
			||||||
				includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
 | 
									includeRenotedMyNotes: this.$store.state.settings.showRenotedMyNotes,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,8 @@ export default Vue.extend({
 | 
				
			||||||
		this.$root.api('users/notes', {
 | 
							this.$root.api('users/notes', {
 | 
				
			||||||
			userId: this.user.id,
 | 
								userId: this.user.id,
 | 
				
			||||||
			withFiles: true,
 | 
								withFiles: true,
 | 
				
			||||||
			limit: 9
 | 
								limit: 9,
 | 
				
			||||||
 | 
								untilDate: new Date().getTime() + 1000 * 86400 * 365
 | 
				
			||||||
		}).then(notes => {
 | 
							}).then(notes => {
 | 
				
			||||||
			notes.forEach(note => {
 | 
								notes.forEach(note => {
 | 
				
			||||||
				note.files.forEach(file => {
 | 
									note.files.forEach(file => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,7 +63,7 @@ export default Vue.extend({
 | 
				
			||||||
				this.$root.api('users/notes', {
 | 
									this.$root.api('users/notes', {
 | 
				
			||||||
					userId: this.user.id,
 | 
										userId: this.user.id,
 | 
				
			||||||
					limit: fetchLimit + 1,
 | 
										limit: fetchLimit + 1,
 | 
				
			||||||
					untilDate: this.date ? this.date.getTime() : undefined,
 | 
										untilDate: this.date ? this.date.getTime() : new Date().getTime() + 1000 * 86400 * 365,
 | 
				
			||||||
					includeReplies: this.mode == 'with-replies',
 | 
										includeReplies: this.mode == 'with-replies',
 | 
				
			||||||
					withFiles: this.mode == 'with-media'
 | 
										withFiles: this.mode == 'with-media'
 | 
				
			||||||
				}).then(notes => {
 | 
									}).then(notes => {
 | 
				
			||||||
| 
						 | 
					@ -86,7 +86,7 @@ export default Vue.extend({
 | 
				
			||||||
				limit: fetchLimit + 1,
 | 
									limit: fetchLimit + 1,
 | 
				
			||||||
				includeReplies: this.mode == 'with-replies',
 | 
									includeReplies: this.mode == 'with-replies',
 | 
				
			||||||
				withFiles: this.mode == 'with-media',
 | 
									withFiles: this.mode == 'with-media',
 | 
				
			||||||
				untilId: (this.$refs.timeline as any).tail().id
 | 
									untilDate: new Date((this.$refs.timeline as any).tail().createdAt).getTime()
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			promise.then(notes => {
 | 
								promise.then(notes => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,8 @@ export default Vue.extend({
 | 
				
			||||||
				this.$root.api('users/notes', {
 | 
									this.$root.api('users/notes', {
 | 
				
			||||||
					userId: this.user.id,
 | 
										userId: this.user.id,
 | 
				
			||||||
					withFiles: this.withMedia,
 | 
										withFiles: this.withMedia,
 | 
				
			||||||
					limit: fetchLimit + 1
 | 
										limit: fetchLimit + 1,
 | 
				
			||||||
 | 
										untilDate: new Date().getTime() + 1000 * 86400 * 365
 | 
				
			||||||
				}).then(notes => {
 | 
									}).then(notes => {
 | 
				
			||||||
					if (notes.length == fetchLimit + 1) {
 | 
										if (notes.length == fetchLimit + 1) {
 | 
				
			||||||
						notes.pop();
 | 
											notes.pop();
 | 
				
			||||||
| 
						 | 
					@ -66,7 +67,7 @@ export default Vue.extend({
 | 
				
			||||||
				userId: this.user.id,
 | 
									userId: this.user.id,
 | 
				
			||||||
				withFiles: this.withMedia,
 | 
									withFiles: this.withMedia,
 | 
				
			||||||
				limit: fetchLimit + 1,
 | 
									limit: fetchLimit + 1,
 | 
				
			||||||
				untilId: (this.$refs.timeline as any).tail().id
 | 
									untilDate: new Date((this.$refs.timeline as any).tail().createdAt).getTime()
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			promise.then(notes => {
 | 
								promise.then(notes => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,8 @@ export default Vue.extend({
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
	mounted() {
 | 
						mounted() {
 | 
				
			||||||
		this.$root.api('users/notes', {
 | 
							this.$root.api('users/notes', {
 | 
				
			||||||
			userId: this.user.id
 | 
								userId: this.user.id,
 | 
				
			||||||
 | 
								untilDate: new Date().getTime() + 1000 * 86400 * 365
 | 
				
			||||||
		}).then(notes => {
 | 
							}).then(notes => {
 | 
				
			||||||
			this.notes = notes;
 | 
								this.notes = notes;
 | 
				
			||||||
			this.fetching = false;
 | 
								this.fetching = false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,8 @@ export default Vue.extend({
 | 
				
			||||||
		this.$root.api('users/notes', {
 | 
							this.$root.api('users/notes', {
 | 
				
			||||||
			userId: this.user.id,
 | 
								userId: this.user.id,
 | 
				
			||||||
			withFiles: true,
 | 
								withFiles: true,
 | 
				
			||||||
			limit: 6
 | 
								limit: 6,
 | 
				
			||||||
 | 
								untilDate: new Date().getTime() + 1000 * 86400 * 365
 | 
				
			||||||
		}).then(notes => {
 | 
							}).then(notes => {
 | 
				
			||||||
			notes.forEach(note => {
 | 
								notes.forEach(note => {
 | 
				
			||||||
				note.media.forEach(media => {
 | 
									note.media.forEach(media => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,9 +153,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//#region Construct query
 | 
						//#region Construct query
 | 
				
			||||||
	const sort = {
 | 
						const sort = { } as any;
 | 
				
			||||||
		_id: -1
 | 
					 | 
				
			||||||
	};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const query = {
 | 
						const query = {
 | 
				
			||||||
		deletedAt: null,
 | 
							deletedAt: null,
 | 
				
			||||||
| 
						 | 
					@ -168,15 +166,17 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
 | 
				
			||||||
			$gt: ps.sinceId
 | 
								$gt: ps.sinceId
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (ps.untilId) {
 | 
						} else if (ps.untilId) {
 | 
				
			||||||
 | 
							sort._id = -1;
 | 
				
			||||||
		query._id = {
 | 
							query._id = {
 | 
				
			||||||
			$lt: ps.untilId
 | 
								$lt: ps.untilId
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (ps.sinceDate) {
 | 
						} else if (ps.sinceDate) {
 | 
				
			||||||
		sort._id = 1;
 | 
							sort.createdAt = 1;
 | 
				
			||||||
		query.createdAt = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$gt: new Date(ps.sinceDate)
 | 
								$gt: new Date(ps.sinceDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	} else if (ps.untilDate) {
 | 
						} else if (ps.untilDate) {
 | 
				
			||||||
 | 
							sort.createdAt = -1;
 | 
				
			||||||
		query.createdAt = {
 | 
							query.createdAt = {
 | 
				
			||||||
			$lt: new Date(ps.untilDate)
 | 
								$lt: new Date(ps.untilDate)
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue