You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.4 KiB

3 years ago
import 'dart:convert';
import 'package:provider/provider.dart';
import 'package:teso/Classes/Payload.dart';
import 'package:teso/providers/user_provider.dart';
import 'package:url_launcher/url_launcher.dart';
class NotificationSplitter {
static Future<Payload> getPayload(data, context) async {
Payload payload = new Payload();
switch (data["notificationType"]) {
case "chats":
payload.loadID = "TESN004";
payload.load1 = data["senderID"];
payload.load2 = data["firstname"];
payload.load3 = data["surname"];
return payload;
break;
case "likes":
Provider.of<UserProvider>(context, listen: false).pullAds();
payload.loadID = "TESN000";
payload.load1 = data["post"];
return payload;
break;
case "comments":
Provider.of<UserProvider>(context, listen: false).pullAds();
payload.loadID = "TESN000";
payload.load1 = data["post"];
return payload;
break;
case "friendapproval":
Provider.of<UserProvider>(context, listen: false).loadFriends();
payload.loadID = "TESN000";
return payload;
break;
case "friendrequest":
payload.loadID = "TESN000";
return payload;
break;
case "gifted":
Provider.of<UserProvider>(context, listen: false).getCoupons();
payload.loadID = "TESN000";
payload.load1 = data["couponID"];
return payload;
break;
case "cancellation":
Provider.of<UserProvider>(context, listen: false).getCoupons();
payload.loadID = "TESN000";
payload.load1 = data["couponID"];
return payload;
break;
case "personalized":
payload.loadID = "TESN000";
payload.load1 = data["coupon"];
payload.load2 = data["notificationType"];
payload.load3 = data["documentRef"];
payload.load4 = data["couponCondition"];
payload.load5 = data["businessName"];
payload.load6 = data["originalPrice"];
payload.load7 = data["productName"];
return payload;
break;
case "campaign":
var coup = jsonDecode(data["campaign"]);
payload.loadID = "TESN005";
payload.load1 = coup["businessID"];
payload.load2 = coup["campaignID"];
payload.load3 = coup["campaignDescription"];
payload.load4 = coup["status"];
payload.load5 = coup["targetProduct"];
payload.load6 = coup["title"];
payload.load7 = coup["goldReward"].toString();
payload.load8 = coup["startDate"].toString();
return payload;
break;
case "reward":
payload.loadID = "TESN0R0";
return payload;
break;
case "expired":
Provider.of<UserProvider>(context, listen: false).getCoupons();
payload.loadID = "TESN000";
payload.load1 = data["couponID"];
return payload;
break;
case "refund":
Provider.of<UserProvider>(context, listen: false).getUserInformation();
payload.loadID = "TESN000";
payload.load1 = data["couponID"];
return payload;
break;
case "coinpurchase":
Provider.of<UserProvider>(context, listen: false).getUserInformation();
payload.loadID = "TESN000";
payload.load1 = data["orderID"];
await closeWebView();
return payload;
break;
default:
return payload;
break;
}
}
}