use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEvents method parseWebSocketEvent.
public NotificationEvent parseWebSocketEvent(Matcher matcher) {
NotificationEvent wsEvent = null;
if (matcher.find()) {
wsEvent = new NotificationEvent();
switch(matcher.group(3)) {
case NotificationEvent.SRC_TYPE_THEME:
wsEvent.setSource(NotificationEvent.Source.THEME);
break;
case NotificationEvent.SRC_TYPE_SITE:
wsEvent.setSource(NotificationEvent.Source.SITE);
break;
case NotificationEvent.SRC_TYPE_QMS:
wsEvent.setSource(NotificationEvent.Source.QMS);
break;
default:
// // TODO: 02.10.17 сделать обратку нотификации форума
return null;
}
wsEvent.setSourceId(Integer.parseInt(matcher.group(4)));
switch(Integer.parseInt(matcher.group(5))) {
case NotificationEvent.SRC_EVENT_NEW:
wsEvent.setType(NotificationEvent.Type.NEW);
break;
case NotificationEvent.SRC_EVENT_READ:
wsEvent.setType(NotificationEvent.Type.READ);
break;
case NotificationEvent.SRC_EVENT_MENTION:
wsEvent.setType(NotificationEvent.Type.MENTION);
break;
case NotificationEvent.SRC_EVENT_HAT_EDITED:
wsEvent.setType(NotificationEvent.Type.HAT_EDITED);
break;
}
wsEvent.setMessageId(Integer.parseInt(matcher.group(6)));
}
return wsEvent;
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEvents method getFavoritesEvents.
public List<NotificationEvent> getFavoritesEvents(String response) {
List<NotificationEvent> events = new ArrayList<>();
Matcher matcher = inspectorFavoritesPattern.matcher(response);
while (matcher.find()) {
NotificationEvent event = getFavoritesEvent(matcher);
events.add(event);
}
return events;
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class NotificationEvents method getFavoritesEvent.
public NotificationEvent getFavoritesEvent(Matcher matcher) {
NotificationEvent event = new NotificationEvent();
event.setSourceEventText(matcher.group());
event.setSource(NotificationEvent.Source.THEME);
event.setType(NotificationEvent.Type.NEW);
event.setSourceId(Integer.parseInt(matcher.group(1)));
event.setSourceTitle(ApiUtils.fromHtml(matcher.group(2)));
event.setMsgCount(Integer.parseInt(matcher.group(3)));
event.setUserId(Integer.parseInt(matcher.group(4)));
event.setUserNick(ApiUtils.fromHtml(matcher.group(5)));
event.setTimeStamp(Integer.parseInt(matcher.group(6)));
event.setLastTimeStamp(Integer.parseInt(matcher.group(7)));
event.setImportant(matcher.group(8).equals("1"));
return event;
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class QmsContactsFragment method handleEvent.
private void handleEvent(TabNotification event) {
bindView();
if (true)
return;
SparseIntArray sparseArray = new SparseIntArray();
if (realm.isClosed())
return;
results = realm.where(QmsContactBd.class).findAll();
ArrayList<QmsContact> currentItems = new ArrayList<>();
for (QmsContactBd qmsContactBd : results) {
QmsContact contact = new QmsContact(qmsContactBd);
currentItems.add(contact);
}
for (NotificationEvent loadedEvent : event.getLoadedEvents()) {
int count = sparseArray.get(loadedEvent.getUserId());
count += loadedEvent.getMsgCount();
sparseArray.put(loadedEvent.getUserId(), count);
}
for (int i = sparseArray.size() - 1; i >= 0; i--) {
int id = sparseArray.keyAt(i);
int count = sparseArray.valueAt(i);
for (QmsContact item : currentItems) {
if (item.getId() == id) {
item.setCount(count);
Collections.swap(currentItems, currentItems.indexOf(item), 0);
break;
}
}
}
if (realm.isClosed())
return;
realm.executeTransactionAsync(r -> {
r.delete(QmsContactBd.class);
List<QmsContactBd> bdList = new ArrayList<>();
for (QmsContact qmsContact : currentItems) {
bdList.add(new QmsContactBd(qmsContact));
}
r.copyToRealmOrUpdate(bdList);
bdList.clear();
}, this::bindView);
// adapter.notifyDataSetChanged();
/*ArrayList<IFavItem> newItems = new ArrayList<>();
newItems.addAll(currentItems);
refreshList(newItems);*/
}
use of forpdateam.ru.forpda.api.events.models.NotificationEvent in project ForPDA by RadiationX.
the class QmsHelper method handleEvent.
private void handleEvent(TabNotification event) {
Realm realm = Realm.getDefaultInstance();
RealmResults<QmsThemesBd> themes = realm.where(QmsThemesBd.class).findAll();
QmsThemeBd targetTheme = null;
QmsThemesBd targetDialog = null;
for (QmsThemesBd dialog : themes) {
for (QmsThemeBd theme : dialog.getThemes()) {
if (theme.getId() == event.getEvent().getSourceId()) {
targetDialog = dialog;
targetTheme = theme;
break;
}
}
if (targetTheme != null) {
break;
}
}
if (targetTheme != null) {
QmsThemeBd finalTargetTheme = targetTheme;
QmsThemesBd finalTargetDialog = targetDialog;
realm.executeTransaction(realm1 -> {
if (event.isWebSocket()) {
if (NotificationEvent.isRead(event.getType())) {
finalTargetTheme.setCountNew(0);
}
} else {
if (NotificationEvent.isNew(event.getType())) {
finalTargetTheme.setCountNew(event.getEvent().getMsgCount());
}
}
QmsContactBd contact = realm1.where(QmsContactBd.class).equalTo("id", finalTargetDialog.getUserId()).findFirst();
if (contact != null) {
int count = 0;
for (QmsThemeBd theme : finalTargetDialog.getThemes()) {
count += theme.getCountNew();
}
contact.setCount(count);
}
});
}
int globalCount = 0;
for (NotificationEvent ev : event.getLoadedEvents()) {
globalCount += ev.getMsgCount();
}
ClientHelper.setQmsCount(globalCount);
ClientHelper.get().notifyCountsChanged();
realm.close();
notifyQms(event);
}
Aggregations