/** * Notify subscribers about outbound Client notifications. * * @param clientNotification Client notification to notify subscribers about. */ public void notifyAboutOutboundClientNotification(final ClientNotification clientNotification) { for (final SubscriptionInternal<OutboundNotification> outboundNotificationSubscriptionInternal : outboundNotificationObservable.getSubscriptions()) { if (outboundNotificationSubscriptionInternal.getNotificationType() != null && outboundNotificationSubscriptionInternal .getNotificationType() .equals(clientNotification.getBaseNotificationType())) { final OutboundNotification outboundNotification = new OutboundNotification(clientNotification); new Handler(Looper.getMainLooper()) .post( new Runnable() { @Override public void run() { if (outboundNotificationSubscriptionInternal.getBatchListener() != null) { List<OutboundNotification> outboundNotifications = new LinkedList<>(); outboundNotifications.add(outboundNotification); outboundNotificationSubscriptionInternal .getBatchListener() .onNotification(outboundNotifications); } else if (outboundNotificationSubscriptionInternal.getListener() != null) { outboundNotificationSubscriptionInternal .getListener() .onNotification(outboundNotification); } } }); } } }
/** * Get all subscriptions registered for server notifications. * * @param category Category of server notification - {@link * net.donky.core.network.ServerNotification#NOTIFICATION_CATEGORY_DONKY} or {@link * net.donky.core.network.ServerNotification#NOTIFICATION_CATEGORY_CUSTOM} * @param type Type of notification that the subscriber is registered to listen for. * @return Subscriptions for given notification type. */ public List<SubscriptionInternal<ServerNotification>> getSubscriptionsForServerNotification( String category, String type) { List<SubscriptionInternal<ServerNotification>> triggeredInboundNotificationSubscriptions = new LinkedList<>(); NotificationObservable<ServerNotification> observable = null; if (ServerNotification.NOTIFICATION_CATEGORY_CUSTOM.equals(category)) { observable = inboundContentNotificationObservable; } else if (ServerNotification.NOTIFICATION_CATEGORY_DONKY.equals(category)) { observable = inboundDonkyNotificationObservable; } if (type != null && observable != null) { for (final SubscriptionInternal<ServerNotification> inboundNotificationSubscription : observable.getSubscriptions()) { if (inboundNotificationSubscription.getNotificationType() != null && inboundNotificationSubscription.getNotificationType().equals(type)) { triggeredInboundNotificationSubscriptions.add(inboundNotificationSubscription); } } } return triggeredInboundNotificationSubscriptions; }