fix boosts for anon AP/honk

This commit is contained in:
Iris Lightshard 2024-12-03 23:44:11 -07:00
parent 5b20ff3135
commit a053406fc5
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
6 changed files with 32 additions and 29 deletions

View file

@ -286,36 +286,24 @@ func (self *anonAPAdapter) Fetch(etype string, ids []string) error {
if err != nil {
return err
}
fmt.Println(a.Object)
objectData := getBodyJson(res)
object := apObject{}
json.Unmarshal(objectData, &object)
ogMsg := self.toMsg(object)
if ogMsg != nil {
self.send(ogMsg)
}
// if we couldn't fetch the original, skip it
if ogMsg != nil && ogMsg.Author != "" {
t, err := time.Parse(time.RFC3339, a.Published)
if err != nil {
t = time.Now()
}
vis := strings.Split(a.To, "#")
if len(vis) > 1 {
a.To = vis[1]
rt := t.UnixMilli()
ogMsg.RenoteId = &a.Id
ogMsg.Renoter = &a.Actor
ogMsg.RenoteTime = &rt
self.send(ogMsg)
}
boostMsg := models.Message{
Datagram: models.Datagram{
Id: a.Id,
Uri: a.Id,
Protocol: self.protocol,
Adapter: self.nickname,
Type: "message",
Created: t.UnixMilli(),
},
Author: a.Actor,
RenoteId: &ogMsg.Id,
Visibility: a.To,
}
self.send(boostMsg)
}
}
// for each item in outbox, check if it's a Create/Update or an Announce

View file

@ -49,12 +49,12 @@ export class AuthorMessagesElement extends HTMLElement {
}
let msg = datastore.messages.get(next);
if (msg) {
const existingIdx = this._messages.findIndex(m=>m.id == msg.id && ((m.edited ?? m.created) < (msg.edited ?? msg.created)));
const existingIdx = this._messages.findIndex(m=>(m.renoteId ?? m.id) == (msg.renoteId ?? msg.id) && ((m.edited ?? m.created) < (msg.edited ?? msg.created)));
// first we update the backing data store
if (existingIdx >= 0) {
this._messages[existingIdx] = msg;
} else if (!this._messages.some(m=>m.id == msg.id)) {
} else if (!this._messages.some(m=>(m.renoteId ?? m.id) == (msg.renoteId ?? msg.id))) {
this._messages.push(msg);
}
@ -64,7 +64,7 @@ export class AuthorMessagesElement extends HTMLElement {
// first pass through the dom, try to update a message if it's there
for (let i = 0; i < ul.childElementCount; i++){
const id = ul.children[i]?.children[0]?.getAttribute("data-target");
const ogMsg = this._messages.find(m=>m.id == id);
const ogMsg = this._messages.find(m=>(m.renoteId ?? m.id) == id);
if (ogMsg && existingIdx >= 0) {
ul.children[i]?.children[0]?.setAttribute("data-latest", id ?? "");
return;
@ -77,8 +77,8 @@ export class AuthorMessagesElement extends HTMLElement {
// second pass, try to place it in reverse-chronological order
for (let i = 0; i < ul.childElementCount; i++){
const id = ul.children[i]?.children[0]?.getAttribute("data-target");
const ogMsg = this._messages.find(m=>m.id == id);
if (ogMsg && ogMsg.created < msg.created) {
const ogMsg = this._messages.find(m=>(m.renoteId ?? m.id) == id);
if (ogMsg && (ogMsg.renoteTime ?? ogMsg.created) < (msg.renoteTime ?? msg.created)) {
ul.insertBefore(e, ul.children[i])
e.children[0].setAttribute("data-latest", next);
return;
@ -89,7 +89,6 @@ export class AuthorMessagesElement extends HTMLElement {
ul.append(e);
e.children[0].setAttribute("data-latest", next);
}
console.log(JSON.stringify(this._messages));
}
}
}

View file

@ -56,7 +56,12 @@ export class MessageElement extends HTMLElement {
const content = this.querySelector(".message_content");
const attachments = this.querySelector(".message_attachments");
if (metadata) {
metadata.innerHTML = `<span class="message_author">${this._message.author}</span><span class="message_timestamp">${new Date(this._message.created)}</span><span class="message_visibility">${this._message.visibility}</span><span class="message_protocol">${this._message.protocol}</span>`
if (this._message.renoteId) {
metadata.innerHTML = `<span class="message_renoter">${this._message.renoter}</span><span class="message_renotetime">${new Date(this._message.renoteTime ?? 0)}</span>`
} else {
metadata.innerHTML = "";
}
metadata.innerHTML += `<span class="message_author">${this._message.author}</span><span class="message_timestamp">${new Date(this._message.created)}</span><span class="message_visibility">${this._message.visibility}</span><span class="message_protocol">${this._message.protocol}</span>`
}
if (content) {
content.innerHTML = this._message.content;

View file

@ -13,6 +13,8 @@ export class Message {
public edited: number | null = null;
public visibility: string = "public";
public renoteId: string | null = null;
public renoter: string | null = null;
public renoteTime: Date | null = null;
}
export class Author {

View file

@ -48,7 +48,7 @@ export class DatagramSocket {
// typeswitch on the incoming data type and fill the memory
switch (data.type) {
case "message":
store.messages.set(data.id, <Message>data);
store.messages.set(data.renoteId ?? data.id, <Message>data);
break;
case "author":
store.profileCache.set(data.id, <Author>data);
@ -67,6 +67,13 @@ export class DatagramSocket {
byAuthorTargets.forEach(t=>{
t.setAttribute("data-latest", data.id);
});
if (data.renoter) {
let byAuthorTargetsForBoosts = document.querySelectorAll(`underbbs-author-messages[data-adapter="${data.adapter}"][data-target="${data.renoter}"]`);
byAuthorTargetsForBoosts.forEach(t=>{
console.log("setting renote id on data-latest")
t.setAttribute("data-latest", data.renoteId);
});
}
}
}

View file

@ -26,6 +26,8 @@ type Message struct {
Mentions []string `json:"mentions"`
Visibility string `json:"visibility"`
RenoteId *string `json:"renoteId,omitempty"`
Renoter *string `json:"renoter,omitempty"`
RenoteTime *int64 `json:"renoteTime,omitempty"`
}
type Author struct {