From 354988a7078a54bccf8afc8b49d3a178ae42789f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 24 Dec 2022 03:27:37 +0300 Subject: Revert "Fetch ActivityPub profiles directly without our proxy" This reverts commit a999bbb93bc6d2e15f7edfcccc590b83eee3c8ca. # Conflicts: # src/main/assets/scripts.js --- src/main/assets/scripts.js | 53 ++++++++++++++++++---------------------------- 1 file 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); } -- cgit v1.2.3