Thread viewer for Bluesky
at master 2.1 kB view raw
1class NotificationsPage { 2 3 constructor() { 4 this.pageElement = $id('thread'); 5 } 6 7 show() { 8 document.title = `Notifications - Skythread`; 9 showLoader(); 10 11 let isLoading = false; 12 let firstPageLoaded = false; 13 let finished = false; 14 let cursor; 15 16 Paginator.loadInPages((next) => { 17 if (isLoading || finished) { return; } 18 isLoading = true; 19 20 accountAPI.loadMentions(cursor).then(data => { 21 let posts = data.posts.map(x => new Post(x)); 22 23 if (posts.length > 0) { 24 if (!firstPageLoaded) { 25 hideLoader(); 26 firstPageLoaded = true; 27 28 let header = $tag('header'); 29 let h2 = $tag('h2', { text: "Replies & Mentions:" }); 30 header.append(h2); 31 32 this.pageElement.appendChild(header); 33 this.pageElement.classList.add('notifications'); 34 } 35 36 for (let post of posts) { 37 if (post.parentReference) { 38 let p = $tag('p.back'); 39 p.innerHTML = `<i class="fa-solid fa-reply"></i> `; 40 41 let { repo, rkey } = atURI(post.parentReference.uri); 42 let url = linkToPostById(repo, rkey); 43 let parentLink = $tag('a', { href: url }); 44 p.append(parentLink); 45 46 if (repo == accountAPI.user.did) { 47 parentLink.innerText = 'Reply to you'; 48 } else { 49 parentLink.innerText = 'Reply'; 50 api.fetchHandleForDid(repo).then(handle => { 51 parentLink.innerText = `Reply to @${handle}`; 52 }); 53 } 54 55 this.pageElement.appendChild(p); 56 } 57 58 let postView = new PostComponent(post, 'feed').buildElement(); 59 this.pageElement.appendChild(postView); 60 } 61 } 62 63 isLoading = false; 64 cursor = data.cursor; 65 66 if (!cursor) { 67 finished = true; 68 } else if (posts.length == 0) { 69 next(); 70 } 71 }).catch(error => { 72 hideLoader(); 73 console.log(error); 74 isLoading = false; 75 }); 76 }); 77 } 78}