diff options
Diffstat (limited to 'src/main/assets/scripts.js')
-rw-r--r-- | src/main/assets/scripts.js | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js index 73ca80df..bf74cfb5 100644 --- a/src/main/assets/scripts.js +++ b/src/main/assets/scripts.js @@ -514,20 +514,15 @@ function addTag(tag) { var users = {}; -/** - * Fetch ActivityPub user profile info - * - * @param {string} dataUri user URI - * @param {*} callback callback - */ function fetchUserUri(dataUri, callback) { if (users[dataUri]) { callback(users[dataUri]); } else { - fetch(dataUri, { - headers: { - 'Accept': 'application/ld+json' - } + let data = new FormData(); + data.append('uri', dataUri); + fetch('/u/', { + method: 'POST', + body: data }).then(handleErrors) .then(response => { return response.json(); @@ -753,23 +748,19 @@ ready(() => { if (dataUri) { setTimeout(() => fetchUserUri(dataUri, user => { let header = el.closest('.msg-header'); - if (header) { - Array.from(header.querySelectorAll('.a-username')).forEach(a => { - a.setAttribute('href', dataUri); - let img = a.querySelector('img'); - if (img && user.icon) { - img.setAttribute('src', user.icon.url); - img.setAttribute('alt', user.preferredUsername); - } - let textNode = a.childNodes[0]; - if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue && textNode.nodeValue.trim().length > 0) { - let uname = document.createTextNode(user.preferredUsername || dataUri); - if (a.firstChild) { - a.replaceChild(uname, a.firstChild); - } - } - }); - } + Array.from(header.querySelectorAll('.a-username')).forEach(a => { + a.setAttribute('href', user.uri); + let img = a.querySelector('img'); + if (img && user.avatar) { + img.setAttribute('src', user.avatar); + img.setAttribute('alt', user.uname); + } + let textNode = a.childNodes[0]; + if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { + let uname = document.createTextNode(user.uname); + a.replaceChild(uname, a.firstChild); + } + }); }), 100); } }); @@ -778,11 +769,9 @@ ready(() => { if (dataUri) { setTimeout(() => fetchUserUri(dataUri, user => { let textNode = el.childNodes[0]; - if (textNode && textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue && textNode.nodeValue.trim().length > 0) { - let uname = document.createTextNode(`@${user.preferredUsername}`); - if (el.firstChild) { - el.replaceChild(uname, el.firstChild); - } + if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { + let uname = document.createTextNode(`@${user.uname}`); + el.replaceChild(uname, el.firstChild); } }), 100); } |