fixing problems with new post

This commit is contained in:
jeena 2013-07-17 00:44:47 +02:00
parent 3fff224924
commit 16d7016e29
10 changed files with 851 additions and 807 deletions

View file

@ -171,13 +171,12 @@ class Controller(QtCore.QObject):
pass pass
@QtCore.pyqtSlot(str) @QtCore.pyqtSlot(str)
def openNewMessageWidow(self, is_private=False, string=""): def openNewMessageWidow(self):
string = str(string) self.openNewMessageWindowInReplyTostatus(None)
self.openNewMessageWindowInReplyTostatusIdwithStringIsPrivate(None, None, string, is_private)
@QtCore.pyqtSlot(str, str, str, bool) @QtCore.pyqtSlot(str, str, str, bool)
def openNewMessageWindowInReplyTostatusIdwithStringIsPrivate(self, entity, status_id, string, is_private): def openNewMessageWindowInReplyTostatus(self, status_string):
new_message_window = Windows.NewPost(self.app, string, "[]", is_private) new_message_window = Windows.NewPost(self.app)
new_message_window.show() new_message_window.show()
new_message_window.setAttribute(QtCore.Qt.WA_DeleteOnClose) new_message_window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.app.new_message_windows.append(new_message_window) self.app.new_message_windows.append(new_message_window)

View file

@ -329,11 +329,12 @@ class FindEntity(QtGui.QDialog):
class NewPost(Helper.RestorableWindow): class NewPost(Helper.RestorableWindow):
def __init__(self, app, string, mentions, is_private): def __init__(self, app, string=None, mentions="[]", is_private=False, post_id=None):
self.app = app self.app = app
self.string = string self.string = string
self.mentions = mentions self.mentions = mentions
self.is_private = is_private self.is_private = is_private
self.post_id = post_id
Helper.RestorableWindow.__init__(self, "newpost", self.app) Helper.RestorableWindow.__init__(self, "newpost", self.app)
self.activateWindow() self.activateWindow()
@ -414,7 +415,11 @@ class NewPost(Helper.RestorableWindow):
if self.is_private: if self.is_private:
is_private = "true" is_private = "true"
callback = "function() { bungloo.newpost.setString('%s'); bungloo.newpost.setIsPrivate(%s); bungloo.newpost.setMentions(%s);}" % (self.string, is_private, self.mentions) post_id = ""
if self.post_id:
post_id = self.post_id
callback = "function() { bungloo.newpost.setString('%s'); bungloo.newpost.setIsPrivate(%s); bungloo.newpost.setMentions(%s); bungloo.newPostAction.setPostId(%s); }" % (self.string, is_private, self.mentions, post_id)
script = "function HostAppGo() { start('newpost', " + callback + "); }" script = "function HostAppGo() { start('newpost', " + callback + "); }"
self.webView.page().mainFrame().evaluateJavaScript(script) self.webView.page().mainFrame().evaluateJavaScript(script)
@ -425,6 +430,11 @@ class NewPost(Helper.RestorableWindow):
self.webView.page().mainFrame().evaluateJavaScript(script) self.webView.page().mainFrame().evaluateJavaScript(script)
def sendMessage(self): def sendMessage(self):
script = "bungloo.newpost.send()"
self.webView.page().mainFrame().evaluateJavaScript(script)
self.close()
"""
count = len(self.textInput.toPlainText()) count = len(self.textInput.toPlainText())
if count > 0 and count <= 256: if count > 0 and count <= 256:
message = Helper.PostModel() message = Helper.PostModel()
@ -438,6 +448,7 @@ class NewPost(Helper.RestorableWindow):
self.close() self.close()
else: else:
QtGui.qApp.beep() QtGui.qApp.beep()
"""
def openFileDialog(self): def openFileDialog(self):
fileNamePath = QtGui.QFileDialog.getOpenFileName(self, "Choose a image", "", "Images (*.png *.gif *.jpg *.jpeg)") fileNamePath = QtGui.QFileDialog.getOpenFileName(self, "Choose a image", "", "Images (*.png *.gif *.jpg *.jpeg)")

