Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
This catches the development branch up with v1.0.39 in master.
  • Loading branch information
scottnonnenberg committed Nov 22, 2017
2 parents 16d94a8 + 93a34e5 commit 0e328f3
Show file tree
Hide file tree
Showing 18 changed files with 9,700 additions and 254 deletions.
4 changes: 4 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module.exports = function(grunt) {
files: [
'Gruntfile.js',
'js/**/*.js',
'!js/jquery.js',
'!js/libtextsecure.js',
'!js/WebAudioRecorderMp3.js',
'!js/Mp3LameEncoder.min.js',
Expand Down Expand Up @@ -132,6 +133,9 @@ module.exports = function(grunt) {
}, {
src: 'components/webaudiorecorder/lib/WebAudioRecorderMp3.js',
dest: 'js/WebAudioRecorderMp3.js'
}, {
src: 'components/jquery/dist/jquery.js',
dest: 'js/jquery.js'
}],
},
res: {
Expand Down
16 changes: 13 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"description": "Button shown if the user runs into an error during import, allowing them to start over"
},
"importInstructions": {
"message": "The first step is to tell us where you previously exported your Signal data. It will be a directory whose name starts with 'Signal Export.'",
"message": "The first step is to tell us where you previously <a href='https://support.signal.org/hc/en-us/articles/115002502511'>exported your Signal data</a>. It will be a directory whose name starts with 'Signal Export.'<br><br><b>NOTE</b>: You must only import a set of exported data <b>once</b>. Import makes a copy of the exported client, and duplicate clients interfere with each other.",
"description": "Description of the export process"
},
"importing": {
Expand Down Expand Up @@ -906,7 +906,7 @@
},
"leftTheGroup": {
"message": "$name$ left the group.",
"description": "Shown in the conversation history when someone leaves the group",
"description": "Shown in the conversation history when a single person leaves the group",
"placeholders": {
"name": {
"content": "$1",
Expand All @@ -929,8 +929,18 @@
}
},
"joinedTheGroup": {
"message": "$name$ joined the group.",
"description": "Shown in the conversation history when a single person joins the group",
"placeholders": {
"name": {
"content": "$1",
"example": "Alice"
}
}
},
"multipleJoinedTheGroup": {
"message": "$names$ joined the group.",
"description": "Shown in the conversation history when people join the group",
"description": "Shown in the conversation history when more than one person joins the group",
"placeholders": {
"names": {
"content": "$1",
Expand Down
10 changes: 10 additions & 0 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
<a href="https://signal.org">signal.org</a>
</div>

<script type='text/javascript' src='js/jquery.js'></script>
<script>
$(document).on('keyup', function(e) {
if (e.keyCode === 27) {
window.closeAbout();
}
});
</script>


</body>

</html>
8 changes: 4 additions & 4 deletions app/auto_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function checkForUpdates() {
}

var showingDialog = false;
function showUpdateDialog(messages) {
function showUpdateDialog(mainWindow, messages) {
if (showingDialog) {
return;
}
Expand All @@ -38,7 +38,7 @@ function showUpdateDialog(messages) {
cancelId: LATER_BUTTON
}

dialog.showMessageBox(options, function(response) {
dialog.showMessageBox(mainWindow, options, function(response) {
if (response == RESTART_BUTTON) {
windowState.markShouldQuit();
autoUpdater.quitAndInstall();
Expand All @@ -52,7 +52,7 @@ function onError(error) {
console.log("Got an error while updating: ", error.stack);
}

function initialize(messages) {
function initialize(getMainWindow, messages) {
if (!messages) {
throw new Error('auto-update initialize needs localized messages');
}
Expand All @@ -62,7 +62,7 @@ function initialize(messages) {
}

autoUpdater.addListener('update-downloaded', function() {
showUpdateDialog(messages);
showUpdateDialog(getMainWindow(), messages);
});
autoUpdater.addListener('error', onError);

Expand Down
123 changes: 90 additions & 33 deletions js/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@

_.each(storeNames, function(storeName) {
var transaction = idb_db.transaction(storeNames, 'readwrite');
transaction.onerror = function(error) {
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'exportToJsonFile: transaction error',
error && error.stack ? error.stack : error
Expand All @@ -116,8 +117,13 @@
var request = store.openCursor();
var count = 0;
request.onerror = function(e) {
console.log('Error attempting to export store', storeName);
reject(e);
var error = e.target.error;
console.log(
'Error attempting to export store',
storeName,
error && error.stack ? error.stack : error
);
reject(error);
};
request.onsuccess = function(event) {
if (count === 0) {
Expand Down Expand Up @@ -188,7 +194,14 @@
};

var transaction = idb_db.transaction(storeNames, 'readwrite');
transaction.onerror = reject;
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'importFromJsonString error:',
error && error.stack ? error.stack : error
);
reject(error || new Error('importFromJsonString: transaction.onerror'));
};
transaction.oncomplete = finish.bind(null, 'transaction complete');

_.each(storeNames, function(storeName) {
Expand Down Expand Up @@ -216,14 +229,16 @@
}
}
};
request.onerror = function(error) {
request.onerror = function(e) {
var error = e.target.error;
console.log(
'Error adding object to store',
storeName,
':',
toAdd
toAdd,
error && error.stack ? error.stack : error
);
reject(error);
reject(error || new Error('importFromJsonString: request.onerror'));
};
});
});
Expand Down Expand Up @@ -384,13 +399,14 @@
return new Promise(function(resolve, reject) {
var transaction = idb_db.transaction('messages', 'readwrite');
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'exportConversation transaction error for conversation',
name,
':',
e && e.stack ? e.stack : e
error && error.stack ? error.stack : error
);
return reject(e);
return reject(error || new Error('exportConversation: transaction.onerror'));
};
transaction.oncomplete = function() {
// this doesn't really mean anything - we may have attachment processing to do
Expand All @@ -408,13 +424,14 @@
stream.write('{"messages":[');

request.onerror = function(e) {
var error = e.target.error;
console.log(
'exportConversation: error pulling messages for conversation',
name,
':',
e && e.stack ? e.stack : e
error && error.stack ? error.stack : error
);
return reject(e);
return reject(error || new Error('exportConversation: request.onerror'));
};
request.onsuccess = function(event) {
var cursor = event.target.result;
Expand Down Expand Up @@ -498,11 +515,12 @@
return new Promise(function(resolve, reject) {
var transaction = idb_db.transaction('conversations', 'readwrite');
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'exportConversations: transaction error:',
e && e.stack ? e.stack : e
error && error.stack ? error.stack : error
);
return reject(e);
return reject(error || new Error('exportConversations: transaction.onerror'));
};
transaction.oncomplete = function() {
// not really very useful - fires at unexpected times
Expand All @@ -512,11 +530,12 @@
var store = transaction.objectStore('conversations');
var request = store.openCursor();
request.onerror = function(e) {
var error = e.target.error;
console.log(
'exportConversations: error pulling conversations:',
e && e.stack ? e.stack : e
error && error.stack ? error.stack : error
);
return reject(e);
return reject(error || new Error('exportConversations: request.onerror'));
};
request.onsuccess = function(event) {
var cursor = event.target.result;
Expand Down Expand Up @@ -602,11 +621,12 @@

var transaction = idb_db.transaction('messages', 'readwrite');
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'saveAllMessages transaction error:',
e && e.stack ? e.stack : e
error && error.stack ? error.stack : error
);
return reject(e);
return reject(error || new Error('saveAllMessages: transaction.onerror'));
};
transaction.oncomplete = finish.bind(null, 'transaction complete');

Expand All @@ -620,7 +640,7 @@
count += 1;
if (count === messages.length) {
console.log(
'Done importing',
'Saved',
messages.length,
'messages for conversation',
// Don't know if group or private conversation, so we blindly redact
Expand All @@ -629,35 +649,63 @@
finish('puts scheduled');
}
};
request.onerror = function(event) {
console.log('Error adding object to store:', event);
reject(new Error('saveAllMessage: onerror fired'));
request.onerror = function(e) {
var error = e.target.error;
console.log(
'Error adding object to store:',
error && error.stack ? error.stack : error
);
reject(error || new Error('saveAllMessages: request.onerror'));
};
});
});
}

// To reduce the memory impact of attachments, we make individual saves to the
// database for every message with an attachment. We load the attachment for a
// message, save it, and only then do we move on to the next message. Thus, every
// message with attachments needs to be removed from our overall message save with the
// filter() call.
function importConversation(idb_db, dir) {
return readFileAsText(dir, 'messages.json').then(function(contents) {
var promiseChain = Promise.resolve();

var json = JSON.parse(contents);
var messages = json.messages;
_.forEach(messages, function(message) {
var conversationId;
if (json.messages && json.messages.length) {
conversationId = json.messages[0].conversationId;
}

var messages = _.filter(json.messages, function(message) {
message = unstringify(message);

if (message.attachments && message.attachments.length) {
var process = function() {
return loadAttachments(dir, message);
return loadAttachments(dir, message).then(function() {
return saveAllMessages(idb_db, [message]);
});
};

promiseChain = promiseChain.then(process);

return null;
}
});

return promiseChain.then(function() {
return saveAllMessages(idb_db, messages);
return message;
});

return saveAllMessages(idb_db, messages)
.then(function() {
return promiseChain;
})
.then(function() {
console.log(
'Finished importing conversation',
// Don't know if group or private conversation, so we blindly redact
conversationId ? '[REDACTED]' + conversationId.slice(-3) : 'with no messages'
);
});

}, function() {
console.log('Warning: could not access messages.json in directory: ' + dir);
});
Expand Down Expand Up @@ -689,10 +737,18 @@
var storeNames = idb_db.objectStoreNames;
var transaction = idb_db.transaction(storeNames, 'readwrite');

transaction.oncomplete = function() {
// unused
var finished = false;
var finish = function(via) {
console.log('clearing all stores done via', via);
if (finished) {
resolve();
}
finished = true;
};
transaction.onerror = function(error) {

transaction.oncomplete = finish.bind(null, 'transaction complete');
transaction.onerror = function(e) {
var error = e.target.error;
console.log(
'saveAllMessages transaction error:',
error && error.stack ? error.stack : error
Expand All @@ -711,16 +767,17 @@

if (count >= storeNames.length) {
console.log('Done clearing all indexeddb stores');
return resolve();
return finish('clears complete');
}
};

request.onerror = function(error) {
request.onerror = function(e) {
var error = e.target.error;
console.log(
'clearAllStores transaction error:',
error && error.stack ? error.stack : error
);
return reject(error);
return reject(error || new Error('clearAllStores: request.onerror'));
};
});
});
Expand Down

0 comments on commit 0e328f3

Please sign in to comment.