diff --git a/src/app/services/data/post.service.ts b/src/app/services/data/post.service.ts index 408bcea..c6dbe8b 100644 --- a/src/app/services/data/post.service.ts +++ b/src/app/services/data/post.service.ts @@ -20,7 +20,7 @@ export class PostService { let result: Array = new Array(); let currentUser = await this.usersvc.getCurrentUser(); - let posts = await firstValueFrom(this.afs.collection('post').valueChanges({ idField: 'id' })); + let posts = await firstValueFrom(this.afs.collection('post', ref => ref.orderBy('date', 'desc')).valueChanges({ idField: 'id' })); posts.forEach(async post=>{ let user = await firstValueFrom(this.afs.doc((post as any).user).valueChanges()) as User; @@ -51,7 +51,7 @@ export class PostService { // /user -> currentUser let user = await this.usersvc.getCurrentUser(); let userRef = this.afs.doc('/user/' + user.username).ref; - let posts = (await firstValueFrom(this.afs.collection('post', ref => ref.where('user', '==', userRef)).valueChanges({ idField: 'id' }))); + let posts = (await firstValueFrom(this.afs.collection('post', ref => ref.where('user', '==', userRef).orderBy('date', 'desc')).valueChanges({ idField: 'id' }))); posts.forEach(async (post) => { let likes = await firstValueFrom(this.afs.collection('like', ref => ref.where('post', '==', this.afs.doc('/post/' + post.id).ref)).valueChanges()); result.push({ @@ -70,7 +70,7 @@ export class PostService { let user = await this.usersvc.getUser(username); let userRef = this.afs.doc('/user/' + user.username).ref; let currentUser = await this.usersvc.getCurrentUser(); - let posts = (await firstValueFrom(this.afs.collection('post', ref => ref.where('user', '==', userRef)).valueChanges({ idField: 'id' }))); + let posts = (await firstValueFrom(this.afs.collection('post', ref => ref.where('user', '==', userRef).orderBy('date', 'desc')).valueChanges({ idField: 'id' }))); posts.forEach(async (post) => { let likes = await firstValueFrom(this.afs.collection('like', ref => ref.where('post', '==', this.afs.doc('/post/' + post.id).ref)).valueChanges()); result.push({ @@ -96,7 +96,8 @@ export class PostService { this.afs.collection('post').add({ user: this.afs.doc('/user/' + user.username).ref, content: content, - image: image + image: image, + date: Date.now() }) .then(() => resolve()) .catch(() => reject())