Skip to content

Commit

Permalink
Add support for attachment file names
Browse files Browse the repository at this point in the history
Send, receive, and save attachment filenames. Use them as suggested
names when saving files.

// FREEBIE
  • Loading branch information
liliakai committed Apr 18, 2017
1 parent a256f17 commit fc514aa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions js/libtextsecure.js
Expand Up @@ -39049,6 +39049,9 @@ MessageSender.prototype = {
proto.id = id;
proto.contentType = attachment.contentType;
proto.digest = result.digest;
if (attachment.fileName) {
proto.fileName = attachment.fileName;
}
return proto;
});
}.bind(this));
Expand Down
4 changes: 4 additions & 0 deletions js/views/attachment_view.js
Expand Up @@ -91,6 +91,10 @@
}
},
suggestedName: function() {
if (this.model.fileName) {
return this.model.fileName;
}

var suggestion = 'signal';
if (this.timestamp) {
suggestion += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
Expand Down
9 changes: 7 additions & 2 deletions js/views/file_input_view.js
Expand Up @@ -223,12 +223,17 @@
},

readFile: function(file) {
var contentType = file.type;
return new Promise(function(resolve, reject) {
var FR = new FileReader();
FR.onload = function(e) {
resolve({data: e.target.result, contentType: contentType});
resolve({
data: e.target.result,
contentType: file.type,
fileName: file.name
});
};
FR.onerror = reject;
FR.onabort = reject;
FR.readAsArrayBuffer(file);
});
},
Expand Down
3 changes: 3 additions & 0 deletions libtextsecure/sendmessage.js
Expand Up @@ -124,6 +124,9 @@ MessageSender.prototype = {
proto.id = id;
proto.contentType = attachment.contentType;
proto.digest = result.digest;
if (attachment.fileName) {
proto.fileName = attachment.fileName;
}
return proto;
});
}.bind(this));
Expand Down
1 change: 1 addition & 0 deletions protos/IncomingPushMessageSignal.proto
Expand Up @@ -123,6 +123,7 @@ message AttachmentPointer {
optional uint32 size = 4;
optional bytes thumbnail = 5;
optional bytes digest = 6;
optional string fileName = 7;
}

message GroupContext {
Expand Down

0 comments on commit fc514aa

Please sign in to comment.