use of br.ufrj.caronae.models.RideEndedEvent in project caronae-android by caronae.
the class MyFirebaseMessagingService method onMessageReceived.
@Override
public void onMessageReceived(final RemoteMessage remoteMessage) {
Log.i("onMessageReceived", "onMessageReceived");
if (App.isUserLoggedIn() && remoteMessage.getData() != null) {
Map data = remoteMessage.getData();
String msgType = (String) data.get("msgType");
if (msgType != null && msgType.equals("alert")) {
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(MSG_TYPE_ALERT, (String) data.get(ALERT_KEY)).apply();
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(MSG_TYPE_ALERT_HEADER, (String) data.get(ALERT_HEADER_KEY)).commit();
} else {
String message = (String) data.get("message");
String senderName = (String) data.get("senderName");
final String rideId = (String) data.get("rideId");
Log.i("onMessageReceived", message);
if (msgType != null && msgType.equals("chat")) {
String senderId = (String) data.get("senderId");
// noinspection ConstantConditions
if (senderId.equals(App.getUser().getDbId() + "")) {
return;
}
List<ChatMessageReceived> listOldMessages = ChatMessageReceived.find(ChatMessageReceived.class, "ride_id = ?", rideId);
ChatMessageReceived lastMessage = null;
if (listOldMessages.size() != 0) {
lastMessage = listOldMessages.get(listOldMessages.size() - 1);
}
String since;
if (lastMessage == null) {
since = null;
} else {
since = lastMessage.getTime();
}
if (!SharedPref.getChatActIsForeground()) {
startService(new Intent(this, FetchReceivedMessagesService.class).putExtra("rideId", rideId).putExtra("since", since));
}
}
if (msgType != null && msgType.equals("joinRequest")) {
new RideRequestReceived(Integer.valueOf(rideId)).save();
}
if (msgType != null && msgType.equals("finished")) {
FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId);
App.getBus().post(new RideEndedEvent(rideId));
ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
}
// TODO: Carona cancelada Nao esta rebendo notificacao
if (msgType != null && msgType.equals("cancelled")) {
FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId);
App.getBus().post(new RideEndedEvent(rideId));
ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
}
if (msgType != null && msgType.equals("accepted")) {
FirebaseTopicsHandler.CheckSubFirebaseTopic(rideId);
// new DeleteConflictingRequests().execute(rideId);
}
if (SharedPref.getNotifPref().equals("true"))
if (msgType != null && msgType.equals("chat")) {
if (!SharedPref.getChatActIsForeground()) {
createNotification(msgType, senderName, message, rideId);
} else {
App.getBus().post(rideId);
}
} else
createNotification(msgType, senderName, message, rideId);
}
}
}
Aggregations