Fix sending duplicate subscriptions

This commit is contained in:
Jonathan Staab 2023-02-24 11:23:08 -06:00
parent 5c02fd21de
commit 1ae66cbc88
5 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,5 @@
# Current
- [ ] Relay detail page, with more information about the relay + tabbed feeds (notes, more?)
- [ ] Add customize icon and route with editable custom view cards using "lists" nip
- nevent1qqspjcqw2hu5gfcpkrjhs0aqvxuzjgtp50l375mcqjfpmk48cg5hevgpr3mhxue69uhkummnw3ez6un9d3shjtnhd3m8xtnnwpskxegpzamhxue69uhkummnw3ezuendwsh8w6t69e3xj7spramhxue69uhkummnw3ez6un9d3shjtnwdahxxefwv93kzer9d4usz9rhwden5te0wfjkccte9ejxzmt4wvhxjmcpr9mhxue69uhkummnw3ezuer9d3hjuum0ve68wctjv5n8hwfg
- [ ] Custom views should combine pubkeys, relays, event ids, and topics
@ -18,6 +17,7 @@
# More
- [ ] Support https://github.com/nostr-protocol/nips/pull/211 as a bech32 entity
- [ ] Add new DM button to dms list
- [ ] Add suggested relays based on follows or topics
- [ ] Combine alerts/messages and any other top-level subscriptions to avoid sub limit

View File

@ -248,6 +248,10 @@ const subscribe = async (
log(`Starting subscription ${id} with ${relays.length} relays`, filter, relays)
}
if (relays.length !== new Set(pluck('url', relays)).size) {
error(`Subscribed to non-unique relays`, relays)
}
const promises = relays.map(async relay => {
const conn = await connect(relay.url)

View File

@ -157,7 +157,7 @@ export const sampleRelays = (relays, scale = 1) => {
)
}
return relays
return uniqByUrl(relays)
}
export const aggregateScores = relayGroups => {

View File

@ -242,14 +242,14 @@ export const where = filters =>
// https://stackoverflow.com/a/21682946
//
export const stringToColor = (value, saturation = 100, lightness = 50) => {
export const stringToColor = (value, {saturation = 100, lightness = 50, opacity = 1} = {}) => {
let hash = 0;
for (let i = 0; i < value.length; i++) {
hash = value.charCodeAt(i) + ((hash << 5) - hash)
hash = hash & hash
}
return `hsl(${(hash % 360)}, ${saturation}%, ${lightness}%)`;
return `hsl(${(hash % 360)}, ${saturation}%, ${lightness}%, ${opacity})`;
}
export const tryJson = f => {

View File

@ -1,7 +1,7 @@
<script lang="ts">
import {last, find, propEq} from 'ramda'
import {onMount} from 'svelte'
import {poll} from "src/util/misc"
import {poll, stringToColor} from "src/util/misc"
import {between} from 'hurdak/lib/hurdak'
import Content from "src/partials/Content.svelte"
import Anchor from "src/partials/Anchor.svelte"
@ -41,7 +41,11 @@
<div class="flex gap-2 items-center justify-between">
<div class="flex gap-2 items-center text-xl">
<i class={relay.url.startsWith('wss') ? "fa fa-lock" : "fa fa-unlock"} />
<span>{last(relay.url.split('://'))}</span>
<span
class="border-b border-solid"
style={`border-color: ${stringToColor(relay.url)}`}>
{last(relay.url.split('://'))}
</span>
<span
on:mouseout={() => {showStatus = false}}
on:mouseover={() => {showStatus = true}}
@ -86,6 +90,8 @@
{#if relay.description}
<p>{relay.description}</p>
{/if}
<div class="border-b border-solid border-medium -mx-6" />
</Content>
<div class="border-b border-solid border-medium" />
<Content>
<Feed relays={[relay]} filter={{kinds: [1]}} />
</Content>