mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 10:57:04 +00:00
Fix indexeddb deletes
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
<script lang="ts">
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {pubkey} from "@welshman/app"
|
||||
import {ManagementMethod} from "@welshman/util"
|
||||
import {pubkey, manageRelay, repository} from "@welshman/app"
|
||||
import Code2 from "@assets/icons/code-2.svg?dataurl"
|
||||
import TrashBin2 from "@assets/icons/trash-bin-2.svg?dataurl"
|
||||
import Danger from "@assets/icons/danger.svg?dataurl"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Confirm from "@lib/components/Confirm.svelte"
|
||||
import EventInfo from "@app/components/EventInfo.svelte"
|
||||
import EventReport from "@app/components/EventReport.svelte"
|
||||
import EventDeleteConfirm from "@app/components/EventDeleteConfirm.svelte"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {deriveUserIsSpaceAdmin} from "@app/core/state"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
@@ -19,6 +23,8 @@
|
||||
|
||||
const {url, event, onClick}: Props = $props()
|
||||
|
||||
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
||||
|
||||
const report = () => {
|
||||
onClick()
|
||||
pushModal(EventReport, {url, event})
|
||||
@@ -33,6 +39,26 @@
|
||||
onClick()
|
||||
pushModal(EventDeleteConfirm, {url, event})
|
||||
}
|
||||
|
||||
const showAdminDelete = () =>
|
||||
pushModal(Confirm, {
|
||||
title: `Delete Message`,
|
||||
message: `Are you sure you want to delete this message from the space?`,
|
||||
confirm: async () => {
|
||||
const {error} = await manageRelay(url, {
|
||||
method: ManagementMethod.BanEvent,
|
||||
params: [event.id],
|
||||
})
|
||||
|
||||
if (error) {
|
||||
pushToast({theme: "error", message: error})
|
||||
} else {
|
||||
pushToast({message: "Event has successfully been deleted!"})
|
||||
repository.removeEvent(event.id)
|
||||
history.back()
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<ul class="menu whitespace-nowrap rounded-box bg-base-100 p-2 shadow-md">
|
||||
@@ -56,5 +82,13 @@
|
||||
Report Content
|
||||
</Button>
|
||||
</li>
|
||||
{#if $userIsAdmin}
|
||||
<li>
|
||||
<Button class="text-error" onclick={showAdminDelete}>
|
||||
<Icon size={4} icon={TrashBin2} />
|
||||
Delete Message
|
||||
</Button>
|
||||
</li>
|
||||
{/if}
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
@@ -80,7 +80,7 @@ const rankEvent = (event: TrustedEvent) => {
|
||||
|
||||
const eventsAdapter = {
|
||||
name: "events",
|
||||
keyPath: ["id"],
|
||||
keyPath: "id",
|
||||
init: async (table: IDBTable<TrustedEvent>) => {
|
||||
const initialEvents = await table.getAll()
|
||||
|
||||
@@ -127,7 +127,7 @@ type TrackerItem = {id: string; relays: string[]}
|
||||
|
||||
const trackerAdapter = {
|
||||
name: "tracker",
|
||||
keyPath: ["id"],
|
||||
keyPath: "id",
|
||||
init: async (table: IDBTable<TrackerItem>) => {
|
||||
const relaysById = new Map<string, Set<string>>()
|
||||
|
||||
@@ -183,7 +183,7 @@ const trackerAdapter = {
|
||||
|
||||
const relaysAdapter = {
|
||||
name: "relays",
|
||||
keyPath: ["url"],
|
||||
keyPath: "url",
|
||||
init: async (table: IDBTable<RelayProfile>) => {
|
||||
relays.set(await table.getAll())
|
||||
|
||||
@@ -193,7 +193,7 @@ const relaysAdapter = {
|
||||
|
||||
const relayStatsAdapter = {
|
||||
name: "relayStats",
|
||||
keyPath: ["url"],
|
||||
keyPath: "url",
|
||||
init: async (table: IDBTable<RelayStats>) => {
|
||||
relayStats.set(await table.getAll())
|
||||
|
||||
@@ -203,7 +203,7 @@ const relayStatsAdapter = {
|
||||
|
||||
const handlesAdapter = {
|
||||
name: "handles",
|
||||
keyPath: ["nip05"],
|
||||
keyPath: "nip05",
|
||||
init: async (table: IDBTable<Handle>) => {
|
||||
handles.set(await table.getAll())
|
||||
|
||||
@@ -213,7 +213,7 @@ const handlesAdapter = {
|
||||
|
||||
const zappersAdapter = {
|
||||
name: "zappers",
|
||||
keyPath: ["lnurl"],
|
||||
keyPath: "lnurl",
|
||||
init: async (table: IDBTable<Zapper>) => {
|
||||
zappers.set(await table.getAll())
|
||||
|
||||
@@ -225,7 +225,7 @@ type FreshnessItem = {key: string; value: number}
|
||||
|
||||
const freshnessAdapter = {
|
||||
name: "freshness",
|
||||
keyPath: ["key"],
|
||||
keyPath: "key",
|
||||
init: async (table: IDBTable<FreshnessItem>) => {
|
||||
const initialRecords = await table.getAll()
|
||||
|
||||
@@ -241,7 +241,7 @@ type PlaintextItem = {key: string; value: string}
|
||||
|
||||
const plaintextAdapter = {
|
||||
name: "plaintext",
|
||||
keyPath: ["key"],
|
||||
keyPath: "key",
|
||||
init: async (table: IDBTable<PlaintextItem>) => {
|
||||
const initialRecords = await table.getAll()
|
||||
|
||||
@@ -255,7 +255,7 @@ const plaintextAdapter = {
|
||||
|
||||
const wrapManagerAdapter = {
|
||||
name: "wrapManager",
|
||||
keyPath: ["id"],
|
||||
keyPath: "id",
|
||||
init: async (table: IDBTable<WrapItem>) => {
|
||||
wrapManager.load(await table.getAll())
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {Maybe} from "@welshman/lib"
|
||||
|
||||
export type IDBAdapter = {
|
||||
name: string
|
||||
keyPath: string[]
|
||||
keyPath: string
|
||||
init: (table: IDBTable<any>) => Promise<Unsubscriber>
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +211,7 @@
|
||||
const seen = new Set()
|
||||
|
||||
let previousDate
|
||||
let previousKind
|
||||
let previousPubkey
|
||||
let newMessagesSeen = false
|
||||
|
||||
@@ -247,10 +248,14 @@
|
||||
id: event.id,
|
||||
type: "note",
|
||||
value: event,
|
||||
showPubkey: date !== previousDate || previousPubkey !== event.pubkey,
|
||||
showPubkey:
|
||||
date !== previousDate ||
|
||||
previousPubkey !== event.pubkey ||
|
||||
[ROOM_ADD_MEMBER, ROOM_REMOVE_MEMBER].includes(previousKind!),
|
||||
})
|
||||
|
||||
previousDate = date
|
||||
previousKind = event.kind
|
||||
previousPubkey = event.pubkey
|
||||
seen.add(event.id)
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
const seen = new Set()
|
||||
|
||||
let previousDate
|
||||
let previousKind
|
||||
let previousPubkey
|
||||
let newMessagesSeen = false
|
||||
|
||||
@@ -172,10 +173,14 @@
|
||||
id: event.id,
|
||||
type: "note",
|
||||
value: event,
|
||||
showPubkey: date !== previousDate || previousPubkey !== event.pubkey,
|
||||
showPubkey:
|
||||
date !== previousDate ||
|
||||
previousPubkey !== event.pubkey ||
|
||||
[RELAY_ADD_MEMBER, RELAY_REMOVE_MEMBER].includes(previousKind!),
|
||||
})
|
||||
|
||||
previousDate = date
|
||||
previousKind = event.kind
|
||||
previousPubkey = event.pubkey
|
||||
seen.add(event.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user