From 0d06538f11792582aaea0651d2e4b773dedc174e Mon Sep 17 00:00:00 2001 From: Satender Saroha Date: Thu, 18 Apr 2013 16:29:57 +0530 Subject: [PATCH] Bug 837029 - [SMS] - Fix when SMS app attempts to show deleted sms from new message notification r=julienw,borjasalguero --- apps/sms/js/activity_handler.js | 47 +++++++++++++++++++++++---- apps/sms/locales/sms.en-US.properties | 1 + 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/apps/sms/js/activity_handler.js b/apps/sms/js/activity_handler.js index 30646efcec37..6a6848073c5f 100644 --- a/apps/sms/js/activity_handler.js +++ b/apps/sms/js/activity_handler.js @@ -3,7 +3,27 @@ 'use strict'; -function showThreadFromSystemMessage(number, body) { +function handleMessageNotification(options) { + //Validate if message still exists before opening message thread + //See issue https://bugzilla.mozilla.org/show_bug.cgi?id=837029 + if ((!options) || (!options.id)) { + return; + } + var message = navigator.mozSms.getMessage(options.id); + message.onerror = function onerror() { + alert(navigator.mozL10n.get('deleted-sms')); + }; + message.onsuccess = function onsuccess() { + showThreadFromSystemMessage(options); + }; +} + +function showThreadFromSystemMessage(options) { + if (!options) { + return; + } + var number = options.number ? options.number : null; + var body = options.body ? options.body : null; var showAction = function act_action(number) { // If we only have a body, just trigger a new message. if (!number && body) { @@ -69,8 +89,11 @@ window.navigator.mozSetMessageHandler('activity', function actHandle(activity) { return; MessageManager.lockActivity = true; activity.postResult({ status: 'accepted' }); - showThreadFromSystemMessage(activity.source.data.number, - activity.source.data.body); + var options = { + number: activity.source.data.number, + body: activity.source.data.body + }; + showThreadFromSystemMessage(options); }); /* === Incoming SMS support === */ @@ -104,6 +127,8 @@ if (!window.location.hash.length) { // The black list includes numbers for which notifications should not // progress to the user. Se blackllist.js for more information. var number = message.sender; + var id = message.id; + // Class 0 handler: if (message.messageClass === 'class-0') { // XXX: Hack hiding the message class in the icon URL @@ -150,11 +175,15 @@ if (!window.location.hash.length) { // Stashing the number at the end of the icon URL to make sure // we get it back even via system message - iconURL += '?sms-received?' + number; + iconURL += '?sms-received?' + number + '?' + id; var goToMessage = function() { app.launch(); - showThreadFromSystemMessage(number); + var options = { + number: number, + id: id + }; + handleMessageNotification(options); }; Contacts.findByPhoneNumber(message.sender, function gotContact( @@ -186,8 +215,14 @@ if (!window.location.hash.length) { var notificationType = message.imageURL.split('?')[1]; // Case regular 'sms-received' if (notificationType == 'sms-received') { + var number = message.imageURL.split('?')[2]; - showThreadFromSystemMessage(number); + var id = message.imageURL.split('?')[3]; + var options = { + number: number, + id: id + }; + handleMessageNotification(options); return; } var number = message.title; diff --git a/apps/sms/locales/sms.en-US.properties b/apps/sms/locales/sms.en-US.properties index 07a7148823ac..bda179bac4f3 100644 --- a/apps/sms/locales/sms.en-US.properties +++ b/apps/sms/locales/sms.en-US.properties @@ -63,6 +63,7 @@ sendGeneralErrorBtnOk = OK sendAirplaneModeTitle = Airplane mode activated sendAirplaneModeBody = To send a message, first disable airplane mode. sendAirplaneModeBtnOk = OK +deleted-sms = Sorry but the message you are trying to access has already been deleted # Labels for contact fields mobile = Mobile