start implementing boost carousel
This commit is contained in:
parent
7a2eb99eb6
commit
09c7eb8318
6 changed files with 37 additions and 7 deletions
|
@ -216,6 +216,7 @@ func (self *MisskeyAdapter) toMessage(n mkm.Note, bustCache bool) *Message {
|
|||
ReplyTo: n.ReplyID,
|
||||
ReplyCount: int(n.RepliesCount),
|
||||
Replies: []string{},
|
||||
RenoteId: (*string)(n.RenoteID),
|
||||
}
|
||||
|
||||
for _, f := range n.Files {
|
||||
|
|
|
@ -24,6 +24,7 @@ export class AdapterElement extends HTMLElement {
|
|||
// TODO: use visibility of the thread to organize into DMs and public threads
|
||||
private _threads: MessageThread[] = [];
|
||||
private _orphans: Message[] = [];
|
||||
private _boosts: Message[] = [];
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -102,6 +103,7 @@ export class AdapterElement extends HTMLElement {
|
|||
tse.setAttribute("data-author", this._latest);
|
||||
}
|
||||
}
|
||||
// also update any boosts by this author
|
||||
case "thread":
|
||||
case "profile":
|
||||
break;
|
||||
|
@ -113,7 +115,7 @@ export class AdapterElement extends HTMLElement {
|
|||
}
|
||||
|
||||
setIdxView() {
|
||||
this.innerHTML = "<ul id='dm_list'></ul><ul id='public_list'></ul>"
|
||||
this.innerHTML = "<ul id='boost_carousel'></ul><ul id='dm_list'></ul><ul id='public_list'></ul>"
|
||||
}
|
||||
|
||||
setThreadView() {
|
||||
|
@ -132,6 +134,8 @@ export class AdapterElement extends HTMLElement {
|
|||
}
|
||||
|
||||
populateIdxView() {
|
||||
// populate boost carousel
|
||||
|
||||
// skip dm list for now
|
||||
// public/unified list
|
||||
const pl = util.$("public_list");
|
||||
|
@ -149,11 +153,12 @@ export class AdapterElement extends HTMLElement {
|
|||
const existingThread = document.querySelector(threadSelector);
|
||||
const thread = this._threads.find(t=>t.root.data.id == rootId);
|
||||
if (existingThread && thread) {
|
||||
debugger;
|
||||
existingThread.setAttribute("data-latest", `${thread.latest}`);
|
||||
existingThread.setAttribute("data-len", `${thread.messageCount}`);
|
||||
existingThread.setAttribute("data-new", "true");
|
||||
} else {
|
||||
// if latest is a boost, put it in the carousel
|
||||
|
||||
// unified/public list for now
|
||||
const pl = util.$("public_list");
|
||||
if (pl && thread) {
|
||||
|
@ -190,14 +195,14 @@ export class AdapterElement extends HTMLElement {
|
|||
return;
|
||||
}
|
||||
// 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
|
||||
// placed in a thread, the boost carousel, or orphaned and waiting for its parent to be returned
|
||||
do{
|
||||
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.size);
|
||||
}, 0) + this._boosts.length + this._orphans.length < datastore.messages.size);
|
||||
}
|
||||
|
||||
placeMsg(k: string): string | null {
|
||||
|
@ -211,11 +216,20 @@ export class AdapterElement extends HTMLElement {
|
|||
util.errMsg(`message [${this._name}:${k}] doesn't exist`);
|
||||
return null;
|
||||
}
|
||||
if (msg.renoteId) {
|
||||
// fetch the referent thread and put the boost in the carousel
|
||||
this._convoyBatchTimer.queue(msg.renoteId, 2000);
|
||||
if (!this._boosts.some(m=>m.id == msg.id)) {
|
||||
this._boosts.push(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
for (let t of this._threads) {
|
||||
// avoid processing nodes again on subsequent passes
|
||||
if (!msg || t.findNode(t.root, msg.id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (msg.replyTo) {
|
||||
let x = t.addReply(msg.replyTo, msg);
|
||||
if (x) {
|
||||
|
|
14
frontend/ts/boost-tile-element.ts
Normal file
14
frontend/ts/boost-tile-element.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export class BoostTileElement extends HTMLElement {
|
||||
|
||||
static observedAttributes = [ "data-boostid", "data-msgid", "data-author", "data-booster" ];
|
||||
|
||||
constructor() {
|
||||
this.innerHTML = "<div class='boost_booster'></div><div class='boost_author'></div><div class='boost_content'></div>";
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
}
|
||||
|
||||
attributeChangedCallback(attr: string, prev: string, next: string) {
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ export class Message {
|
|||
public created: number = 0;
|
||||
public edited: number | null = null;
|
||||
public visibility: string = "public";
|
||||
public renoteId: string | null = null;
|
||||
}
|
||||
|
||||
export class Author {
|
||||
|
|
|
@ -58,13 +58,12 @@ export class DatagramSocket {
|
|||
}
|
||||
|
||||
static connect(): void {
|
||||
|
||||
|
||||
|
||||
const wsProto = location.protocol == "https:" ? "wss" : "ws";
|
||||
const _conn = new WebSocket(`${wsProto}://${location.host}/subscribe`, "underbbs");
|
||||
|
||||
_conn.addEventListener("open", DatagramSocket.onOpen);
|
||||
_conn.addEventListener("message", DatagramSocket.onMsg);
|
||||
|
||||
_conn.addEventListener("error", (e: any) => {
|
||||
console.log("websocket connection error");
|
||||
console.log(JSON.stringify(e));
|
||||
|
|
|
@ -25,6 +25,7 @@ type Message struct {
|
|||
ReplyCount int `json:"replyCount"`
|
||||
Mentions []string `json:"mentions"`
|
||||
Visibility string `json:"visibility"`
|
||||
RenoteId *string `json:"renoteId,omitempty"`
|
||||
}
|
||||
|
||||
type Author struct {
|
||||
|
|
Loading…
Reference in a new issue