fixing problems with new post
This commit is contained in:
parent
3fff224924
commit
16d7016e29
10 changed files with 851 additions and 807 deletions
|
@ -29,7 +29,7 @@ function() {
|
|||
this.counter = $("<span>256</span>");
|
||||
var buttons = $(
|
||||
"<p>" +
|
||||
"<button id='images'><img src='images/images.png'></button>" +
|
||||
//"<button id='images'><img src='images/images.png'></button>" +
|
||||
"<button id='private'><img src='images/public.png'></button>" +
|
||||
"<button id='send'><img src='images/send.png'></button>" +
|
||||
"</p>");
|
||||
|
@ -50,6 +50,12 @@ function() {
|
|||
this.textarea.focus()
|
||||
}
|
||||
|
||||
NewPost.prototype.setStatus = function(status_string) {
|
||||
this.status = JSON.parse(status_string);
|
||||
debug(this.status)
|
||||
// FIXME set string, private, mentions, etc.
|
||||
};
|
||||
|
||||
NewPost.prototype.setString = function(string) {
|
||||
this.textarea.val(string);
|
||||
}
|
||||
|
@ -190,8 +196,133 @@ function() {
|
|||
NewPost.prototype.send = function() {
|
||||
debug("Send not implemented yet");
|
||||
$("textarea").focus();
|
||||
var count = 256 - this.textarea.val().length + (this.mentions.length * 6);
|
||||
if(count >= 0) {
|
||||
this.sentNewMessage();
|
||||
} else {
|
||||
debug("BEEP");
|
||||
}
|
||||
}
|
||||
|
||||
NewPost.prototype.sendNewMessage = function() {
|
||||
|
||||
var content = this.textarea.val();
|
||||
|
||||
var url = URI(HostApp.serverUrl("new_post"));
|
||||
|
||||
var type = in_reply_to_status_id.length == 0 ? "https://tent.io/types/status/v0#" : "https://tent.io/types/status/v0#reply";
|
||||
|
||||
var data = {
|
||||
"type": type,
|
||||
"published_at": parseInt(new Date().getTime(), 10),
|
||||
"permissions": {
|
||||
"public": !is_private
|
||||
},
|
||||
"content": {
|
||||
"text": content,
|
||||
},
|
||||
};
|
||||
|
||||
if (location) {
|
||||
//data["content"]["location"] = { "type": "Point", "coordinates": location }
|
||||
}
|
||||
|
||||
var mentions = this.parseMentions(content, in_reply_to_status_id, in_reply_to_entity);
|
||||
|
||||
if (mentions.length > 0) {
|
||||
data["mentions"] = mentions;
|
||||
if (is_private) {
|
||||
var entities = {};
|
||||
for (var i = 0; i < mentions.length; i++) {
|
||||
var entity = mentions[i]["entity"]
|
||||
entities[entity] = true;
|
||||
};
|
||||
|
||||
data["permissions"]["entities"] = entities;
|
||||
}
|
||||
}
|
||||
|
||||
// APICalls.http_call(url.toString(), http_method, callback, JSON.stringify(data));
|
||||
APICalls.post(url.toString(), JSON.stringify(data), {
|
||||
content_type: data.type,
|
||||
callback: callback
|
||||
});
|
||||
}
|
||||
/*
|
||||
NewPost.prototype.sendNewMessageWithImage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, is_private, callback) {
|
||||
|
||||
var url = URI(APICalls.mkApiRootPath("/posts"));
|
||||
|
||||
var data = {
|
||||
"type": "https://tent.io/types/post/photo/v0.1.0",
|
||||
"published_at": parseInt(new Date().getTime() / 1000, 10),
|
||||
"permissions": {
|
||||
"public": !is_private
|
||||
},
|
||||
"content": {
|
||||
"caption": content,
|
||||
},
|
||||
};
|
||||
|
||||
if (location) {
|
||||
data["content"]["location"] = { "type": "Point", "coordinates": location }
|
||||
}
|
||||
|
||||
var mentions = this.parseMentions(content, in_reply_to_status_id, in_reply_to_entity);
|
||||
if (mentions.length > 0) {
|
||||
data["mentions"] = mentions;
|
||||
if (is_private) {
|
||||
var entities = {};
|
||||
for (var i = 0; i < mentions.length; i++) {
|
||||
var entity = mentions[i]["entity"]
|
||||
entities[entity] = true;
|
||||
};
|
||||
|
||||
data["permissions"]["entities"] = entities;
|
||||
}
|
||||
}
|
||||
|
||||
var data_string = JSON.stringify(data);
|
||||
|
||||
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';
|
||||
post += 'Content-Type: application/vnd.tent.v0+json\r\n';
|
||||
post += 'Content-Transfer-Encoding: binary\r\n\r\n';
|
||||
post += data_string;
|
||||
|
||||
post += "\r\n--" + boundary + "\r\n";
|
||||
|
||||
var blob_string = image_data_uri.split(',')[1];
|
||||
var mime_type = image_data_uri.split(',')[0].split(':')[1].split(';')[0];
|
||||
var ext = "png";
|
||||
if (mime_type == "image/jpeg") {
|
||||
ext = "jpeg";
|
||||
} else if (mime_type == "image/gif") {
|
||||
ext = "gif";
|
||||
}
|
||||
|
||||
|
||||
post += 'Content-Disposition: form-data; name="photos[0]"; filename="photo.' + ext + '"\r\n';
|
||||
post += 'Content-Length: ' + blob_string.length + "\r\n";
|
||||
post += 'Content-Type: ' + mime_type + "\r\n";
|
||||
post += 'Content-Transfer-Encoding: base64\r\n\r\n';
|
||||
post += blob_string;
|
||||
post += "\r\n--" + boundary + "--\r\n";
|
||||
|
||||
var newCallback = function(resp) {
|
||||
if (resp.status == 403) {
|
||||
var err = JSON.parse(resp.responseText);
|
||||
HostApp.alertTitleWithMessage(resp.statusText, err.error);
|
||||
}
|
||||
callback(resp);
|
||||
}
|
||||
|
||||
APICalls.postMultipart(url.toString(), newCallback, post, boundary);
|
||||
}
|
||||
*/
|
||||
|
||||
return NewPost;
|
||||
})
|
|
@ -96,7 +96,6 @@ function(HostApp, APICalls, Hmac) {
|
|||
those.entity = those.profile.content.entity;
|
||||
HostApp.setStringForKey(those.entity, "entity")
|
||||
HostApp.setServerUrls(those.profile.content.servers[0].urls);
|
||||
|
||||
APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), {
|
||||
content_type: "https://tent.io/types/app/v0#",
|
||||
no_auth: true,
|
||||
|
@ -112,7 +111,7 @@ function(HostApp, APICalls, Hmac) {
|
|||
callback: function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
those.authRequest(data.post, app_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
}});
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -46,9 +46,13 @@ function(Core, APICalls, HostApp, URI) {
|
|||
}
|
||||
|
||||
|
||||
Timeline.prototype.newStatus = function(statuses, append) {
|
||||
Timeline.prototype.newStatus = function(_statuses, append) {
|
||||
|
||||
statuses = statuses.data;
|
||||
for (var entity in _statuses.profiles) {
|
||||
bungloo.cache.profiles[entity] = _statuses.profiles[entity];
|
||||
}
|
||||
|
||||
statuses = _statuses.posts;
|
||||
if(statuses != null && statuses.length > 0) {
|
||||
|
||||
this.before.loading = false;
|
||||
|
@ -63,7 +67,7 @@ function(Core, APICalls, HostApp, URI) {
|
|||
this.since_id_entity = status.entity;
|
||||
}
|
||||
|
||||
if (status.type == "https://tent.io/types/status/v0#" || status.type == "https://tent.io/types/post/photo/v0.1.0") {
|
||||
if (status.type == "https://tent.io/types/status/v0#") {
|
||||
|
||||
var new_node = this.getStatusDOMElement(status);
|
||||
|
||||
|
@ -110,9 +114,11 @@ function(Core, APICalls, HostApp, URI) {
|
|||
"https://tent.io/types/delete/v0#",
|
||||
//"https://tent.io/types/post/photo/v0.1.0"
|
||||
];
|
||||
//url.addSearch("types", post_types.join(","));
|
||||
url.addSearch("types", post_types.join(","));
|
||||
//url.addSearch("sort_by", "published_at");
|
||||
url.addSearch("limit", this.posts_limit);
|
||||
url.addSearch("max_refs", 20);
|
||||
url.addSearch("profiles", "entity");
|
||||
|
||||
if(this.since_id && !append) {
|
||||
url.addSearch("since_id", this.since_id);
|
||||
|
@ -144,7 +150,7 @@ function(Core, APICalls, HostApp, URI) {
|
|||
|
||||
if (!this.reload_blocked) {
|
||||
this.reload_blocked = true;
|
||||
// APICalls.http_call(url.toString(), http_method, callback, data); // FIXME: error callback
|
||||
|
||||
APICalls.get(url.toString(), { callback: callback });
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue