feat: added the ability to re-broadcast sigit #309

Merged
b merged 2 commits from issue-240 into staging 2025-01-31 10:20:40 +00:00
2 changed files with 83 additions and 2 deletions
Showing only changes of commit 5db4d1b429 - Show all commits

View File

@ -16,6 +16,7 @@ interface FileListProps {
setCurrentFile: (file: CurrentUserFile) => void
handleExport?: () => void
handleEncryptedExport?: () => void
reBroadcastSigit?: () => void
}
const FileList = ({
@ -23,7 +24,8 @@ const FileList = ({
currentFile,
setCurrentFile,
handleExport,
handleEncryptedExport
handleEncryptedExport,
reBroadcastSigit
}: FileListProps) => {
const isActive = (file: CurrentUserFile) => file.id === currentFile.id
return (
@ -91,6 +93,12 @@ const FileList = ({
)}
</PopupState>
)}
{typeof reBroadcastSigit === 'function' && (
<Button variant="contained" onClick={reBroadcastSigit}>
Re-Broadcast
</Button>
)}
</div>
)
}

View File

@ -28,7 +28,8 @@ import {
ARRAY_BUFFER,
DEFLATE,
uploadMetaToFileStorage,
decrypt
decrypt,
SignStatus
} from '../../utils'
import styles from './style.module.scss'
import { useLocation, useParams } from 'react-router-dom'
@ -217,6 +218,7 @@ export const VerifyPage = () => {
encryptionKey,
signers,
viewers,
signersStatus,
fileHashes,
parsedSignatureEvents,
timestamps
@ -732,6 +734,76 @@ export const VerifyPage = () => {
return Promise.resolve(arrayBuffer)
}
const reBroadcastSigit = async () => {
const usersNpub = hexToNpub(usersPubkey!)
if (!encryptionKey) {
toast.error('Encryption key is missing')
return
}
setIsLoading(true)
setLoadingSpinnerDesc('storing meta on blossom server')
let metaUrl: string
try {
metaUrl = await uploadMetaToFileStorage(meta, encryptionKey)
} catch (error) {
if (error instanceof Error) {
toast.error(error.message)
}
console.error(error)
setIsLoading(false)
return
}
const userSet = new Set<`npub1${string}`>()
if (submittedBy && submittedBy !== usersPubkey) {
userSet.add(hexToNpub(submittedBy))
}
// add all the signers who have signed and next signer to userSet
signers.forEach((signer) => {
// skip current user
if (signer === usersNpub) return
if (signersStatus[signer] === SignStatus.Signed) {
userSet.add(signer)
} else if (signersStatus[signer] === SignStatus.Awaiting) {
userSet.add(signer)
}
})
// If all signers have signed then include viewers too
if (
signers.every((signer) => signersStatus[signer] === SignStatus.Signed)
) {
viewers.forEach((viewer) => {
// skip current user
if (viewer === usersNpub) return
userSet.add(viewer)
})
}
setLoadingSpinnerDesc('Sending notifications')
const users = Array.from(userSet)
const promises = users.map((user) =>
sendNotification(npubToHex(user)!, { metaUrl, keys: meta.keys })
)
await Promise.all(promises)
.then(() => {
toast.success('Notifications sent successfully')
setMeta(meta)
})
.catch(() => {
toast.error('Failed to publish notifications')
})
setIsLoading(false)
}
return (
<>
{isLoading && <LoadingSpinner desc={loadingSpinnerDesc} />}
@ -780,6 +852,7 @@ export const VerifyPage = () => {
setCurrentFile={setCurrentFile}
handleExport={handleExport}
handleEncryptedExport={handleEncryptedExport}
reBroadcastSigit={reBroadcastSigit}
/>
)
}