mastodon_algorithm_frontend/js/suggestions.js

43 lines
1.5 KiB
JavaScript

import {client, databases, accountDetails} from "./setup.js";
document.querySelectorAll('.mastodon_server').forEach((element) => {
element.innerHTML = accountDetails.prefs.user_server_uri
});
document.querySelectorAll('.mastodon_user').forEach((element) => {
element.innerHTML = JSON.parse(accountDetails.prefs.account_details).acct
});
let suggestions = await databases.listDocuments(APPWRITE_DB_ID, 'suggested', [
Appwrite.Query.orderDesc('points')
]);
suggestions = suggestions.documents;
function display_suggestions(suggestions) {
let suggestion_body = '';
suggestions.forEach(element => {
suggestion_body += '<iframe src="' + element.post_link + '/embed" class=\"mastodon-embed\" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><br>';
suggestion_body += '<a href="' + element.local_link + '" target="blank">View on your homeserver - ' + element.points + ' points</a><br><br>';
});
if(suggestion_body !== '') {
document.getElementById('suggestions').innerHTML = suggestion_body;
}
}
display_suggestions(suggestions);
console.log(suggestions);
client.subscribe('databases.' + APPWRITE_DB_ID + '.collections.suggested.documents', async (response) => {
// suggestions.push(response.payload);
let suggestions = await databases.listDocuments(APPWRITE_DB_ID, 'suggested', [
Appwrite.Query.orderDesc('points')
]);
suggestions = suggestions.documents;
display_suggestions(suggestions);
});