<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui.utils;

import java.util.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.protocol.*;

public class NotificationManager
{
    public static final String INCOMING_MESSAGE = "IncomingMessage";
    
    public static final String INCOMING_CALL = "IncomingCall";
    
    public static final String OUTGOING_CALL = "OutgoingCall";
    
    public static final String BUSY_CALL = "BusyCall";
    
    private static Hashtable soundHandlers = new Hashtable();
    
    public static void registerGuiNotifications()
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();
        
        if(notificationService == null)
            return;
        
        // Register incoming message notifications.
        notificationService.registerNotificationForEvent(
                INCOMING_MESSAGE,
                NotificationService.ACTION_POPUP_MESSAGE,
                null,
                null);

        notificationService.registerNotificationForEvent(
                INCOMING_MESSAGE,
                NotificationService.ACTION_SOUND,
                Sounds.INCOMING_MESSAGE,
                null);
        
        // Register incoming call notifications.
        notificationService.registerNotificationForEvent(
                INCOMING_CALL,
                NotificationService.ACTION_POPUP_MESSAGE,
                null,
                null);
    
        SoundNotificationHandler inCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.INCOMING_CALL, 2000);
        
        notificationService.registerNotificationForEvent(
                INCOMING_CALL,
                NotificationService.ACTION_SOUND,
                inCallSoundHandler);

        soundHandlers.put(INCOMING_CALL, inCallSoundHandler);
        
        // Register outgoing call notifications.
        SoundNotificationHandler outCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.OUTGOING_CALL, 3000);
        
        notificationService.registerNotificationForEvent(
                OUTGOING_CALL,
                NotificationService.ACTION_SOUND,
                outCallSoundHandler);
    
        soundHandlers.put(OUTGOING_CALL, outCallSoundHandler);

        // Register busy call notifications.
        SoundNotificationHandler busyCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.BUSY, 1);
        
        notificationService.registerNotificationForEvent(
                BUSY_CALL,
                NotificationService.ACTION_SOUND,
                busyCallSoundHandler);
    
        soundHandlers.put(OUTGOING_CALL, outCallSoundHandler);

    }

    /**
     * Fires a message notification for the given event type through the
     * <tt>NotificationService</tt>.
     * 
     * @param eventType the event type for which we fire a notification
     * @param messageTitle the title of the message
     * @param message the content of the message
     */
    public static void fireNotification(String eventType,
                                        String messageTitle,
                                        String message)
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();
        
        if(notificationService == null)
            return;

        notificationService.fireNotification(eventType, messageTitle, message);

    }

    /**
     * Fires a chat message notification for the given event type through the
     * <tt>NotificationService</tt>.
     * 
     * @param contact the contact to which the chat message corresponds
     * @param eventType the event type for which we fire a notification
     * @param messageTitle the title of the message
     * @param message the content of the message
     */
    public static void fireChatNotification(Contact contact,
                                            String eventType,
                                            String messageTitle,
                                            String message)
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();

        if(notificationService == null)
            return;

        NotificationActionHandler popupActionHandler = null;

        if(eventType.equals(INCOMING_MESSAGE)
            && GuiActivator.getUIService().getChat(contact).isChatFocused())
        {
            popupActionHandler = notificationService
                .getEventNotificationActionHandler(
                                    eventType,
                                    NotificationService.ACTION_POPUP_MESSAGE);
<commit_msg>Disable notifications for system chat rooms.<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui.utils;

import java.util.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.notification.*;
import net.java.sip.communicator.service.protocol.*;

public class NotificationManager
{
    public static final String INCOMING_MESSAGE = "IncomingMessage";
    
    public static final String INCOMING_CALL = "IncomingCall";
    
    public static final String OUTGOING_CALL = "OutgoingCall";
    
    public static final String BUSY_CALL = "BusyCall";
    
    private static Hashtable soundHandlers = new Hashtable();
    
    public static void registerGuiNotifications()
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();
        
        if(notificationService == null)
            return;
        
        // Register incoming message notifications.
        notificationService.registerNotificationForEvent(
                INCOMING_MESSAGE,
                NotificationService.ACTION_POPUP_MESSAGE,
                null,
                null);

        notificationService.registerNotificationForEvent(
                INCOMING_MESSAGE,
                NotificationService.ACTION_SOUND,
                Sounds.INCOMING_MESSAGE,
                null);
        
        // Register incoming call notifications.
        notificationService.registerNotificationForEvent(
                INCOMING_CALL,
                NotificationService.ACTION_POPUP_MESSAGE,
                null,
                null);
    
        SoundNotificationHandler inCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.INCOMING_CALL, 2000);
        
        notificationService.registerNotificationForEvent(
                INCOMING_CALL,
                NotificationService.ACTION_SOUND,
                inCallSoundHandler);

        soundHandlers.put(INCOMING_CALL, inCallSoundHandler);
        
        // Register outgoing call notifications.
        SoundNotificationHandler outCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.OUTGOING_CALL, 3000);
        
        notificationService.registerNotificationForEvent(
                OUTGOING_CALL,
                NotificationService.ACTION_SOUND,
                outCallSoundHandler);
    
        soundHandlers.put(OUTGOING_CALL, outCallSoundHandler);

        // Register busy call notifications.
        SoundNotificationHandler busyCallSoundHandler
            = (SoundNotificationHandler) notificationService
                .createSoundNotificationHandler(Sounds.BUSY, 1);
        
        notificationService.registerNotificationForEvent(
                BUSY_CALL,
                NotificationService.ACTION_SOUND,
                busyCallSoundHandler);
    
        soundHandlers.put(OUTGOING_CALL, outCallSoundHandler);

    }

    /**
     * Fires a message notification for the given event type through the
     * <tt>NotificationService</tt>.
     * 
     * @param eventType the event type for which we fire a notification
     * @param messageTitle the title of the message
     * @param message the content of the message
     */
    public static void fireNotification(String eventType,
                                        String messageTitle,
                                        String message)
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();
        
        if(notificationService == null)
            return;

        notificationService.fireNotification(eventType, messageTitle, message);

    }

    /**
     * Fires a chat message notification for the given event type through the
     * <tt>NotificationService</tt>.
     * 
     * @param contact the chat contact to which the chat message corresponds;
     * the chat contact could be a Contact or a ChatRoom.
     * @param eventType the event type for which we fire a notification
     * @param messageTitle the title of the message
     * @param message the content of the message
     */
    public static void fireChatNotification(Object contact,
                                            String eventType,
                                            String messageTitle,
                                            String message)
    {
        NotificationService notificationService
            = GuiActivator.getNotificationService();

        if(notificationService == null)
            return;

        NotificationActionHandler popupActionHandler = null;

        Chat chatPanel = null;

        if (contact instanceof Contact)
            chatPanel = GuiActivator.getUIService().getChat((Contact) contact);
        else if (contact instanceof ChatRoom)
        {
            // For system rooms we don't want to send notification events.
            if ((contact instanceof ChatRoom)
                && ((ChatRoom) contact).isSystem())
                return;

            chatPanel = GuiActivator.getUIService().getChat((ChatRoom) contact);
        }

        if(eventType.equals(INCOMING_MESSAGE)
            && chatPanel.isChatFocused())
        {
            popupActionHandler = notificationService
                .getEventNotificationActionHandler(
                                    eventType,
                                    NotificationService.ACTION_POPUP_MESSAGE);

{'fraction_non_alphanumeric': 0.05853658536585366, 'fraction_numerical': 0.0016566958122411412, 'mean_word_length': 2.020011117287382, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '679868', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2357, 'n_words': 595}