fixed conversation view
This commit is contained in:
parent
27a9c51106
commit
512688f5ab
7 changed files with 93 additions and 96 deletions
|
@ -286,6 +286,10 @@ aside {
|
|||
visibility: hidden;
|
||||
}
|
||||
|
||||
.repost, .remove {
|
||||
display: none; /* FIXME: remove this; */
|
||||
}
|
||||
|
||||
li:hover aside .reply_to, li:hover aside .repost, li:hover aside .remove, li:hover aside .ago:before {
|
||||
visibility: visible;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,15 @@ function(HostApp, Core, APICalls, URI) {
|
|||
|
||||
document.getElementById("content").appendChild(this.container);
|
||||
if(!this.standalone) this.hide();
|
||||
|
||||
// Stop loading if ESC is pressed
|
||||
this.stopLoading = false;
|
||||
var _this = this;
|
||||
$(document).keydown(function(e) {
|
||||
if (e.keyCode == 27) { // Esc
|
||||
_this.stopLoading = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Conversation.prototype = Object.create(Core.prototype);
|
||||
|
@ -57,104 +66,92 @@ function(HostApp, Core, APICalls, URI) {
|
|||
|
||||
Conversation.prototype.append = function(id, entity, node, add_after) {
|
||||
|
||||
if(this.stopLoading) return;
|
||||
|
||||
var _this = this;
|
||||
|
||||
var callback = function(resp) {
|
||||
|
||||
var status = JSON.parse(resp.responseText);
|
||||
var _statuses = JSON.parse(resp.responseText);
|
||||
|
||||
for (var entity in _statuses.profiles) {
|
||||
if (_statuses.profiles[entity] != null) {
|
||||
bungloo.cache.profiles[entity] = _statuses.profiles[entity];
|
||||
} else {
|
||||
bungloo.cache.profiles[entity] = {};
|
||||
}
|
||||
}
|
||||
|
||||
var status = _statuses.post;
|
||||
|
||||
var dom_element = _this.getStatusDOMElement(status);
|
||||
|
||||
if (node) {
|
||||
|
||||
if(add_after) {
|
||||
node.parentNode.insertBefore(dom_element, node.nextSibling);
|
||||
} else {
|
||||
node.parentNode.insertBefore(dom_element, node);
|
||||
}
|
||||
|
||||
} else {
|
||||
dom_element.className = "highlight";
|
||||
_this.body.appendChild(dom_element);
|
||||
|
||||
_this.appendMentioned(id, entity, dom_element);
|
||||
}
|
||||
|
||||
// child posts
|
||||
_this.appendMentioned(id, entity, dom_element);
|
||||
|
||||
// parent posts
|
||||
if(status.mentions) {
|
||||
for (var i = 0; i < status.mentions.length; i++) {
|
||||
var mention = status.mentions[i];
|
||||
if(mention.post) {
|
||||
// don't load if it is already there
|
||||
if(!document.getElementById("post-" + mention.post + "-" + _this.action)) {
|
||||
_this.append(mention.post, mention.entity, dom_element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRemoteStatus(profile) {
|
||||
var server = profile["https://tent.io/types/info/core/v0.1.0"].servers[0];
|
||||
APICalls.http_call(URI(server + "/posts/" + id).toString(), "GET", callback, null, false);
|
||||
}
|
||||
|
||||
var profile = this.cache.profiles.getItem(entity);
|
||||
|
||||
if (entity == HostApp.stringForKey("entity")) {
|
||||
|
||||
var url = URI(APICalls.mkApiRootPath("/posts/" + id));
|
||||
APICalls.http_call(url.toString(), "GET", callback, null);
|
||||
|
||||
} else if(profile) {
|
||||
|
||||
getRemoteStatus(profile);
|
||||
|
||||
} else {
|
||||
|
||||
APICalls.findProfileURL(entity, function(profile_url) {
|
||||
|
||||
if (profile_url) {
|
||||
|
||||
var profile = this.cache.profiles.getItem(entity);
|
||||
if (profile) {
|
||||
|
||||
getRemoteStatus(profile);
|
||||
|
||||
} else {
|
||||
|
||||
APICalls.http_call(profile_url, "GET", function(resp) {
|
||||
|
||||
var profile = JSON.parse(resp.responseText)
|
||||
this.cache.profiles.setItem(entity, profile);
|
||||
getRemoteStatus(profile);
|
||||
|
||||
}, null, false); // do not send auth-headers
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var url = HostApp.serverUrl("post")
|
||||
.replace(/\{entity\}/, encodeURIComponent(entity))
|
||||
.replace(/\{post\}/, id)
|
||||
+ "?profiles=entity";
|
||||
|
||||
APICalls.get(url, { callback: callback });
|
||||
}
|
||||
|
||||
Conversation.prototype.appendMentioned = function(id, entity, node) {
|
||||
|
||||
var url = URI(APICalls.mkApiRootPath("/posts"));
|
||||
url.addSearch("mentioned_post", id);
|
||||
url.addSearch("post_types", "https%3A%2F%2Ftent.io%2Ftypes%2Fpost%2Fstatus%2Fv0.1.0");
|
||||
|
||||
var _this = this;
|
||||
var callback = function(resp) {
|
||||
|
||||
var statuses = JSON.parse(resp.responseText);
|
||||
var statuses = JSON.parse(resp.responseText).mentions;
|
||||
|
||||
for (var i = 0; i < statuses.length; i++) {
|
||||
|
||||
var status = statuses[i];
|
||||
var dom_element = _this.getStatusDOMElement(status);
|
||||
_this.body.appendChild(dom_element);
|
||||
|
||||
_this.appendMentioned(status.id, status.entity, dom_element);
|
||||
// don't load if it is already there
|
||||
if(!document.getElementById("post-" + status.post + "-" + _this.action)) {
|
||||
_this.append(status.post, status.entity ,node, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
APICalls.http_call(url.toString(), "GET", callback);
|
||||
var url = HostApp.serverUrl("post")
|
||||
.replace(/\{entity\}/, encodeURIComponent(entity))
|
||||
.replace(/\{post\}/, id);
|
||||
|
||||
APICalls.get(url, {
|
||||
callback: callback,
|
||||
accept: "application/vnd.tent.post-mentions.v0+json"
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// /posts?limit=10&mentioned_post=gnqqyt&post_types=https%3A%2F%2Ftent.io%2Ftypes%2Fpost%2Fstatus%2Fv0.1.0,https%3A%2F%2Ftent.io%2Ftypes%2Fpost%2Frepost%2Fv0.1.0 HTTP/1.1" 200 - 0.0582
|
||||
|
||||
|
||||
|
||||
return Conversation;
|
||||
|
||||
});
|
|
@ -78,9 +78,11 @@ function(HostApp, Timeline, URI, APICalls, Core) {
|
|||
Mentions.prototype.setAllMentionsRead = function() {
|
||||
this.unread_mentions = 0;
|
||||
HostApp.unreadMentions(this.unread_mentions);
|
||||
this.updateLatestMentionRead();
|
||||
//this.updateLatestMentionRead();
|
||||
}
|
||||
|
||||
// FIXME: those two functions need to be rewritten
|
||||
/*
|
||||
Mentions.prototype.updateLatestMentionRead = function() {
|
||||
|
||||
for (var i = 0; i < this.body.childNodes.length; i++) {
|
||||
|
@ -142,7 +144,7 @@ function(HostApp, Timeline, URI, APICalls, Core) {
|
|||
APICalls.http_call(url.toString(), "GET", callback); // FIXME: error callback
|
||||
});
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
return Mentions;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ function(HostApp, Core, APICalls, URI, Timeline) {
|
|||
function Profile() {
|
||||
|
||||
Timeline.call(this);
|
||||
clearTimeout(this.reloadIntervall); // FIXME: reload for new data instead
|
||||
|
||||
this.action = "profile";
|
||||
|
||||
|
|
|
@ -35,14 +35,13 @@ function(jQuery, HostApp, Hmac, Cache) {
|
|||
if((options.http_method == "POST" || options.http_method == "PUT") && !options.content_type) {
|
||||
console.error("No content type for " + options.url);
|
||||
return;
|
||||
} else if(options.content_type != "AAA") {
|
||||
|
||||
} else {
|
||||
if(options.content_type == "application/json") {
|
||||
content_type = "application/json";
|
||||
} else if(options.content_type) {
|
||||
content_type = "application/vnd.tent.post.v0+json; charset=UTF-8; type=\"" + options.content_type + "\"";
|
||||
}
|
||||
} else {
|
||||
content_type = 'application/vnd.tent.post.v0+json; charset=UTF-8; type="https://tent.io/types/status/v0#"';
|
||||
}
|
||||
|
||||
var settings = {
|
||||
|
|
|
@ -233,7 +233,7 @@ function(jQuery, APICalls, URI, HostApp) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(bungloo.cache.profiles[status.entity].name) template.username.innerText = bungloo.cache.profiles[status.entity].name;
|
||||
if(bungloo.cache.profiles[status.entity] && bungloo.cache.profiles[status.entity].name) template.username.innerText = bungloo.cache.profiles[status.entity].name;
|
||||
else template.username.innerText = status.entity;
|
||||
template.username.href = status.entity;
|
||||
template.username.title = status.entity;
|
||||
|
@ -552,6 +552,7 @@ function(jQuery, APICalls, URI, HostApp) {
|
|||
if (e.substring(0,7) != "http://" && e.substring(0,8) != "https://") {
|
||||
e = "https://" + e;
|
||||
}
|
||||
if(mentions) {
|
||||
for (var j = 0; j < mentions.length; j++) {
|
||||
var m = mentions[j];
|
||||
if(m.entity.startsWith(e)) {
|
||||
|
@ -563,6 +564,7 @@ function(jQuery, APICalls, URI, HostApp) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _this = this;
|
||||
for (var i = 0; i < mentions_in_text.length; i++) {
|
||||
|
@ -601,13 +603,6 @@ function(jQuery, APICalls, URI, HostApp) {
|
|||
}
|
||||
}
|
||||
|
||||
var p = _this.cache.profiles.getItem(mention.entity);
|
||||
if (p) {
|
||||
|
||||
profile(p);
|
||||
|
||||
} else {
|
||||
|
||||
APICalls.findProfileURL(mention.entity, function(profile_url) {
|
||||
if (profile_url) {
|
||||
APICalls.http_call(profile_url, "GET", function(resp) {
|
||||
|
@ -619,7 +614,6 @@ function(jQuery, APICalls, URI, HostApp) {
|
|||
}, null, false); // do not send auth-headers
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})(mention);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ function loadCssPlugin(css_url) {
|
|||
function debug(string) {
|
||||
|
||||
if (typeof string != "string") {
|
||||
string = JSON.stringify(string);
|
||||
string = JSON.stringify(string, null, ' ');
|
||||
}
|
||||
|
||||
console.debug(string);
|
||||
|
|
Reference in a new issue