forked from coracle/flotilla
Add request utils for complex requests
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import {get, derived} from "svelte/store"
|
||||
import {dev} from "$app/environment"
|
||||
import {bytesToHex, hexToBytes} from "@noble/hashes/utils"
|
||||
import {identity, uniq, sleep, take, sortBy, ago, now, HOUR, WEEK, Worker} from "@welshman/lib"
|
||||
import {identity, sleep, take, sortBy, ago, now, HOUR, WEEK, Worker} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {
|
||||
PROFILE,
|
||||
@@ -15,9 +15,6 @@
|
||||
RELAYS,
|
||||
INBOX_RELAYS,
|
||||
WRAP,
|
||||
MESSAGE,
|
||||
COMMENT,
|
||||
THREAD,
|
||||
getPubkeyTagValues,
|
||||
getListTags,
|
||||
} from "@welshman/util"
|
||||
@@ -39,7 +36,6 @@
|
||||
dropSession,
|
||||
getRelayUrls,
|
||||
userInboxRelaySelections,
|
||||
load,
|
||||
} from "@welshman/app"
|
||||
import * as lib from "@welshman/lib"
|
||||
import * as util from "@welshman/util"
|
||||
@@ -51,17 +47,11 @@
|
||||
import {setupTracking} from "@app/tracking"
|
||||
import {setupAnalytics} from "@app/analytics"
|
||||
import {theme} from "@app/theme"
|
||||
import {
|
||||
INDEXER_RELAYS,
|
||||
getMembershipUrls,
|
||||
getMembershipRooms,
|
||||
userMembership,
|
||||
ensureUnwrapped,
|
||||
canDecrypt,
|
||||
GENERAL,
|
||||
} from "@app/state"
|
||||
import {loadUserData, subscribePersistent} from "@app/commands"
|
||||
import {INDEXER_RELAYS, userMembership, ensureUnwrapped, canDecrypt} from "@app/state"
|
||||
import {loadUserData} from "@app/commands"
|
||||
import {subscribePersistent, listenForNotifications} from "@app/requests"
|
||||
import * as commands from "@app/commands"
|
||||
import * as requests from "@app/requests"
|
||||
import {checked} from "@app/notifications"
|
||||
import * as notifications from "@app/notifications"
|
||||
import * as state from "@app/state"
|
||||
@@ -86,6 +76,7 @@
|
||||
...app,
|
||||
...state,
|
||||
...commands,
|
||||
...requests,
|
||||
...notifications,
|
||||
})
|
||||
|
||||
@@ -199,30 +190,7 @@
|
||||
|
||||
userMembership.subscribe($membership => {
|
||||
unsubSpaces?.()
|
||||
|
||||
const since = ago(30)
|
||||
const rooms = uniq(getMembershipRooms($membership).map(m => m.room)).concat(GENERAL)
|
||||
const relays = uniq(getMembershipUrls($membership))
|
||||
|
||||
// Get one event for each of our notification categories
|
||||
load({
|
||||
relays,
|
||||
filters: [
|
||||
{kinds: [THREAD], limit: 1},
|
||||
{kinds: [COMMENT], "#K": [String(THREAD)], limit: 1},
|
||||
...rooms.map(room => ({kinds: [MESSAGE], "#h": [room], limit: 1})),
|
||||
],
|
||||
})
|
||||
|
||||
// Listen for new notifications/memberships
|
||||
unsubSpaces = subscribePersistent({
|
||||
relays,
|
||||
filters: [
|
||||
{kinds: [THREAD], since},
|
||||
{kinds: [COMMENT], "#K": [String(THREAD)], since},
|
||||
{kinds: [MESSAGE], "#h": rooms, since},
|
||||
],
|
||||
})
|
||||
unsubSpaces = listenForNotifications()
|
||||
})
|
||||
|
||||
// Listen for chats, populate chat-based notifications
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte"
|
||||
import ChatStart from "@app/components/ChatStart.svelte"
|
||||
import ChatItem from "@app/components/ChatItem.svelte"
|
||||
import {chatSearch, pullConservatively} from "@app/state"
|
||||
import {chatSearch} from "@app/state"
|
||||
import {pullConservatively} from "@app/requests"
|
||||
import {pushModal} from "@app/modal"
|
||||
|
||||
const startChat = () => pushModal(ChatStart)
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
import {derived} from "svelte/store"
|
||||
import type {Editor} from "svelte-tiptap"
|
||||
import {page} from "$app/stores"
|
||||
import {sleep, now, ctx} from "@welshman/lib"
|
||||
import {sleep, ctx} from "@welshman/lib"
|
||||
import type {TrustedEvent, EventContent} from "@welshman/util"
|
||||
import {throttled} from "@welshman/store"
|
||||
import {createEvent, DELETE, MESSAGE} from "@welshman/util"
|
||||
import {formatTimestampAsDate, load, publishThunk, deriveRelay} from "@welshman/app"
|
||||
import {createEvent, MESSAGE} from "@welshman/util"
|
||||
import {formatTimestampAsDate, publishThunk, deriveRelay} from "@welshman/app"
|
||||
import {slide} from "@lib/transition"
|
||||
import {createScroller, type Scroller} from "@lib/html"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
@@ -22,7 +22,6 @@
|
||||
import ChannelMessage from "@app/components/ChannelMessage.svelte"
|
||||
import ChannelCompose from "@app/components/ChannelCompose.svelte"
|
||||
import {
|
||||
pullConservatively,
|
||||
userSettingValues,
|
||||
userMembership,
|
||||
decodeRelay,
|
||||
@@ -34,13 +33,8 @@
|
||||
displayChannel,
|
||||
} from "@app/state"
|
||||
import {setChecked} from "@app/notifications"
|
||||
import {
|
||||
nip29,
|
||||
addRoomMembership,
|
||||
removeRoomMembership,
|
||||
getThunkError,
|
||||
subscribePersistent,
|
||||
} from "@app/commands"
|
||||
import {nip29, addRoomMembership, removeRoomMembership, getThunkError} from "@app/commands"
|
||||
import {listenForChannelMessages} from "@app/requests"
|
||||
import {PROTECTED} from "@app/state"
|
||||
import {popKey} from "@app/implicit"
|
||||
import {pushToast} from "@app/toast"
|
||||
@@ -96,7 +90,7 @@
|
||||
delay: $userSettingValues.send_delay,
|
||||
})
|
||||
|
||||
let limit = 15
|
||||
let limit = 30
|
||||
let loading = true
|
||||
let unsub: () => void
|
||||
let element: HTMLElement
|
||||
@@ -135,32 +129,16 @@
|
||||
// Sveltekiiit
|
||||
await sleep(100)
|
||||
|
||||
if (!nip29.isSupported($relay)) {
|
||||
load({
|
||||
delay: 0,
|
||||
relays: [url],
|
||||
filters: [{kinds: [LEGACY_MESSAGE], "#~": [legacyRoom]}],
|
||||
})
|
||||
}
|
||||
|
||||
pullConservatively({
|
||||
relays: [url],
|
||||
filters: [{kinds: [MESSAGE, DELETE], "#h": [room]}],
|
||||
})
|
||||
|
||||
scroller = createScroller({
|
||||
element,
|
||||
delay: 300,
|
||||
threshold: 3000,
|
||||
onScroll: () => {
|
||||
limit += 15
|
||||
limit += 30
|
||||
},
|
||||
})
|
||||
|
||||
unsub = subscribePersistent({
|
||||
relays: [url],
|
||||
filters: [{kinds: [MESSAGE], "#h": [room], since: now()}],
|
||||
})
|
||||
unsub = listenForChannelMessages(url, room)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
import EventItem from "@app/components/EventItem.svelte"
|
||||
import EventCreate from "@app/components/EventCreate.svelte"
|
||||
import {pushModal} from "@app/modal"
|
||||
import {deriveEventsForUrl, pullConservatively, decodeRelay} from "@app/state"
|
||||
import {deriveEventsForUrl, decodeRelay} from "@app/state"
|
||||
import {pullConservatively} from "@app/requests"
|
||||
import {setChecked} from "@app/notifications"
|
||||
|
||||
const url = decodeRelay($page.params.relay)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import ThreadActions from "@app/components/ThreadActions.svelte"
|
||||
import ThreadReply from "@app/components/ThreadReply.svelte"
|
||||
import {deriveEvent, decodeRelay} from "@app/state"
|
||||
import {subscribePersistent} from "@app/commands"
|
||||
import {subscribePersistent} from "@app/requests"
|
||||
import {setChecked} from "@app/notifications"
|
||||
|
||||
const {relay, id} = $page.params
|
||||
|
||||
Reference in New Issue
Block a user