Commit 9b331899 authored by Michal Cikatricis's avatar Michal Cikatricis
Browse files

Feat (postcard): fixed mapping for a new postcard to postcard entity +...

Feat (postcard): fixed mapping for a new postcard to postcard entity + postcards are now received according to users location as well
parent 300ed239
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -103,6 +103,7 @@ class CreatePostcardNotifier extends ChangeNotifier {
        destinationLocation: _destination!.name,
        destinationLocation: _destination!.name,
        text: text,
        text: text,
        senderId: _authService.currentUser.id,
        senderId: _authService.currentUser.id,
        receiverId: '',
        timestamp: Timestamp.now(),
        timestamp: Timestamp.now(),
      ),
      ),
    );
    );
+3 −0
Original line number Original line Diff line number Diff line
@@ -25,10 +25,13 @@ class PostcardService {
  PostcardService(this._userService, this._authService);
  PostcardService(this._userService, this._authService);


  Stream<List<Postcard>> get availablePostcardStream {
  Stream<List<Postcard>> get availablePostcardStream {
    final user = _authService.currentUser;
    final thirtyMinutesAgo = DateTime.now().subtract(Duration(minutes: 30));
    final thirtyMinutesAgo = DateTime.now().subtract(Duration(minutes: 30));
    Timestamp timestamp = Timestamp.fromDate(thirtyMinutesAgo);
    Timestamp timestamp = Timestamp.fromDate(thirtyMinutesAgo);
    final snapshots = _postcardCollection
    final snapshots = _postcardCollection
        .where('receiverId', isEqualTo: '')
        .where('receiverId', isEqualTo: '')
        .where('destinationLocation',
            isEqualTo: user.lastLocation)
        .where('timestamp', isGreaterThanOrEqualTo: timestamp)
        .where('timestamp', isGreaterThanOrEqualTo: timestamp)
        .orderBy('timestamp', descending: true)
        .orderBy('timestamp', descending: true)
        .limit(8)
        .limit(8)