Skip to content

Commit

Permalink
Bug 837029 - [SMS] - Fix when SMS app attempts to show deleted sms fr…
Browse files Browse the repository at this point in the history
…om new message notification r=julienw,borjasalguero
  • Loading branch information
ssaroha committed May 1, 2013
1 parent 1ab9bc8 commit 0d06538
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
47 changes: 41 additions & 6 deletions apps/sms/js/activity_handler.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 === */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions apps/sms/locales/sms.en-US.properties
Expand Up @@ -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
Expand Down

0 comments on commit 0d06538

Please sign in to comment.