This commit is contained in:
parent
949a226b59
commit
b5975949f4
1 changed files with 10 additions and 7 deletions
|
@ -119,16 +119,18 @@ class FediSocial extends HTMLElement {
|
||||||
|
|
||||||
customElements.define('fedi-social', FediSocial)
|
customElements.define('fedi-social', FediSocial)
|
||||||
|
|
||||||
function renderReplies(status, replies, replyContainer, template) {
|
function renderReplies(status, replies, replyContainer, template, sharingUrl) {
|
||||||
const repliesToThis = replies.filter(d => d.in_reply_to_id == status.id);
|
const repliesToThis = replies.filter(d => d.in_reply_to_id == status.id);
|
||||||
|
|
||||||
repliesToThis.forEach(reply => {
|
repliesToThis.forEach(reply => {
|
||||||
const article = template.content.cloneNode(true);
|
const article = template.content.cloneNode(true);
|
||||||
|
|
||||||
|
const permalink = sharingUrl ? sharingUrl.replace("{uri}", reply.uri) : reply.url
|
||||||
|
|
||||||
article.querySelector('.avatar').src = reply.account.avatar
|
article.querySelector('.avatar').src = reply.account.avatar
|
||||||
article.querySelector('a.name').href = reply.account.url
|
article.querySelector('a.name').href = reply.account.url
|
||||||
article.querySelector('.name').innerText = reply.account.display_name
|
article.querySelector('.name').innerText = reply.account.display_name
|
||||||
article.querySelector('a.permalink').href = reply.url
|
article.querySelector('a.permalink').href = permalink
|
||||||
article.querySelector('time.dt-published').datetime = reply.created_at
|
article.querySelector('time.dt-published').datetime = reply.created_at
|
||||||
article.querySelector('time.dt-published').innerText = luxon.DateTime.fromISO(reply.created_at).toRelative()
|
article.querySelector('time.dt-published').innerText = luxon.DateTime.fromISO(reply.created_at).toRelative()
|
||||||
|
|
||||||
|
@ -149,7 +151,8 @@ function renderReplies(status, replies, replyContainer, template) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
article.querySelector('a.source').href = reply.url
|
article.querySelector('a.source').href = permalink
|
||||||
|
article.querySelectorAll('.fedi-social a').forEach(a => a.href = permalink)
|
||||||
article.querySelector('.application').innerText = reply.application.name
|
article.querySelector('.application').innerText = reply.application.name
|
||||||
article.querySelector('.replies-count').innerText = reply.replies_count
|
article.querySelector('.replies-count').innerText = reply.replies_count
|
||||||
article.querySelector('.favourites-count').innerText = reply.favourites_count
|
article.querySelector('.favourites-count').innerText = reply.favourites_count
|
||||||
|
@ -158,7 +161,7 @@ function renderReplies(status, replies, replyContainer, template) {
|
||||||
if(reply.replies_count > 0) {
|
if(reply.replies_count > 0) {
|
||||||
const section = document.createElement('section')
|
const section = document.createElement('section')
|
||||||
section.classList.add('replies')
|
section.classList.add('replies')
|
||||||
renderReplies(reply, replies, section, template)
|
renderReplies(reply, replies, section, template, sharingUrl)
|
||||||
article.querySelector('article').appendChild(section)
|
article.querySelector('article').appendChild(section)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +169,7 @@ function renderReplies(status, replies, replyContainer, template) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadContext(status, replyContainer, template) {
|
async function loadContext(status, replyContainer, template, sharingUrl) {
|
||||||
try{
|
try{
|
||||||
const res = await fetch(`https://monrepos.casa/api/v1/statuses/${status.id}/context`, {
|
const res = await fetch(`https://monrepos.casa/api/v1/statuses/${status.id}/context`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -180,7 +183,7 @@ async function loadContext(status, replyContainer, template) {
|
||||||
h1.innerText = "Replies"
|
h1.innerText = "Replies"
|
||||||
replyContainer.appendChild(h1)
|
replyContainer.appendChild(h1)
|
||||||
|
|
||||||
renderReplies(status, json.descendants, replyContainer, template)
|
renderReplies(status, json.descendants, replyContainer, template, sharingUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(ex){
|
catch(ex){
|
||||||
|
@ -222,7 +225,7 @@ function fediverse() {
|
||||||
|
|
||||||
const replyContainer = document.getElementById('fedi-social-replies')
|
const replyContainer = document.getElementById('fedi-social-replies')
|
||||||
const template = document.getElementById('fedi-social-reply')
|
const template = document.getElementById('fedi-social-reply')
|
||||||
if(replyContainer && template && status.replies_count > 0) loadContext(status, replyContainer, template)
|
if(replyContainer && template && status.replies_count > 0) loadContext(status, replyContainer, template, data.template)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(ex){
|
catch(ex){
|
||||||
|
|
Loading…
Reference in a new issue