chatInputGlobal function
Future<bool>
chatInputGlobal(
- RemoteMessage message
)
Implementation
Future<bool> chatInputGlobal(RemoteMessage message) async {
bool stat = false;
if (!isStack) {
isStack = true;
final dataList = await ChatDatabase.getDataListChat();
List list = dataList.where((element) => element['groupToken'] == message.data['token']).toList();
if (list.isEmpty) {
await StaticData.addListChat(
ListChat(
id: dataList.length + 1,
person: Profile(name: 'Testing ${dataList.length + 1}', pathImage: 'assets/p.png'),
read: 1,
updated: DateTime.now(),
lastMessage: message.data['message'],
groupToken: message.data['token'],
token: message.data['token'],
chatType: ChatTypes(type: chatType.text),
),
);
final dataLists = await ChatDatabase.getDataListChat();
list = dataLists.where((element) => element['groupToken'] == message.data['token']).toList();
}
final data = await ChatDatabase.getData(
idList: list.isNotEmpty ? list.first['id'] : 0,
);
bool label = false;
if (data.isEmpty) {
label = true;
} else if (data.where((element) => DateTime.parse(element['date'].toString().split(' ').first).difference(DateTime.parse(message.data['date'].toString().split(' ').first)).inDays == 0 && element['isLabel'] == 'true').isEmpty) {
label = true;
}
chatType types = enumChatTypeParse(int.parse(message.data['chat_type']));
final person = PersonChat(
type: Person.other,
id: data.isEmpty ? 0 : data.first['id'] + 1,
message: message.data['message'],
date: DateTime.parse(message.data['date']),
listId: list.first['id'],
person: Profile(
name: message.data['person'],
pathImage: message.data['person_name'],
),
timezone: int.parse(message.data['timezone']),
isLabel: label,
chatType: ChatTypes(
type: enumChatTypeParse(int.parse(message.data['chat_type'])),
file: enumFileTypeParse(message.data['file_type']),
path: types == chatType.file ? message.data['message'] : '',
progress: 0,
status: 0,
),
);
await StaticData.addChatBackground(person, list);
if (isInChat) {
++incrementId;
}
final notif.FlutterLocalNotificationsPlugin notifs = notif.FlutterLocalNotificationsPlugin();
final notif.InitializationSettings initializationSettings = notif.InitializationSettings(
android: const notif.AndroidInitializationSettings('app_icon'),
iOS: notif.IOSInitializationSettings(
onDidReceiveLocalNotification: (int? id, String? title, String? body, String? payload) {
// showDialog(
// context: context!,
// builder: (BuildContext context) => CupertinoAlertDialog(
// title: Text(title ?? ''),
// content: Text(body ?? ''),
// actions: [
// CupertinoDialogAction(
// isDefaultAction: true,
// child: const Text('Ok'),
// onPressed: () async {
// Navigator.of(context, rootNavigator: true).pop();
// },
// )
// ],
// ),
// );
},
),
);
await showNotification(
body: types == chatType.file ? message.data['message'].split('/').last : message.data['message'],
id: data.isEmpty ? 0 : data.first['id'] + 1,
title: message.data['person_name'],
token: message.data['token'],
);
isStack = false;
}
return stat;
}