diff --git a/Mac/Controller.h b/Mac/Controller.h index 1ee60ff..9d7a875 100644 --- a/Mac/Controller.h +++ b/Mac/Controller.h @@ -81,6 +81,7 @@ - (IBAction)showConversationForPostId:(NSString *)postId andEntity:(NSString *)entity; +- (IBAction)clearCache:(id)sender; OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData); diff --git a/Mac/Controller.m b/Mac/Controller.m index 063d39a..84909ef 100644 --- a/Mac/Controller.m +++ b/Mac/Controller.m @@ -476,6 +476,11 @@ [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } +- (IBAction)clearCache:(id)sender +{ + [timelineView stringByEvaluatingJavaScriptFromString:@"tentia_instance.cache.clear()"]; +} + - (IBAction)showProfileForEntity:(NSString *)entity { NSString *js = [NSString stringWithFormat:@"tentia_instance.showProfileForEntity('%@');", entity]; diff --git a/Mac/English.lproj/MainMenu.xib b/Mac/English.lproj/MainMenu.xib index 98e454d..d5b00c6 100644 --- a/Mac/English.lproj/MainMenu.xib +++ b/Mac/English.lproj/MainMenu.xib @@ -104,6 +104,14 @@ + + + Clear cache + + 2147483647 + + + YES @@ -851,7 +859,6 @@ {397, 581} - @@ -871,7 +878,6 @@ {397, 581} - {{0, 0}, {2560, 1418}} @@ -922,7 +928,6 @@ {376, 581} - @@ -940,7 +945,6 @@ {376, 581} - {{0, 0}, {2560, 1418}} @@ -988,7 +992,6 @@ {376, 581} - @@ -999,7 +1002,6 @@ {376, 581} - {{0, 0}, {2560, 1418}} @@ -1047,7 +1049,6 @@ {376, 581} - @@ -1058,7 +1059,6 @@ {376, 581} - {{0, 0}, {2560, 1418}} @@ -1076,7 +1076,7 @@ - + 256 YES @@ -1228,7 +1228,6 @@ {480, 186} - _NS:20 @@ -1716,6 +1715,14 @@ 663 + + + clearCache: + + + + 665 + makeKeyAndOrderFront: @@ -2055,6 +2062,7 @@ + @@ -2591,6 +2599,11 @@ + + 664 + + + @@ -2714,6 +2727,7 @@ 658.NSWindowTemplate.visibleAtLaunch 659.IBPluginDependency 660.IBPluginDependency + 664.IBPluginDependency 72.IBPluginDependency 73.IBPluginDependency 79.IBPluginDependency @@ -2846,6 +2860,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -2860,7 +2875,7 @@ - 663 + 665 @@ -2872,24 +2887,43 @@ YES YES + clearCache: login: logout: + openNewMessageWindow: + sendTweet: + showConversationForPostId:andEntity: + showProfileForEntity: YES id id + id + id + id + NSString + NSString YES YES + clearCache: login: logout: + openNewMessageWindow: + sendTweet: + showConversationForPostId:andEntity: + showProfileForEntity: YES + + clearCache: + id + login: id @@ -2898,6 +2932,22 @@ logout: id + + openNewMessageWindow: + id + + + sendTweet: + id + + + showConversationForPostId:andEntity: + NSString + + + showProfileForEntity: + NSString + diff --git a/WebKit/scripts/controller/Timeline.js b/WebKit/scripts/controller/Timeline.js index 6f00c27..51e4f9e 100644 --- a/WebKit/scripts/controller/Timeline.js +++ b/WebKit/scripts/controller/Timeline.js @@ -91,6 +91,7 @@ function(Core, Paths, HostApp, URI) { url.addSearch("post_types", post_types.join(",")); 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); @@ -119,6 +120,7 @@ function(Core, Paths, HostApp, URI) { var data = null; if (HostApp.stringForKey("user_access_token")) { + if (!this.reload_blocked) { this.reload_blocked = true; Paths.getURL(url.toString(), http_method, callback, data); // FIXME: error callback diff --git a/WebKit/scripts/helper/Core.js b/WebKit/scripts/helper/Core.js index 3047ea8..3e0bee7 100644 --- a/WebKit/scripts/helper/Core.js +++ b/WebKit/scripts/helper/Core.js @@ -183,6 +183,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { template.username.innerText = status.entity; template.username.href = status.entity; + template.username.title = status.entity; template.username.onclick = function() { HostApp.showProfileForEntity(status.entity); return false; @@ -208,6 +209,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { var p = this.cache.profiles.getItem(status.entity); if (p && p != "null") { + profile_callback(p); } else { @@ -215,9 +217,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { Paths.findProfileURL(status.entity, function(profile_url) { if (profile_url) { - Paths.getURL(profile_url, "GET", function(resp) { - var p = JSON.parse(resp.responseText); if (p && p != "null") { _this.cache.profiles.setItem(status.entity, p); @@ -371,7 +371,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { var _this = this; var callback = function(resp) { - if (resp.status >= 200 && resp.status < 300) { + if (resp.status >= 200 && resp.status < 300 && before_node) { var status = JSON.parse(resp.responseText); status.__repost = repost; var li = _this.getStatusDOMElement(status); @@ -522,6 +522,7 @@ function(jQuery, Paths, URI, HostApp, Cache) { if (confirm("Really delete this post?")) { var url = URI(Paths.mkApiRootPath("/posts/" + id)); + Paths.getURL(url.toString(), "DELETE", callback); } } @@ -595,20 +596,24 @@ function(jQuery, Paths, URI, HostApp, Cache) { var basic = profile["https://tent.io/types/info/basic/v0.1.0"]; if (profile && basic) { - if(basic.name) { - var new_text = node.innerHTML.replace( - mention.text, - "" - + basic.name - + "" - ); - - node.innerHTML = new_text; - $(node).find("a.name").click(function(e) { - HostApp.showProfileForEntity(e.target.title); - return false; - }); + var name = mention.text; + if (basic.name) { + name = basic.name; } + + var new_text = node.innerHTML.replace( + mention.text, + "" + + name + + "" + ); + + node.innerHTML = new_text; + $(node).find("a.name").click(function(e) { + HostApp.showProfileForEntity(e.target.title); + return false; + }); + } } diff --git a/WebKit/scripts/helper/Paths.js b/WebKit/scripts/helper/Paths.js index 5d9610c..f93be35 100644 --- a/WebKit/scripts/helper/Paths.js +++ b/WebKit/scripts/helper/Paths.js @@ -25,13 +25,13 @@ function(jQuery, HostApp, Hmac, Cache) { Paths.getURL = function(url, http_method, callback, data, auth_header, accepts) { - accepts = accepts || "application/vnd.tent.v0+json"; + if(accepts !== false) accepts = accepts || "application/vnd.tent.v0+json; charset=utf-8"; - jQuery.ajax({ + var options = { beforeSend: function(xhr) { - xhr.setRequestHeader("Accept", accepts); + if(accepts !== false) xhr.setRequestHeader("Accept", accepts); if (data) xhr.setRequestHeader("Content-Length", data.length); @@ -64,7 +64,9 @@ function(jQuery, HostApp, Hmac, Cache) { error: function(xhr, ajaxOptions, thrownError) { console.error("getURL (" + xhr.status + ")" + xhr.statusText + " " + http_method + " (" + url + "): '" + xhr.responseText + "'"); } - }); + } + + jQuery.ajax(options); } Paths.postMultipart = function(url, callback, data, boundary, accepts) { @@ -105,7 +107,6 @@ function(jQuery, HostApp, Hmac, Cache) { } Paths.findProfileURL = function(entity, callback, errorCallback) { - var profile_url = Paths.cache.profile_urls.getItem(entity); if (profile_url && profile_url != "null") { @@ -134,7 +135,31 @@ function(jQuery, HostApp, Hmac, Cache) { Paths.cache.profile_urls.setItem(entity, profile_url); callback(profile_url); } else { - if(errorCallback) errorCallback(entity + " has no profile URL"); + Paths.getURL(entity, "GET", function(resp) { + + if (resp.status >= 200 && resp.status < 300) { + var div = document.createElement("div"); + div.innerHTML = resp.responseText; + var links = $(div).find("link[rel='https://tent.io/rels/profile']"); + + if (links.length > 0) { + var href = links.get(0).href; + Paths.cache.profile_urls.setItem(entity, href); + if (!href.startsWith("http")) { + href = entity + "/profile"; + } + callback(href); + + } else { + if(errorCallback) errorCallback(entity + " has no profile URL"); + } + } else { + if(errorCallback) errorCallback(entity + " has no profile URL"); + } + + }, null, false, false); + + //if(errorCallback) errorCallback(entity + " has no profile URL"); } } },