Merge branch 'master' into PROFIL_PAGE_LDE

PROFIL_PAGE_LDE
Lucas Delanier 2 years ago
commit b502084aff

@ -88,4 +88,28 @@ class AuthService {
void signOut() async {
await FirebaseAuth.instance.signOut();
}
Future<void> delete() async {
try {
User? currentUser = FirebaseAuth.instance.currentUser;
await MyApp.db
.collection("users")
.doc(currentUser?.uid)
.delete()
.then((value) => print("Firestore deleted user"))
.catchError(
(error) => print("Error deleting user from Firestore: $error"));
await currentUser?.delete();
await FirebaseAuth.instance.signOut();
} on FirebaseAuthException catch (e) {
if (e.code == 'requires-recent-login') {
throw ('Please log in again to delete your account');
}
rethrow;
} catch (error) {
rethrow;
}
}
}

@ -1,6 +1,8 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../main.dart';
class NotificationService {
sendPushMessage(String token, String title, String body) async {
try {
@ -25,7 +27,13 @@ class NotificationService {
"to": token,
}));
} catch (e) {
print("error push notification");
print("error push notification: ${e.toString()}");
}
}
sendNotifyComment(String token, String text) async {
var pseudo = MyApp.userViewModel.userCurrent.pseudo;
await sendPushMessage(
token, "Nouveau message", "$pseudo à réagi à votre post,\"$text\".");
}
}

@ -99,4 +99,33 @@ class PostService {
return !isTodayAvailable;
}
Future<List<bool>> recapSevenDays(String id) async {
List<bool> recapList = [];
DateTime sevenDaysAgo = DateTime.now().subtract(Duration(days: 7));
QuerySnapshot<Map<String, dynamic>> response = await FirebaseFirestore
.instance
.collection("posts")
.where("user_id", isEqualTo: id)
.get();
List<Map<String, dynamic>?> postList = response.docs
.map((DocumentSnapshot<Map<String, dynamic>> doc) => doc.data())
.toList();
for (int i = 0; i < 7; i++) {
DateTime date = sevenDaysAgo.add(Duration(days: i));
bool postExists = postList.any((post) =>
post?["date"] != null &&
post?["date"].toDate().year == date.year &&
post?["date"].toDate().month == date.month &&
post?["date"].toDate().day == date.day);
recapList.add(postExists);
}
return recapList;
}
}

@ -80,6 +80,15 @@ class PostViewModel {
throw new Error();
}
Future<List<bool>> recapSevenDays(String id) async {
try {
return await _postService.recapSevenDays(id);
} catch (e) {
print(e);
rethrow;
}
}
Future<bool> getAvailable() async {
try {
return await _postService

@ -112,6 +112,10 @@ class UserViewModel {
authService.signOut();
}
delete() {
authService.delete();
}
bool isFriend(String id) {
return _userCurrent.followed.contains(id);
}

Loading…
Cancel
Save