use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.
the class NotificationsService method hardHandleEvent.
private void hardHandleEvent(List<NotificationEvent> events, NotificationEvent.Source source) {
Log.d("SUKA", "hardHandleEvent " + events.size() + " : " + source);
if (NotificationEvent.fromSite(source)) {
if (Preferences.Notifications.Mentions.isEnabled(getApplicationContext())) {
for (NotificationEvent event : events) {
sendNotification(event);
}
}
return;
}
loadEvents(loadedEvents -> {
List<NotificationEvent> savedEvents = getSavedEvents(source);
// savedEvents = new ArrayList<>();
saveEvents(loadedEvents, source);
List<NotificationEvent> newEvents = compareEvents(savedEvents, loadedEvents, events, source);
List<NotificationEvent> stackedNewEvents = new ArrayList<>(newEvents);
checkOldEvents(loadedEvents, source);
// Удаляем из общего уведомления текущие уведомление
for (NotificationEvent event : events) {
for (NotificationEvent newEvent : newEvents) {
if (newEvent.getSourceId() == event.getSourceId()) {
stackedNewEvents.remove(newEvent);
newEvent.setType(event.getType());
newEvent.setMessageId(event.getMessageId());
TabNotification tabNotification = new TabNotification();
tabNotification.setType(newEvent.getType());
tabNotification.setSource(newEvent.getSource());
tabNotification.setEvent(newEvent);
tabNotification.getLoadedEvents().addAll(loadedEvents);
tabNotification.getNewEvents().addAll(newEvents);
tabNotification.setWebSocket(false);
notifyTabs(tabNotification);
sendNotification(newEvent);
} else if (event.isMention() && !Preferences.Notifications.Favorites.isEnabled(getApplicationContext())) {
stackedNewEvents.remove(newEvent);
}
}
}
sendNotifications(stackedNewEvents, source);
}, source);
}
use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.
the class NotificationsService method handleWebSocketEvent.
private void handleWebSocketEvent(NotificationEvent event) {
TabNotification tabNotification = new TabNotification();
tabNotification.setType(event.getType());
tabNotification.setSource(event.getSource());
tabNotification.setEvent(event);
tabNotification.setWebSocket(true);
notifyTabs(tabNotification);
if (event.isRead()) {
checkOldEvent(event);
return;
}
List<NotificationEvent> events = new ArrayList<>();
events.add(event);
handleEvent(events, event.getSource());
}
use of forpdateam.ru.forpda.data.models.TabNotification in project ForPDA by RadiationX.
the class NotificationsService method checkOldEvents.
private void checkOldEvents(List<NotificationEvent> loadedEvents, NotificationEvent.Source source) {
List<NotificationEvent> oldEvents = new ArrayList<>();
for (int i = 0; i < eventsHistory.size(); i++) {
NotificationEvent event = eventsHistory.valueAt(i);
if (event.getSource() == source) {
oldEvents.add(event);
}
}
for (NotificationEvent oldEvent : oldEvents) {
boolean exist = false;
for (NotificationEvent loadedEvent : loadedEvents) {
if (oldEvent.getSourceId() == loadedEvent.getSourceId()) {
exist = true;
break;
}
}
if (!exist) {
mNotificationManager.cancel(oldEvent.notifyId());
eventsHistory.remove(oldEvent.notifyId(NotificationEvent.Type.NEW));
TabNotification tabNotification = new TabNotification();
tabNotification.setSource(oldEvent.getSource());
tabNotification.setEvent(oldEvent);
tabNotification.setType(NotificationEvent.Type.READ);
tabNotification.setWebSocket(true);
notifyTabs(tabNotification);
}
}
}
Aggregations