implemented photo post type
This commit is contained in:
parent
00e1f54636
commit
0786f1cf3f
5 changed files with 64 additions and 17 deletions
|
@ -256,3 +256,9 @@ li.mentioned {
|
|||
.mentions li.mentioned {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.photo {
|
||||
margin-top: 10px;
|
||||
max-width: 100%;
|
||||
border-radius: 3px;
|
||||
}
|
|
@ -98,7 +98,7 @@ function(HostApp, Paths, Hmac) {
|
|||
|
||||
this.state = Hmac.makeid(19);
|
||||
var auth = "/oauth/authorize?client_id=" + register_data["id"]
|
||||
+ "&redirect_uri=" + this.app_info["redirect_uris"][0] // Check if this still works on mac
|
||||
+ "&redirect_uri=" + this.app_info["redirect_uris"][0]
|
||||
+ "&scope=" + Object.keys(this.app_info["scopes"]).join(",")
|
||||
+ "&state=" + this.state
|
||||
+ "&tent_post_types=all";
|
||||
|
|
|
@ -42,15 +42,22 @@ function(Core, Paths, HostApp, URI) {
|
|||
this.since_id = status.id;
|
||||
this.since_id_entity = status.entity;
|
||||
|
||||
if (status.type == "https://tent.io/types/post/status/v0.1.0") {
|
||||
if (status.type == "https://tent.io/types/post/status/v0.1.0" || status.type == "https://tent.io/types/post/photo/v0.1.0") {
|
||||
|
||||
var new_node = this.getStatusDOMElement(status);
|
||||
|
||||
if(this.body.childNodes.length > 0) {
|
||||
|
||||
if(this.body.childNodes.length > this.max_length) {
|
||||
|
||||
this.body.removeChild(this.body.lastChild);
|
||||
}
|
||||
this.body.insertBefore(this.getStatusDOMElement(status), this.body.firstChild);
|
||||
|
||||
this.body.insertBefore(new_node, this.body.firstChild);
|
||||
|
||||
} else {
|
||||
this.body.appendChild(this.getStatusDOMElement(status));
|
||||
|
||||
this.body.appendChild(new_node);
|
||||
}
|
||||
|
||||
} else if (status.type == "https://tent.io/types/post/delete/v0.1.0") {
|
||||
|
@ -78,7 +85,8 @@ function(Core, Paths, HostApp, URI) {
|
|||
var post_types = [
|
||||
"https://tent.io/types/post/repost/v0.1.0",
|
||||
"https://tent.io/types/post/status/v0.1.0",
|
||||
"https://tent.io/types/post/delete/v0.1.0"
|
||||
"https://tent.io/types/post/delete/v0.1.0",
|
||||
"https://tent.io/types/post/photo/v0.1.0"
|
||||
];
|
||||
url.addSearch("post_types", post_types.join(","));
|
||||
|
||||
|
|
|
@ -211,7 +211,15 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
|||
|
||||
template.in_reply.parentNode.className = "hidden";
|
||||
|
||||
var text = status.content.text.escapeHTML().replace(/\n/g, "<br>");
|
||||
var text = "";
|
||||
|
||||
if (status.type == "https://tent.io/types/post/photo/v0.1.0") {
|
||||
text = status.content.caption;
|
||||
} else {
|
||||
text = status.content.text;
|
||||
}
|
||||
|
||||
text = text.escapeHTML().replace(/\n/g, "<br>");
|
||||
|
||||
var entities = [status.entity];
|
||||
status.mentions.map(function (mention) {
|
||||
|
@ -222,6 +230,25 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
|||
this.replaceURLWithHTMLLinks(text, entities, template.message)
|
||||
);
|
||||
|
||||
if (status.type == "https://tent.io/types/post/photo/v0.1.0") {
|
||||
|
||||
for (var i = 0; i < status.attachments.length; i++) {
|
||||
|
||||
var attachment = status.attachments[i];
|
||||
var img = new Image();
|
||||
img.className = "photo";
|
||||
template.message.parentNode.insertBefore(img, template.message.nextSibling);
|
||||
|
||||
var url = Paths.mkApiRootPath("/posts/" + status.id + "/attachments/" + attachment.name);
|
||||
|
||||
var callback = function(resp) {
|
||||
img.src = "data:image/png;base64," + resp.responseText;
|
||||
}
|
||||
|
||||
Paths.getURL(url.toString(), "GET", callback, null, null, attachment.type);
|
||||
};
|
||||
}
|
||||
|
||||
this.findMentions(template.message, status.mentions);
|
||||
|
||||
for (var i = 0; i < status.mentions.length; i++) {
|
||||
|
@ -320,8 +347,8 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
|||
|
||||
var data_string = JSON.stringify(data);
|
||||
|
||||
var boundary = "-----------TentAttachment";
|
||||
var post = boundary + "\r\n";
|
||||
var boundary = "TentAttachment----------TentAttachment";
|
||||
var post = "--" + boundary + "\r\n";
|
||||
|
||||
post += 'Content-Disposition: form-data; name="post"; filename="post.json"\r\n';
|
||||
post += 'Content-Length: ' + data_string.length + '\r\n';
|
||||
|
@ -329,10 +356,15 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
|||
post += 'Content-Transfer-Encoding: binary\r\n\r\n';
|
||||
post += data_string;
|
||||
|
||||
post += "\r\n" + boundary + "\r\n";
|
||||
post += "\r\n--" + boundary + "\r\n";
|
||||
|
||||
var binary_data = this.dataURItoBlob(image_data_uri);
|
||||
var ext = "png";
|
||||
if (binary_data.mime_type == "image/jpeg") {
|
||||
ext = "jpeg";
|
||||
} else if (binary_data.mime_type == "image/gif") {
|
||||
ext = "gif";
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
|
@ -341,9 +373,9 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
|||
post += 'Content-Disposition: form-data; name="photos[0]"; filename="photo.' + ext + '"\r\n';
|
||||
post += 'Content-Length: ' + blob_string.length + "\r\n";
|
||||
post += 'Content-Type: ' + binary_data.mime_type + "\r\n";
|
||||
post += 'Content-Transfer-Encoding: binary\r\n\r\n';
|
||||
post += 'Content-Transfer-Encoding: base64\r\n\r\n';
|
||||
post += image_data_uri.split(',')[1];
|
||||
post += "\r\n" + boundary + "--\r\n";
|
||||
post += "\r\n--" + boundary + "--\r\n";
|
||||
|
||||
Paths.postMultipart(url.toString(), callback, post, boundary);
|
||||
}
|
||||
|
|
|
@ -20,11 +20,16 @@ function(jQuery, HostApp, Hmac) {
|
|||
return vars;
|
||||
}
|
||||
|
||||
Paths.getURL = function(url, http_method, callback, data, auth_header) {
|
||||
Paths.getURL = function(url, http_method, callback, data, auth_header, accepts) {
|
||||
|
||||
accepts = accepts || "application/vnd.tent.v0+json";
|
||||
|
||||
jQuery.ajax({
|
||||
|
||||
beforeSend: function(xhr) {
|
||||
|
||||
xhr.setRequestHeader("Accept", accepts);
|
||||
|
||||
if (data) xhr.setRequestHeader("Content-Length", data.length);
|
||||
|
||||
if (auth_header) { // if is_set? auth_header
|
||||
|
@ -40,7 +45,6 @@ function(jQuery, HostApp, Hmac) {
|
|||
auth_header = Hmac.makeAuthHeader(
|
||||
url,
|
||||
http_method,
|
||||
//HostApp.stringForKey("user_mac_key"),
|
||||
HostApp.secret(),
|
||||
user_access_token
|
||||
);
|
||||
|
@ -49,7 +53,6 @@ function(jQuery, HostApp, Hmac) {
|
|||
}
|
||||
},
|
||||
url: url,
|
||||
accepts: "application/vnd.tent.v0+json",
|
||||
contentType: "application/vnd.tent.v0+json",
|
||||
type: http_method,
|
||||
complete: callback,
|
||||
|
@ -62,8 +65,6 @@ function(jQuery, HostApp, Hmac) {
|
|||
}
|
||||
|
||||
Paths.postMultipart = function(url, callback, data, boundary) {
|
||||
debug(url)
|
||||
debug(data)
|
||||
|
||||
jQuery.ajax({
|
||||
|
||||
|
@ -79,7 +80,7 @@ function(jQuery, HostApp, Hmac) {
|
|||
auth_header = Hmac.makeAuthHeader(
|
||||
url,
|
||||
"POST",
|
||||
HostApp.stringForKey("user_mac_key"),
|
||||
HostApp.secret(),
|
||||
user_access_token
|
||||
);
|
||||
debug(auth_header)
|
||||
|
|
Reference in a new issue