Commit 114123fc2e260a5e795bc6abf7ca968e769f3db6

  • avatar
  • root <root @qem…86.(none)>
  • Wed Sep 30 20:48:28 CEST 2009
Updated to work with 1.2
  
2121 Mojo.Log.info("[CV] ****** chatview considerForNotification --- screen is on!");
2222 if(data.notificationType == this.Messaging.notificationTypes.newMessage) {
2323- data = {playSoundOnly:true};
24+ data = $H(data);
25+ data = data.merge({playSoundOnly:true});
24+ data = $H(data);
25+ data = data.merge({playSoundOnly:true});
2626 } else if( data.notificationType == this.Messaging.notificationTypes.sendFailure) {
2727 data = {}; // wipe out the notification because we are in the chat
2828 }
3030===================================================================
3131--- .orig/usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
3232+++ /usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
33@@ -993,5 +993,170 @@ var MessagingMojoService = {
33@@ -993,5 +993,168 @@ var MessagingMojoService = {
3434 method: 'setSMSCAddressAndEmailGateway',
3535 parameters: {smscAddr:address, emailGateway: gateway}
3636 });
37- }
38-};
39\ No newline at end of file
4037+ },
41+
42+ isNumberValid: function(number) {
38+
39+ isNumberValid: function(number) {
4340+ return !(number === undefined
44+ || number == null
45+ || number == ""
46+ || number == "unknown"
47+ || number == "unknown caller"
48+ || number == "blocked caller")
41+ || number == null
42+ || number == ""
43+ || number == "unknown"
44+ || number == "unknown caller"
45+ || number == "blocked caller")
4946+ },
50+
51+ // use contacts service and carrier book to perform reverse lookup on number.stores results in passed contact object.
47+
48+ // use contacts service and carrier book to perform reverse lookup on number. stores results in passed contact object.
5249+ // runs callback when done.
5350+ // if the number isn't valid, marks contact lookup complete
5451+ // if there's already one happening, or one already completed, just fires callback
5552+ // if there's a lateCallback provided, calls that if the result comes much later
5653+ rLookup: function(number, contact, callback, lateCallback){
57+
54+
5855+ //Reset contact to always get the tone
59+ contact = {};
56+ contact = {};
6057+ Mojo.Log.error("Current contact value: %j",contact);
6158+ Mojo.Log.error("SMS ID: %j",number);
62+
59+
6360+ // bail if the number is invalid
6461+ if (!(this.isNumberValid(number))) {
65+ this.finishLookup(contact, callback);
66+ return;
62+ this.finishLookup(contact, callback);
63+ return;
6764+ }
68+
65+
6966+ if (contact.lookupComplete) {
70+ callback(contact);
67+ callback(contact);
7168+ return;
7269+ }
73+
70+
7471+ if (contact.lookupPending) {
75+ callback(contact);
72+ callback(contact);
7673+ return;
7774+ }
78+
79+
75+
76+
8077+ // use contacts service to perform lookup.
8178+ // if contact already has an id in it, use person lookup
8279+ // instead of doing reverse lookup on number
8181+ var method, params;
8282+ if (contact.initialId) {
8383+ method = 'basicDetails'
84+ params ={'id' : contact.initialId}
84+ params = {'id' : contact.initialId}
8585+ delete contact.initialId;
8686+ } else {
8787+ method = 'reverseLookup'
8888+ params = {
89+ 'value': number,
90+ 'type': "phone"
89+ 'value': number,
90+ 'type': "phone"
91+ }
9192+ }
92+ }
9393+ this.lastRequest = new Mojo.Service.Request('palm://com.palm.contacts', {
9494+ 'method': method,
95+ parameters: params,
96+ onSuccess: this.onLookup.bind(this, number, contact, callback, lateCallback),
95+ parameters: params,
96+ onSuccess: this.onLookup.bind(this, number, contact, callback, lateCallback),
9797+ onFailure: function() {
98+ // cancel previous lookup, so this doesn't fire on a service crash
99+ if (this.lastRequest) {
100+ this.lastRequest.cancel();
101+ this.lastRequest = undefined;
102+ }
103+
104+ this.carrierBookLookup(number,contact);
105+ this.finishLookup(contact, callback);
106+ }.bind(this)
107+ });
108+
98+ // cancel previous lookup, so this doesn't fire on a service crash
99+ if (this.lastRequest) {
100+ this.lastRequest.cancel();
101+ this.lastRequest = undefined;
102+ }
103+
104+ this.carrierBookLookup(number,contact);
105+ this.finishLookup(contact, callback);
106+ }.bind(this)
107+ });
108+
109109+ // timeout if lookup hasn't completed in 4 seconds
110110+ this.lookupTimeout = setTimeout(this.onLookupTimeout.bind(this, contact, callback, lateCallback), 4000);
111+ },
112+
113+ // when contact lookup returns, check for valid result
114+ // if valid result, grab name, ringtone; if there's a picture, start loading and set callback to measure it
115+ // if no valid result, look in carrier book
116+ // fire callback when done
117+ onLookup: function(number, contact, callback, lateCallback, result){
118+ Mojo.Log.info( "PhoneApp: Contact::onLookup CALLER ID LOOKUP %s RETURNED %j" , number , result);
111+ },
112+
113+ // when contact lookup returns, check for valid result
114+ // if valid result, grab name, ringtone; if there's a picture, start loading and set callback to measure it
115+ // if no valid result, look in carrier book
116+ // fire callback when done
117+ onLookup: function(number, contact, callback, lateCallback, result){
118+ Mojo.Log.info( "PhoneApp: Contact::onLookup CALLER ID LOOKUP %s RETURNED %j" , number , result);
119119+ var statusChange = "";
120+
120+
121121+ // cancel previous lookup, so this doesn't fire on a service crash
122122+ if (this.lastRequest) {
123123+ this.lastRequest.cancel();
124124+ this.lastRequest = undefined;
125125+ }
126+
126+
127127+ if (result.record) {
128+ /*
128+ /*
129129+ // don't match if the number we get back is different than the number
130130+ // we passed in (provided the lengths are the same)
131131+ if (!(result.record.number)
132132+ || ( (result.record.number) && ( (result.record.number.length !== number.length)
133+ || (result.record.number.length === number.length
134+ && result.record.number === number)))) {
135+ */
136+ contact.id = result.record.id;
137+
138+
139+ contact.ringtoneLoc = result.record.messagingRingtoneLoc;
140+ Mojo.Log.error("MSGTone: %j",contact.ringtoneLoc);
141+
142+ }
143+
144+ this.finishLookup(contact, callback, lateCallback);
145+ },
146+
147+
148+
149+ // mark complete; cancel timeout; fire callback if it hasn't fired yet
150+ finishLookup: function(contact, callback, lateCallback) {
151+ contact.lookupPending = false;
152+
153+ // cancel lookup timeout
154+ clearTimeout(this.lookupTimeout);
155+ this.lookupTimeout = undefined;
156+
157+ if (!(contact.lookupComplete)) {
158+ contact.lookupComplete = true;
159+ callback(contact);
160+ // if we have a late return, and we got a contact result, call
161+ // the late return update
162+ } else if (lateCallback && contact.doLateCallback && contact.id) {
163+ contact.doLateCallback = false;
164+ lateCallback.delay(5, contact);
165+ } else {
166+ }
167+
168+ },
169+
170+ // flag lookup as done; proceed with callback
171+ onLookupTimeout: function(contact, callback, lateCallback) {
172+
173+ if (lateCallback) {
174+ contact.doLateCallback = true;
175+ } else if (this.lastRequest && !lateCallback) {
176+ // cancel previous lookup, so this doesn't fire on a service crash
177+ this.lastRequest.cancel();
178+ this.lastRequest = undefined;
179+ }
180+
181+ // clear timeout
182+ this.lookupTimeout = undefined;
183+
184+ // flag done; fire callback if it hasn't yet
185+ contact.lookupComplete = true;
186+ var lookupWasPending = contact.lookupPending;
187+ contact.lookupPending = false;
188+ if (lookupWasPending)
189+ callback(contact);
190+ },
191+
192+ getMessagetone:function(callback) {
193+ var request = new Mojo.Service.Request('palm://com.palm.systemservice', {
194+ method: 'getPreferences',
195+ parameters: {"keys":["messagetone"]},
196+ onSuccess: callback,
197+ onFailure: callback
198+ });
199+ return request;
200+ }
133+ || (result.record.number.length === number.length
134+ && result.record.number === number)))) {
135+ */
136+ contact.id = result.record.id;
137+
138+
139+ contact.ringtoneLoc = result.record.messagingRingtoneLoc;
140+ Mojo.Log.error("MSGTone: %j",contact.ringtoneLoc);
201141+
202+};
142+ }
143+
144+ this.finishLookup(contact, callback, lateCallback);
145+ },
146+
147+
203148+
149+ // mark complete; cancel timeout; fire callback if it hasn't fired yet
150+ finishLookup: function(contact, callback, lateCallback) {
151+ contact.lookupPending = false;
152+
153+ // cancel lookup timeout
154+ clearTimeout(this.lookupTimeout);
155+ this.lookupTimeout = undefined;
156+
157+ if (!(contact.lookupComplete)) {
158+ contact.lookupComplete = true;
159+ callback(contact);
160+ // if we have a late return, and we got a contact result, call
161+ // the late return update
162+ } else if (lateCallback && contact.doLateCallback && contact.id) {
163+ contact.doLateCallback = false;
164+ lateCallback.delay(5, contact);
165+ } else {
166+ }
167+
168+ },
169+
170+ // flag lookup as done; proceed with callback
171+ onLookupTimeout: function(contact, callback, lateCallback) {
172+
173+ if (lateCallback) {
174+ contact.doLateCallback = true;
175+ } else if (this.lastRequest && !lateCallback) {
176+ // cancel previous lookup, so this doesn't fire on a service crash
177+ this.lastRequest.cancel();
178+ this.lastRequest = undefined;
179+ }
180+
181+ // clear timeout
182+ this.lookupTimeout = undefined;
183+
184+ // flag done; fire callback if it hasn't yet
185+ contact.lookupComplete = true;
186+ var lookupWasPending = contact.lookupPending;
187+ contact.lookupPending = false;
188+ if (lookupWasPending)
189+ callback(contact);
190+ },
191+
192+ getMessagetone: function(callback) {
193+ var request = new Mojo.Service.Request('palm://com.palm.systemservice', {
194+ method: 'getPreferences',
195+ parameters: {"keys":["messagetone"]},
196+ onSuccess: callback,
197+ onFailure: callback
198+ });
199+ return request;
200 }
201 };
202\ No newline at end of file
204203Index: /usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
205204===================================================================
206205--- .orig/usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
213213 NotificationAssistant.prototype.subscribeToNotifications = function(){
214214 this.messageNotificationRequest = MessagingMojoService.registerForIncomingMessages({onSuccess: this.sendNotification.bind(this, this.Messaging.notificationTypes.newMessage)});
215215 this.sendErrorNotificationRequest = MessagingMojoService.registerForSendFailures(this.sendNotification.bind(this, this.Messaging.notificationTypes.sendFailure));
216@@ -51,6 +53,37 @@ NotificationAssistant.prototype.sendNoti
217 }
216@@ -35,6 +37,37 @@ NotificationAssistant.prototype.subscrib
217 this.airplaneModeNotificationRequest = MessagingMojoService.registerForAirplaneModeNotifications(this.sendAirplaneModeNotification.bind(this));
218218 };
219219
220220+NotificationAssistant.prototype.doBanner = function(bannerParams,bannerLaunchParams,bannerType,payload) {
232232+
233233+NotificationAssistant.prototype.doB = function(bannerParams,bannerLaunchParams,bannerType,contact) {
234234+ Mojo.Log.error("Banner Ringtone: %j",contact.ringtoneLoc);
235+ if (contact.ringtoneLoc) {
236+ bannerParams.soundFile = contact.ringtoneLoc;
237+ this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
238+ } else {
239+ MessagingMojoService.getMessagetone(this.doBanner.bind(this,bannerParams,bannerLaunchParams,'chat'));
240+ }
235+ if (contact.ringtoneLoc) {
236+ bannerParams.soundFile = contact.ringtoneLoc;
237+ this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
238+ } else {
239+ MessagingMojoService.getMessagetone(this.doBanner.bind(this,bannerParams,bannerLaunchParams,'chat'));
240+ }
241241+};
242+
242+
243243+NotificationAssistant.prototype.playmsgtone = function(contact){
244+ Mojo.Log.error("Playmsgtone Ringtone: %j",contact.ringtoneLoc);
245+ if (contact.ringtoneLoc)
246+ this.controller.playSoundNotification('alerts',contact.ringtoneLoc);
247+ else
248+ MessagingMojoService.getMessagetone(this.playMessagetone.bind(this));
244+ Mojo.Log.error("Playmsgtone Ringtone: %j",contact.ringtoneLoc);
245+ if (contact.ringtoneLoc)
246+ this.controller.playSoundNotification('alerts',contact.ringtoneLoc);
247+ else
248+ MessagingMojoService.getMessagetone(this.playMessagetone.bind(this));
249249+};
250250+
251 /*
252 * <ReminderCode>
253 */
251 NotificationAssistant.prototype.sendNotification = function(notificationType, resp){
252 if (window.PalmSystem && !resp.returnValue) {
253 try {
254254@@ -140,7 +173,8 @@ NotificationAssistant.prototype.consider
255255
256256 // check if we should only play a sound (when you are already in a chat & a new message comes in)
257257 if(notificationData.get('playSoundOnly') && this.Messaging.messagingPrefs.enableNotificationSound) {
258258- this.controller.playSoundNotification('alerts','');
259259+ var smsid = notificationData.get('address');
260+ MessagingMojoService.rLookup(smsid,contact,this.playmsgtone.bind(this),this.playmsgtone.bind(this));
260+ MessagingMojoService.rLookup(smsid,contact,this.playmsgtone.bind(this),this.playmsgtone.bind(this));
261261 return; // don't display any visual notification
262262 }
263263
275275 var class0Stage = this.controller.getStageController(Class0AlertStageName);
276276
277277 if(class0Stage) {
278@@ -188,6 +223,9 @@ NotificationAssistant.prototype.renderCl
278@@ -188,6 +223,8 @@ NotificationAssistant.prototype.renderCl
279279 var soundClass = 'none';
280280 if(playSound) {
281281 soundClass = 'alerts';
282282+ if(messageTone)
283283+ soundFile = messageTone;
284+ }
285284 }
286285
287286 var pushClass0AlertScene = function(stageController) {
288@@ -198,7 +236,8 @@ NotificationAssistant.prototype.renderCl
287@@ -198,7 +235,8 @@ NotificationAssistant.prototype.renderCl
289288 name: Class0AlertStageName,
290289 lightweight: true,
291290 height: 300,
294294 }, pushClass0AlertScene, 'popupalert');
295295 }
296296
297@@ -253,8 +292,6 @@ NotificationAssistant.prototype.sendNewM
297@@ -253,8 +291,6 @@ NotificationAssistant.prototype.sendNewM
298298 var bannerParams = {
299299 messageText: notificationText
300300 };
303303 var bannerLaunchParams = {
304304 chatThreadId: chatThreadId,
305305 clearBanner: true
306@@ -262,10 +299,16 @@ NotificationAssistant.prototype.sendNewM
306@@ -262,10 +298,17 @@ NotificationAssistant.prototype.sendNewM
307307
308308 if (this.Messaging.DisplayState.isDisplayOn()) {
309309 Mojo.Log.info("notificationAssistant - executing full banner notification");
310310- this.controller.showBanner(bannerParams, bannerLaunchParams, 'chat');
311311+ if (this.Messaging.messagingPrefs.enableNotificationSound) {
312+ var smsid = notificationData.get('address');
312+ var smsid = notificationData.get('address');
313313+ bannerParams.soundClass = "alerts";
314314+ MessagingMojoService.rLookup(smsid,contact,this.doB.bind(this,bannerParams,bannerLaunchParams,'chat'),this.doB.bind(this,bannerParams,bannerLaunchParams,'chat'));
315315+ } else {
316+ Mojoa.Log.error("Setting banner params");
316317+ this.controller.showBanner(bannerParams, bannerLaunchParams, 'chat');
317318+ }
318319 } else if (this.Messaging.messagingPrefs.enableNotificationSound) {
319320- Mojo.Log.info("notificationAssistant - playing sound notification only");
320321- this.controller.playSoundNotification('alerts','');
321+ var smsid = notificationData.get('address');
322+ var smsid = notificationData.get('address');
322323+ MessagingMojoService.rLookup(smsid,contact,this.playmsgtone.bind(this),this.playmsgtone.bind(this));
323324 }
324325