fix bug of empty pubkey
This commit is contained in:
parent
e00a3fc19c
commit
a3dc27febd
2 changed files with 16 additions and 14 deletions
|
|
@ -39,10 +39,10 @@
|
||||||
const input = document.getElementById('message-input');
|
const input = document.getElementById('message-input');
|
||||||
const message = input.value;
|
const message = input.value;
|
||||||
input.value = '';
|
input.value = '';
|
||||||
let extraParams = { tags: [] };
|
let extraParams = { tags: [], tagPubKeys: [] };
|
||||||
|
|
||||||
// if this is the rootLevel we want to tag the owner of the site's pubkey
|
// if this is the rootLevel we want to tag the owner of the site's pubkey
|
||||||
if (!rootNoteId) { extraParams.tagPubKeys = [websiteOwnerPubkey] }
|
if (!rootNoteId && websiteOwnerPubkey) { extraParams.tagPubKeys = [websiteOwnerPubkey] }
|
||||||
|
|
||||||
// if we are responding to an event, we want to tag the event and the pubkey
|
// if we are responding to an event, we want to tag the event and the pubkey
|
||||||
if ($selectedMessage) {
|
if ($selectedMessage) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class NstrAdapter {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
this.referenceTags = referenceTags;
|
this.referenceTags = referenceTags;
|
||||||
|
|
||||||
// handle connection
|
// handle connection
|
||||||
if (this.#pool) { this.#disconnect() }
|
if (this.#pool) { this.#disconnect() }
|
||||||
this.#connect()
|
this.#connect()
|
||||||
|
|
@ -50,7 +50,7 @@ class NstrAdapter {
|
||||||
|
|
||||||
console.log('this.tags', this.tags);
|
console.log('this.tags', this.tags);
|
||||||
console.log('this.referenceTags', this.referenceTags);
|
console.log('this.referenceTags', this.referenceTags);
|
||||||
|
|
||||||
// handle subscriptions
|
// handle subscriptions
|
||||||
// if this is DM type then subscribe to chats with this website owner
|
// if this is DM type then subscribe to chats with this website owner
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
|
|
@ -68,7 +68,7 @@ class NstrAdapter {
|
||||||
if (this.referenceTags && this.referenceTags.length > 0) {
|
if (this.referenceTags && this.referenceTags.length > 0) {
|
||||||
filters.push({kinds: [1], '#r': this.referenceTags, limit: 20});
|
filters.push({kinds: [1], '#r': this.referenceTags, limit: 20});
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ class NstrAdapter {
|
||||||
tags: [
|
tags: [
|
||||||
['p', this.#websiteOwnerPubkey],
|
['p', this.#websiteOwnerPubkey],
|
||||||
...tags
|
...tags
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
|
|
@ -147,7 +147,9 @@ class NstrAdapter {
|
||||||
|
|
||||||
if (tagPubKeys) {
|
if (tagPubKeys) {
|
||||||
for (let pubkey of tagPubKeys) {
|
for (let pubkey of tagPubKeys) {
|
||||||
event.tags.push(['p', pubkey]);
|
if (pubkey) {
|
||||||
|
event.tags.push(['p', pubkey]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,7 +229,7 @@ class NstrAdapter {
|
||||||
// alert('unknown event kind ' + event.kind)
|
// alert('unknown event kind ' + event.kind)
|
||||||
console.log('unknown event kind', event.kind, event);
|
console.log('unknown event kind', event.kind, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToEventAndResponses(eventId) {
|
subscribeToEventAndResponses(eventId) {
|
||||||
|
|
@ -239,7 +241,7 @@ class NstrAdapter {
|
||||||
// this.subscribeToResponses(e)
|
// this.subscribeToResponses(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeToResponses(event) {
|
subscribeToResponses(event) {
|
||||||
this.subscribe([
|
this.subscribe([
|
||||||
{'#e': [event.id]},
|
{'#e': [event.id]},
|
||||||
|
|
@ -257,7 +259,7 @@ class NstrAdapter {
|
||||||
this.relayStatus[url] = 'disconnected';
|
this.relayStatus[url] = 'disconnected';
|
||||||
});
|
});
|
||||||
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
||||||
|
|
||||||
// console.log('connecting to relay', this.relayUrls);
|
// console.log('connecting to relay', this.relayUrls);
|
||||||
this.#pool = new RelayPool(this.relayUrls)
|
this.#pool = new RelayPool(this.relayUrls)
|
||||||
this.#pool.on('open', (relay) => {
|
this.#pool.on('open', (relay) => {
|
||||||
|
|
@ -265,13 +267,13 @@ class NstrAdapter {
|
||||||
this.relayStatus[relay.url] = 'connected';
|
this.relayStatus[relay.url] = 'connected';
|
||||||
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
||||||
})
|
})
|
||||||
|
|
||||||
this.#pool.on('error', (relay, r, e) => {
|
this.#pool.on('error', (relay, r, e) => {
|
||||||
this.relayStatus[relay.url] = 'error';
|
this.relayStatus[relay.url] = 'error';
|
||||||
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
||||||
console.log('error from relay', relay.url, r, e)
|
console.log('error from relay', relay.url, r, e)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.#pool.on('close', (relay, r) => {
|
this.#pool.on('close', (relay, r) => {
|
||||||
this.relayStatus[relay.url] = 'closed';
|
this.relayStatus[relay.url] = 'closed';
|
||||||
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
this.#eventEmitter.emit('connectivity', this.relayStatus);
|
||||||
|
|
@ -300,13 +302,13 @@ class NstrAdapter {
|
||||||
reqProfile(pubkey) {
|
reqProfile(pubkey) {
|
||||||
this.#addProfileRequest(pubkey);
|
this.#addProfileRequest(pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
#addProfileRequest(pubkey, event=null) {
|
#addProfileRequest(pubkey, event=null) {
|
||||||
if (this.#profileRequestQueue.includes(pubkey)) { return; }
|
if (this.#profileRequestQueue.includes(pubkey)) { return; }
|
||||||
if (this.#requestedProfiles.includes(pubkey)) { return; }
|
if (this.#requestedProfiles.includes(pubkey)) { return; }
|
||||||
this.#profileRequestQueue.push(pubkey);
|
this.#profileRequestQueue.push(pubkey);
|
||||||
this.#requestedProfiles.push(pubkey);
|
this.#requestedProfiles.push(pubkey);
|
||||||
|
|
||||||
if (!this.#profileRequestTimer) {
|
if (!this.#profileRequestTimer) {
|
||||||
this.#profileRequestTimer = setTimeout(() => {
|
this.#profileRequestTimer = setTimeout(() => {
|
||||||
this.#profileRequestTimer = null;
|
this.#profileRequestTimer = null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue