get pull a user's public posts, we just need to fill the dom with the data
This commit is contained in:
parent
cae8c8b597
commit
51bd3a6505
7 changed files with 98 additions and 11 deletions
65
frontend/ts/author-messages-element.ts
Normal file
65
frontend/ts/author-messages-element.ts
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { Author, Message } from "./message"
|
||||
import util from "./util"
|
||||
import { BatchTimer } from "./batch-timer"
|
||||
import { AdapterState } from "./adapter"
|
||||
|
||||
export class AuthorMessagesElement extends HTMLElement {
|
||||
static observedAttributes = [ "data-latest", "data-adapter", "data-target" ];
|
||||
|
||||
private _id: string | null = null;
|
||||
private _adapter: string = "";
|
||||
|
||||
private _messages: Message[] = [];
|
||||
private _byAuthorTimer: BatchTimer | null = null;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.innerHTML = "<ul class='author_msglist'></ul>"
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this._id = this.getAttribute("data-target");
|
||||
this._adapter = this.getAttribute("data-adapter") ?? "";
|
||||
const gateway = this.getAttribute("data-gateway") ?? "";
|
||||
this._byAuthorTimer = new BatchTimer((ids: string[])=>{
|
||||
let url = `${gateway}/api/adapters/${this._adapter}/fetch?entity_type=byAuthor`;
|
||||
for (let id of ids) {
|
||||
url += `&entity_id=${id}`;
|
||||
}
|
||||
util.authorizedFetch("GET", url, null);
|
||||
});
|
||||
}
|
||||
|
||||
attributeChangedCallback(attr: string, prev: string, next: string) {
|
||||
switch (attr) {
|
||||
case "data-target":
|
||||
if (!next) {
|
||||
return
|
||||
}
|
||||
this._id = next;
|
||||
if (this._byAuthorTimer) {
|
||||
this._byAuthorTimer.queue(next, 100)
|
||||
}
|
||||
break;
|
||||
case "data-latest":
|
||||
let datastore = AdapterState._instance.data.get(this._adapter);
|
||||
if (!datastore) {
|
||||
console.log("no data yet, wait for some to come in maybe...");
|
||||
return;
|
||||
}
|
||||
let msg = datastore.messages.get(next);
|
||||
if (msg) {
|
||||
// if _messages has this one, and this updated date is greater
|
||||
const existingIdx = this._messages.findIndex(m=>m.id == msg.id && ((m.edited ?? 0) < (msg.edited ?? 0)));
|
||||
if (existingIdx >= 0) {
|
||||
this._messages[existingIdx] = msg;
|
||||
// and update it in the dom
|
||||
} else {
|
||||
this._messages.push(msg);
|
||||
// and insert in into the dom
|
||||
}
|
||||
console.log(JSON.stringify(this._messages));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import { SettingsElement } from "./settings-element"
|
|||
import { AdapterElement } from "./adapter-element"
|
||||
import { ThreadSummaryElement } from "./thread-summary-element"
|
||||
import { ProfileElement } from "./profile-element"
|
||||
import { AuthorMessagesElement } from "./author-messages-element"
|
||||
import {DatagramSocket} from "./websocket"
|
||||
|
||||
function main() {
|
||||
|
@ -20,6 +21,7 @@ function main() {
|
|||
customElements.define("underbbs-adapter", AdapterElement);
|
||||
customElements.define("underbbs-thread-summary", ThreadSummaryElement);
|
||||
customElements.define("underbbs-profile", ProfileElement);
|
||||
customElements.define("underbbs-author-messages", AuthorMessagesElement);
|
||||
|
||||
util._("closeErr", util.closeErr);
|
||||
let settingsParent = util.$("settings_parent");
|
||||
|
@ -31,6 +33,11 @@ function main() {
|
|||
if (profileParent) {
|
||||
profileParent.innerHTML = "<underbbs-profile data-adapter='honk' data-target='https://cafe.nilfm.cc/u/nilix'></underbbs-profile>"
|
||||
}
|
||||
|
||||
let honksParent = util.$("honks_parent");
|
||||
if (honksParent) {
|
||||
honksParent.innerHTML = "<underbbs-author-messages data-adapter='honk' data-target='https://cafe.nilfm.cc/u/nilix'></underbbs-author-messages>";
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
@ -2,19 +2,26 @@ import util from "./util"
|
|||
var _ = util._
|
||||
|
||||
export class MessageElement extends HTMLElement {
|
||||
static observedAttributes = [ "data-id", "data-adapter", "data-replyCt", "data-reactionCt", "data-boostCt" ]
|
||||
static observedAttributes = [ "data-target", "data-latest", "data-adapter", "data-replyCt", "data-reactionCt", "data-boostCt" ]
|
||||
|
||||
private _id: string | null = null;
|
||||
private _adapter: any;
|
||||
private _adapter: string | null = null;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this._id = this.getAttribute("data-id");
|
||||
this._adapter = _("settings").adapters.filter((a: any)=>a.nickname == this.getAttribute("data-adapter"))[0];
|
||||
this._id = this.getAttribute("data-target");
|
||||
this._adapter = this.getAttribute("data-adapter");
|
||||
|
||||
// grab message content from the store and format our innerHTML
|
||||
}
|
||||
|
||||
attributeChangedCallback(attr: string, prev: string, next: string) {
|
||||
switch (attr) {
|
||||
case "data-target":
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import { BatchTimer } from "./batch-timer"
|
|||
import { AdapterState } from "./adapter"
|
||||
|
||||
export class ProfileElement extends HTMLElement {
|
||||
static observedAttributes = [ "data-latest", "data-adapter", "data-target" ]
|
||||
static observedAttributes = [ "data-latest", "data-adapter", "data-target" ];
|
||||
|
||||
private _id: string | null = null;
|
||||
private _adapter: string = "";
|
||||
|
@ -42,7 +42,6 @@ export class ProfileElement extends HTMLElement {
|
|||
}
|
||||
this._id = next;
|
||||
if (this._authorTimer) {
|
||||
|
||||
this._authorTimer.queue(next, 100);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -116,7 +116,7 @@ export class SettingsElement extends HTMLElement {
|
|||
break;
|
||||
case "honk":
|
||||
const handle = (util.$("settings_newadapter_honk_handle") as HTMLInputElement)?.value ?? "";
|
||||
const password = (util.$("settings_newadapter_honk_password") as HTMLInputElement)?.value ?? "";
|
||||
const password = (util.$("settings_newadapter_honk_password") as HTMLInputElement)?.value || null;
|
||||
adapterdata = { nickname: nickname, protocol: proto.options[proto.selectedIndex].value, handle: handle, password: password };
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,11 @@ export class DatagramSocket {
|
|||
const target = p.getAttribute("data-target");
|
||||
p.setAttribute("data-target", target ?? "");
|
||||
});
|
||||
const feeds = document.querySelectorAll("underbbs-author-messages");
|
||||
feeds.forEach(f=>{
|
||||
const target = f.getAttribute("data-target");
|
||||
f.setAttribute("data-target", target ?? "");
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
|
@ -53,9 +58,13 @@ export class DatagramSocket {
|
|||
}
|
||||
}
|
||||
console.log(store);
|
||||
// now search for any components with this adapter and target
|
||||
let targets = document.querySelectorAll(`*[data-adapter="${data.adapter}"][data-target="${data.id}"]`);
|
||||
targets.forEach(t=>{
|
||||
// go through each type of component and give it the latest if it's relevant to them
|
||||
let profileTargets = document.querySelectorAll(`underbbs-profile[data-adapter="${data.adapter}"][data-target="${data.id}"]`);
|
||||
profileTargets.forEach(t=>{
|
||||
t.setAttribute("data-latest", data.id);
|
||||
});
|
||||
let byAuthorTargets = document.querySelectorAll(`underbbs-author-messages[data-adapter="${data.adapter}"][data-target="${data.author}"]`);
|
||||
byAuthorTargets.forEach(t=>{
|
||||
t.setAttribute("data-latest", data.id);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ type Datagram struct {
|
|||
Type string `json:"type"`
|
||||
Target *string `json:"target,omitempty"`
|
||||
Created int64 `json:"created"`
|
||||
Updated *int64 `json:"updated,omitempty"`
|
||||
Updated *int64 `json:"edited,omitempty"`
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
|
|
Loading…
Reference in a new issue