more work on posting and showing status posts

This commit is contained in:
jeena 2013-05-27 09:44:43 +02:00
parent f73ce7d196
commit 650f107d21
7 changed files with 108 additions and 135 deletions

View file

@ -10,6 +10,7 @@ function(HostApp, Timeline, URI, APICalls, Core) {
function Mentions() {
return // FIXME
this.is_not_init = false;
this.unread_mentions = 0;

View file

@ -87,31 +87,40 @@ function(HostApp, APICalls, Hmac) {
Oauth.prototype.register = function (url) {
var those = this;
APICalls.get(url, { callback: function(resp) {
debug(url)
APICalls.get(url, {
no_auth: true,
callback: function(resp) {
those.profile = JSON.parse(resp.responseText);
those.entity = those.profile.content.entity;
HostApp.setStringForKey(those.entity, "entity")
HostApp.setServerUrls(those.profile.content.servers[0].urls);
var callback = function(resp) {
APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), {
content_type: "https://tent.io/types/app/v0#",
no_auth: true,
callback: function(resp) {
var app_id = JSON.parse(resp.responseText).id;
var header_string = resp.getAllResponseHeaders();
var regexp = /https:\/\/tent.io\/rels\/credentials/i
var url = APICalls.parseHeaderForLink(header_string, regexp);
APICalls.http_call(url, "GET", function(resp) {
var data = JSON.parse(resp.responseText);
those.authRequest(data, app_id);
}, null, false)
}
APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), {callback: callback});
APICalls.get(url, {
content_type: "https://tent.io/types/app/v0#",
no_auth: true,
callback: function(resp) {
var data = JSON.parse(resp.responseText);
those.authRequest(data, app_id);
}});
}});
}});
}
Oauth.prototype.authRequest = function(credentials, app_id) {
HostApp.setStringForKey(app_id, "app_id");
HostApp.setStringForKey(credentials.id, "app_hawk_id");
HostApp.setStringForKey(credentials.content.hawk_key, "app_hawk_key");
@ -137,20 +146,20 @@ function(HostApp, APICalls, Hmac) {
});
var those = this;
var http_method = "POST";
var callback = function(resp) {
those.requestAccessTokenTicketFinished(resp.responseText);
};
var auth_header = Hmac.makeHawkAuthHeader(
url,
http_method,
"POST",
HostApp.stringForKey("app_hawk_id"),
HostApp.stringForKey("app_hawk_key"),
requestBody
);
APICalls.http_call(url, http_method, callback, requestBody, auth_header);
APICalls.post(url, requestBody, {
content_type: "https://tent.io/types/app/v0#",
auth_header: auth_header,
callback: function(resp) {
those.requestAccessTokenTicketFinished(resp.responseText);
}});
} else {
console.error("State is not the same: {" + this.state + "} vs {" + urlVars["state"] + "}")
@ -162,6 +171,7 @@ function(HostApp, APICalls, Hmac) {
Oauth.prototype.requestAccessTokenTicketFinished = function(responseBody) {
var access = JSON.parse(responseBody);
debug(access)
HostApp.setStringForKey(access["access_token"], "user_access_token");
HostApp.setSecret(access["hawk_key"]);

View file

@ -51,7 +51,7 @@ function(HostApp, APICalls, Cache) {
document.body.className = "body-timeline";
document.body.id = "with-sidebar";
this.setEntityAvatar();
//this.setEntityAvatar(); FIXME
this.setOnScroll();
}

View file

@ -30,7 +30,7 @@ function(Core, APICalls, HostApp, URI) {
document.getElementById("content").appendChild(this.container);
var _this = this;
this.reloadIntervall = setInterval(function() { _this.getNewData() }, this.timeout);
//this.reloadIntervall = setInterval(function() { _this.getNewData() }, this.timeout); //FIXME back
this.getNewData();
}
@ -48,6 +48,7 @@ function(Core, APICalls, HostApp, URI) {
Timeline.prototype.newStatus = function(statuses, append) {
statuses = statuses.data;
if(statuses != null && statuses.length > 0) {
this.before.loading = false;
@ -62,7 +63,7 @@ function(Core, APICalls, HostApp, URI) {
this.since_id_entity = status.entity;
}
if (status.type == "https://tent.io/types/post/status/v0.1.0" || status.type == "https://tent.io/types/post/photo/v0.1.0") {
if (status.type == "https://tent.io/types/status/v0#" || status.type == "https://tent.io/types/post/photo/v0.1.0") {
var new_node = this.getStatusDOMElement(status);
@ -100,15 +101,16 @@ function(Core, APICalls, HostApp, URI) {
add_to_search = add_to_search || {};
var those = this;
var url = URI(APICalls.mkApiRootPath("/posts"));
var url = URI(HostApp.serverUrl("posts_feed"));
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/photo/v0.1.0"
"https://tent.io/types/status/v0#",
"https://tent.io/types/status/v0#reply",
"https://tent.io/types/repost/v0#",
"https://tent.io/types/delete/v0#",
//"https://tent.io/types/post/photo/v0.1.0"
];
url.addSearch("post_types", post_types.join(","));
//url.addSearch("types", post_types.join(","));
//url.addSearch("sort_by", "published_at");
url.addSearch("limit", this.posts_limit);
@ -127,7 +129,6 @@ function(Core, APICalls, HostApp, URI) {
those.reload_blocked = false;
try {
var json = JSON.parse(resp.responseText);
those.newStatus(json, append);
@ -143,7 +144,8 @@ 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.http_call(url.toString(), http_method, callback, data); // FIXME: error callback
APICalls.get(url.toString(), { callback: callback });
}
}
}