feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,406 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:secure_string_operations/secure_string_operations.dart';
|
||||
import 'package:siro_admin/constant/info.dart';
|
||||
|
||||
import '../../constant/api_key.dart';
|
||||
import '../../constant/box_name.dart';
|
||||
import '../../constant/char_map.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../../constant/style.dart';
|
||||
import '../../main.dart';
|
||||
import '../../print.dart';
|
||||
import '../../views/widgets/elevated_btn.dart';
|
||||
import '../../views/widgets/snackbar.dart';
|
||||
import '../notification_controller.dart';
|
||||
import 'notification_service.dart';
|
||||
|
||||
class FirebaseMessagesController extends GetxController {
|
||||
final fcmToken = FirebaseMessaging.instance;
|
||||
|
||||
List<String> tokens = [];
|
||||
List<String> tokensPassengers = [];
|
||||
List dataTokens = [];
|
||||
List dataTokensPassenger = [];
|
||||
late String driverID;
|
||||
late String driverToken;
|
||||
NotificationSettings? notificationSettings;
|
||||
bool isLoading = false;
|
||||
Future<void> getNotificationSettings() async {
|
||||
// Get the current notification settings
|
||||
NotificationSettings? notificationSettings =
|
||||
await FirebaseMessaging.instance.getNotificationSettings();
|
||||
'Notification authorization status: ${notificationSettings.authorizationStatus}';
|
||||
|
||||
// Call the update function if needed
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> requestFirebaseMessagingPermission() async {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
// Check if the platform is Android
|
||||
if (kIsWeb) {
|
||||
await messaging.requestPermission();
|
||||
} else if (Platform.isAndroid) {
|
||||
// Request permission for Android
|
||||
await messaging.requestPermission();
|
||||
} else if (Platform.isIOS) {
|
||||
// Request permission for iOS
|
||||
await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: true,
|
||||
badge: true,
|
||||
carPlay: true,
|
||||
criticalAlert: true,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
messaging.setForegroundNotificationPresentationOptions(
|
||||
alert: true, badge: true, sound: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future getTokens() async {
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.getTokens),
|
||||
headers: {
|
||||
'Authorization':
|
||||
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
||||
},
|
||||
body: {},
|
||||
);
|
||||
var jsonResponse = jsonDecode(res.body);
|
||||
if (jsonResponse['status'] == 'success') {
|
||||
dataTokens = jsonResponse['data'];
|
||||
for (var i = 0; i < dataTokens.length; i++) {
|
||||
tokens.add(jsonResponse['data'][i]['token']);
|
||||
}
|
||||
box.write(BoxName.tokens, tokens);
|
||||
} else {
|
||||
Get.defaultDialog(title: "Warning", middleText: "Server Error");
|
||||
}
|
||||
}
|
||||
|
||||
var currentPage = 1;
|
||||
var totalPages = 1;
|
||||
Future<void> getAllTokenDrivers() async {
|
||||
isLoading = true;
|
||||
try {
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.getDriversPhonesAndTokens),
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
|
||||
},
|
||||
body: {
|
||||
// 'page': page.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
var jsonResponse = jsonDecode(res.body);
|
||||
Log.print('jsonResponse: $jsonResponse');
|
||||
if (jsonResponse['status'] == 'success') {
|
||||
// var newData = jsonResponse['data'] as List;
|
||||
// Log.print('newData: ${newData}');
|
||||
// // if (page == 1) {
|
||||
// // dataTokens.clear();
|
||||
// // tokens.clear();
|
||||
// // }
|
||||
// dataTokens.addAll(newData);
|
||||
// for (var item in newData) {
|
||||
// tokens.add(item['token']);
|
||||
// }
|
||||
// currentPage = int.parse(jsonResponse['currentPage']);
|
||||
// totalPages = jsonResponse['totalPages'];
|
||||
box.write(BoxName.tokensDrivers, jsonResponse);
|
||||
Log.print(
|
||||
'box.write(BoxName.tokensDrivers: ${box.read(BoxName.tokensDrivers)}');
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: "Warning", middleText: "No more data available");
|
||||
}
|
||||
} catch (e) {
|
||||
Get.defaultDialog(title: "Error", middleText: "Server Error: $e");
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
var currentPagePassenger = 1;
|
||||
var totalPagesPassenger = 1;
|
||||
Future<void> getAllTokenPassenger({int page = 1}) async {
|
||||
isLoading = true;
|
||||
try {
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.getAllTokenPassengers),
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
},
|
||||
body: {},
|
||||
);
|
||||
|
||||
var jsonResponse = jsonDecode(res.body);
|
||||
if (jsonResponse['status'] == 'success') {
|
||||
box.write(BoxName.tokensPassengers, jsonResponse);
|
||||
Log.print(
|
||||
'box.write(BoxName.tokensPassenger: ${box.read(BoxName.tokensPassengers)}');
|
||||
} else {
|
||||
Get.defaultDialog(
|
||||
title: "Warning", middleText: "No more data available");
|
||||
}
|
||||
} catch (e) {
|
||||
Get.defaultDialog(title: "Error", middleText: "Server Error: $e");
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isSendingNotifications = false;
|
||||
Future<void> loadAllPagesAndSendNotifications() async {
|
||||
isSendingNotifications = true;
|
||||
// currentPage = 1;
|
||||
|
||||
// while (currentPage <= totalPages) {
|
||||
// await getAllTokenDrivers(page: currentPage);
|
||||
await getAllTokenDrivers();
|
||||
// Log.print('tokens: ${tokens}');
|
||||
await NotificationController().sendNotificationDrivers();
|
||||
// print(tokens);
|
||||
|
||||
// if (currentPage < totalPages) {
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
// }
|
||||
// currentPage++;
|
||||
// }
|
||||
|
||||
isSendingNotifications = false;
|
||||
mySnackbarSuccess("All notifications sent!");
|
||||
}
|
||||
|
||||
bool isSendingNotificationsPassenger = false;
|
||||
Future<void> loadAllPagesAndSendNotificationsPassengers() async {
|
||||
isSendingNotificationsPassenger = true;
|
||||
currentPage = 1;
|
||||
|
||||
// while (currentPagePassenger <= totalPagesPassenger) {
|
||||
await getAllTokenPassenger();
|
||||
await NotificationController().sendNotificationPassengers();
|
||||
// print(tokensPassengers);
|
||||
// if (currentPagePassenger < totalPagesPassenger) {
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
// }
|
||||
// currentPagePassenger++;
|
||||
// }
|
||||
|
||||
isSendingNotificationsPassenger = false;
|
||||
mySnackbarSuccess("All notifications sent!");
|
||||
}
|
||||
|
||||
Future getAllTokenPassengers() async {
|
||||
var res = await http.post(
|
||||
Uri.parse(AppLink.getAllTokenPassengers),
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
'Authorization':
|
||||
'Bearer ${X.r(X.r(X.r(box.read(BoxName.jwt), cn), cC), cs).toString().split(AppInformation.addd)[0]}'
|
||||
// 'Authorization': 'Bearer ${box.read(BoxName.jwt)}'
|
||||
},
|
||||
body: {},
|
||||
);
|
||||
var jsonResponse = jsonDecode(res.body);
|
||||
if (jsonResponse['status'] == 'success') {
|
||||
dataTokens = jsonResponse['data'];
|
||||
for (var i = 0; i < dataTokens.length; i++) {
|
||||
tokensPassengers.add(jsonResponse['data'][i]['token']);
|
||||
}
|
||||
box.write(BoxName.tokensPassengers, jsonResponse['data']);
|
||||
} else {
|
||||
Get.defaultDialog(title: "Warning", middleText: "Server Error");
|
||||
}
|
||||
}
|
||||
|
||||
Future getToken() async {
|
||||
fcmToken.getToken().then((token) {
|
||||
if (box.read(BoxName.email) == null) {
|
||||
box.write(BoxName.tokenDriver, token);
|
||||
} else {
|
||||
box.write(BoxName.tokenFCM, token);
|
||||
}
|
||||
});
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
// If the app is in the background or terminated, show a system tray message
|
||||
// if (message.notification != null) {
|
||||
if (message.data.isNotEmpty && message.notification != null) {
|
||||
fireBaseTitles(message);
|
||||
}
|
||||
});
|
||||
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
if (message.data['type'] == 'marketing_report') {
|
||||
Get.toNamed('/social-intelligence');
|
||||
}
|
||||
});
|
||||
|
||||
FirebaseMessaging.instance
|
||||
.getInitialMessage()
|
||||
.then((RemoteMessage? message) {
|
||||
if (message != null && message.data['type'] == 'marketing_report') {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Get.toNamed('/social-intelligence');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void fireBaseTitles(RemoteMessage message) {
|
||||
if (message.notification!.title! == 'Order') {
|
||||
if (kIsWeb) {
|
||||
// Handle web push payload
|
||||
} else if (Platform.isAndroid) {
|
||||
// NotificationController().showNotification('Order', '', 'order');
|
||||
}
|
||||
var myListString = message.data['DriverList'];
|
||||
// var points = message.data['PolylineJson'];
|
||||
|
||||
var myList = jsonDecode(myListString) as List<dynamic>;
|
||||
// var myPoints = jsonDecode(points) as List<dynamic>;
|
||||
driverToken = myList[14].toString();
|
||||
// This is for location using and uploading status
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void driverAppliedTripSnakBar() {
|
||||
mySnackbarSuccess('Driver Applied the Ride for You'.tr);
|
||||
}
|
||||
|
||||
Future<dynamic> passengerDialog(String message) {
|
||||
return Get.defaultDialog(
|
||||
barrierDismissible: false,
|
||||
title: 'message From passenger'.tr,
|
||||
titleStyle: AppStyle.title,
|
||||
middleTextStyle: AppStyle.title,
|
||||
middleText: message.tr,
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok'.tr,
|
||||
onPressed: () {
|
||||
// FirebaseMessagesController().sendNotificationToPassengerToken(
|
||||
// 'Hi ,I will go now'.tr,
|
||||
// 'I will go now'.tr,
|
||||
// Get.find<MapPassengerController>().driverToken, []);
|
||||
// Get.find<MapPassengerController>()
|
||||
// .startTimerDriverWaitPassenger5Minute();
|
||||
|
||||
Get.back();
|
||||
}));
|
||||
}
|
||||
|
||||
// Future<dynamic> driverFinishTripDialoge(List<dynamic> driverList) {
|
||||
// return Get.defaultDialog(
|
||||
// title: 'Driver Finish Trip'.tr,
|
||||
// content: const DriverTipWidget(),
|
||||
// confirm: MyElevatedButton(
|
||||
// title: 'Yes'.tr,
|
||||
// onPressed: () async {
|
||||
// var tip = (Get.find<MapPassengerController>().totalPassenger) *
|
||||
// (double.parse(box.read(BoxName.tipPercentage.toString())));
|
||||
// var res = await CRUD().post(link: AppLink.addTips, payload: {
|
||||
// 'passengerID': box.read(BoxName.passengerID),
|
||||
// 'driverID': driverList[0].toString(),
|
||||
// 'rideID': driverList[1].toString(),
|
||||
// 'tipAmount': tip.toString(),
|
||||
// });
|
||||
// await CRUD().post(link: AppLink.addPassengersWallet, payload: {
|
||||
// 'passenger_id': box.read(BoxName.passengerID).toString(),
|
||||
// 'balance': ((-1) * tip).toString()
|
||||
// });
|
||||
|
||||
// await CRUD().post(link: AppLink.addDriversWalletPoints, payload: {
|
||||
// 'driverID': driverList[0].toString(),
|
||||
// 'paymentID': '${Get.find<MapPassengerController>().rideId}tip',
|
||||
// 'amount': (tip * 100).toString(),
|
||||
// 'paymentMethod': 'visa-tip',
|
||||
// });
|
||||
|
||||
// if (res != 'failure') {
|
||||
// FirebaseMessagesController().sendNotificationToAnyWithoutData(
|
||||
// 'You Have Tips',
|
||||
// '${'${tip.toString()}\$${' tips\nTotal is'.tr}'} ${tip + (Get.find<MapPassengerController>().totalPassenger)}',
|
||||
// driverList[2].toString(),
|
||||
// );
|
||||
// }
|
||||
// Get.to(() => RateDriverFromPassenger(), arguments: {
|
||||
// 'driverId': driverList[0].toString(),
|
||||
// 'rideId': driverList[1].toString(),
|
||||
// 'price': driverList[3].toString()
|
||||
// });
|
||||
// },
|
||||
// kolor: AppColor.greenColor,
|
||||
// ),
|
||||
// cancel: MyElevatedButton(
|
||||
// title: 'No,I want'.tr,
|
||||
// onPressed: () {
|
||||
// Get.to(() => RateDriverFromPassenger(), arguments: {
|
||||
// 'driverId': driverList[0].toString(),
|
||||
// 'rideId': driverList[1].toString(),
|
||||
// 'price': driverList[3].toString()
|
||||
// });
|
||||
// },
|
||||
// kolor: AppColor.redColor,
|
||||
// ));
|
||||
// }
|
||||
|
||||
// for (var i = 0; i < tokens.length; i++) {
|
||||
// http
|
||||
// .post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json',
|
||||
// 'Authorization': 'key=${storage.read(key: BoxName.serverAPI}'
|
||||
// },
|
||||
// body: jsonEncode({
|
||||
// 'notification': <String, dynamic>{
|
||||
// 'title': title,
|
||||
// 'body': body,
|
||||
// 'sound': 'true'
|
||||
// },
|
||||
// 'priority': 'high',
|
||||
// 'data': <String, dynamic>{
|
||||
// 'click_action': 'FLUTTER_NOTIFICATION_CLICK',
|
||||
// 'id': '1',
|
||||
// 'status': 'done'
|
||||
// },
|
||||
// 'to': tokens[i],
|
||||
// }))
|
||||
// .whenComplete(() {})
|
||||
// .catchError((e) {
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//android/app/src/main/res/raw/iphone_ringtone.wav
|
||||
|
||||
void sendNotificationAll(String title, body) async {
|
||||
// Deprecated: Admin panel notifications are sent via NotificationService.
|
||||
}
|
||||
|
||||
void sendNotificationToAnyWithoutData(
|
||||
String title, String body, String token, String tone) async {
|
||||
await NotificationService.sendNotification(
|
||||
target: token,
|
||||
title: title,
|
||||
body: body,
|
||||
category: 'fromAdmin',
|
||||
tone: tone,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user