use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEvents method getQmsEvents.
public List<NotificationEvent> getQmsEvents(String response) {
List<NotificationEvent> events = new ArrayList<>();
Matcher matcher = inspectorQmsPattern.matcher(response);
while (matcher.find()) {
NotificationEvent event = getQmsEvent(matcher);
events.add(event);
}
return events;
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method checkOldEvent.
private void checkOldEvent(NotificationEvent event) {
NotificationEvent oldEvent = eventsHistory.get(event.notifyId(NotificationEvent.Type.NEW));
boolean delete = false;
if (event.fromTheme()) {
// Убираем уведомления избранного
if (oldEvent != null && event.getMessageId() >= oldEvent.getMessageId()) {
mNotificationManager.cancel(oldEvent.notifyId());
delete = true;
}
// Убираем уведомление упоминаний
oldEvent = eventsHistory.get(event.notifyId(NotificationEvent.Type.MENTION));
if (oldEvent != null) {
mNotificationManager.cancel(oldEvent.notifyId());
delete = true;
}
} else if (event.fromQms()) {
// Убираем уведомление кумыса
if (oldEvent != null) {
mNotificationManager.cancel(oldEvent.notifyId());
delete = true;
}
}
if (delete) {
eventsHistory.remove(event.notifyId(NotificationEvent.Type.NEW));
}
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent 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.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationsService method createStackedContent.
private CharSequence createStackedContent(List<NotificationEvent> events) {
StringBuilder content = new StringBuilder();
int size = Math.min(events.size(), STACKED_MAX);
for (int i = 0; i < size; i++) {
NotificationEvent event = events.get(i);
if (event.fromQms()) {
String nick = event.getUserNick();
if (nick == null || nick.isEmpty())
nick = "Сообщения 4PDA";
content.append("<b>").append(nick).append("</b>");
content.append(": ").append(event.getSourceTitle());
} else if (event.fromTheme()) {
content.append(event.getSourceTitle());
}
if (i < size - 1) {
content.append("<br>");
}
}
if (events.size() > size) {
content.append("<br>");
content.append("...и еще ").append(events.size() - size);
}
return ApiUtils.spannedFromHtml(content.toString());
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent 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());
}
Aggregations