fixed mentions badget and cursor
This commit is contained in:
parent
8a1e17d41c
commit
e8392eff7a
3 changed files with 161 additions and 105 deletions
|
@ -60,7 +60,7 @@ function(HostApp, Timeline, URI, APICalls, Core) {
|
||||||
|
|
||||||
Timeline.prototype.getNewData.call(this, add_to_search, append, query);
|
Timeline.prototype.getNewData.call(this, add_to_search, append, query);
|
||||||
|
|
||||||
//this.getLatestMentionRead();
|
this.getLatestMentionRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mentions.prototype.mentionRead = function(id, entity) {
|
Mentions.prototype.mentionRead = function(id, entity) {
|
||||||
|
@ -73,73 +73,130 @@ function(HostApp, Timeline, URI, APICalls, Core) {
|
||||||
Mentions.prototype.setAllMentionsRead = function() {
|
Mentions.prototype.setAllMentionsRead = function() {
|
||||||
this.unread_mentions = 0;
|
this.unread_mentions = 0;
|
||||||
HostApp.unreadMentions(this.unread_mentions);
|
HostApp.unreadMentions(this.unread_mentions);
|
||||||
//this.updateLatestMentionRead();
|
this.updateLatestMentionRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: those two functions need to be rewritten
|
|
||||||
/*
|
|
||||||
Mentions.prototype.updateLatestMentionRead = function() {
|
Mentions.prototype.updateLatestMentionRead = function() {
|
||||||
|
|
||||||
|
var cursor_url = HostApp.serverUrl("posts_feed") + "?types=" + "https://tent.io/types/cursor/v0";
|
||||||
|
|
||||||
|
// find the first real post
|
||||||
for (var i = 0; i < this.body.childNodes.length; i++) {
|
for (var i = 0; i < this.body.childNodes.length; i++) {
|
||||||
|
|
||||||
var status = this.body.childNodes[i].status;
|
var status = this.body.childNodes[i].status;
|
||||||
|
|
||||||
if (!status.__repost) {
|
if (!status.__repost) {
|
||||||
if (status && status.type == "https://tent.io/types/post/status/v0.1.0") {
|
if (status && status.type.startsWith("https://tent.io/types/status/v0#")) {
|
||||||
|
|
||||||
var url = URI(APICalls.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
|
// First find out if there is such a cursor or if we need to create it first
|
||||||
var body = {
|
APICalls.get(cursor_url, { callback: function(resp) {
|
||||||
"mentions": {
|
|
||||||
"https://tent.io/types/post/status/v0.1.0": {
|
var posts = JSON.parse(resp.responseText).posts;
|
||||||
|
var mentions_post = null;
|
||||||
|
|
||||||
|
for (var i = 0; i < posts.length; i++) {
|
||||||
|
var post = posts[i];
|
||||||
|
|
||||||
|
if(post.type == "https://tent.io/types/cursor/v0#https://tent.io/rels/status-mentions") {
|
||||||
|
|
||||||
|
mentions_post = post;
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now prepare the cursor
|
||||||
|
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
type: "https://tent.io/types/cursor/v0#https://tent.io/rels/status-mentions",
|
||||||
|
content: {},
|
||||||
|
permissions: {
|
||||||
|
public: false,
|
||||||
|
},
|
||||||
|
refs: [
|
||||||
|
{
|
||||||
"post": status.id,
|
"post": status.id,
|
||||||
|
"type": status.type,
|
||||||
"entity": status.entity
|
"entity": status.entity
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
// update version if the post exists
|
||||||
|
if(mentions_post) {
|
||||||
|
data.version = {
|
||||||
|
parents: [
|
||||||
|
{
|
||||||
|
version: mentions_post.version.id
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var callback = function(resp) {
|
var options = {
|
||||||
|
content_type: data.type,
|
||||||
|
accept: 'application/vnd.tent.post.v0+json; type="https://tent.io/types/cursor/v0#https://tent.io/rels/status-mentions"',
|
||||||
|
callback: function(resp) {
|
||||||
|
|
||||||
|
}};
|
||||||
|
|
||||||
|
// either update or create the cursor
|
||||||
|
if(mentions_post) {
|
||||||
|
var url = HostApp.serverUrl("post")
|
||||||
|
.replace(/\{entity\}/, encodeURIComponent(HostApp.stringForKey("entity")))
|
||||||
|
.replace(/\{post\}/, mentions_post.id)
|
||||||
|
APICalls.put(url, JSON.stringify(data), options);
|
||||||
|
} else {
|
||||||
|
var url = HostApp.serverUrl("posts_feed");
|
||||||
|
APICalls.post(url, JSON.stringify(data), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
APICalls.http_call(url.toString(), "PUT", callback, JSON.stringify(body));
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Mentions.prototype.getLatestMentionRead = function() {
|
Mentions.prototype.getLatestMentionRead = function() {
|
||||||
|
|
||||||
var cursor_url = URI(APICalls.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
|
var cursor_url = HostApp.serverUrl("posts_feed") + "?types=" + "https://tent.io/types/cursor/v0";
|
||||||
|
|
||||||
APICalls.http_call(cursor_url.toString(), "GET", function(resp) {
|
APICalls.get(cursor_url, { callback: function(resp) {
|
||||||
|
|
||||||
var url = URI(APICalls.mkApiRootPath("/posts/count"));
|
var posts = JSON.parse(resp.responseText).posts;
|
||||||
|
|
||||||
|
for (var i = 0; i < posts.length; i++) {
|
||||||
|
var post = posts[i];
|
||||||
|
|
||||||
|
if(post.type == "https://tent.io/types/cursor/v0#https://tent.io/rels/status-mentions") {
|
||||||
|
|
||||||
|
var since = post.version.received_at;
|
||||||
|
var post_id = post.refs[0].post;
|
||||||
var post_types = [
|
var post_types = [
|
||||||
"https://tent.io/types/post/status/v0.1.0",
|
"https://tent.io/types/status/v0#reply",
|
||||||
|
"https://tent.io/types/status/v0#"
|
||||||
];
|
];
|
||||||
url.addSearch("post_types", post_types.join(","));
|
|
||||||
url.addSearch("mentioned_entity", HostApp.stringForKey("entity"));
|
|
||||||
|
|
||||||
|
var uri = URI(HostApp.serverUrl("posts_feed"));
|
||||||
|
uri.addSearch("types", post_types.join(","));
|
||||||
|
uri.addSearch("since", since);
|
||||||
|
uri.addSearch("mentions", HostApp.stringForKey("entity"));
|
||||||
|
|
||||||
try { // don't crash when there is no cursor yet
|
APICalls.head(uri.toString(), { callback: function(resp) {
|
||||||
var body = JSON.parse(resp.responseText);
|
|
||||||
var cursor = body["mentions"]["https://tent.io/types/post/status/v0.1.0"];
|
|
||||||
url.addSearch("since_id", cursor["post"]);
|
|
||||||
url.addSearch("since_id_entity", cursor["entity"]);
|
|
||||||
} catch(e) { }
|
|
||||||
|
|
||||||
var callback = function(resp) {
|
this.unread_mentions = APICalls.getCount(resp);
|
||||||
this.unread_mentions = parseInt(resp.responseText, 10);
|
|
||||||
HostApp.unreadMentions(this.unread_mentions);
|
HostApp.unreadMentions(this.unread_mentions);
|
||||||
}
|
|
||||||
|
|
||||||
APICalls.http_call(url.toString(), "GET", callback); // FIXME: error callback
|
}});
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return Mentions;
|
return Mentions;
|
||||||
|
|
||||||
|
|
|
@ -267,9 +267,8 @@ function(APICalls, HostApp) {
|
||||||
|
|
||||||
var content = this.textarea.val();
|
var content = this.textarea.val();
|
||||||
|
|
||||||
var type = "https://tent.io/types/status/v0#";
|
|
||||||
var data = {
|
var data = {
|
||||||
type: type,
|
type: "https://tent.io/types/status/v0#",
|
||||||
content: {
|
content: {
|
||||||
text: content
|
text: content
|
||||||
},
|
},
|
||||||
|
|
|
@ -131,7 +131,7 @@ function(Core, APICalls, HostApp, URI) {
|
||||||
uri.addSearch("types", post_types.join(","));
|
uri.addSearch("types", post_types.join(","));
|
||||||
//uri.addSearch("sort_by", "published_at");
|
//uri.addSearch("sort_by", "published_at");
|
||||||
uri.addSearch("limit", this.posts_limit);
|
uri.addSearch("limit", this.posts_limit);
|
||||||
uri.addSearch("max_refs", 20);
|
//uri.addSearch("max_refs", 20);
|
||||||
uri.addSearch("profiles", "entity");
|
uri.addSearch("profiles", "entity");
|
||||||
|
|
||||||
if(this.since_time) {
|
if(this.since_time) {
|
||||||
|
|
Reference in a new issue