forked from coracle/flotilla
Refactor pomade, add password reset flow
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import {nwc} from "@getalby/sdk"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {get, derived} from "svelte/store"
|
||||
import {Client} from "@pomade/core"
|
||||
import type {SessionItem} from "@pomade/core"
|
||||
import {
|
||||
first,
|
||||
sha256,
|
||||
@@ -73,7 +71,6 @@ import {
|
||||
waitForThunkError,
|
||||
getPubkeyRelays,
|
||||
userBlossomServerList,
|
||||
isPomadeSession,
|
||||
getThunkError,
|
||||
} from "@welshman/app"
|
||||
import {compressFile} from "@lib/html"
|
||||
@@ -702,58 +699,3 @@ export const updateProfile = async ({
|
||||
|
||||
await publishThunk({event, relays}).complete
|
||||
}
|
||||
|
||||
// Pomade
|
||||
|
||||
export type PomadeSessionWithPeers = SessionItem & {peers: string[]}
|
||||
|
||||
export const loadOtherPomadeSessions = async () => {
|
||||
const $session = get(session)
|
||||
|
||||
if (isPomadeSession($session)) {
|
||||
const client = new Client($session.clientOptions)
|
||||
const result = await client.listSessions()
|
||||
const pubkey = await client.getPubkey()
|
||||
|
||||
if (result.ok) {
|
||||
// Group sessions by client pubkey and collect peers
|
||||
const sessionMap = new Map<string, PomadeSessionWithPeers>()
|
||||
|
||||
for (const message of result.messages) {
|
||||
if (!message.res?.items) continue
|
||||
|
||||
for (const item of message.res.items) {
|
||||
if (item.client === pubkey) {
|
||||
continue
|
||||
}
|
||||
|
||||
const existing = sessionMap.get(item.client)
|
||||
|
||||
if (existing) {
|
||||
existing.peers.push(message.url)
|
||||
} else {
|
||||
sessionMap.set(item.client, {...item, peers: [message.url]})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(sessionMap.values())
|
||||
}
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
export const deleteOldPomadeSessions = async () => {
|
||||
const $session = get(session)
|
||||
|
||||
if (isPomadeSession($session)) {
|
||||
const client = new Client($session.clientOptions)
|
||||
|
||||
for (const item of await loadOtherPomadeSessions()) {
|
||||
if (item.deactivated_at) {
|
||||
await client.deleteSession(item.client, item.peers)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user