aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-07-10 20:24:06 +0300
committerGravatar Vitaly Takmazov2022-07-10 20:24:06 +0300
commita999bbb93bc6d2e15f7edfcccc590b83eee3c8ca (patch)
tree9e474baac7085d88842de028a7d4130b140fcd56 /src/main
parent9f169dea843c13dc234d554bef51b3c98131587b (diff)
Fetch ActivityPub profiles directly without our proxy
* Profiles were fetched through proxy because of CORS issues in Mastodon, now issues are solved
Diffstat (limited to 'src/main')
-rw-r--r--src/main/assets/scripts.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js
index 87fdf7a4..00d7d616 100644
--- a/src/main/assets/scripts.js
+++ b/src/main/assets/scripts.js
@@ -517,15 +517,20 @@ 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 {
- let data = new FormData();
- data.append('uri', dataUri);
- fetch('/u/', {
- method: 'POST',
- body: data
+ fetch(dataUri, {
+ headers: {
+ 'Accept': 'application/ld+json'
+ }
}).then(handleErrors)
.then(response => {
return response.json();
@@ -736,15 +741,15 @@ ready(() => {
setTimeout(() => fetchUserUri(dataUri, user => {
let header = el.closest('.msg-header');
Array.from(header.querySelectorAll('.a-username')).forEach(a => {
- a.setAttribute('href', user.uri);
+ a.setAttribute('href', dataUri);
let img = a.querySelector('img');
- if (img && user.avatar) {
- img.setAttribute('src', user.avatar);
- img.setAttribute('alt', user.uname);
+ if (img && user.icon) {
+ img.setAttribute('src', user.icon.url);
+ img.setAttribute('alt', user.preferredUsername);
}
let textNode = a.childNodes[0];
if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) {
- let uname = document.createTextNode(user.uname);
+ let uname = document.createTextNode(user.preferredUsername);
a.replaceChild(uname, a.firstChild);
}
});
@@ -757,7 +762,7 @@ ready(() => {
setTimeout(() => fetchUserUri(dataUri, user => {
let textNode = el.childNodes[0];
if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) {
- let uname = document.createTextNode(`@${user.uname}`);
+ let uname = document.createTextNode(`@${user.preferredUsername}`);
el.replaceChild(uname, el.firstChild);
}
}), 100);