cache full text of truncated queets in localStorage
This commit is contained in:
parent
8463546ec8
commit
9a4147fb60
|
@ -930,11 +930,20 @@ function expand_queet(q,doScrolling) {
|
|||
// if shortened queet, get full text
|
||||
if(q.children('.queet').find('span.attachment.more').length>0) {
|
||||
var attachmentId = q.children('.queet').find('span.attachment.more').attr('data-attachment-id');
|
||||
getFromAPI("attachment/" + attachmentId + ".json",function(data){
|
||||
|
||||
// get full html for queet, first try localstorage cache
|
||||
localStorageObjectCache_GET('fullQueetHtml',qid,function(data){
|
||||
if(data) {
|
||||
console.log(data);
|
||||
q.children('.queet').find('.queet-text').html($.trim(data.replace(/@<a/gi,'<a').replace(/!<a/gi,'<a').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/!<span class="vcard">/gi,'<span class="vcard">').replace(/#<span class="tag">/gi,'<span class="tag">').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/!<span class="vcard">/gi,'<span class="vcard">').replace(/#<span class="tag">/gi,'<span class="tag">')));
|
||||
}
|
||||
else {
|
||||
getFromAPI("attachment/" + attachmentId + ".json",function(data){
|
||||
if(data) {
|
||||
localStorageObjectCache_STORE('fullQueetHtml',qid,data);
|
||||
q.children('.queet').find('.queet-text').html($.trim(data.replace(/@<a/gi,'<a').replace(/!<a/gi,'<a').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/!<span class="vcard">/gi,'<span class="vcard">').replace(/#<span class="tag">/gi,'<span class="tag">').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/@<span class="vcard">/gi,'<span class="vcard">').replace(/!<span class="vcard">/gi,'<span class="vcard">').replace(/#<span class="tag">/gi,'<span class="tag">')));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1692,6 +1701,13 @@ function addToFeed(feed, after, extraClasses, isReply) {
|
|||
|
||||
function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isConversation) {
|
||||
|
||||
// if we have the full html for a truncated notice cached in localstorage, we use that
|
||||
localStorageObjectCache_GET('fullQueetHtml',obj.id,function(data){
|
||||
if(data) {
|
||||
obj.statusnet_html = data;
|
||||
}
|
||||
});
|
||||
|
||||
// we don't want to print 'null' in in_reply_to_screen_name-attribute, someone might have that username!
|
||||
var in_reply_to_screen_name = '';
|
||||
if(obj.in_reply_to_screen_name != null) {
|
||||
|
|
|
@ -33,6 +33,57 @@
|
|||
· ·
|
||||
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
|
||||
|
||||
|
||||
/* ·
|
||||
·
|
||||
· Store in localStorage object cache
|
||||
·
|
||||
· @param name: the name of this type of object
|
||||
· @param unique_id: some unique_id – the key in localStorage will be name-unique_id
|
||||
· @param object: the object to store
|
||||
·
|
||||
· · · · · · · · · */
|
||||
|
||||
function localStorageObjectCache_STORE(name, unique_id, object) {
|
||||
|
||||
if(localStorageIsEnabled()) {
|
||||
|
||||
if(object.length < 1) {
|
||||
// an empty object means we remove this entry
|
||||
if(typeof localStorage[name + '-' + unique_id] != 'undefined' && localStorage[name + '-' + unique_id] !== null) {
|
||||
delete localStorage[name + '-' + unique_id];
|
||||
}
|
||||
}
|
||||
else {
|
||||
localStorage[name + '-' + unique_id] = JSON.stringify(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ·
|
||||
·
|
||||
· Get from localStorage object cache
|
||||
·
|
||||
· @param name: the name of this type of object
|
||||
· @param unique_id: some unique_id – the key in localStorage will be name-unique_id
|
||||
· @param callback: callback function, returns false if not found
|
||||
·
|
||||
· · · · · · · · · */
|
||||
|
||||
function localStorageObjectCache_GET(name, unique_id, callback) {
|
||||
|
||||
if(localStorageIsEnabled()) {
|
||||
if(typeof localStorage[name + '-' + unique_id] != 'undefined' && localStorage[name + '-' + unique_id] !== null) {
|
||||
callback(JSON.parse(localStorage[name + '-' + unique_id]));
|
||||
}
|
||||
else {
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ·
|
||||
·
|
||||
· Display unread notifications
|
||||
|
@ -555,7 +606,11 @@ function remove_spinner() {
|
|||
function convertAttachmentMoreHref() {
|
||||
$('a.attachment.more').each(function() {
|
||||
if(typeof $(this).attr('href') != 'undefined') {
|
||||
$(this).replaceWith($('<span class="attachment more" data-attachment-id="' + $(this).attr('href').substring(29) + '">…</span>'));
|
||||
var attachment_href = $(this).attr('href');
|
||||
var attachment_id = attachment_href.substr((~-attachment_href.lastIndexOf("/") >>> 0) + 2);
|
||||
if(attachment_id.length>0) {
|
||||
$(this).replaceWith($('<span class="attachment more" data-attachment-id="' + attachment_id + '">…</span>'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user