From d567956d90792c95adad2abd57548cdca6205dd4 Mon Sep 17 00:00:00 2001 From: Rafael <1024481@stud.hs-mannheim.de> Date: Tue, 13 Aug 2024 18:01:49 +0200 Subject: [PATCH] Active User Flag --- lib/pages/registration_complete_page.dart | 5 +++++ lib/pages/user_matching_page.dart | 6 ++++-- lib/services/user_service.dart | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/pages/registration_complete_page.dart b/lib/pages/registration_complete_page.dart index eda6646..b6dd065 100644 --- a/lib/pages/registration_complete_page.dart +++ b/lib/pages/registration_complete_page.dart @@ -1,12 +1,17 @@ import 'package:flutter/material.dart'; import '../components/text_bold.dart'; import '../services/auth/auth_gate.dart'; +import '../services/auth/auth_service.dart'; +import '../services/user_service.dart'; class RegistrationCompletePage extends StatelessWidget { const RegistrationCompletePage({super.key}); @override Widget build(BuildContext context) { + // Set the user as active when the page is built + UserService.setUserActive(true, AuthService().getCurrentUser()!.uid); + return Scaffold( appBar: AppBar( automaticallyImplyLeading: false, // remove back button diff --git a/lib/pages/user_matching_page.dart b/lib/pages/user_matching_page.dart index d904d04..453bc8d 100644 --- a/lib/pages/user_matching_page.dart +++ b/lib/pages/user_matching_page.dart @@ -98,10 +98,12 @@ class UserMatchingPageState extends State { // add profiles accordingly allUsers.add(userProfile); // Exclude (1) the current user's profile, (2) the already liked profiles - // and (3) users that were disliked less than 24 hours ago + // (3) users that were disliked less than 24 hours ago + // and (4) not active profile if (userDoc.id != currentUserId && !likedUserIds.contains(userDoc.id) && - !dislikedUserIds.contains(userDoc.id)) { + !dislikedUserIds.contains(userDoc.id) && + (userProfile.active ?? false)) { showProfiles.add(userProfile); } } // end for diff --git a/lib/services/user_service.dart b/lib/services/user_service.dart index 51b4f83..9b32d16 100644 --- a/lib/services/user_service.dart +++ b/lib/services/user_service.dart @@ -365,4 +365,14 @@ class UserService { return e.toString(); } } + + /// Update the active field of [userId] to given [value] + static Future setUserActive(bool value, String userId) async { + await FirebaseFirestore.instance + .collection(Constants.dbCollectionUsers) + .doc(userId) + .update({ + Constants.dbFieldUsersActive: value, + }); + } }