From 41216f1378899709d03507649e4a602cebb0d064 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 12 Jan 2017 13:51:38 -0800 Subject: [PATCH] Add timestamps to attachment filenames --- js/views/attachment_view.js | 12 +++++++++--- js/views/message_view.js | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index f00005f6..95e39c59 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -61,12 +61,15 @@ Whisper.AttachmentView = Backbone.View.extend({ tagName: 'span', className: 'attachment', - initialize: function() { + initialize: function(options) { this.blob = new Blob([this.model.data], {type: this.model.contentType}); var parts = this.model.contentType.split('/'); this.contentType = parts[0]; this.fileType = parts[1]; + if (options.timestamp) { + this.timestamp = options.timestamp; + } }, events: { 'click': 'onclick' @@ -89,9 +92,12 @@ }, saveFile: function() { var blob = this.blob; - var suggestedName; + var suggestedName = 'signal'; + if (this.timestamp) { + suggestedName += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss'); + } if (this.fileType) { - suggestedName = 'signal.' + this.fileType; + suggestedName += '.' + this.fileType; } var w = extension.windows.getViews()[0]; if (w && w.chrome && w.chrome.fileSystem) { diff --git a/js/views/message_view.js b/js/views/message_view.js index c342e741..dfb6d574 100644 --- a/js/views/message_view.js +++ b/js/views/message_view.js @@ -259,7 +259,10 @@ }, loadAttachments: function() { this.model.get('attachments').forEach(function(attachment) { - var view = new Whisper.AttachmentView({ model: attachment }); + var view = new Whisper.AttachmentView({ + model: attachment, + timestamp: this.model.get('sent_at') + }); this.listenTo(view, 'update', function() { if (!view.el.parentNode) { this.trigger('beforeChangeHeight');