restructuring of the whole code basis
This commit is contained in:
parent
2efbbd1d0a
commit
d99ff86520
60 changed files with 14404 additions and 2490 deletions
0
WebKit/scripts/controller/Conversation.js
Normal file
0
WebKit/scripts/controller/Conversation.js
Normal file
45
WebKit/scripts/controller/Mentions.js
Normal file
45
WebKit/scripts/controller/Mentions.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
define([
|
||||
"helper/HostApp",
|
||||
"controller/Timeline"
|
||||
],
|
||||
|
||||
function(HostApp, Timeline) {
|
||||
|
||||
|
||||
function Mentions() {
|
||||
|
||||
this.is_not_init = false;
|
||||
this.action = "mentions";
|
||||
this.unread_mentions = 0;
|
||||
|
||||
Timeline.call(this);
|
||||
}
|
||||
|
||||
Mentions.prototype = Object.create(Timeline.prototype);
|
||||
|
||||
Mentions.prototype.newStatus = function(status) {
|
||||
|
||||
Timeline.prototype.newStatus.call(this, status);
|
||||
|
||||
if(this.action == "mentions" && this.is_not_init) {
|
||||
this.unread_mentions += status.length;
|
||||
HostApp.unreadMentions(this.unread_mentions);
|
||||
}
|
||||
|
||||
this.is_not_init = true;
|
||||
|
||||
}
|
||||
|
||||
Mentions.prototype.getNewData = function(add_to_search) {
|
||||
add_to_search = add_to_search || {};
|
||||
|
||||
if (!add_to_search["mentioned_entity"]) {
|
||||
add_to_search["mentioned_entity"] = HostApp.stringForKey("entity");
|
||||
}
|
||||
|
||||
Timeline.prototype.getNewData.call(this, add_to_search);
|
||||
}
|
||||
|
||||
return Mentions;
|
||||
|
||||
});
|
134
WebKit/scripts/controller/Oauth.js
Normal file
134
WebKit/scripts/controller/Oauth.js
Normal file
|
@ -0,0 +1,134 @@
|
|||
define([
|
||||
"helper/HostApp",
|
||||
"helper/Paths",
|
||||
"helper/Hmac"
|
||||
],
|
||||
|
||||
function(HostApp, Paths, Hmac) {
|
||||
|
||||
function Oauth() {
|
||||
this.app_info = {
|
||||
"id": null,
|
||||
"name": "Tentia",
|
||||
"description": "A small TentStatus client.",
|
||||
"url": "http://jabs.nu/Tentia/",
|
||||
"icon": "http://jabs.nu/Tentia/icon.png",
|
||||
"redirect_uris": [
|
||||
"tentia://oauthtoken"
|
||||
],
|
||||
"scopes": {
|
||||
"read_posts": "Uses posts to show them in a list",
|
||||
"write_posts": "Posts on users behalf"
|
||||
}
|
||||
};
|
||||
|
||||
this.register_data = null;
|
||||
this.profile = null;
|
||||
this.state = null;
|
||||
}
|
||||
|
||||
Oauth.prototype.authenticate = function() {
|
||||
this.entity = HostApp.stringForKey("entity");
|
||||
this.requestProfileURL(this.entity);
|
||||
}
|
||||
|
||||
Oauth.prototype.apiRoot = function() {
|
||||
return this.profile["https://tent.io/types/info/core/v0.1.0"]["servers"][0];
|
||||
}
|
||||
|
||||
Oauth.prototype.requestProfileURL = function (entity) {
|
||||
var those = this;
|
||||
Paths.findProfileURL(entity, function(profile_url) {
|
||||
those.register(profile_url);
|
||||
});
|
||||
}
|
||||
|
||||
Oauth.prototype.register = function (url) {
|
||||
var those = this;
|
||||
Paths.getURL(url, "GET", function(resp) {
|
||||
those.profile = JSON.parse(resp.responseText);
|
||||
HostApp.setStringForKey(those.apiRoot(), "api_root");
|
||||
var callback = function(resp) {
|
||||
var data = JSON.parse(resp.responseText);
|
||||
those.authRequest(data);
|
||||
}
|
||||
Paths.getURL(Paths.mkApiRootPath("/apps"), "POST", callback, JSON.stringify(those.app_info));
|
||||
});
|
||||
}
|
||||
|
||||
Oauth.prototype.authRequest = function(register_data) {
|
||||
// id
|
||||
// mac_key_id
|
||||
// mac_key
|
||||
// mac_algorithm
|
||||
this.register_data = register_data;
|
||||
|
||||
// Needed for later App Registration Modification
|
||||
HostApp.setStringForKey(register_data["mac_key"], "app_mac_key");
|
||||
HostApp.setStringForKey(register_data["mac_key_id"], "app_mac_key_id");
|
||||
HostApp.setStringForKey(register_data["id"], "app_id");
|
||||
HostApp.setStringForKey(register_data["mac_algorithm"], "app_mac_algorithm");
|
||||
|
||||
this.state = Hmac.makeid(19);
|
||||
var auth = "/oauth/authorize?client_id=" + register_data["id"]
|
||||
+ "&redirect_uri=" + escape(this.app_info["redirect_uris"][0])
|
||||
+ "&scope=" + Object.keys(this.app_info["scopes"]).join(",")
|
||||
+ "&state=" + this.state
|
||||
+ "&tent_post_types=" + escape("https://tent.io/types/posts/status/v0.1.0");
|
||||
|
||||
HostApp.openURL(this.apiRoot() + auth);
|
||||
}
|
||||
|
||||
Oauth.prototype.requestAccessToken = function(responseBody) {
|
||||
// /oauthtoken?code=51d0115b04d1ed94001dde751c5b360f&state=aQfH1VEohYsQr86qqyv
|
||||
var urlVars = Paths.getUrlVars(responseBody);
|
||||
if(this.state && this.state != "" && urlVars["state"] == this.state) {
|
||||
|
||||
var url = Paths.mkApiRootPath("/apps/") + this.register_data["id"] + "/authorizations";
|
||||
|
||||
var requestBody = JSON.stringify({
|
||||
'code' : urlVars["code"],
|
||||
'token_type' : "mac"
|
||||
});
|
||||
|
||||
var those = this;
|
||||
var http_method = "POST";
|
||||
var callback = function(resp) {
|
||||
those.requestAccessTokenTicketFinished(resp.responseText);
|
||||
};
|
||||
|
||||
var auth_header = Hmac.makeAuthHeader(
|
||||
url,
|
||||
http_method,
|
||||
HostApp.stringForKey("app_mac_key"),
|
||||
HostApp.stringForKey("app_mac_key_id")
|
||||
);
|
||||
|
||||
Paths.getURL(url, http_method, callback, requestBody, auth_header);
|
||||
|
||||
} else {
|
||||
alert("State is not the same: {" + this.state + "} vs {" + urlVars["state"] + "}")
|
||||
}
|
||||
|
||||
this.state = null; // reset the state
|
||||
}
|
||||
|
||||
Oauth.prototype.requestAccessTokenTicketFinished = function(responseBody) {
|
||||
|
||||
var access = JSON.parse(responseBody);
|
||||
|
||||
HostApp.setStringForKey(access["access_token"], "user_access_token");
|
||||
HostApp.setStringForKey(access["mac_key"], "user_mac_key");
|
||||
HostApp.setStringForKey(access["mac_algorithm"], "user_mac_algorithm");
|
||||
HostApp.setStringForKey(access["token_type"], "user_token_type");
|
||||
|
||||
HostApp.loggedIn();
|
||||
}
|
||||
|
||||
Oauth.prototype.logout = function() {
|
||||
|
||||
}
|
||||
|
||||
return Oauth;
|
||||
|
||||
});
|
106
WebKit/scripts/controller/Timeline.js
Normal file
106
WebKit/scripts/controller/Timeline.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
define([
|
||||
"helper/Core",
|
||||
"helper/Paths",
|
||||
"helper/HostApp",
|
||||
"lib/URI"
|
||||
],
|
||||
|
||||
function(Core, Paths, HostApp, URI) {
|
||||
|
||||
function Timeline() {
|
||||
|
||||
Core.call(this);
|
||||
|
||||
this.action = "timeline";
|
||||
|
||||
this.max_length = 20;
|
||||
this.timeout = 10 * 1000; // every 10 seconds
|
||||
this.since_id = null;
|
||||
this.since_id_entity = null;
|
||||
this.since_time = 0;
|
||||
|
||||
this.body = document.createElement("ol");
|
||||
this.body.className = this.action;
|
||||
document.body.appendChild(this.body);
|
||||
|
||||
var _this = this;
|
||||
this.reloadIntervall = setInterval(function() { _this.getNewData() }, this.timeout);
|
||||
|
||||
this.getNewData();
|
||||
}
|
||||
|
||||
Timeline.prototype = Object.create(Core.prototype);
|
||||
|
||||
|
||||
Timeline.prototype.newStatus = function(statuses) {
|
||||
|
||||
if(statuses != null && statuses.length > 0) {
|
||||
for(var i = statuses.length-1, c=0; i>=c; --i) {
|
||||
|
||||
var status = statuses[i];
|
||||
this.since_id = status.id;
|
||||
this.since_id_entity = status.entity;
|
||||
|
||||
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);
|
||||
} else {
|
||||
this.body.appendChild(this.getStatusDOMElement(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timeline.prototype.getNewData = function(add_to_search) {
|
||||
|
||||
add_to_search = add_to_search || {};
|
||||
|
||||
var those = this;
|
||||
var url = URI(Paths.mkApiRootPath("/posts"));
|
||||
url.addSearch("post_types", "https://tent.io/types/post/status/v0.1.0");
|
||||
url.addSearch("limit", this.max_length);
|
||||
if(this.since_id) {
|
||||
url.addSearch("since_id", this.since_id);
|
||||
url.addSearch("since_id_entity", this.since_id_entity);
|
||||
}
|
||||
|
||||
for (key in add_to_search) {
|
||||
url.addSearch(key, add_to_search[key]);
|
||||
}
|
||||
|
||||
var http_method = "GET";
|
||||
var callback = function(resp) {
|
||||
|
||||
try {
|
||||
var json = JSON.parse(resp.responseText)
|
||||
} catch (e) {
|
||||
//alert(resp.responseText);
|
||||
alert(url + " JSON parse error");
|
||||
throw e;
|
||||
}
|
||||
|
||||
those.newStatus(json);
|
||||
}
|
||||
|
||||
var data = null;
|
||||
|
||||
if (HostApp.stringForKey("user_access_token")) {
|
||||
Paths.getURL(url.toString(), http_method, callback, data); // FIXME: error callback
|
||||
}
|
||||
}
|
||||
|
||||
Timeline.prototype.sendNewMessage = function(content, in_reply_to_status_id, in_reply_to_entity) {
|
||||
var _this = this;
|
||||
var callback = function(data) { _this.getNewData(); }
|
||||
Core.prototype.sendNewMessage.call(this, content, in_reply_to_status_id, in_reply_to_entity, callback);
|
||||
}
|
||||
|
||||
Timeline.prototype.foo = function(a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
return Timeline;
|
||||
|
||||
});
|
Reference in a new issue