all repos — underbbs @ c03fbd7950f214c640fa5f6dff520a136abc5ba7

decentralized social media client

index view kinda working
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZoeDbAAKCRBohAcXSWbK
80IwAQDXAHR2WdKzne3Kl/RYYf288aEGyIjTgtvGZoelJfUmkAD/eFiINhd7kXFJ
QLMILcN0Ql6dKxbIY3qFh+S0+Yk1Mw0=
=csrD
-----END PGP SIGNATURE-----
commit

c03fbd7950f214c640fa5f6dff520a136abc5ba7

parent

fd2abcbb76e9e70883e86e29b93a3f0b24e08f29

4 files changed, 66 insertions(+), 54 deletions(-)

jump to
M ts/adapter-element.tsts/adapter-element.ts

@@ -24,8 +24,9 @@

connectedCallback() { const name = this.getAttribute("data-name"); this._name = name ?? ""; + this._view = ""; this.buildThreads(); - this.attributeChangedCallback(); + this.setAttribute("data-view", "index"); } attributeChangedCallback() {

@@ -43,9 +44,10 @@ }

// initialize the view if it's changed const view = this.getAttribute("data-view"); - if (this._view != view) { + if (this._view != view ?? "index") { console.log("view changed! let's go") - this._view = view ?? ""; + this._view = view ?? "index"; + console.log(this._view); switch (this._view) { case "index": this.setIdxView();

@@ -127,11 +129,11 @@ // skip dm list for now

// public/unified list const pl = $("public_list"); if (pl) { - console.log(JSON.stringify(this._threads)); + let html = ""; for (const t of this._threads) { - console.log(t.root.data.id); - pl.append(`<li><underbbs-thread-summary data-len="${t.messageCount}" data-adapter="${t.root.data.adapter}" data-msg="${t.root.data.id}" data-latest="${t.latest}" data-created="${t.created}" data-new=""></underbbs-thread-summary></li>`); + html +=`<li><underbbs-thread-summary data-len="${t.messageCount}" data-adapter="${t.root.data.adapter}" data-msg="${t.root.data.id}" data-created="${t.created}"></underbbs-thread-summary></li>`; } + pl.innerHTML = html; } }

