vFirebaseMessagingBackgroundHandler function
Implementation
@pragma('vm:entry-point')
Future<void> vFirebaseMessagingBackgroundHandler(RemoteMessage message) async {
final nativeLocal = VLocalNativeApi();
await nativeLocal.init();
final number = await nativeLocal.room.getTotalUnReadCount();
if (await FlutterAppBadger.isAppBadgeSupported()) {
FlutterAppBadger.updateBadgeCount(number);
}
await VAppPref.init();
final String? fromVChat = message.data['fromVChat'];
final String? vMessage = message.data['vMessage'];
if (fromVChat == null || vMessage == null) return Future<void>.value();
final msg = MessageFactory.createBaseMessage(
jsonDecode(vMessage) as Map<String, dynamic>,
);
final token = VAppPref.getHashedString(key: "vAccessToken");
if (token != null) {
try {
await setDeliverForThisRoom(msg.roomId, token);
} catch (err) {
if (kDebugMode) {
print(err);
}
}
}
final insertRes = await nativeLocal.message.safeInsertMessage(msg);
if (insertRes == 1) {
await nativeLocal.room.updateRoomUnreadCountAddOne(msg.roomId);
}
return Future<void>.value(null);
}