Search in sources :

Example 1 with PendingNotification

use of im.actor.core.modules.notifications.entity.PendingNotification in project actor-platform by actorapp.

the class NotificationsActor method onNewMessage.

/**
 * Handling event about incoming notification
 *
 * @param peer                  peer of message
 * @param sender                sender uid of message
 * @param date                  date of message
 * @param description           content description of message
 * @param hasCurrentUserMention does message have user mention
 */
public void onNewMessage(Peer peer, int sender, long date, ContentDescription description, boolean hasCurrentUserMention, int messagesCount, int dialogsCount) {
    // for already read messages
    if (date <= getLastReadDate(peer)) {
        return;
    }
    // If wee need to play "out-app" notification for message
    boolean isEnabled = isNotificationsEnabled(peer, hasCurrentUserMention);
    // Save to pending storage
    if (isEnabled) {
        List<PendingNotification> pendingNotifications = getNotifications();
        PendingNotification pendingNotification = new PendingNotification(peer, sender, date, description);
        pendingNotifications.add(pendingNotification);
        pendingStorage.setMessagesCount(messagesCount);
        pendingStorage.setDialogsCount(dialogsCount);
        allPendingNotifications.add(pendingNotification);
        saveStorage();
    }
    // This peers will be released during call onNotificationsResumed
    if (isNotificationsPaused) {
        if (!notificationsDuringPause.containsKey(peer)) {
            notificationsDuringPause.put(peer, hasCurrentUserMention);
        } else {
            if (hasCurrentUserMention && !notificationsDuringPause.get(peer)) {
                notificationsDuringPause.put(peer, true);
            }
        }
        return;
    }
    if (isAppVisible) {
        if (visiblePeer != null && visiblePeer.equals(peer)) {
            // If message arrive to visible chat
            if (isMobilePlatform) {
                // Play sound effect on mobile
                playEffectIfEnabled();
            } else {
            // Do nothing on desktop as it is very distracting
            // Most of the people use mobile messengers occasionally and
            // with disabled sounds and it doesn't make problems as much as on
            // non-mobile platforms
            }
        } else {
            if (isMobilePlatform) {
            // Don't play any sounds not in chat screen on mobile phone
            // We done this because we have unread badge in chat screen on mobile
            } else {
                // doesn't explicitly disabled
                if (isEnabled) {
                    playEffectIfEnabled();
                }
            }
        }
    } else {
        // If application is not visible play regular notification for enabled chats
        if (isEnabled) {
            showNotification();
        }
    }
}
Also used : PendingNotification(im.actor.core.modules.notifications.entity.PendingNotification)

Example 2 with PendingNotification

use of im.actor.core.modules.notifications.entity.PendingNotification in project actor-platform by actorapp.

the class NotificationsActor method performNotificationImp.

/**
 * Method for showing/updating notifications
 *
 * @param performUpdate is need to perform update instead of showing
 */
private void performNotificationImp(boolean performUpdate) {
    // Getting pending notifications list
    List<PendingNotification> destNotifications = getNotifications();
    if (destNotifications.size() == 0) {
        hideNotification();
        return;
    }
    // Converting to PendingNotifications
    List<Notification> res = new ArrayList<>();
    for (PendingNotification p : destNotifications) {
        boolean isChannel = false;
        if (p.getPeer().getPeerType() == PeerType.GROUP) {
            isChannel = groups().getValue(p.getPeer().getPeerId()).getGroupType() == GroupType.CHANNEL;
        }
        res.add(new Notification(p.getPeer(), isChannel, p.getSender(), p.getContent()));
    }
    // Performing notifications
    if (performUpdate) {
        config().getNotificationProvider().onUpdateNotification(context().getMessenger(), res, pendingStorage.getMessagesCount(), pendingStorage.getDialogsCount());
    } else {
        config().getNotificationProvider().onNotification(context().getMessenger(), res, pendingStorage.getMessagesCount(), pendingStorage.getDialogsCount());
    }
}
Also used : ArrayList(java.util.ArrayList) PendingNotification(im.actor.core.modules.notifications.entity.PendingNotification) Notification(im.actor.core.entity.Notification) PendingNotification(im.actor.core.modules.notifications.entity.PendingNotification)

Aggregations

PendingNotification (im.actor.core.modules.notifications.entity.PendingNotification)2 Notification (im.actor.core.entity.Notification)1 ArrayList (java.util.ArrayList)1