@@ -158,31 +160,32 @@ populateProfileView() {

} buildThreads() { + console.log("building threads for " + this._name); const datastore = _("datastore")[this._name]; // make multiple passes over the store until every message is either // placed in a thread, or orphaned and waiting for its parent to be returned do{ + console.log("making a pass at all the messages"); for (let k of datastore.messages.keys()) { this.placeMsg(k); } } while (this._threads.reduce((sum: number, thread: MessageThread)=>{ return sum + thread.messageCount; }, 0) + this._orphans.length < datastore.messages.keys().length) + console.log("all messages have been placed"); + console.log(JSON.stringify(this._threads)); } placeMsg(k: string): string | null { const msg = _("datastore")[this._name].messages.get(k); - if (msg.replyTo) { - for (let t of this._threads) { - // avoid processing nodes again on subsequent passes - if (t.findNode(t.root, msg.id)) { - return null; - } - - let x = t.findNode(t.root, msg.replyTo); + for (let t of this._threads) { + // avoid processing nodes again on subsequent passes + if (t.findNode(t.root, msg.id)) { + return null; + } + if (msg.replyTo) { + let x = t.addReply(msg.replyTo, msg); if (x) { - t.addReply(msg.replyTo, msg); - // after adding, we try to adopt some orphans const orphanChildren = this._orphans.filter(m=>m.replyTo == k); for (let o of orphanChildren) {

@@ -192,17 +195,23 @@ this._orphans.splice(this._orphans.indexOf(o), 1);

} } return t.root.data.id; - } - } - if (this._orphans.filter(o=>o.id == msg.id).length == 0) { - this._orphans.push(msg); - // TODO: request the parent's data - } - return null; - } else { + } + } + } + // if we made it this far, this message doesn't go in any existing thread + + // if it doesn't have a parent, we can make a new thread with it + if (!msg.replyTo) { this._threads.push(new MessageThread(msg)); - return k; + return msg.id; } + + // otherwise we can orphan it and try to fill it in later + if (this._orphans.filter(o=>o.id == msg.id).length == 0) { + this._orphans.push(msg); + // TODO: request the parent's data + } + return null; }
M ts/tabbar-element.tsts/tabbar-element.ts

@@ -76,7 +76,7 @@ showAdapterFunc(self: TabBarElement, adapter: string): ()=>void {

return ()=>{ let x = $("mainarea_injectparent"); if (x) { - x.innerHTML = `<underbbs-adapter id="adapter_${adapter}" data-name="${adapter}" data-view="index"></underbbs-adapter>`; + x.innerHTML = `<underbbs-adapter id="adapter_${adapter}" data-name="${adapter}"></underbbs-adapter>`; self.setAttribute("data-currentadapter", adapter); } }
M ts/thread-summary-element.tsts/thread-summary-element.ts

@@ -4,7 +4,7 @@ var _ = util._

var $ = util.$ export class ThreadSummaryElement extends HTMLElement { - static observedAttributes = [ "data-len", "data-msg", "data-author", "data-latest", "data-created", "data-new" ]; + static observedAttributes = [ "data-len", "data-author", "data-latest", "data-new" ]; private _len: number = 0;; private _msg: Message | null = null;;

@@ -32,7 +32,7 @@

attributeChangedCallback() { const datastore = _("datastore")[this._adapter]; const msgId = this.getAttribute("data-msg"); - if (msgId && datastore && ((this._msg && this._msg.id != msgId) || !this._msg)) { + if (msgId && datastore && !this._msg) { this._msg = datastore.messages.get(msgId); if (this._msg) { const threadText = this.querySelector(".thread_text");

@@ -47,25 +47,26 @@ this._author = author || <Author>{ id: this._msg.author };

const threadAuthor = this.querySelector(".thread_author"); if (threadAuthor && this._author) { threadAuthor.innerHTML = this._author.profilePic - ? `<img src="${this._author.profilePic}" alt="${this._author.id}"/> <a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}>${this._author.id}</a>` - : `<a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}>${this._author.id}</a>`; + ? `<img src="${this._author.profilePic}" alt="${this._author.id}"/> <a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}">${this._author.id}</a>` + : `<a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}">${this._author.id}</a>`; } - + } + } - const authorId = this.getAttribute("data-author"); - if (authorId) { - let author = datastore?.profileCache?.get(this._msg?.author); - if (author) { - this._author = author; - const threadAuthor = this.querySelector(".thread_author"); - if (threadAuthor && this._author) { - threadAuthor.innerHTML = this._author.profilePic - ? `<img src="${this._author.profilePic}" alt="${this._author.id}"/> <a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}>${this._author.id}</a>` - : `<a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${author.id}>${this._author.id}</a>` ; - } - } + // update author if it's passed in the attribute + const authorId = this.getAttribute("data-author"); + if (authorId) { + let author = datastore?.profileCache?.get(this._msg?.author); + if (author) { + this._author = author; + const threadAuthor = this.querySelector(".thread_author"); + if (threadAuthor && this._author && this._msg) { + threadAuthor.innerHTML = this._author.profilePic + ? `<img src="${this._author.profilePic}" alt="${this._author.id}"/> <a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${this._author.id}>${this._author.id}</a>` + : `<a id="thread_${this._adapter}_${this._msg.id}_${this._author.id}" href="#author?id=${author.id}>${this._author.id}</a>` ; } - } } + } + } const l = parseInt(this.getAttribute("data-len") ?? "0"); const latest = new Date(this.getAttribute("data-latest") ?? 0);

@@ -74,18 +75,20 @@ const newness = this.getAttribute("data-new") ? true : false;

let metadataChanged = false; - if (l != this._len) { + if (l && l != this._len) { metadataChanged = true; this._len = l; } - if (latest != this._latest) { + if (created && created != this._created) { metadataChanged = true; - this._latest = latest; + this._created = created; + this._latest = created; } - if (created != this._created) { + if (latest && latest != this._latest) { metadataChanged = true; - this._created = created; + this._latest = latest; } + if (newness != this._new) { metadataChanged = true; this._new = newness;

@@ -97,8 +100,7 @@ if (threadMeta) {

threadMeta.innerHTML = `<span>${this._new ? "!" : ""}[${this._len}] created: ${this._created}, updated: ${this._latest}</span>`; } } - } - + } viewThread(self: ThreadSummaryElement) { return () => { const a = $(`adapter_${self._adapter}`);
M ts/thread.tsts/thread.ts

@@ -38,16 +38,18 @@ this.created = first.created;

this.latest = first.edited ? first.edited : first.created; } - addReply(parentID: string, reply: Message) { + addReply(parentID: string, reply: Message): boolean { let node = this.findNode(this.root, parentID); if (node) { node.children.push(new MessageNode(reply, node)); this.messageCount++; const mtime = reply.edited ? reply.edited : reply.created; - if (this.latest < mtime) { + if (this.latest.getTime() < mtime.getTime()) { this.latest = mtime; } + return true; } + return false; } findNode(node: MessageNode, id: string): MessageNode | null {

@@ -55,7 +57,6 @@ if (node.data.id == id) {

return node; } else { for (let n of node.children) { - console.log("descending through children...") const x = this.findNode(n, id); if (x != null) { return x;