diff options
author | Vitaly Takmazov | 2022-12-24 03:27:37 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-12-24 03:27:37 +0300 |
commit | 354988a7078a54bccf8afc8b49d3a178ae42789f (patch) | |
tree | 570b767d21fd2eae7c55fa89f44a9e49d216c7e1 | |
parent | 9d02035a13bbdb69c62b9447e5c5c4cfbffd8049 (diff) |
Revert "Fetch ActivityPub profiles directly without our proxy"
This reverts commit a999bbb93bc6d2e15f7edfcccc590b83eee3c8ca.
# Conflicts:
# 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); } |