View file

@ -29,7 +29,7 @@ function() {
this.counter = $("<span>256</span>"); this.counter = $("<span>256</span>");
var buttons = $( var buttons = $(
"<p>" + "<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='private'><img src='images/public.png'></button>" +
"<button id='send'><img src='images/send.png'></button>" + "<button id='send'><img src='images/send.png'></button>" +
"</p>"); "</p>");
@ -50,6 +50,12 @@ function() {
this.textarea.focus() 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) { NewPost.prototype.setString = function(string) {
this.textarea.val(string); this.textarea.val(string);
} }
@ -190,8 +196,133 @@ function() {
NewPost.prototype.send = function() { NewPost.prototype.send = function() {
debug("Send not implemented yet"); debug("Send not implemented yet");
$("textarea").focus(); $("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; return NewPost;
}) })

View file

@ -96,7 +96,6 @@ function(HostApp, APICalls, Hmac) {
those.entity = those.profile.content.entity; those.entity = those.profile.content.entity;
HostApp.setStringForKey(those.entity, "entity") HostApp.setStringForKey(those.entity, "entity")
HostApp.setServerUrls(those.profile.content.servers[0].urls); HostApp.setServerUrls(those.profile.content.servers[0].urls);
APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), { APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), {
content_type: "https://tent.io/types/app/v0#", content_type: "https://tent.io/types/app/v0#",
no_auth: true, no_auth: true,

View file

@ -231,57 +231,67 @@ function(HostApp, Core, APICalls, URI) {
this.profile_template.following_button.style.display = "none"; this.profile_template.following_button.style.display = "none";
} }
var profile = this.cache.profiles.getItem(this.entity);
if (profile && profile != "null") {
this.showProfile(profile);
this.profile = profile;
} else {
var url = HostApp.serverUrl("posts_feed") + "?types=" + encodeURIComponent("https://tent.io/types/meta/v0") + "&entities=" + encodeURIComponent(this.entity) var url = HostApp.serverUrl("posts_feed") + "?types=" + encodeURIComponent("https://tent.io/types/meta/v0") + "&entities=" + encodeURIComponent(this.entity)
//var url = HostApp.serverUrl("discover").replace(/{entity}/, encodeURIComponent(this.entity));
APICalls.get(url, { APICalls.get(url, {
callback: function(resp) { callback: function(resp) {
profile = JSON.parse(resp.responseText); var profile = JSON.parse(resp.responseText);
_this.showProfile(profile); _this.showProfile(profile);
_this.profile = profile; _this.profile = profile;
}}); }});
} }
}
Profile.prototype.getFollowing = function() { Profile.prototype.getFollowing = function() {
if(this.entity != HostApp.stringForKey("entity")) { if(this.entity != HostApp.stringForKey("entity")) {
var url = APICalls.mkApiRootPath("/followings") + "/" + encodeURIComponent(this.entity);
var url = HostApp.serverUrl("posts_feed") + "?mentions=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#https://tent.io/types/status/v0");
var _this = this; var _this = this;
APICalls.http_call(url, "GET", function(resp) {
if (resp.status >= 200 && resp.status < 400) { APICalls.head(url, {callback: function(resp) {
var following = JSON.parse(resp.responseText);
_this.following_id = following.id var count = APICalls.getCount(resp);
if (count > 0) {
_this.setFollowingButton(true); _this.setFollowingButton(true);
} else { } else {
_this.setFollowingButton(false); _this.setFollowingButton(false);
_this.following_id = null;
} }
})
}});
} else { } else {
this.setFollowingButton(false); this.setFollowingButton(false);
this.following_id = null; this.following_id = null;
} }
} }
Profile.prototype.showProfile = function(profile) { Profile.prototype.showProfile = function(profiles) {
//debug(profile) if(profiles.posts.length < 1) return;
return var profile = profiles.posts[0];
var basic = profile.content.profile;
var basic = profile["https://tent.io/types/info/basic/v0.1.0"];
if (profile && basic) { if (profile && basic) {
if(basic.avatar_url) { // Find and apply avatar
this.profile_template.avatar.onerror = function() { this.profile_template.avatar.src = 'img/default-avatar.png' }; if(profile.attachments.length > 0) {
this.profile_template.avatar.src = basic.avatar_url;
var digest = null;
for (var i = 0; i < profile.attachments.length; i++) {
var attachment = profile.attachments[i];
if(attachment.category == "avatar") {
digest = attachment.digest;
break;
}
}
if(digest) {
var _this = this;
this.profile_template.avatar.onerror = function() { _this.profile_template.avatar.src = 'img/default-avatar.png' };
var avatar_url = profile.content.servers[0].urls.attachment.replace(/\{entity\}/, encodeURIComponent(profile.entity));
this.profile_template.avatar.src = avatar_url.replace(/\{digest\}/, digest);
}
} }
this.populate(this.profile_template.name, basic.name); this.populate(this.profile_template.name, basic.name);
@ -290,9 +300,9 @@ function(HostApp, Core, APICalls, URI) {
this.populate(this.profile_template.gender, basic.gender); this.populate(this.profile_template.gender, basic.gender);
this.populate(this.profile_template.bio, basic.bio); this.populate(this.profile_template.bio, basic.bio);
if(basic.website_url) { if(basic.website) {
var url = basic.website_url; var url = basic.website;
this.profile_template.url.innerText = url; this.profile_template.url.innerText = url;
this.profile_template.url.parentNode.parentNode.style.display = ""; this.profile_template.url.parentNode.parentNode.style.display = "";
@ -305,9 +315,9 @@ function(HostApp, Core, APICalls, URI) {
} }
if (profile) { if (profile) {
this.server = profile["https://tent.io/types/info/core/v0.1.0"]["servers"][0]; this.profile = profile;
this.getMeta(this.server); this.getMeta(this.profile);
this.getStatuses(this.server); //this.getStatuses(this.server);
} }
} }
@ -319,18 +329,32 @@ function(HostApp, Core, APICalls, URI) {
} }
} }
Profile.prototype.getMeta = function(root_url) { Profile.prototype.getMeta = function(profile) {
var _this = this; var _this = this;
APICalls.http_call(URI(root_url + "/followings/count").toString(), "GET", function(resp) {
_this.populate(_this.profile_template.following, resp.responseText); var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/relationship/v0#follower");
}, null, false); APICalls.head(url, {
callback: function(resp) {
debug(APICalls.getCount(resp))
_this.populate(_this.profile_template.followed, APICalls.getCount(resp)+" ");
}
});
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/relationship/v0#following");
APICalls.head(url, {
callback: function(resp) {
_this.populate(_this.profile_template.following, APICalls.getCount(resp) + " ");
}
});
return;
APICalls.http_call(URI(root_url + "/followers/count").toString(), "GET", function(resp) {
_this.populate(_this.profile_template.followed, resp.responseText);
}, null, false);
if (this.entity != HostApp.stringForKey("entity")) { if (this.entity != HostApp.stringForKey("entity")) {
APICalls.http_call(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) { APICalls.http_call(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) {
@ -352,6 +376,7 @@ function(HostApp, Core, APICalls, URI) {
this.setRelationships(); this.setRelationships();
} }
var url = URI(root_url + "/posts/count"); var url = URI(root_url + "/posts/count");
var post_types = [ var post_types = [
"https://tent.io/types/post/repost/v0.1.0", "https://tent.io/types/post/repost/v0.1.0",
@ -368,7 +393,7 @@ function(HostApp, Core, APICalls, URI) {
Profile.prototype.setRelationships = function() { Profile.prototype.setRelationships = function() {
var relation = "none"; var relation = "none";
if (this.relationships.it_is_you) { if (HostApp.stringForKey("entity") == this.entity) {
relation = "it's you"; relation = "it's you";
} else { } else {
if (this.relationships.following_you && !this.relationships.followed_by_you) { if (this.relationships.following_you && !this.relationships.followed_by_you) {
@ -492,6 +517,8 @@ function(HostApp, Core, APICalls, URI) {
if (this.following_id) { if (this.following_id) {
this.setFollowingButton(false); this.setFollowingButton(false);
/*
var url = APICalls.mkApiRootPath("/followings/") + this.following_id; var url = APICalls.mkApiRootPath("/followings/") + this.following_id;
APICalls.http_call(url, "DELETE", function(resp) { APICalls.http_call(url, "DELETE", function(resp) {
if (resp.status >= 200 && resp.status < 300) { if (resp.status >= 200 && resp.status < 300) {
@ -500,22 +527,32 @@ function(HostApp, Core, APICalls, URI) {
} else { } else {
_this.setFollowingButton(true); _this.setFollowingButton(true);
} }
}); });*/
} else { } else {
this.setFollowingButton(true); this.setFollowingButton(true);
var url = URI(APICalls.mkApiRootPath("/followings"));
var data = JSON.stringify({"entity": this.entity });
APICalls.http_call(url.toString(), "POST", function(resp) { var url = HostApp.serverUrl("new_post");
var data = JSON.stringify({
type: "https://tent.io/types/subscription/v0#https://tent.io/types/status/v0",
mentions: [{
entity: this.entity
}]
});
APICalls.post(url, data, {
content_type: "https://tent.io/types/subscription/v0",
callback: function(resp) {
debug(resp.status)
if (resp.status >= 200 && resp.status < 300) { if (resp.status >= 200 && resp.status < 300) {
_this.following_id = JSON.parse(resp.responseText).id
_this.setFollowingButton(true); _this.setFollowingButton(true);
} else { } else {
_this.setFollowingButton(false); _this.setFollowingButton(false);
} }
}, data); }
});
} }
} }
@ -659,6 +696,8 @@ function(HostApp, Core, APICalls, URI) {
} }
return Profile; return Profile;
}); });

View file

@ -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) { if(statuses != null && statuses.length > 0) {
this.before.loading = false; this.before.loading = false;
@ -63,7 +67,7 @@ function(Core, APICalls, HostApp, URI) {
this.since_id_entity = status.entity; 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); 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/delete/v0#",
//"https://tent.io/types/post/photo/v0.1.0" //"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("sort_by", "published_at");
url.addSearch("limit", this.posts_limit); url.addSearch("limit", this.posts_limit);
url.addSearch("max_refs", 20);
url.addSearch("profiles", "entity");
if(this.since_id && !append) { if(this.since_id && !append) {
url.addSearch("since_id", this.since_id); url.addSearch("since_id", this.since_id);
@ -144,7 +150,7 @@ function(Core, APICalls, HostApp, URI) {
if (!this.reload_blocked) { if (!this.reload_blocked) {
this.reload_blocked = true; this.reload_blocked = true;
// APICalls.http_call(url.toString(), http_method, callback, data); // FIXME: error callback
APICalls.get(url.toString(), { callback: callback }); APICalls.get(url.toString(), { callback: callback });
} }
} }

View file

@ -36,10 +36,10 @@ function(jQuery, HostApp, Hmac, Cache) {
console.error("No content type for " + options.url); console.error("No content type for " + options.url);
return; return;
} else { } else {
if(options.content_type != "application/json") { if(options.content_type == "application/json") {
content_type = "application/vnd.tent.post.v0+json; type=\"" + options.content_type + "\""; content_type = "application/json";
} else { } else {
content_type = options.content_type; content_type = "application/vnd.tent.post.v0+json; type=\"" + options.content_type + "\"";
} }
} }
@ -64,6 +64,7 @@ function(jQuery, HostApp, Hmac, Cache) {
} else if(!options.no_auth) { } else if(!options.no_auth) {
console.error("No user_access_token yet - " + options.url); console.error("No user_access_token yet - " + options.url);
} }
xhr.setRequestHeader("Cache-Control", "no-cache");
}, },
url: options.url, url: options.url,
contentType: content_type, contentType: content_type,
@ -72,13 +73,26 @@ function(jQuery, HostApp, Hmac, Cache) {
data: options.data, data: options.data,
processData: false, processData: false,
error: function(xhr, ajaxOptions, thrownError) { error: function(xhr, ajaxOptions, thrownError) {
console.error("HTTP CALL (" + xhr.status + ")" + xhr.statusText + " " + options.http_method + " (" + options.url + "): '" + xhr.responseText + "'"); console.error("HTTP CALL (" + xhr.status + ") " + xhr.statusText + " " + options.http_method + " URL(" + options.url + "): '" + xhr.responseText + "'");
} }
}; };
jQuery.ajax(settings); jQuery.ajax(settings);
} }
APICalls.head = function(url, options) {
var settings = {
url: url,
http_method: "HEAD",
};
for (var key in options) {
settings[key] = options[key];
}
APICalls.http_call(settings);
}
APICalls.get = function(url, options) { APICalls.get = function(url, options) {
var settings = { var settings = {
url: url, url: url,
@ -225,6 +239,23 @@ function(jQuery, HostApp, Hmac, Cache) {
return APICalls.parseHeaderForLink(header_string, regexp); return APICalls.parseHeaderForLink(header_string, regexp);
} }
APICalls.parseHeader = function(header_string) {
var header_strings = header_string.split(/\n/);
var headers = {};
for (var i = 0; i < header_strings.length; i++) {
var hs = header_strings[i].split(/:(.+)?/);
headers[hs[0]] = hs[1];
}
return headers;
}
APICalls.getCount = function(resp) {
var count = 0;
var headers = APICalls.parseHeader(resp.getAllResponseHeaders());
if(headers["Count"]) count = parseInt(headers["Count"], 10);
return count;
}
APICalls.parseHeaderForLink = function(header_string, match) { APICalls.parseHeaderForLink = function(header_string, match) {
var headers = header_string.split(/\n/); var headers = header_string.split(/\n/);
var links = []; var links = [];

View file

@ -69,6 +69,7 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
image.className = "image"; image.className = "image";
image.src = "img/default-avatar.png"; image.src = "img/default-avatar.png";
image.onmousedown = function(e) { e.preventDefault(); }; image.onmousedown = function(e) { e.preventDefault(); };
image.onerror = function() { this.src = 'img/default-avatar.png' };
item.appendChild(image); item.appendChild(image);
var image_username = a.cloneNode(); var image_username = a.cloneNode();
@ -224,7 +225,7 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
mentions.push(mention); mentions.push(mention);
} }
_this.replyTo(status.entity, status.id, mentions, (status && status.permissions && !status.permissions.public)); _this.replyTo(status);
return false; return false;
} }
@ -234,7 +235,7 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
return false; return false;
} }
template.username.innerText = status.entity; if(bungloo.cache.profiles[status.entity].name) template.username.innerText = bungloo.cache.profiles[status.entity].name;
template.username.href = status.entity; template.username.href = status.entity;
template.username.title = status.entity; template.username.title = status.entity;
template.username.onclick = function() { template.username.onclick = function() {
@ -242,47 +243,12 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
return false; return false;
} }
if(bungloo.cache.profiles[status.entity].avatar_digest) {
template.image.src = HostApp.serverUrl("attachment").replace(/\{entity\}/, encodeURIComponent(status.entity)).replace(/\{digest\}/, bungloo.cache.profiles[status.entity].avatar_digest);
}
template.image.onclick = template.username.onclick; template.image.onclick = template.username.onclick;
var profile_callback = function(p) {
var basic = p["https://tent.io/types/info/basic/v0.1.0"];
if (p && basic) {
if(basic.name) {
template.username.title = template.username.innerText;
template.username.innerText = basic.name;
}
if(basic.avatar_url) {
template.image.onerror = function() { template.image.src = 'img/default-avatar.png' };
template.image.src = basic.avatar_url;
}
}
}
var p = this.cache.profiles.getItem(status.entity);
if (p && p != "null") {
profile_callback(p);
} else {
APICalls.findProfileURL(status.entity, function(profile_url) {
if (profile_url) {
APICalls.http_call(profile_url, "GET", function(resp) {
var p = JSON.parse(resp.responseText);
if (p && p != "null") {
_this.cache.profiles.setItem(status.entity, p);
profile_callback(p);
}
}, null, false); // do not send auth-headers
}
});
}
if (status && status.permissions && !status.permissions.public) { if (status && status.permissions && !status.permissions.public) {
template.is_private.style.display = ''; template.is_private.style.display = '';
@ -389,10 +355,12 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
template.source.innerHTML = status.__repost.app.name; template.source.innerHTML = status.__repost.app.name;
template.source.title = status.__repost.app.url; template.source.title = status.__repost.app.url;
} else { } else {
if(status.app) {
template.source.href = status.app.url; template.source.href = status.app.url;
template.source.innerHTML = status.app.name; template.source.innerHTML = status.app.name;
template.source.title = status.app.url; template.source.title = status.app.url;
} }
}
return template.item; return template.item;
} }
@ -498,60 +466,6 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
} }
} }
Core.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, is_private, callback) {
if (image_data_uri) {
this.sendNewMessageWithImage(content, in_reply_to_status_id, in_reply_to_entity, location, image_data_uri, is_private, callback);
} else {
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";
debug(typeof in_reply_to_status_id)
debug(in_reply_to_status_id.length)
debug(type)
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
});
}
}
Core.prototype.repost = function(id, entity, callback) { Core.prototype.repost = function(id, entity, callback) {
var url = URI(APICalls.mkApiRootPath("/posts")); var url = URI(APICalls.mkApiRootPath("/posts"));
@ -582,80 +496,6 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
APICalls.http_call(url.toString(), "POST", new_callback, JSON.stringify(data)); APICalls.http_call(url.toString(), "POST", new_callback, JSON.stringify(data));
} }
Core.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);
}
Core.prototype.remove = function(id, callback, type) { Core.prototype.remove = function(id, callback, type) {
type = type || "post"; type = type || "post";
if (confirm("Really delete this " + type + "?")) { if (confirm("Really delete this " + type + "?")) {
@ -920,19 +760,8 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
} }
} }
Core.prototype.replyTo = function(entity, status_id, mentions, is_private) { Core.prototype.replyTo = function(status) {
HostApp.openNewMessageWidow(status);
var string = "^" + entity.replace("https://", "") + " ";
var ms = "";
for (var i = 0; i < mentions.length; i++) {
var e = mentions[i].entity.replace("https://", "");
if(string.indexOf(e) == -1) ms += " ^" + e;
}
if(ms.length > 0) string += "\n\n/cc" + ms;
HostApp.openNewMessageWidow(entity, status_id, string, is_private);
} }
Core.prototype.postDeleted = function(post_id, entity) { Core.prototype.postDeleted = function(post_id, entity) {

View file

@ -85,13 +85,12 @@ define(function() {
} }
} }
HostApp.openNewMessageWidow = function(entity, status_id, string, is_private) { HostApp.openNewMessageWidow = function(status) {
if (OS_TYPE == "mac") { if (OS_TYPE == "mac") {
controller.openNewMessageWindowInReplyTo_statusId_withString_isPrivate_(entity, status_id, string, is_private); controller.openNewMessageWindowInReplyToStatus(JSON.stringify(status));
} else { } else {
is_private = is_private == true controller.openNewMessageWindowInReplyTostatus(JSON.stringify(status));
controller.openNewMessageWindowInReplyTostatusIdwithStringIsPrivate(entity, status_id, string, is_private);
} }
} }

View file

@ -7,7 +7,7 @@ var bungloo = {
entityProfile: null, entityProfile: null,
conversation: null, conversation: null,
search: null, search: null,
cache: {}, cache: { profiles: {}},
newpost: null newpost: null
}; };