Patch Messaging Sounds

From WebOS Internals
Revision as of 23:51, 21 July 2009 by Hopspitfire (talk | contribs) (New page: '''Description:''' This mod will allow you to specify the sound played on an incoming message, distinct from the alert and notification sounds. '''History:''' This is based //heavily// on...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description: This mod will allow you to specify the sound played on an incoming message, distinct from the alert and notification sounds.

History: This is based //heavily// on the Sounds and Alerts Program Modification by Kaerey. The three steps of this mod are replics of the three steps in that mod, adding "messages" to "alerts" and "notifications". It is recommended, though not necessary, that you do that mod first. Throughout these instructions, I will refer to that mod as the "Sounds and Alerts Mod".

Disclaimer: This is very involved. I //highly// recommend that you back up every file before you change it.

Short Cut: If you are using [*http://forums.precentral.net/homebrew-apps/188729-my-notification-no-rooting-needed.html My Notification] then you can skip to step 4. The function under the Advanced Options of the app can be used to select your message sound. And you do not need to edit the Sounds and Alerts Program

Step One: Modify the Sounds and Alerts Program to add the new fields

Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html

Between lines 50 and 51 (or immediately after the changes made in Step 1 of the Sounds and Alerts Mod)

<div id='currentmessagerow' class="palm-row" x-mojo-tap-highlight="momentary">
                <div class="palm-row-wrapper">
                    <div class="label" x-mojo-loc=''>Message</div>
                    <div id='currentmessage' class="title"></div>                    
                </div>
             </div>

Step Two: Create the database calls

Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js

Find the Section of Code that deals with getRingtone and setRingtone starting on line 9:

SystemService.setRingtone = function(value,callback) {

    var request = new Mojo.Service.Request(SystemService.identifier, {
            method: 'setPreferences',
            parameters: {"ringtone":value},             
        });
    return request;
}

SystemService.getRingtone = function(callback) {

    var request = new Mojo.Service.Request(SystemService.identifier, {
            method: 'getPreferences',
            parameters: {"keys":["ringtone"],"subscribe":true}, 
            onSuccess: callback,
            onFailure: callback
        });
    return request;
}

We are going to create a like section for Messages:

SystemService.getMessages = function(callback) {
    var request = new Mojo.Service.Request(SystemService.identifier, {
            method: 'getPreferences',
            parameters: {"keys":["messagetone"]},
            onSuccess: callback,
            onFailure: callback
        });
    return request;
}

SystemService.setMessages = function(value){
    var request = new Mojo.Service.Request(SystemService.identifier, {
            method: 'setPreferences',
            parameters: {"messagetone":value},
        });
    return request;
}

Step Three: Create the handlers for the new components

Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js

At line 81, you will see:

$('currentringtonerow').observe(Mojo.Event.tap, this.showAudioFilePicker.bindAsEventListener(this));

Create an entry for Messages, either after the line above, or after the additions to this section made in Step 3 of the Sounds and Alerts Mod:

$('currentmessagerow').observe(Mojo.Event.tap, this.showMessageFilePicker.bindAsEventListener(this));

Below that section you will see:

this.getCurrentVolumes();
this.getCurrentRingtone();
this.getVibrateSettings();    
this.getOtherSettings();

Add a line for Messages:

this.getCurrentMessage();

Find the Code near line 215:

getCurrentRingtone: function() {
        this.getCurrentRingtoneReq = SystemService.getRingtone(this.getCurrentRingtoneQuery.bind(this));
    },

    getCurrentRingtoneQuery: function(payload) {        
        if (payload.ringtone) {
            $('currentringtone').innerHTML = payload.ringtone.name;
            this.currRingtonePath = payload.ringtone.fullPath;    
        }
        else 
            $('currentringtone').innerHTML = $L("Pick a ringtone");

    },

    showAudioFilePicker: function(event) {
        var params = {"kinds": ["ringtone"],"filePath":this.currRingtonePath,"onSelect":this.selectedAudioFile.bind(this),actionType:"attach",actionName: $L("Done")};
        Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
    },

    selectedAudioFile: function(file) {        
        //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
        this.setRingtoneReq = SystemService.setRingtone(file);
        $('currentringtone').innerHTML = file.name;
    },

Add this code for Messages:

// Message Picking
    getCurrentMessage: function() {
        this.getCurrentMessageReq = SystemService.getMessages(this.getCurrentMessageQuery.bind(this));
    },

    getCurrentMessageQuery: function(payload) {        
        if (payload.messagetone) {
            $('currentmessage').innerHTML = payload.messagetone.name;
            this.currMessagePath = payload.messagetone.fullPath;    
        }
        else 
            $('currentmessage').innerHTML = $L("Pick a message sound");

    },

    showMessageFilePicker: function(event) {
        var params = {"kinds": ["ringtone"],"filePath":this.currMessagePath,"onSelect":this.selectedMessageFile.bind(this),actionType:"attach",actionName: $L("Done")};
        Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
    },

    selectedMessageFile: function(file) {        
        //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
        this.setMessageReq = SystemService.setMessages(file);
        $('currentmessage').innerHTML = file.name;
    },

Step Four: Add the database call to the Messages Application

Back up and modify /usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js

After line 7, add:

  getMessagetone:  function(callback) {
        var request = new Mojo.Service.Request('palm://com.palm.systemservice', {
                method: 'getPreferences',
                parameters: {"keys":["messagetone"]},
                onSuccess: callback,
                onFailure: callback
         });
        return request;
  },

Step Five: Have the Message Application play the sound from the database

Back up and modify /usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js

Below line 44 (just above the <ReminderCode> comment block), add:

NotificationAssistant.prototype.getandPlayMessagetone = function(bannerParams,bannerLaunchParams,bannerType){
	MessagingMojoService.getMessagetone(this.doBanner.bind(this,bannerParams,bannerLaunchParams,bannerType));
};

NotificationAssistant.prototype.doBanner = function(bannerParams,bannerLaunchParams,bannerType,payload) {
        if (payload.messagetone)
                bannerParams.soundFile = payload.messagetone.fullPath;
        this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
};

NotificationAssistant.prototype.playMessagetone = function(payload){
        if (payload.messagetone)
                this.controller.playSoundNotification('alerts',payload.messagetone.fullPath);
        else
		this.controller.playSoundNotification('alerts','');
};

In the next function, NotificationAssistant.prototype.sendReminderNotification, find the block of code:

        var bannerLaunchParams =  {
                reminderPersonId: resp.personId,
                clearBanner: true
        };
        this.controller.showBanner(bannerParams,bannerLaunchParams,'reminder');

Change that to:

	var bannerLaunchParams =  {
                reminderPersonId: resp.personId,
                clearBanner: true
        };
        this.getandPlayMessagetone(bannerParams,bannerLaunchParams,'reminder');

In the function NotificationAssistant.prototype.considerForNotification, find the block of code:

        // check if we should only play a sound (when you are already in a chat & a new message comes in)
        if(notificationData.get('playSoundOnly') && this.Messaging.messagingPrefs.enableNotificationSound) {
                this.controller.playSoundNotification('alerts','');
                return; // don't display any visual notification
        }

Change that to:

        // check if we should only play a sound (when you are already in a chat & a new message comes in)
        if(notificationData.get('playSoundOnly') && this.Messaging.messagingPrefs.enableNotificationSound) {
                MessagingMojoService.getMessagetone(this.playMessagetone.bind(this));
                return; // don't display any visual notification
        }

In the function NotificationAssistant.prototype.sendNewMessageNotificationAndUpdateDashboard, find the block of code:

        var bannerParams = {
                messageText: notificationText
        };
        if (this.Messaging.messagingPrefs.enableNotificationSound)
                bannerParams.soundClass = "alerts";
        var bannerLaunchParams =  {
                chatThreadId: notificationData.get('chatThreadId'),
                clearBanner: true
        };
        this.controller.showBanner(bannerParams,bannerLaunchParams,'chat');

Change that to:

        var bannerParams = {
                messageText: notificationText
        };
        var bannerLaunchParams =  {
                chatThreadId: notificationData.get('chatThreadId'),
                clearBanner: true
        };
        if (this.Messaging.messagingPrefs.enableNotificationSound) {
                bannerParams.soundClass = "alerts";
		this.getandPlayMessagetone(bannerParams,bannerLaunchParams,'chat');
	} else
		this.controller.showBanner(bannerParams,bannerLaunchParams,'chat');

Finally, as it looks like the immediate dashboard creation when the screen is off is causing the sound not to be played, in the same function, find this block of code:

		// delay creating the dashboard window for the case where the banner is clicked on
                // to take you to the chat view.  This will likely result in the dashboard data
                // being cleared.  If the dashboard data is empty, we do not need to create the dashboard.              
                if (this.Messaging.DisplayState.isDisplayOn()) {
                        if (!this.isNewMessageDashboardPending) {
                                this.isNewMessageDashboardPending = true;
                                createDashboard.delay(5);
                        }

                } else {
                        createDashboard(); // if the screen is off, create the dashboard right away
                }

Change that to:

		// delay creating the dashboard window for the case where the banner is clicked on
                // to take you to the chat view.  This will likely result in the dashboard data
                // being cleared.  If the dashboard data is empty, we do not need to create the dashboard.
                // if (this.Messaging.DisplayState.isDisplayOn()) {
                        if (!this.isNewMessageDashboardPending) {
                                this.isNewMessageDashboardPending = true;
                                createDashboard.delay(5);
                        }

                // } else {
                        // createDashboard(); // if the screen is off, create the dashboard right away
                // }


Copy your desired message sound to the "ringtones" directory in /media/internal/ringtones and it will be visible in the FilePicker.

Reboot the phone for changes to take effect.

Credits

The changes to the Sounds and Alerts app are slight modifications to the submissions of Kaerey. The rest is submitted by JackieRipper.