Add functions recapSevenDays and sendNotifyComment
continuous-integration/drone/push Build is passing Details

FAVORITE_MUSICS_EKA
Emre KARTAL 2 years ago
parent 5125645e5c
commit 120735e0c6

@ -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

Loading…
Cancel
Save