Threads progress

This commit is contained in:
2022-12-18 22:23:52 +00:00
parent e6ef1a5bc9
commit e617d6d528
13 changed files with 131 additions and 57 deletions

View File

@ -31,7 +31,7 @@ export default class Connection {
break;
}
case "EOSE": {
// ignored for now
this._OnEnd(msg[1]);
break;
}
default: {
@ -90,7 +90,15 @@ export default class Connection {
if (this.Subscriptions[subId]) {
this.Subscriptions[subId].OnEvent(ev);
} else {
console.warn("No subscription for event!");
console.warn(`No subscription for event! ${subId}`);
}
}
_OnEnd(subId) {
if (this.Subscriptions[subId]) {
this.Subscriptions[subId].OnEnd(this);
} else {
console.warn(`No subscription for end! ${subId}`);
}
}
}

View File

@ -75,7 +75,7 @@ export default class Event {
this.PubKey,
this.CreatedAt,
this.Kind,
this.Tags.map(a => a.ToObject()),
this.Tags.map(a => a.ToObject()).filter(a => a !== null),
this.Content
];
@ -130,7 +130,7 @@ export default class Event {
pubkey: this.PubKey,
created_at: this.CreatedAt,
kind: this.Kind,
tags: this.Tags.map(a => a.ToObject()),
tags: this.Tags.map(a => a.ToObject()).filter(a => a !== null),
content: this.Content,
sig: this.Signature
};

View File

@ -1,4 +1,5 @@
import { v4 as uuid } from "uuid";
import Connection from "./Connection";
export class Subscriptions {
constructor() {
@ -52,6 +53,12 @@ export class Subscriptions {
*/
this.OnEvent = (e) => { console.warn(`No event handler was set on subscription: ${this.Id}`) };
/**
* End of data event
* @param {Connection} c
*/
this.OnEnd = (c) => {};
/**
* Collection of OR sub scriptions linked to this
*/

View File

@ -5,6 +5,7 @@ export default class Tag {
this.PubKey = null;
this.Relay = null;
this.Marker = null;
this.Other = null;
switch (this.Key) {
case "e": {
@ -19,17 +20,24 @@ export default class Tag {
this.PubKey = tag[1];
break;
}
default: {
this.Other = tag;
break;
}
}
}
ToObject() {
switch(this.Key) {
switch (this.Key) {
case "e": {
return ["e", this.Event, this.Relay, this.Marker].filter(a => a !== null);
}
}
case "p": {
return ["p", this.PubKey];
}
default: {
return this.Other;
}
}
return null;
}