work on profile
This commit is contained in:
parent
213c83f3e9
commit
07b043c159
2 changed files with 61 additions and 112 deletions
|
@ -2,32 +2,28 @@ define([
|
||||||
"helper/HostApp",
|
"helper/HostApp",
|
||||||
"helper/Core",
|
"helper/Core",
|
||||||
"helper/APICalls",
|
"helper/APICalls",
|
||||||
"lib/URI"
|
"lib/URI",
|
||||||
|
"controller/Timeline"
|
||||||
],
|
],
|
||||||
|
|
||||||
function(HostApp, Core, APICalls, URI) {
|
function(HostApp, Core, APICalls, URI, Timeline) {
|
||||||
|
|
||||||
|
|
||||||
function Profile() {
|
function Profile() {
|
||||||
|
|
||||||
Core.call(this);
|
Timeline.call(this);
|
||||||
|
|
||||||
this.action = "profile";
|
this.action = "profile";
|
||||||
|
|
||||||
this.posts_limit = 25;
|
|
||||||
|
|
||||||
this.container = document.createElement("div");
|
this.container = document.createElement("div");
|
||||||
this.container.className = this.action;
|
this.container.className = this.action;
|
||||||
document.getElementById("content").appendChild(this.container);
|
document.getElementById("content").appendChild(this.container);
|
||||||
|
|
||||||
this.initProfileTemplate();
|
this.initProfileTemplate();
|
||||||
this.hide();
|
this.hide();
|
||||||
|
|
||||||
//var _this = this;
|
|
||||||
//setTimeout(function() { _this.showProfileForEntity() }, 500); // Load users profile on start
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile.prototype = Object.create(Core.prototype);
|
Profile.prototype = Object.create(Timeline.prototype);
|
||||||
|
|
||||||
|
|
||||||
Profile.prototype.show = function() {
|
Profile.prototype.show = function() {
|
||||||
|
@ -61,6 +57,8 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
entity = HostApp.stringForKey("entity");
|
entity = HostApp.stringForKey("entity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug(entity)
|
||||||
|
|
||||||
this.clear();
|
this.clear();
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.following = null;
|
this.following = null;
|
||||||
|
@ -70,6 +68,7 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
|
|
||||||
this.getProfile();
|
this.getProfile();
|
||||||
this.getFollowing();
|
this.getFollowing();
|
||||||
|
this.getStatuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile.prototype.initProfileTemplate = function() {
|
Profile.prototype.initProfileTemplate = function() {
|
||||||
|
@ -322,8 +321,10 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
|
||||||
|
// FIXME
|
||||||
this.getMeta(this.profile);
|
this.getMeta(this.profile);
|
||||||
//this.getStatuses(this.server);
|
this.getStatuses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,11 +339,10 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
Profile.prototype.getMeta = function(profile) {
|
Profile.prototype.getMeta = function(profile) {
|
||||||
|
|
||||||
// FIXME!
|
// FIXME!
|
||||||
return;
|
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
/*
|
||||||
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/relationship/v0#follower");
|
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#");
|
||||||
APICalls.head(url, {
|
APICalls.head(url, {
|
||||||
callback: function(resp) {
|
callback: function(resp) {
|
||||||
_this.populate(_this.profile_template.followed, APICalls.getCount(resp) + " ");
|
_this.populate(_this.profile_template.followed, APICalls.getCount(resp) + " ");
|
||||||
|
@ -356,11 +356,47 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/status/v0#");
|
||||||
|
APICalls.head(url, {
|
||||||
|
callback: function(resp) {
|
||||||
|
_this.populate(_this.profile_template.posts, APICalls.getCount(resp) + " ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
// is following you
|
||||||
|
// FIXME: should use HEAD
|
||||||
|
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#https://tent.io/types/status/v0") + "&mentions=" + encodeURIComponent(HostApp.stringForKey("entity"));
|
||||||
|
APICalls.get(url, {
|
||||||
|
callback: function(resp) {
|
||||||
|
var json = JSON.parse(resp.responseText);
|
||||||
|
if (json.posts.length > 0) {
|
||||||
|
_this.relationships.following_you = true;
|
||||||
|
} else {
|
||||||
|
_this.relationships.following_you = false;
|
||||||
|
}
|
||||||
|
_this.setRelationships();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// is followed by you
|
||||||
|
// FIXME: should use HEAD
|
||||||
|
var url = HostApp.serverUrl("posts_feed") + "?mentions=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#https://tent.io/types/status/v0");
|
||||||
|
APICalls.get(url, {
|
||||||
|
callback: function(resp) {
|
||||||
|
var json = JSON.parse(resp.responseText);
|
||||||
|
debug(json)
|
||||||
|
if (json.posts.length > 0) {
|
||||||
|
_this.relationships.followed_by_you = true;
|
||||||
|
} else {
|
||||||
|
_this.relationships.followed_by_you = false;
|
||||||
|
}
|
||||||
|
_this.setRelationships();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (this.entity != HostApp.stringForKey("entity")) {
|
if (this.entity != HostApp.stringForKey("entity")) {
|
||||||
|
@ -395,7 +431,7 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
APICalls.http_call(url.toString(), "GET", function(resp) {
|
APICalls.http_call(url.toString(), "GET", function(resp) {
|
||||||
|
|
||||||
_this.populate(_this.profile_template.posts, resp.responseText);
|
_this.populate(_this.profile_template.posts, resp.responseText);
|
||||||
}, null, false);
|
}, null, false);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile.prototype.setRelationships = function() {
|
Profile.prototype.setRelationships = function() {
|
||||||
|
@ -415,93 +451,9 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Profile.prototype.getStatuses = function(root_url, add_search, append) {
|
Profile.prototype.getStatuses = function() {
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
add_search = add_search || {};
|
|
||||||
|
|
||||||
var url = URI(root_url + "/posts");
|
|
||||||
url.addSearch("limit", this.posts_limit);
|
|
||||||
|
|
||||||
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/photo/v0.1.0"
|
|
||||||
];
|
|
||||||
url.addSearch("post_types", post_types.join(","));
|
|
||||||
|
|
||||||
for(var key in add_search) {
|
|
||||||
url.addSearch(key, add_search[key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
APICalls.http_call(url.toString(), "GET", function(resp) {
|
|
||||||
|
|
||||||
var statuses = JSON.parse(resp.responseText);
|
|
||||||
|
|
||||||
_this.newStatus(statuses, append);
|
|
||||||
|
|
||||||
}, null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Profile.prototype.newStatus = function(statuses, append) {
|
|
||||||
|
|
||||||
if(statuses != null && statuses.length > 0) {
|
|
||||||
|
|
||||||
this.before.loading = false;
|
|
||||||
|
|
||||||
if (append) statuses = statuses.reverse();
|
|
||||||
|
|
||||||
for(var i = statuses.length-1, c=0; i>=c; --i) {
|
|
||||||
|
|
||||||
var status = statuses[i];
|
|
||||||
|
|
||||||
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(!append && this.body.childNodes.length > 0) {
|
|
||||||
|
|
||||||
if(this.body.childNodes.length > this.max_length) {
|
|
||||||
|
|
||||||
this.body.removeChild(this.body.lastChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.body.insertBefore(new_node, this.body.firstChild);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.body.appendChild(new_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (status.type == "https://tent.io/types/post/delete/v0.1.0") {
|
|
||||||
|
|
||||||
var li = document.getElementById("post-" + status.content.id + "-" + this.action);
|
|
||||||
if (li) {
|
|
||||||
this.body.removeChild(li);
|
|
||||||
}
|
|
||||||
} else if (status.type == "https://tent.io/types/post/repost/v0.1.0") {
|
|
||||||
|
|
||||||
this.getRepost(status, this.body.firstChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Profile.prototype.getMoreStatusPosts = function() {
|
|
||||||
if (!this.before.loading) {
|
|
||||||
this.before.loading = true;
|
|
||||||
var add_search = {
|
|
||||||
"before_id": this.body.lastChild.status.id,
|
|
||||||
"before_id_entity": this.body.lastChild.status.entity
|
|
||||||
}
|
|
||||||
this.getStatuses(this.server, add_search, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Profile.prototype.mention = function() {
|
|
||||||
|
|
||||||
|
Timeline.prototype.getNewData.call(this, {entities: this.entity});
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile.prototype.setFollowingButton = function(following) {
|
Profile.prototype.setFollowingButton = function(following) {
|
||||||
|
@ -533,6 +485,7 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
} else {
|
} else {
|
||||||
_this.setFollowingButton(true);
|
_this.setFollowingButton(true);
|
||||||
}
|
}
|
||||||
|
_this.getMeta();
|
||||||
}});
|
}});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -561,6 +514,7 @@ function(HostApp, Core, APICalls, URI) {
|
||||||
} else {
|
} else {
|
||||||
_this.setFollowingButton(false);
|
_this.setFollowingButton(false);
|
||||||
}
|
}
|
||||||
|
_this.getMeta();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,11 +132,6 @@ function(Core, APICalls, HostApp, URI) {
|
||||||
uri.addSearch("max_refs", 20);
|
uri.addSearch("max_refs", 20);
|
||||||
uri.addSearch("profiles", "entity");
|
uri.addSearch("profiles", "entity");
|
||||||
|
|
||||||
if(this.since_id && !append) {
|
|
||||||
uri.addSearch("since_id", this.since_id);
|
|
||||||
uri.addSearch("since_id_entity", this.since_id_entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (key in add_to_search) {
|
for (key in add_to_search) {
|
||||||
uri.addSearch(key, add_to_search[key]);
|
uri.addSearch(key, add_to_search[key]);
|
||||||
}
|
}
|
||||||
|
@ -147,13 +142,13 @@ function(Core, APICalls, HostApp, URI) {
|
||||||
url += query;
|
url += query;
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = null;
|
|
||||||
|
|
||||||
if (HostApp.stringForKey("user_access_token")) {
|
if (HostApp.stringForKey("user_access_token")) {
|
||||||
|
|
||||||
if (!this.reload_blocked) {
|
if (!this.reload_blocked) {
|
||||||
this.reload_blocked = true;
|
this.reload_blocked = true;
|
||||||
|
|
||||||
|
debug(url)
|
||||||
|
|
||||||
APICalls.get(url, { callback: function(resp) {
|
APICalls.get(url, { callback: function(resp) {
|
||||||
|
|
||||||
those.reload_blocked = false;
|
those.reload_blocked = false;
|
||||||
|
|
Reference in a new issue