forked from coracle/flotilla
Compare commits
12 Commits
video-demo
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| fe20fbfd28 | |||
| 4f3a2a1660 | |||
| 1c8457a4bf | |||
| 8710043a02 | |||
| dc46b42cb6 | |||
| 2f1972e70a | |||
| c5fcf12165 | |||
| 61ed632579 | |||
| 86f4b75c52 | |||
| b26ab916d5 | |||
| c882198206 | |||
| 4aef27ffd5 |
+1
-1
@@ -9,4 +9,4 @@ build
|
||||
|
||||
# Env files (keep .env for build; exclude local overrides)
|
||||
.env.local
|
||||
.env.*.local
|
||||
.env.*.local
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# Env
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
## Project Overview
|
||||
|
||||
Flotilla is a Nostr "relays as groups" community chat client. It implements NIP-29 (relay-based groups) to create Discord-like spaces (servers) and rooms (channels).
|
||||
|
||||
Please visit our [issue tracker](https://gitea.coracle.social/coracle/flotilla/issues) to contribute. Any new issues should be opened without a milestone, label, or project and the project owners will triage them.
|
||||
|
||||
### Milestones
|
||||
|
||||
Milestones indicate how soon a given task should be tackled.
|
||||
|
||||
- [Current](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&milestone=1) issues are immediately actionable.
|
||||
- [Next](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&milestone=2) means an issue is blocked.
|
||||
- [Future](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&milestone=3) means we're deferring work until a later date.
|
||||
|
||||
### Labels
|
||||
|
||||
- [Design](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&labels=15) issues need design work before being implemented. This might take the form of a high-quality mockup, wireframes, user flows, or just a couple notes about where things go, depending on the nature of the task.
|
||||
- [Dev](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&labels=16) issues are ready to be implemented. Most of the work will be related to architecting and writing code.
|
||||
- [Easy](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&labels=14) issues have no dependencies, and are scoped quite narrowly.
|
||||
- [Priority](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&labels=6) issues include bugs and urgent feature requests. These should get attention first if possible, although sometimes long-standing performance issues or subtle bugs might end up here for a while.
|
||||
- [Ideas](https://gitea.coracle.social/coracle/flotilla/issues?type=all&state=open&labels=13) are for things that aren't scoped out yet, or which need protocol work before getting designed or implemented.
|
||||
|
||||
### Projects
|
||||
|
||||
Issues may or may not have a project. Projects are used to group issues thematically just for organization.
|
||||
|
||||
## Coding conventions
|
||||
|
||||
There are a few conventions that are helpful to know right out of the gate.
|
||||
|
||||
- Most nostr protocol functionality is implemented via the [welshman library](https://welshman.coracle.social/)
|
||||
- Use Svelte 4 **stores** rather than runes for all state outside UI components
|
||||
- Most global state flows through Welshman's `repository` (unidirectional)
|
||||
- Query state using `deriveEventsMapped` or `deriveProfile` etc
|
||||
- Events are published via `publishThunk`, which allows for optimistic UI updates during signing/pow generation.
|
||||
- Components should have minimal props - e.g. instead of passing a whole `relay` through, pass its `url`.
|
||||
- Use `AbortController` when possible instead of request ids
|
||||
- Use `undefined` or optional properties instead of `null`
|
||||
- Do not use `any`. If there are type errors related to `unknown`, they are likely because the upstream definition of the data is incorrect.
|
||||
- Avoid using `as`, except where necessary. Instead, annotate function parameters, and ensure upstream values are typed correctly.
|
||||
- When dynamically building classes, use `cx` from `classnames`.
|
||||
- Do not define svelte event handlers inline, instead name them and put them in the script section of templates.
|
||||
|
||||
## Contributing Workflow
|
||||
|
||||
To contribute, do the following:
|
||||
|
||||
- Find or create an issue and assign yourself (comment instead if you're not able to self-assign)
|
||||
- If the issue is a design task, attach or link out to any mockups/wireframes/flowcharts
|
||||
- Once a design task is completed, a maintainer will remove the `design` label and add the `dev` label
|
||||
- If the issue is a development task, fork the repository and create a branch prefixed by the issue number, e.g. `105-deep-links`
|
||||
- Before requesting a review, be sure to review any agent-generated code, run the pre-commit hooks, and test the changes.
|
||||
- Open a PR and request a review. A maintainer will get back to you with requested changes, or will merge the PR.
|
||||
- Keep your PR up-to-date by rebasing frequently on `dev`. Avoid force-pushing to `dev`.
|
||||
- PRs are rebased, squashed, and merged to keep commit history simple.
|
||||
- An issue may have multiple PRs. Once complete, it can be closed.
|
||||
@@ -16,11 +16,13 @@ You can also optionally create an `.env.local` file and populate it with the fol
|
||||
- `VITE_PLATFORM_ACCENT` - A hex color for the app's accent color
|
||||
- `VITE_PLATFORM_DESCRIPTION` - A description of the app
|
||||
|
||||
These values **won't** be used for a built version. Instead, env variables should be provided to `build.sh` directly or to the built container.
|
||||
|
||||
If you're deploying a custom version of flotilla, be sure to remove the `plausible.coracle.social` script from `app.html`. This sends analytics to a server hosted by the developer.
|
||||
|
||||
## Development
|
||||
|
||||
See [CONTRIBUTING.md](AGENTS.md).
|
||||
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
|
||||
## Deployment
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
temp_env=$(declare -p -x)
|
||||
|
||||
if [ -f .env.template ]; then
|
||||
source .env.template
|
||||
fi
|
||||
if [ -f .env.local ]; then
|
||||
source .env.local
|
||||
if [ -f .env ]; then
|
||||
source .env
|
||||
fi
|
||||
|
||||
# Avoid overwriting env vars provided directly
|
||||
|
||||
@@ -392,7 +392,7 @@
|
||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
MARKETING_VERSION = 1.7.5;
|
||||
MARKETING_VERSION = 1.7.2;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = social.flotilla;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
|
||||
@@ -2,7 +2,7 @@ import dotenv from "dotenv"
|
||||
import {defineConfig, minimalPreset as preset} from "@vite-pwa/assets-generator/config"
|
||||
|
||||
dotenv.config({path: ".env.local"})
|
||||
dotenv.config({path: ".env.template"})
|
||||
dotenv.config({path: ".env"})
|
||||
|
||||
export default defineConfig({
|
||||
preset,
|
||||
|
||||
-42
@@ -394,35 +394,6 @@ progress[value]::-webkit-progress-value {
|
||||
@apply w-full md:left-[18.5rem] md:w-[calc(100%-18.5rem-var(--sair))];
|
||||
}
|
||||
|
||||
.cw-video-call-content {
|
||||
@apply w-full md:left-[calc(18.5rem+18rem)] md:w-[calc(100%-18.5rem-18rem-var(--sair))];
|
||||
}
|
||||
|
||||
/* Voice: desktop split — plain CSS so / in calc is not parsed as Tailwind slash syntax */
|
||||
.cw-split-video {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.cw-split-chat {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.cw-split-video {
|
||||
left: 18.5rem;
|
||||
right: auto;
|
||||
width: calc((100vw - 18.5rem - var(--sair)) / 2);
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.cw-split-chat {
|
||||
left: calc(18.5rem + (100vw - 18.5rem - var(--sair)) / 2);
|
||||
right: auto;
|
||||
width: calc((100vw - 18.5rem - var(--sair)) / 2);
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.cw-full {
|
||||
@apply w-full md:left-[4rem] md:w-[calc(100%-4rem-var(--sair))];
|
||||
}
|
||||
@@ -459,19 +430,6 @@ body.keyboard-open .hide-on-keyboard {
|
||||
@apply min-w-0;
|
||||
}
|
||||
|
||||
.chat__compose-zone.cw-video-call-content {
|
||||
@apply md:left-[calc(18.5rem+18rem)] md:w-[calc(100%-18.5rem-18rem-var(--sair))];
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.chat__compose-zone.cw-split-chat {
|
||||
left: calc(18.5rem + (100vw - 18.5rem - var(--sair)) / 2);
|
||||
right: auto;
|
||||
width: calc((100vw - 18.5rem - var(--sair)) / 2);
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.chat__scroll-down {
|
||||
@apply pb-sai fixed bottom-28 right-4 z-feature md:bottom-16;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import StarFallMinimalistic from "@assets/icons/star-fall-minimalistic.svg?dataurl"
|
||||
import NotesMinimalistic from "@assets/icons/notes-minimalistic.svg?dataurl"
|
||||
import CaseMinimalistic from "@assets/icons/case-minimalistic.svg?dataurl"
|
||||
import Revote from "@assets/icons/revote.svg?dataurl"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
@@ -11,6 +12,7 @@
|
||||
import ThreadCreate from "@app/components/ThreadCreate.svelte"
|
||||
import ClassifiedCreate from "@app/components/ClassifiedCreate.svelte"
|
||||
import GoalCreate from "@app/components/GoalCreate.svelte"
|
||||
import PollCreate from "@app/components/PollCreate.svelte"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
@@ -28,6 +30,8 @@
|
||||
|
||||
const createClassified = () => pushModal(ClassifiedCreate, {url, h})
|
||||
|
||||
const createPoll = () => pushModal(PollCreate, {url, h})
|
||||
|
||||
let ul: Element
|
||||
|
||||
onMount(() => {
|
||||
@@ -60,4 +64,10 @@
|
||||
Create Thread
|
||||
</Button>
|
||||
</li>
|
||||
<li>
|
||||
<Button onclick={createPoll}>
|
||||
<Icon size={4} icon={Revote} />
|
||||
Ask a Question
|
||||
</Button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script lang="ts">
|
||||
import type {ComponentProps} from "svelte"
|
||||
import {EVENT_TIME, ZAP_GOAL, THREAD, CLASSIFIED} from "@welshman/util"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import NoteContentEventTime from "@app/components/NoteContentEventTime.svelte"
|
||||
import NoteContentThread from "@app/components/NoteContentThread.svelte"
|
||||
import NoteContentClassified from "@app/components/NoteContentClassified.svelte"
|
||||
import NoteContentGoal from "@app/components/NoteContentGoal.svelte"
|
||||
import NoteContentPoll from "@app/components/NoteContentPoll.svelte"
|
||||
import Content from "@app/components/Content.svelte"
|
||||
|
||||
const props: ComponentProps<typeof Content> = $props()
|
||||
@@ -19,6 +21,8 @@
|
||||
<NoteContentClassified {...props} />
|
||||
{:else if props.event.kind === ZAP_GOAL}
|
||||
<NoteContentGoal {...props} />
|
||||
{:else if props.event.kind === Poll}
|
||||
<NoteContentPoll {...props} />
|
||||
{:else}
|
||||
<Content {...props} />
|
||||
{/if}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script lang="ts">
|
||||
import type {ComponentProps} from "svelte"
|
||||
import {EVENT_TIME, ZAP_GOAL, THREAD, CLASSIFIED} from "@welshman/util"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import NoteContentMinimalEventTime from "@app/components/NoteContentMinimalEventTime.svelte"
|
||||
import NoteContentMinimalThread from "@app/components/NoteContentMinimalThread.svelte"
|
||||
import NoteContentMinimalClassified from "@app/components/NoteContentMinimalClassified.svelte"
|
||||
import NoteContentMinimalGoal from "@app/components/NoteContentMinimalGoal.svelte"
|
||||
import NoteContentMinimalPoll from "@app/components/NoteContentMinimalPoll.svelte"
|
||||
import ContentMinimal from "@app/components/ContentMinimal.svelte"
|
||||
|
||||
const props: ComponentProps<typeof ContentMinimal> = $props()
|
||||
@@ -19,6 +21,8 @@
|
||||
<NoteContentMinimalClassified {...props} />
|
||||
{:else if props.event.kind === ZAP_GOAL}
|
||||
<NoteContentMinimalGoal {...props} />
|
||||
{:else if props.event.kind === Poll}
|
||||
<NoteContentMinimalPoll {...props} />
|
||||
{:else}
|
||||
<ContentMinimal {...props} />
|
||||
{/if}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
import type {ComponentProps} from "svelte"
|
||||
import {derived} from "svelte/store"
|
||||
import {PollResponse} from "nostr-tools/kinds"
|
||||
import ContentMinimal from "@app/components/ContentMinimal.svelte"
|
||||
import {deriveEvents} from "@app/core/state"
|
||||
import {getPollResults} from "@app/util/polls"
|
||||
|
||||
const props: ComponentProps<typeof ContentMinimal> = $props()
|
||||
|
||||
const responses = deriveEvents([{kinds: [PollResponse], "#e": [props.event.id]}])
|
||||
|
||||
const results = derived(responses, $responses => getPollResults(props.event, $responses))
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-0">
|
||||
<ContentMinimal {...props} />
|
||||
<span class="text-xs opacity-50">{$results.voters} voter{$results.voters === 1 ? "" : "s"}</span>
|
||||
</div>
|
||||
@@ -0,0 +1,29 @@
|
||||
<script lang="ts">
|
||||
import type {ComponentProps} from "svelte"
|
||||
import {onMount} from "svelte"
|
||||
import {request} from "@welshman/net"
|
||||
import {PollResponse} from "nostr-tools/kinds"
|
||||
import PollVotes from "@app/components/PollVotes.svelte"
|
||||
import Content from "@app/components/Content.svelte"
|
||||
|
||||
const props: ComponentProps<typeof Content> = $props()
|
||||
|
||||
onMount(() => {
|
||||
if (!props.url) {
|
||||
return
|
||||
}
|
||||
|
||||
request({
|
||||
relays: [props.url],
|
||||
filters: [{kinds: [PollResponse], "#e": [props.event.id]}],
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-3">
|
||||
<Content event={props.event} showEntire url={props.url} />
|
||||
|
||||
{#if props.url}
|
||||
<PollVotes url={props.url} event={props.event} />
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,238 @@
|
||||
<script lang="ts">
|
||||
import {insertAt, now, randomId, removeAt, removeUndefined} from "@welshman/lib"
|
||||
import {makeEvent} from "@welshman/util"
|
||||
import {publishThunk} from "@welshman/app"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import {isMobile, preventDefault} from "@lib/html"
|
||||
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
||||
import HamburgerMenu from "@assets/icons/hamburger-menu.svg?dataurl"
|
||||
import PlusCircle from "@assets/icons/add-circle.svg?dataurl"
|
||||
import MinusCircle from "@assets/icons/minus-circle.svg?dataurl"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Field from "@lib/components/Field.svelte"
|
||||
import FieldInline from "@lib/components/FieldInline.svelte"
|
||||
import DateTimeInput from "@lib/components/DateTimeInput.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
||||
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import Modal from "@lib/components/Modal.svelte"
|
||||
import ModalBody from "@lib/components/ModalBody.svelte"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {PROTECTED} from "@app/core/state"
|
||||
import {canEnforceNip70} from "@app/core/commands"
|
||||
import type {PollType} from "@app/util/polls"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
h?: string
|
||||
}
|
||||
|
||||
const {url, h}: Props = $props()
|
||||
|
||||
const shouldProtect = canEnforceNip70(url)
|
||||
|
||||
type DraftOption = {
|
||||
id: string
|
||||
value: string
|
||||
}
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const addOption = () => {
|
||||
options = [...options, {id: randomId(), value: ""}]
|
||||
}
|
||||
|
||||
const removeOption = (id: string) => {
|
||||
options = options.filter(option => option.id !== id)
|
||||
}
|
||||
|
||||
const updateOption = (id: string, value: string) => {
|
||||
options = options.map(option => (option.id === id ? {...option, value} : option))
|
||||
}
|
||||
|
||||
const reorderOptions = (targetId: string) => {
|
||||
if (!draggedOptionId) {
|
||||
return
|
||||
}
|
||||
|
||||
const sourceIndex = options.findIndex(option => option.id === draggedOptionId)
|
||||
const targetIndex = options.findIndex(option => option.id === targetId)
|
||||
|
||||
if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex) {
|
||||
return
|
||||
}
|
||||
|
||||
options = insertAt(targetIndex, options[sourceIndex], removeAt(sourceIndex, options))
|
||||
}
|
||||
|
||||
const onDragStart = (e: DragEvent, id: string) => {
|
||||
draggedOptionId = id
|
||||
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.effectAllowed = "move"
|
||||
e.dataTransfer.setData("text/plain", id)
|
||||
}
|
||||
}
|
||||
|
||||
const onDragOver = (e: DragEvent, targetId: string) => {
|
||||
e.preventDefault()
|
||||
reorderOptions(targetId)
|
||||
}
|
||||
|
||||
const onDrop = (e: DragEvent, targetId: string) => {
|
||||
e.preventDefault()
|
||||
reorderOptions(targetId)
|
||||
draggedOptionId = undefined
|
||||
}
|
||||
|
||||
const onDragEnd = () => {
|
||||
draggedOptionId = undefined
|
||||
}
|
||||
|
||||
const submit = async () => {
|
||||
if (!title.trim()) {
|
||||
return pushToast({theme: "error", message: "Please provide a title for your poll."})
|
||||
}
|
||||
|
||||
const nonEmptyOptions = removeUndefined(options.map(option => option.value.trim() || undefined))
|
||||
|
||||
if (nonEmptyOptions.length < 2) {
|
||||
return pushToast({theme: "error", message: "Please provide at least two options."})
|
||||
}
|
||||
|
||||
if (endsAt && endsAt <= now()) {
|
||||
return pushToast({theme: "error", message: "End time must be in the future."})
|
||||
}
|
||||
|
||||
const tags: string[][] = [
|
||||
...nonEmptyOptions.map(option => ["option", randomId(), option]),
|
||||
["polltype", pollType],
|
||||
["relay", url],
|
||||
]
|
||||
|
||||
if (endsAt) {
|
||||
tags.push(["endsAt", String(endsAt)])
|
||||
}
|
||||
|
||||
if (h) {
|
||||
tags.push(["h", h])
|
||||
}
|
||||
|
||||
if (await shouldProtect) {
|
||||
tags.push(PROTECTED)
|
||||
}
|
||||
|
||||
publishThunk({
|
||||
relays: [url],
|
||||
event: makeEvent(Poll, {content: title.trim(), tags}),
|
||||
})
|
||||
|
||||
history.back()
|
||||
}
|
||||
|
||||
let title = $state("")
|
||||
let pollType = $state<PollType>("singlechoice")
|
||||
let endsAt = $state<number | undefined>()
|
||||
let options = $state<DraftOption[]>([
|
||||
{id: randomId(), value: "Yes"},
|
||||
{id: randomId(), value: "No"},
|
||||
])
|
||||
let draggedOptionId = $state<string | undefined>()
|
||||
</script>
|
||||
|
||||
<Modal tag="form" onsubmit={preventDefault(submit)}>
|
||||
<ModalBody>
|
||||
<ModalHeader>
|
||||
<ModalTitle>Create a Poll</ModalTitle>
|
||||
<ModalSubtitle>Ask a question and collect votes right in the feed.</ModalSubtitle>
|
||||
</ModalHeader>
|
||||
<div class="col-8 relative">
|
||||
<Field>
|
||||
{#snippet label()}
|
||||
<p>Question*</p>
|
||||
{/snippet}
|
||||
{#snippet input()}
|
||||
<label class="input input-bordered flex w-full items-center gap-2">
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input
|
||||
autofocus={!isMobile}
|
||||
bind:value={title}
|
||||
class="grow"
|
||||
type="text"
|
||||
placeholder="What would you like to ask?" />
|
||||
</label>
|
||||
{/snippet}
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
{#snippet label()}
|
||||
<p>Options*</p>
|
||||
{/snippet}
|
||||
{#snippet input()}
|
||||
<div class="flex flex-col gap-2" role="list">
|
||||
{#each options as option, index (option.id)}
|
||||
<div
|
||||
class="flex items-center gap-2"
|
||||
draggable="true"
|
||||
role="listitem"
|
||||
ondragstart={e => onDragStart(e, option.id)}
|
||||
ondragover={e => onDragOver(e, option.id)}
|
||||
ondrop={e => onDrop(e, option.id)}
|
||||
ondragend={onDragEnd}>
|
||||
<div class="cursor-move opacity-70" aria-label="Drag handle">
|
||||
<Icon icon={HamburgerMenu} size={4} />
|
||||
</div>
|
||||
<label class="input input-bordered flex w-full items-center gap-2">
|
||||
<input
|
||||
value={option.value}
|
||||
class="grow"
|
||||
type="text"
|
||||
placeholder={`Option ${index + 1}`}
|
||||
oninput={e => updateOption(option.id, e.currentTarget.value)} />
|
||||
</label>
|
||||
<Button class="btn btn-ghost btn-sm" onclick={() => removeOption(option.id)}>
|
||||
<Icon icon={MinusCircle} size={4} />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
<Button class="btn btn-outline btn-sm self-end" onclick={addOption}>
|
||||
<Icon icon={PlusCircle} size={4} />
|
||||
Add option
|
||||
</Button>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Field>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<FieldInline>
|
||||
{#snippet label()}
|
||||
Poll type
|
||||
{/snippet}
|
||||
{#snippet input()}
|
||||
<select class="select select-bordered w-full max-w-xs" bind:value={pollType}>
|
||||
<option value="singlechoice">Single choice</option>
|
||||
<option value="multiplechoice">Multiple choice</option>
|
||||
</select>
|
||||
{/snippet}
|
||||
</FieldInline>
|
||||
<FieldInline>
|
||||
{#snippet label()}
|
||||
Ends at
|
||||
{/snippet}
|
||||
{#snippet input()}
|
||||
<DateTimeInput bind:value={endsAt} />
|
||||
{/snippet}
|
||||
</FieldInline>
|
||||
</div>
|
||||
</div>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button class="btn btn-link" onclick={back}>
|
||||
<Icon icon={AltArrowLeft} />
|
||||
Go back
|
||||
</Button>
|
||||
<Button type="submit" class="btn btn-primary">Create Poll</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {getTagValue} from "@welshman/util"
|
||||
import Link from "@lib/components/Link.svelte"
|
||||
import NoteContent from "@app/components/NoteContent.svelte"
|
||||
import CommentActions from "@app/components/CommentActions.svelte"
|
||||
import RoomLink from "@app/components/RoomLink.svelte"
|
||||
import ProfileLink from "@app/components/ProfileLink.svelte"
|
||||
import {makePollPath} from "@app/util/routes"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
event: TrustedEvent
|
||||
}
|
||||
|
||||
const {url, event}: Props = $props()
|
||||
|
||||
const h = getTagValue("h", event.tags)
|
||||
</script>
|
||||
|
||||
<Link
|
||||
class="cv col-2 card2 bg-alt w-full cursor-pointer shadow-md"
|
||||
href={makePollPath(url, event.id)}>
|
||||
<NoteContent {event} {url} />
|
||||
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
|
||||
<span class="whitespace-nowrap py-1 text-sm opacity-75">
|
||||
Posted by <ProfileLink pubkey={event.pubkey} {url} />
|
||||
{#if h}
|
||||
in <RoomLink {url} {h} />
|
||||
{/if}
|
||||
</span>
|
||||
<CommentActions segment="polls" showActivity {url} {event} />
|
||||
</div>
|
||||
</Link>
|
||||
@@ -0,0 +1,70 @@
|
||||
<script lang="ts">
|
||||
import {tweened} from "svelte/motion"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {noop} from "@welshman/lib"
|
||||
import {stopPropagation} from "@lib/html"
|
||||
import {getPollType, isPollClosed} from "@app/util/polls"
|
||||
|
||||
type Props = {
|
||||
event: TrustedEvent
|
||||
option: {id: string; label: string}
|
||||
results: {voters: number; options: {id: string; votes: number}[]}
|
||||
selectedIds: string[]
|
||||
setSingleChoice: (id: string) => void
|
||||
toggleMultipleChoice: (id: string) => void
|
||||
}
|
||||
|
||||
const {event, option, results, selectedIds, setSingleChoice, toggleMultipleChoice}: Props =
|
||||
$props()
|
||||
|
||||
const pollType = getPollType(event)
|
||||
const closed = isPollClosed(event)
|
||||
|
||||
const selected = $derived(
|
||||
pollType === "singlechoice" ? selectedIds[0] === option.id : selectedIds.includes(option.id),
|
||||
)
|
||||
const onselect = () =>
|
||||
pollType === "singlechoice" ? setSingleChoice(option.id) : toggleMultipleChoice(option.id)
|
||||
|
||||
const votes = $derived(results.options.find(r => r.id === option.id)?.votes || 0)
|
||||
const maxVotes = $derived(Math.max(...results.options.map(r => r.votes), 1))
|
||||
|
||||
const tweenedVotes = tweened(votes, {duration: 300})
|
||||
const tweenedMax = tweened(maxVotes, {duration: 300})
|
||||
|
||||
$effect(() => {
|
||||
tweenedVotes.set(votes)
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
tweenedMax.set(maxVotes)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 card2 card2-sm bg-alt">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<label class="flex min-w-0 flex-grow items-center gap-2">
|
||||
{#if !closed}
|
||||
{#if pollType === "singlechoice"}
|
||||
<input
|
||||
name={event.id}
|
||||
type="radio"
|
||||
class="radio radio-primary radio-sm"
|
||||
checked={selected}
|
||||
onclick={stopPropagation(noop)}
|
||||
onchange={onselect} />
|
||||
{:else}
|
||||
<input
|
||||
type="checkbox"
|
||||
class="checkbox checkbox-primary checkbox-sm"
|
||||
checked={selected}
|
||||
onclick={stopPropagation(noop)}
|
||||
onchange={onselect} />
|
||||
{/if}
|
||||
{/if}
|
||||
<span class="truncate">{option.label}</span>
|
||||
</label>
|
||||
<span class="whitespace-nowrap text-xs opacity-75">{votes} vote{votes === 1 ? "" : "s"}</span>
|
||||
</div>
|
||||
<progress class="progress progress-primary" value={$tweenedVotes} max={$tweenedMax}></progress>
|
||||
</div>
|
||||
@@ -0,0 +1,127 @@
|
||||
<script lang="ts">
|
||||
import {onDestroy} from "svelte"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {pubkey, publishThunk, abortThunk} from "@welshman/app"
|
||||
import {PollResponse} from "nostr-tools/kinds"
|
||||
import {formatTimestampRelative} from "@welshman/lib"
|
||||
import {deriveEvents} from "@app/core/state"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {makePollResponse} from "@app/core/commands"
|
||||
import PollOption from "@app/components/PollOption.svelte"
|
||||
import {
|
||||
getPollEndsAt,
|
||||
getPollOptions,
|
||||
getPollResponseSelections,
|
||||
getPollResults,
|
||||
getPollType,
|
||||
isPollClosed,
|
||||
} from "@app/util/polls"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
event: TrustedEvent
|
||||
}
|
||||
|
||||
const {url, event}: Props = $props()
|
||||
|
||||
const responses = deriveEvents([{kinds: [PollResponse], "#e": [event.id]}])
|
||||
|
||||
const pollType = getPollType(event)
|
||||
const options = getPollOptions(event)
|
||||
const closed = isPollClosed(event)
|
||||
const endsAt = getPollEndsAt(event)
|
||||
const publishDelay = pollType === "multiplechoice" ? 10_000 : undefined
|
||||
|
||||
const getOwnResponse = (responses: TrustedEvent[]) => {
|
||||
let latest: TrustedEvent | undefined
|
||||
|
||||
for (const response of responses) {
|
||||
if (response.pubkey !== $pubkey) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!latest || response.created_at > latest.created_at) {
|
||||
latest = response
|
||||
}
|
||||
}
|
||||
|
||||
return latest
|
||||
}
|
||||
|
||||
const publishSelection = (selection: string[]) => {
|
||||
if (activeThunk) {
|
||||
abortThunk(activeThunk)
|
||||
}
|
||||
|
||||
if (selection.length === 0) {
|
||||
activeThunk = undefined
|
||||
return
|
||||
}
|
||||
|
||||
activeThunk = publishThunk({
|
||||
relays: [url],
|
||||
event: makePollResponse({event, selectedIds: selection}),
|
||||
delay: publishDelay,
|
||||
})
|
||||
}
|
||||
|
||||
const publishCurrentSelection = () => {
|
||||
const selection = pollType === "singlechoice" ? selectedIds.slice(0, 1) : selectedIds
|
||||
|
||||
if (selection.length === 0) {
|
||||
return pushToast({theme: "error", message: "Please select at least one option."})
|
||||
}
|
||||
|
||||
publishSelection(selection)
|
||||
}
|
||||
|
||||
const results = $derived(getPollResults(event, $responses))
|
||||
const ownResponse = $derived(getOwnResponse($responses))
|
||||
|
||||
const setSingleChoice = (id: string) => {
|
||||
selectedIds = [id]
|
||||
publishCurrentSelection()
|
||||
}
|
||||
|
||||
const toggleMultipleChoice = (id: string) => {
|
||||
selectedIds = selectedIds.includes(id)
|
||||
? selectedIds.filter(selectedId => selectedId !== id)
|
||||
: [...selectedIds, id]
|
||||
|
||||
publishCurrentSelection()
|
||||
}
|
||||
|
||||
let selectedIds = $state<string[]>([])
|
||||
let activeThunk: ReturnType<typeof publishThunk> | undefined
|
||||
|
||||
$effect(() => {
|
||||
if (ownResponse) {
|
||||
selectedIds = getPollResponseSelections(ownResponse, pollType)
|
||||
}
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (activeThunk) {
|
||||
abortThunk(activeThunk)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
{#each options as option (option.id)}
|
||||
<PollOption {event} {option} {results} {selectedIds} {setSingleChoice} {toggleMultipleChoice} />
|
||||
{/each}
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="text-sm opacity-75">
|
||||
{pollType === "multiplechoice" ? "Multiple choice" : "Single choice"}
|
||||
{#if endsAt}
|
||||
{#if closed}
|
||||
• Ended {formatTimestampRelative(endsAt)}
|
||||
{:else}
|
||||
• Ends {formatTimestampRelative(endsAt)}
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
<div class="text-sm opacity-75">{results.voters} vote{results.voters === 1 ? "" : "s"}</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -14,7 +14,7 @@
|
||||
import {userSpaceUrls, PLATFORM_RELAYS} from "@app/core/state"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
import {goToChat} from "@app/util/routes"
|
||||
import {goToChat, makeSpacePath} from "@app/util/routes"
|
||||
|
||||
type Props = {
|
||||
children?: Snippet
|
||||
@@ -26,7 +26,9 @@
|
||||
|
||||
const showSettingsMenu = () => pushModal(MenuSettings)
|
||||
|
||||
const anySpaceNotifications = $derived($userSpaceUrls.some(p => $notifications.has(p)))
|
||||
const anySpaceNotifications = $derived(
|
||||
$userSpaceUrls.some(p => $notifications.has(makeSpacePath(p))),
|
||||
)
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<div>
|
||||
<div class="min-w-0">
|
||||
<h2 class="ellipsize whitespace-nowrap text-xl">
|
||||
<RelayName {url} />
|
||||
</h2>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {derived} from "svelte/store"
|
||||
import {displayRelayUrl, EVENT_TIME, ZAP_GOAL, THREAD, CLASSIFIED} from "@welshman/util"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import {deriveRelay, createSearch, pubkey} from "@welshman/app"
|
||||
import {fly} from "@lib/transition"
|
||||
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
||||
@@ -17,6 +18,7 @@
|
||||
import NotesMinimalistic from "@assets/icons/notes-minimalistic.svg?dataurl"
|
||||
import CalendarMinimalistic from "@assets/icons/calendar-minimalistic.svg?dataurl"
|
||||
import CaseMinimalistic from "@assets/icons/case-minimalistic.svg?dataurl"
|
||||
import Revote from "@assets/icons/revote.svg?dataurl"
|
||||
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
|
||||
import ChatRound from "@assets/icons/chat-round.svg?dataurl"
|
||||
import Bell from "@assets/icons/bell.svg?dataurl"
|
||||
@@ -69,6 +71,7 @@
|
||||
const threadsPath = makeSpacePath(url, "threads")
|
||||
const classifiedsPath = makeSpacePath(url, "classifieds")
|
||||
const calendarPath = makeSpacePath(url, "calendar")
|
||||
const pollsPath = makeSpacePath(url, "polls")
|
||||
const userRooms = deriveUserRooms(url)
|
||||
const otherRooms = deriveOtherRooms(url)
|
||||
const otherVoiceRooms = deriveOtherVoiceRooms(url)
|
||||
@@ -257,6 +260,11 @@
|
||||
<Icon icon={CalendarMinimalistic} /> Calendar
|
||||
</SecondaryNavItem>
|
||||
{/if}
|
||||
{#if $spaceKinds.has(Poll)}
|
||||
<SecondaryNavItem href={pollsPath}>
|
||||
<Icon icon={Revote} /> Polls
|
||||
</SecondaryNavItem>
|
||||
{/if}
|
||||
{#if hasNip29($relay)}
|
||||
{#if $userRooms.length > 0}
|
||||
<div class="h-2 flex-shrink-0"></div>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<script lang="ts">
|
||||
import {tick} from "svelte"
|
||||
import {createSearch} from "@welshman/app"
|
||||
import {debounce} from "throttle-debounce"
|
||||
import {request} from "@welshman/net"
|
||||
import {formatTimestampAsDate, groupBy, now, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {MESSAGE} from "@welshman/util"
|
||||
import type {TrustedEvent, Filter} from "@welshman/util"
|
||||
import {sortEventsDesc} from "@welshman/util"
|
||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
||||
import {fly} from "@lib/transition"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import {deriveEventsForUrl} from "@app/core/state"
|
||||
import {CONTENT_KINDS} from "@app/core/state"
|
||||
import {goToEvent} from "@app/util/routes"
|
||||
|
||||
type Props = {
|
||||
@@ -19,14 +20,16 @@
|
||||
|
||||
const {url, h}: Props = $props()
|
||||
|
||||
const spaceMessages = deriveEventsForUrl(
|
||||
url,
|
||||
h ? [{kinds: [MESSAGE], "#h": [h]}] : [{kinds: [MESSAGE]}],
|
||||
)
|
||||
|
||||
let term = $state("")
|
||||
let show = $state(false)
|
||||
let results = $state<TrustedEvent[]>([])
|
||||
let loading = $state(false)
|
||||
let input: HTMLInputElement | undefined = $state()
|
||||
let controller: AbortController | undefined
|
||||
|
||||
const relayStatus = $derived(
|
||||
h ? `Searching this room on relay: ${url}.` : `Searching this space on relay: ${url}.`,
|
||||
)
|
||||
|
||||
const open = () => {
|
||||
show = true
|
||||
@@ -40,21 +43,53 @@
|
||||
const clear = () => {
|
||||
term = ""
|
||||
show = false
|
||||
loading = false
|
||||
results = []
|
||||
controller?.abort()
|
||||
controller = undefined
|
||||
}
|
||||
|
||||
const getRelayUrls = () => [url]
|
||||
|
||||
const getFilter = (searchTerm: string): Filter =>
|
||||
h
|
||||
? {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm}
|
||||
: {kinds: CONTENT_KINDS, search: searchTerm}
|
||||
|
||||
const search = debounce(300, async (searchTerm: string) => {
|
||||
controller?.abort()
|
||||
|
||||
if (!searchTerm.trim()) {
|
||||
loading = false
|
||||
results = []
|
||||
return
|
||||
}
|
||||
|
||||
controller = new AbortController()
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const events = await request({
|
||||
relays: getRelayUrls(),
|
||||
autoClose: true,
|
||||
signal: controller.signal,
|
||||
filters: [getFilter(searchTerm.trim())],
|
||||
})
|
||||
|
||||
results = sortEventsDesc(events)
|
||||
} catch (error) {
|
||||
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
||||
results = []
|
||||
}
|
||||
} finally {
|
||||
loading = false
|
||||
}
|
||||
})
|
||||
|
||||
const onInput = () => {
|
||||
show = true
|
||||
void search(term)
|
||||
}
|
||||
|
||||
const searchIndex = $derived.by(() =>
|
||||
createSearch($spaceMessages, {
|
||||
getValue: event => event.id,
|
||||
fuseOptions: {keys: ["content"]},
|
||||
}),
|
||||
)
|
||||
|
||||
const results = $derived(term ? searchIndex.searchOptions(term) : [])
|
||||
|
||||
const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results))
|
||||
|
||||
const getAgeSection = (createdAt: number) => {
|
||||
@@ -122,10 +157,13 @@
|
||||
oninput={onInput} />
|
||||
</label>
|
||||
<div class="max-h-[65vh] overflow-y-auto">
|
||||
<p class="mb-2 text-xs opacity-70">{relayStatus}</p>
|
||||
{#if !term}
|
||||
<p class="text-sm opacity-70">
|
||||
{h ? "Search for messages in this room." : "Search for messages across this space."}
|
||||
{h ? "Search for content in this room." : "Search for content in this space."}
|
||||
</p>
|
||||
{:else if loading}
|
||||
<p class="text-sm opacity-70">Searching...</p>
|
||||
{:else if eventsByAge.size === 0}
|
||||
<p class="text-sm opacity-70">No results found.</p>
|
||||
{:else}
|
||||
|
||||
@@ -1,247 +0,0 @@
|
||||
<script lang="ts">
|
||||
import cx from "classnames"
|
||||
import {Track} from "livekit-client"
|
||||
import {displayProfileByPubkey, loadProfile} from "@welshman/app"
|
||||
import Pin from "@assets/icons/pin.svg?dataurl"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import ProfileCircle from "@app/components/ProfileCircle.svelte"
|
||||
import VideoCallVideo from "@app/components/VideoCallVideo.svelte"
|
||||
import {
|
||||
currentVoiceSession,
|
||||
currentVoiceRoom,
|
||||
videoCallContentActive,
|
||||
videoCallLayoutRevision,
|
||||
videoPrimaryTileKey,
|
||||
toggleVideoPrimaryTile,
|
||||
pubkeyFromLiveKitIdentity,
|
||||
} from "@app/voice"
|
||||
|
||||
type Variant = "mobile" | "desktop-split" | "desktop-full"
|
||||
|
||||
type Props = {
|
||||
variant: Variant
|
||||
url: string
|
||||
h: string
|
||||
visible?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
type Tile = {
|
||||
identity: string
|
||||
isLocal: boolean
|
||||
trackSid: string
|
||||
attachable: Track | undefined
|
||||
source: Track.Source.Camera | Track.Source.ScreenShare
|
||||
}
|
||||
|
||||
type TileLayout = "spotlight" | "default" | "strip"
|
||||
|
||||
const {variant, url, h, visible = true, class: className = ""}: Props = $props()
|
||||
|
||||
const roomMatches = $derived($currentVoiceRoom?.url === url && $currentVoiceRoom?.h === h)
|
||||
|
||||
const allowEmptyPanel = $derived(variant === "desktop-split" || variant === "desktop-full")
|
||||
|
||||
const showPanel = $derived(
|
||||
visible &&
|
||||
roomMatches &&
|
||||
(variant === "mobile" ? $videoCallContentActive : $videoCallContentActive || allowEmptyPanel),
|
||||
)
|
||||
|
||||
const tiles = $derived.by(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions -- re-run when remote video subscribes
|
||||
$videoCallLayoutRevision
|
||||
const session = $currentVoiceSession
|
||||
if (!session || $currentVoiceRoom?.url !== url || $currentVoiceRoom?.h !== h) {
|
||||
return []
|
||||
}
|
||||
|
||||
const room = session.room
|
||||
const out: Tile[] = []
|
||||
const lp = room.localParticipant
|
||||
|
||||
if (session.cameraOn) {
|
||||
const localPub = lp.getTrackPublication(Track.Source.Camera)
|
||||
out.push({
|
||||
identity: lp.identity,
|
||||
isLocal: true,
|
||||
trackSid: localPub?.trackSid ?? "local-camera",
|
||||
attachable: localPub?.track,
|
||||
source: Track.Source.Camera,
|
||||
})
|
||||
}
|
||||
|
||||
if (session.screenShareOn) {
|
||||
const localPub = lp.getTrackPublication(Track.Source.ScreenShare)
|
||||
out.push({
|
||||
identity: lp.identity,
|
||||
isLocal: true,
|
||||
trackSid: localPub?.trackSid ?? "local-screen",
|
||||
attachable: localPub?.track,
|
||||
source: Track.Source.ScreenShare,
|
||||
})
|
||||
}
|
||||
|
||||
for (const rp of room.remoteParticipants.values()) {
|
||||
const camPub = rp.getTrackPublication(Track.Source.Camera)
|
||||
if (camPub?.isSubscribed && camPub.track) {
|
||||
out.push({
|
||||
identity: rp.identity,
|
||||
isLocal: false,
|
||||
trackSid: camPub.trackSid,
|
||||
attachable: camPub.track,
|
||||
source: Track.Source.Camera,
|
||||
})
|
||||
}
|
||||
const screenPub = rp.getTrackPublication(Track.Source.ScreenShare)
|
||||
if (screenPub?.isSubscribed && screenPub.track) {
|
||||
out.push({
|
||||
identity: rp.identity,
|
||||
isLocal: false,
|
||||
trackSid: screenPub.trackSid,
|
||||
attachable: screenPub.track,
|
||||
source: Track.Source.ScreenShare,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
})
|
||||
|
||||
/** Identity + source only — LiveKit can change trackSid after publish, which broke spotlight + stale-key effect. */
|
||||
const tileKey = (t: Tile) => `${t.identity}\x1f${t.source}`
|
||||
|
||||
const primaryTile = $derived.by(() => {
|
||||
const k = $videoPrimaryTileKey
|
||||
if (k === undefined) return undefined
|
||||
return tiles.find(t => tileKey(t) === k)
|
||||
})
|
||||
|
||||
const secondaryTiles = $derived.by(() => {
|
||||
const p = primaryTile
|
||||
if (p === undefined) return tiles
|
||||
const pk = tileKey(p)
|
||||
return tiles.filter(t => tileKey(t) !== pk)
|
||||
})
|
||||
|
||||
const useSpotlightLayout = $derived(primaryTile !== undefined)
|
||||
const useMultiGrid = $derived(!useSpotlightLayout && tiles.length > 2)
|
||||
|
||||
$effect(() => {
|
||||
const k = $videoPrimaryTileKey
|
||||
if (k === undefined) return
|
||||
if (!tiles.some(t => tileKey(t) === k)) {
|
||||
videoPrimaryTileKey.set(undefined)
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
for (const t of tiles) {
|
||||
const pk = pubkeyFromLiveKitIdentity(t.identity)
|
||||
if (pk) loadProfile(pk)
|
||||
}
|
||||
})
|
||||
|
||||
const labelFor = (identity: string, source: Tile["source"]) => {
|
||||
const pk = pubkeyFromLiveKitIdentity(identity)
|
||||
const name = pk ? displayProfileByPubkey(pk) : "Unknown"
|
||||
return source === Track.Source.ScreenShare ? `${name} · screen` : name
|
||||
}
|
||||
|
||||
const showTileGrid = $derived(tiles.length > 0)
|
||||
|
||||
const spotlightHandlerFor = (key: string) => () => {
|
||||
toggleVideoPrimaryTile(key)
|
||||
}
|
||||
|
||||
const panelChrome = $derived(
|
||||
cx(
|
||||
variant === "mobile" &&
|
||||
"cb ct cw z-compose bg-base-300/95 fixed inset-x-0 flex min-h-0 flex-col gap-2 overflow-hidden p-2 md:hidden",
|
||||
variant === "desktop-split" &&
|
||||
"cb ct cw-split-video z-compose bg-base-300/95 fixed hidden min-h-0 flex-col gap-2 overflow-hidden p-2 md:flex",
|
||||
variant === "desktop-full" &&
|
||||
"cb ct cw z-compose bg-base-300/95 fixed hidden min-h-0 flex-col gap-2 overflow-hidden p-2 md:flex",
|
||||
className,
|
||||
),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#snippet videoTile(tile: Tile, layout: TileLayout)}
|
||||
<div
|
||||
class={cx(
|
||||
"relative isolate overflow-hidden rounded-box shadow-sm",
|
||||
layout === "spotlight" && "min-h-0 flex-1",
|
||||
layout === "default" && "aspect-video w-full min-h-0",
|
||||
layout === "strip" && "aspect-video w-44 shrink-0",
|
||||
tile.source === Track.Source.ScreenShare ? "bg-black" : "bg-base-100",
|
||||
$videoPrimaryTileKey === tileKey(tile) &&
|
||||
"ring-2 ring-primary ring-offset-2 ring-offset-base-300",
|
||||
)}>
|
||||
{#if tile.attachable}
|
||||
<VideoCallVideo
|
||||
track={tile.attachable}
|
||||
muted={tile.isLocal}
|
||||
fit={tile.source === Track.Source.ScreenShare ? "contain" : "cover"}
|
||||
class="pointer-events-none absolute inset-0" />
|
||||
{:else}
|
||||
<div class="absolute inset-0 flex items-center justify-center">
|
||||
<ProfileCircle pubkey={pubkeyFromLiveKitIdentity(tile.identity)} {url} size={14} />
|
||||
</div>
|
||||
{/if}
|
||||
<span
|
||||
class="pointer-events-none absolute bottom-1 left-1 max-w-[calc(100%-0.5rem)] truncate rounded bg-base-100/80 px-1.5 py-0.5 text-xs">
|
||||
{labelFor(tile.identity, tile.source)}{tile.isLocal ? " (you)" : ""}
|
||||
</span>
|
||||
{#if tiles.length > 1}
|
||||
<Button
|
||||
data-tip={$videoPrimaryTileKey === tileKey(tile) ? "Exit spotlight" : "Spotlight"}
|
||||
class="absolute right-1 top-1 z-20 btn btn-xs btn-circle btn-ghost bg-base-100/70"
|
||||
onclick={spotlightHandlerFor(tileKey(tile))}>
|
||||
<Icon icon={Pin} size={3} />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#if showPanel && (showTileGrid || allowEmptyPanel)}
|
||||
<div class={panelChrome}>
|
||||
{#if showTileGrid}
|
||||
{#if useSpotlightLayout && primaryTile}
|
||||
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-hidden">
|
||||
{@render videoTile(primaryTile, "spotlight")}
|
||||
{#if secondaryTiles.length > 0}
|
||||
<div
|
||||
class="flex max-h-40 shrink-0 flex-row gap-2 overflow-x-auto overflow-y-hidden py-0.5">
|
||||
{#each secondaryTiles as tile (tileKey(tile))}
|
||||
{@render videoTile(tile, "strip")}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if useMultiGrid}
|
||||
<div
|
||||
class="grid min-h-0 flex-1 grid-cols-1 content-start gap-2 overflow-y-auto sm:grid-cols-2">
|
||||
{#each tiles as tile (tileKey(tile))}
|
||||
{@render videoTile(tile, "default")}
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto">
|
||||
{#each tiles as tile (tileKey(tile))}
|
||||
{@render videoTile(tile, "default")}
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div
|
||||
class="flex min-h-[12rem] flex-1 flex-col items-center justify-center gap-2 rounded-box bg-base-100/50 p-4 text-center text-sm opacity-80">
|
||||
<p>No camera or screen share yet.</p>
|
||||
<p class="text-xs">
|
||||
Use the camera or screen share control in the voice widget to share video.
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -1,31 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type {Track} from "livekit-client"
|
||||
import cx from "classnames"
|
||||
|
||||
type Props = {
|
||||
track: Track
|
||||
muted?: boolean
|
||||
fit?: "cover" | "contain"
|
||||
class?: string
|
||||
}
|
||||
|
||||
const {track, muted = true, fit = "cover", class: className = ""}: Props = $props()
|
||||
|
||||
let el = $state<HTMLVideoElement | undefined>()
|
||||
|
||||
$effect(() => {
|
||||
const v = el
|
||||
const t = track
|
||||
if (!v) return
|
||||
t.attach(v)
|
||||
return () => {
|
||||
t.detach(v)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<video
|
||||
bind:this={el}
|
||||
class={cx("h-full w-full", fit === "contain" ? "object-contain" : "object-cover", className)}
|
||||
playsinline
|
||||
{muted}></video>
|
||||
@@ -5,6 +5,7 @@
|
||||
import ModalBody from "@lib/components/ModalBody.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
||||
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
||||
import {
|
||||
currentVoiceSession,
|
||||
@@ -25,10 +26,8 @@
|
||||
|
||||
let audioInputs = $state<MediaDeviceInfo[]>([])
|
||||
let audioOutputs = $state<MediaDeviceInfo[]>([])
|
||||
let videoInputs = $state<MediaDeviceInfo[]>([])
|
||||
let selectedInput = $state("")
|
||||
let selectedOutput = $state("")
|
||||
let selectedVideo = $state("")
|
||||
|
||||
const loadDevices = async () => {
|
||||
if (!navigator.mediaDevices?.enumerateDevices) return
|
||||
@@ -36,25 +35,16 @@
|
||||
const devices = await navigator.mediaDevices.enumerateDevices()
|
||||
audioInputs = devices.filter(d => d.kind === "audioinput")
|
||||
audioOutputs = devices.filter(d => d.kind === "audiooutput")
|
||||
videoInputs = devices.filter(d => d.kind === "videoinput")
|
||||
} catch {
|
||||
audioInputs = []
|
||||
audioOutputs = []
|
||||
videoInputs = []
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
void loadDevices()
|
||||
const md = navigator.mediaDevices
|
||||
if (!md?.addEventListener) return
|
||||
const onDeviceChange = () => {
|
||||
void loadDevices()
|
||||
}
|
||||
md.addEventListener("devicechange", onDeviceChange)
|
||||
return () => {
|
||||
md.removeEventListener("devicechange", onDeviceChange)
|
||||
}
|
||||
loadDevices()
|
||||
navigator.mediaDevices?.addEventListener?.("devicechange", loadDevices)
|
||||
return () => navigator.mediaDevices?.removeEventListener?.("devicechange", loadDevices)
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
@@ -65,7 +55,6 @@
|
||||
}
|
||||
selectedInput = selectValueForActiveDevice(session, DeviceKind.AudioInput)
|
||||
selectedOutput = selectValueForActiveDevice(session, DeviceKind.AudioOutput)
|
||||
selectedVideo = selectValueForActiveDevice(session, DeviceKind.VideoInput)
|
||||
})
|
||||
|
||||
const onInputChange = () => {
|
||||
@@ -76,23 +65,20 @@
|
||||
void switchVoiceActiveDevice(DeviceKind.AudioOutput, selectedOutput)
|
||||
}
|
||||
|
||||
const onVideoChange = () => {
|
||||
void switchVoiceActiveDevice(DeviceKind.VideoInput, selectedVideo)
|
||||
}
|
||||
|
||||
const onDone = () => {
|
||||
popModal()
|
||||
}
|
||||
|
||||
// Output not support in Safari
|
||||
const canPickOutput = supportsAudioOutputSelection()
|
||||
</script>
|
||||
|
||||
<Modal>
|
||||
<ModalBody>
|
||||
<ModalHeader>
|
||||
<ModalTitle>Call settings</ModalTitle>
|
||||
<ModalTitle>Audio settings</ModalTitle>
|
||||
<ModalSubtitle>Choose microphone and speaker for this call.</ModalSubtitle>
|
||||
</ModalHeader>
|
||||
<p class="text-sm opacity-80">Microphone, speaker, and camera for this call.</p>
|
||||
<div class="flex flex-col gap-4 pt-2">
|
||||
<FieldInline>
|
||||
{#snippet label()}
|
||||
@@ -134,28 +120,9 @@
|
||||
{/snippet}
|
||||
</FieldInline>
|
||||
{/if}
|
||||
<FieldInline>
|
||||
{#snippet label()}
|
||||
<p>Camera</p>
|
||||
{/snippet}
|
||||
{#snippet input()}
|
||||
<select
|
||||
class="select select-bordered w-full"
|
||||
bind:value={selectedVideo}
|
||||
onchange={onVideoChange}
|
||||
aria-label="Camera">
|
||||
<option value="">Default camera</option>
|
||||
{#each videoInputs as d (d.deviceId)}
|
||||
<option value={d.deviceId}>
|
||||
{d.label || `Camera ${d.deviceId.slice(0, 8)}…`}
|
||||
</option>
|
||||
{/each}
|
||||
</select>
|
||||
{/snippet}
|
||||
</FieldInline>
|
||||
</div>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button class="btn btn-primary" onclick={onDone}>Done</Button>
|
||||
<Button class="btn btn-primary w-full" onclick={onDone}>Done</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
|
||||
@@ -12,9 +12,11 @@
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
||||
import ModalTitle from "@lib/components/ModalTitle.svelte"
|
||||
import {AbortError, TimeoutError} from "$lib/util"
|
||||
import {displayRoom} from "@app/core/state"
|
||||
import {joinVoiceRoom} from "@app/voice"
|
||||
import {popModal} from "@app/util/modal"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
|
||||
type Props = {
|
||||
url: string
|
||||
@@ -45,6 +47,16 @@
|
||||
|
||||
const goBack = () => history.back()
|
||||
|
||||
const handleJoinError = (e: unknown) => {
|
||||
if (e instanceof AbortError) return
|
||||
console.error("Failed to join voice room", e)
|
||||
let message = "Failed to join voice room"
|
||||
if (e instanceof TimeoutError)
|
||||
message = "Connection timed out. Please check your network and try again."
|
||||
else if (e instanceof Error) message = e.message
|
||||
pushToast({theme: "error", message})
|
||||
}
|
||||
|
||||
const joinVoice = async () => {
|
||||
popModal()
|
||||
await joinVoiceRoom(
|
||||
@@ -52,7 +64,7 @@
|
||||
h,
|
||||
startWithoutMic,
|
||||
startWithoutMic ? undefined : selectedDeviceId || undefined,
|
||||
)
|
||||
).catch(handleJoinError)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -77,7 +89,7 @@
|
||||
type="checkbox"
|
||||
class="checkbox"
|
||||
bind:checked={startWithoutMic} />
|
||||
<label for="voice-start-without-mic" class="cursor-pointer text-sm">
|
||||
<label for="voice-start-without-mic" class="text-sm cursor-pointer">
|
||||
Join without microphone (you can unmute later)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
import {displayRelayUrl} from "@welshman/util"
|
||||
import Microphone from "@assets/icons/microphone.svg?dataurl"
|
||||
import MicrophoneOff from "@assets/icons/microphone-off.svg?dataurl"
|
||||
import Videocamera from "@assets/icons/videocamera.svg?dataurl"
|
||||
import VideocameraRecord from "@assets/icons/videocamera-record.svg?dataurl"
|
||||
import Monitor from "@assets/icons/monitor.svg?dataurl"
|
||||
import PhoneRounded from "@assets/icons/phone-rounded.svg?dataurl"
|
||||
import PhoneCallingRounded from "@assets/icons/phone-calling-rounded.svg?dataurl"
|
||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||
@@ -34,8 +31,6 @@
|
||||
voiceState,
|
||||
leaveVoiceRoom,
|
||||
toggleMute,
|
||||
toggleCamera,
|
||||
toggleScreenShare,
|
||||
cancelJoinVoiceRoom,
|
||||
} from "@app/voice"
|
||||
|
||||
@@ -112,23 +107,7 @@
|
||||
<Icon icon={$currentVoiceSession.muted ? MicrophoneOff : Microphone} size={4} />
|
||||
</Button>
|
||||
<Button
|
||||
data-tip={$currentVoiceSession.cameraOn ? "Turn off camera" : "Turn on camera"}
|
||||
class="center tooltip tooltip-top btn btn-sm btn-square {$currentVoiceSession.cameraOn
|
||||
? 'btn-ghost'
|
||||
: 'btn-error'}"
|
||||
onclick={toggleCamera}>
|
||||
<Icon icon={$currentVoiceSession.cameraOn ? VideocameraRecord : Videocamera} size={4} />
|
||||
</Button>
|
||||
<Button
|
||||
data-tip={$currentVoiceSession.screenShareOn ? "Stop sharing" : "Share screen"}
|
||||
class="center tooltip tooltip-top btn btn-sm btn-square {$currentVoiceSession.screenShareOn
|
||||
? 'btn-ghost'
|
||||
: 'btn-error'}"
|
||||
onclick={toggleScreenShare}>
|
||||
<Icon icon={Monitor} size={4} />
|
||||
</Button>
|
||||
<Button
|
||||
data-tip="Call settings"
|
||||
data-tip="Audio settings"
|
||||
class="center tooltip tooltip-top btn btn-sm btn-square btn-ghost"
|
||||
onclick={openAudioSettings}>
|
||||
<Icon icon={Settings} size={4} />
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
import {Nip01Signer} from "@welshman/signer"
|
||||
import type {UploadTask} from "@welshman/editor"
|
||||
import type {TrustedEvent, EventContent, Profile, PublishedRoomMeta} from "@welshman/util"
|
||||
import {PollResponse} from "nostr-tools/kinds"
|
||||
import {
|
||||
DELETE,
|
||||
REPORT,
|
||||
@@ -351,6 +352,22 @@ export const publishReaction = ({relays, ...params}: ReactionParams & {relays: s
|
||||
publishThunk({event: makeReaction({url: relays[0], ...params}), relays})
|
||||
}
|
||||
|
||||
// Polls
|
||||
|
||||
export type PollResponseParams = {
|
||||
event: TrustedEvent
|
||||
selectedIds: string[]
|
||||
}
|
||||
|
||||
export const makePollResponse = ({event, selectedIds}: PollResponseParams) =>
|
||||
makeEvent(PollResponse, {
|
||||
content: "",
|
||||
tags: [["e", event.id], ...selectedIds.map(selectedId => ["response", selectedId])],
|
||||
})
|
||||
|
||||
export const publishPollResponse = ({relays, ...params}: PollResponseParams & {relays: string[]}) =>
|
||||
publishThunk({event: makePollResponse(params), relays})
|
||||
|
||||
// Comments
|
||||
|
||||
export type CommentParams = {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {context as pomadeContext} from "@pomade/core"
|
||||
import {Capacitor} from "@capacitor/core"
|
||||
import {derived, readable, writable} from "svelte/store"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import {
|
||||
on,
|
||||
gt,
|
||||
@@ -191,7 +192,9 @@ export const PLATFORM_TERMS = import.meta.env.VITE_PLATFORM_TERMS
|
||||
|
||||
export const PLATFORM_PRIVACY = import.meta.env.VITE_PLATFORM_PRIVACY
|
||||
|
||||
export const PLATFORM_LOGO = PLATFORM_URL + "/logo.png"
|
||||
export const PLATFORM_LOGO = import.meta.env.PROD
|
||||
? PLATFORM_URL + "/logo.png"
|
||||
: import.meta.env.VITE_PLATFORM_LOGO.replace(/^static/, "") || PLATFORM_URL + "/logo.png"
|
||||
|
||||
export const PLATFORM_NAME = import.meta.env.VITE_PLATFORM_NAME
|
||||
|
||||
@@ -323,7 +326,7 @@ if (ENABLE_ZAPS) {
|
||||
REACTION_KINDS.push(ZAP_RESPONSE)
|
||||
}
|
||||
|
||||
export const CONTENT_KINDS = [ZAP_GOAL, EVENT_TIME, THREAD, CLASSIFIED]
|
||||
export const CONTENT_KINDS = [ZAP_GOAL, EVENT_TIME, THREAD, CLASSIFIED, Poll]
|
||||
|
||||
export const MESSAGE_KINDS = [...CONTENT_KINDS, MESSAGE]
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {page} from "$app/stores"
|
||||
import type {Unsubscriber} from "svelte/store"
|
||||
import {derived, get} from "svelte/store"
|
||||
import {last, call, ifLet, assoc, chunk, sleep, identity, WEEK, ago} from "@welshman/lib"
|
||||
import {PollResponse} from "nostr-tools/kinds"
|
||||
import {
|
||||
getListTags,
|
||||
getRelayTagValues,
|
||||
@@ -281,6 +282,7 @@ const syncSpace = (url: string, rooms: string[]) => {
|
||||
filters: [
|
||||
{kinds: MESSAGE_KINDS, since, "#h": [room]},
|
||||
makeCommentFilter(CONTENT_KINDS, {since, "#h": [room]}),
|
||||
{kinds: [PollResponse], since},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -298,11 +300,9 @@ const syncSpace = (url: string, rooms: string[]) => {
|
||||
url,
|
||||
signal: controller.signal,
|
||||
filters: [
|
||||
{kinds: relayKinds},
|
||||
{kinds: roomMetaKinds},
|
||||
{kinds: roomMemberKinds},
|
||||
{kinds: MESSAGE_KINDS, since},
|
||||
{kinds: [...relayKinds, ...roomMetaKinds, ...roomMemberKinds, ...MESSAGE_KINDS]},
|
||||
makeCommentFilter(CONTENT_KINDS, {since}),
|
||||
{kinds: [PollResponse], since},
|
||||
],
|
||||
onEvent: event => {
|
||||
if (event.kind === ROOM_META) {
|
||||
@@ -314,7 +314,7 @@ const syncSpace = (url: string, rooms: string[]) => {
|
||||
listen({
|
||||
url,
|
||||
signal: controller.signal,
|
||||
filters: [{kinds: REACTION_KINDS}],
|
||||
filters: [{kinds: REACTION_KINDS}, {kinds: [PollResponse]}],
|
||||
})
|
||||
|
||||
return () => controller.abort()
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import {now, removeUndefined, uniq} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {getTagValue, getTags, getTagValues} from "@welshman/util"
|
||||
|
||||
export type PollType = "singlechoice" | "multiplechoice"
|
||||
|
||||
export type PollOption = {
|
||||
id: string
|
||||
label: string
|
||||
votes: number
|
||||
}
|
||||
|
||||
export const getPollType = (event: TrustedEvent): PollType =>
|
||||
getTagValue("polltype", event.tags) === "multiplechoice" ? "multiplechoice" : "singlechoice"
|
||||
|
||||
export const getPollOptions = (event: TrustedEvent) =>
|
||||
removeUndefined(
|
||||
getTags("option", event.tags).map(tag => {
|
||||
const [, id, label = id] = tag
|
||||
|
||||
if (!id) return undefined
|
||||
|
||||
return {id, label}
|
||||
}),
|
||||
)
|
||||
|
||||
export const getPollEndsAt = (event: TrustedEvent) => {
|
||||
const endsAt = getTagValue("endsAt", event.tags)
|
||||
|
||||
if (!endsAt) return undefined
|
||||
|
||||
const timestamp = parseInt(endsAt)
|
||||
|
||||
return Number.isNaN(timestamp) ? undefined : timestamp
|
||||
}
|
||||
|
||||
export const isPollClosed = (event: TrustedEvent) => {
|
||||
const endsAt = getPollEndsAt(event)
|
||||
|
||||
return typeof endsAt === "number" ? endsAt <= now() : false
|
||||
}
|
||||
|
||||
export const getPollResponseSelections = (event: TrustedEvent, pollType = getPollType(event)) => {
|
||||
const selections = getTagValues("response", event.tags)
|
||||
|
||||
return pollType === "singlechoice" ? selections.slice(0, 1) : uniq(selections)
|
||||
}
|
||||
|
||||
export const getPollResults = (event: TrustedEvent, responses: TrustedEvent[]) => {
|
||||
const options = getPollOptions(event).map(option => ({...option, votes: 0}))
|
||||
const counts = new Map(options.map(option => [option.id, option]))
|
||||
const latestByPubkey = new Map<string, TrustedEvent>()
|
||||
|
||||
for (const response of responses) {
|
||||
const current = latestByPubkey.get(response.pubkey)
|
||||
|
||||
if (!current || response.created_at > current.created_at) {
|
||||
latestByPubkey.set(response.pubkey, response)
|
||||
}
|
||||
}
|
||||
|
||||
for (const response of latestByPubkey.values()) {
|
||||
for (const optionId of getPollResponseSelections(response, getPollType(event))) {
|
||||
const option = counts.get(optionId)
|
||||
|
||||
if (option) {
|
||||
option.votes += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
options,
|
||||
voters: latestByPubkey.size,
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {page} from "$app/stores"
|
||||
import {nthEq} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {getAddress} from "@welshman/util"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import {tracker, userMessagingRelayList} from "@welshman/app"
|
||||
import {identity} from "@welshman/lib"
|
||||
import {
|
||||
@@ -90,6 +91,8 @@ export const makeClassifiedPath = (url: string, address?: string) =>
|
||||
export const makeCalendarPath = (url: string, address?: string) =>
|
||||
makeSpacePath(url, "calendar", address)
|
||||
|
||||
export const makePollPath = (url: string, id?: string) => makeSpacePath(url, "polls", id)
|
||||
|
||||
export const scrollToEvent = (id: string) => {
|
||||
const element = document.querySelector(`[data-event="${id}"]`) as any
|
||||
|
||||
@@ -146,6 +149,10 @@ export const getEventPath = (event: TrustedEvent, urls: string[]) => {
|
||||
return makeCalendarPath(url, getAddress(event))
|
||||
}
|
||||
|
||||
if (event.kind === Poll) {
|
||||
return makePollPath(url, event.id)
|
||||
}
|
||||
|
||||
if (event.kind === MESSAGE) {
|
||||
return makeMessagePath(url, event)
|
||||
}
|
||||
@@ -192,5 +199,7 @@ export const getRoomItemPath = (url: string, event: TrustedEvent) => {
|
||||
return makeGoalPath(url, event.id)
|
||||
case EVENT_TIME:
|
||||
return makeCalendarPath(url, getAddress(event))
|
||||
case Poll:
|
||||
return makePollPath(url, event.id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const staticTitles = new Map<string, string>([
|
||||
["/spaces/[relay]/classifieds", "Classifieds"],
|
||||
["/spaces/[relay]/calendar", "Calendar"],
|
||||
["/spaces/[relay]/goals", "Goals"],
|
||||
["/spaces/[relay]/polls", "Polls"],
|
||||
["/chat", "Messages"],
|
||||
["/join", "Join Space"],
|
||||
["/people", "Find People"],
|
||||
@@ -35,6 +36,7 @@ const eventRoutes = new Set([
|
||||
"/spaces/[relay]/goals/[id]",
|
||||
"/spaces/[relay]/calendar/[address]",
|
||||
"/spaces/[relay]/classifieds/[address]",
|
||||
"/spaces/[relay]/polls/[id]",
|
||||
])
|
||||
|
||||
type RouteParams = Record<string, string | undefined>
|
||||
|
||||
+2
-159
@@ -4,13 +4,12 @@
|
||||
*/
|
||||
import {
|
||||
DisconnectReason,
|
||||
LocalParticipant,
|
||||
LocalTrackPublication,
|
||||
Room as LiveKitRoom,
|
||||
RoomEvent,
|
||||
Track,
|
||||
supportsAudioOutputSelection,
|
||||
type AudioCaptureOptions,
|
||||
type LocalParticipant,
|
||||
} from "livekit-client"
|
||||
import {derived, get, writable} from "svelte/store"
|
||||
import {map, removeUndefined, uniqBy} from "@welshman/lib"
|
||||
@@ -33,8 +32,6 @@ export type VoiceSession = {
|
||||
h: string
|
||||
room: LiveKitRoom
|
||||
muted: boolean
|
||||
cameraOn: boolean
|
||||
screenShareOn: boolean
|
||||
}
|
||||
|
||||
export type Pubkey = string
|
||||
@@ -54,7 +51,6 @@ const LIVEKIT_DEFAULT_DEVICE_ID = "default"
|
||||
export enum DeviceKind {
|
||||
AudioInput = "audioinput",
|
||||
AudioOutput = "audiooutput",
|
||||
VideoInput = "videoinput",
|
||||
}
|
||||
|
||||
export const switchVoiceActiveDevice = async (
|
||||
@@ -75,9 +71,6 @@ export const switchVoiceActiveDevice = async (
|
||||
case DeviceKind.AudioOutput:
|
||||
label = "speaker"
|
||||
break
|
||||
case DeviceKind.VideoInput:
|
||||
label = "camera"
|
||||
break
|
||||
}
|
||||
pushToast({theme: "error", message: `Error changing ${label}`})
|
||||
}
|
||||
@@ -89,18 +82,6 @@ export const currentVoiceRoom = writable<Room | undefined>(undefined)
|
||||
|
||||
export const participantPubkeyMap = writable<Map<string, Pubkey>>(new Map())
|
||||
|
||||
/** Bumps when remote video is subscribed/unsubscribed so layout/video UI can react. */
|
||||
export const videoCallLayoutRevision = writable(0)
|
||||
|
||||
/** Spotlight tile id — must match VideoCallContent `tileKey` (identity + source, not trackSid). */
|
||||
export const videoPrimaryTileKey = writable<string | undefined>(undefined)
|
||||
|
||||
export const toggleVideoPrimaryTile = (key: string) => {
|
||||
videoPrimaryTileKey.update(k => (k === key ? undefined : key))
|
||||
}
|
||||
|
||||
const bumpVideoCallLayoutRevision = () => videoCallLayoutRevision.update(n => n + 1)
|
||||
|
||||
const addParticipant = (identity: string) => {
|
||||
participantPubkeyMap.update(m => {
|
||||
const next = new Map(m)
|
||||
@@ -216,8 +197,6 @@ const setUpMicrophone = async (
|
||||
}
|
||||
|
||||
const onRoomDisconnected = (reason?: DisconnectReason) => {
|
||||
videoCallLayoutRevision.set(0)
|
||||
videoPrimaryTileKey.set(undefined)
|
||||
currentVoiceSession.set(undefined)
|
||||
if (reason !== undefined && reason !== DisconnectReason.CLIENT_INITIATED) {
|
||||
voiceState.set(VoiceState.Disconnected)
|
||||
@@ -237,16 +216,11 @@ const onTrackSubscribed = (track: Track) => {
|
||||
element.style.display = "none"
|
||||
document.body.appendChild(element)
|
||||
element.play().catch(() => {})
|
||||
} else if (track.kind === Track.Kind.Video) {
|
||||
bumpVideoCallLayoutRevision()
|
||||
}
|
||||
}
|
||||
|
||||
const onTrackUnsubscribed = (track: Track) => {
|
||||
track.detach().forEach(el => el.remove())
|
||||
if (track.kind === Track.Kind.Video) {
|
||||
bumpVideoCallLayoutRevision()
|
||||
}
|
||||
}
|
||||
|
||||
const onActiveSpeakersChanged = (participants: {identity: string}[]) => {
|
||||
@@ -267,18 +241,6 @@ const onParticipantDisconnected = (participant: {identity: string}) => {
|
||||
deleteParticipant(participant.identity)
|
||||
}
|
||||
|
||||
const onLocalTrackUnpublished = (
|
||||
publication: LocalTrackPublication,
|
||||
participant: LocalParticipant,
|
||||
) => {
|
||||
if (publication.source !== Track.Source.ScreenShare) return
|
||||
const session = get(currentVoiceSession)
|
||||
if (!session || participant.identity !== session.room.localParticipant.identity) return
|
||||
if (!session.screenShareOn) return
|
||||
currentVoiceSession.set({...session, screenShareOn: false})
|
||||
bumpVideoCallLayoutRevision()
|
||||
}
|
||||
|
||||
let joinAbortController: AbortController | undefined
|
||||
|
||||
export const cancelJoinVoiceRoom = () => {
|
||||
@@ -316,7 +278,6 @@ export const joinVoiceRoom = async (
|
||||
liveKitRoom.on(RoomEvent.ParticipantDisconnected, onParticipantDisconnected)
|
||||
liveKitRoom.on(RoomEvent.TrackSubscribed, onTrackSubscribed)
|
||||
liveKitRoom.on(RoomEvent.TrackUnsubscribed, onTrackUnsubscribed)
|
||||
liveKitRoom.on(RoomEvent.LocalTrackUnpublished, onLocalTrackUnpublished)
|
||||
liveKitRoom.on(RoomEvent.ActiveSpeakersChanged, onActiveSpeakersChanged)
|
||||
|
||||
try {
|
||||
@@ -340,14 +301,7 @@ export const joinVoiceRoom = async (
|
||||
|
||||
const muted = await setUpMicrophone(startMuted, preferredMicId, liveKitRoom.localParticipant)
|
||||
|
||||
currentVoiceSession.set({
|
||||
url,
|
||||
h,
|
||||
room: liveKitRoom,
|
||||
muted,
|
||||
cameraOn: false,
|
||||
screenShareOn: false,
|
||||
})
|
||||
currentVoiceSession.set({url, h, room: liveKitRoom, muted})
|
||||
voiceState.set(VoiceState.Connected)
|
||||
playJoinSound()
|
||||
} catch (e) {
|
||||
@@ -366,25 +320,7 @@ export const leaveVoiceRoom = async () => {
|
||||
const audio = new Audio("/leave-voice-room.mp3")
|
||||
audio.play().catch(() => {})
|
||||
|
||||
if (session.cameraOn) {
|
||||
try {
|
||||
await session.room.localParticipant.setCameraEnabled(false)
|
||||
} catch {
|
||||
/* pass */
|
||||
}
|
||||
}
|
||||
|
||||
if (session.screenShareOn) {
|
||||
try {
|
||||
await session.room.localParticipant.setScreenShareEnabled(false)
|
||||
} catch {
|
||||
/* pass */
|
||||
}
|
||||
}
|
||||
|
||||
voiceState.set(VoiceState.Disconnected)
|
||||
videoCallLayoutRevision.set(0)
|
||||
videoPrimaryTileKey.set(undefined)
|
||||
currentVoiceSession.set(undefined)
|
||||
session.room.disconnect()
|
||||
speakingParticipants.set([])
|
||||
@@ -416,96 +352,3 @@ export const toggleMute = async () => {
|
||||
pushToast({theme: "error", message: "Could not access microphone"})
|
||||
}
|
||||
}
|
||||
|
||||
const VISUAL_SOURCES = [Track.Source.Camera, Track.Source.ScreenShare] as const
|
||||
|
||||
const roomHasSubscribedRemoteVisual = (room: LiveKitRoom): boolean => {
|
||||
for (const p of room.remoteParticipants.values()) {
|
||||
for (const source of VISUAL_SOURCES) {
|
||||
const pub = p.getTrackPublication(source)
|
||||
if (pub?.isSubscribed && pub.track) return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/** True when local camera/screen share is on or any subscribed remote camera/screen track. */
|
||||
export const videoCallContentActive = derived(
|
||||
[currentVoiceSession, voiceState, videoCallLayoutRevision],
|
||||
([$session, $state, _rev]) => {
|
||||
if ($state !== VoiceState.Connected || !$session) return false
|
||||
if ($session.cameraOn || $session.screenShareOn) return true
|
||||
return roomHasSubscribedRemoteVisual($session.room)
|
||||
},
|
||||
)
|
||||
|
||||
const countLiveVisualFeeds = (session: VoiceSession): number => {
|
||||
const room = session.room
|
||||
let n = 0
|
||||
const lp = room.localParticipant
|
||||
if (session.cameraOn) {
|
||||
const pub = lp.getTrackPublication(Track.Source.Camera)
|
||||
if (pub?.track) n += 1
|
||||
}
|
||||
if (session.screenShareOn) {
|
||||
const pub = lp.getTrackPublication(Track.Source.ScreenShare)
|
||||
if (pub?.track) n += 1
|
||||
}
|
||||
for (const rp of room.remoteParticipants.values()) {
|
||||
for (const source of VISUAL_SOURCES) {
|
||||
const pub = rp.getTrackPublication(source)
|
||||
if (pub?.isSubscribed && pub.track) n += 1
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
export const videoTileCount = derived(
|
||||
[currentVoiceSession, voiceState, videoCallLayoutRevision],
|
||||
([$session, $state, _rev]) => {
|
||||
if ($state !== VoiceState.Connected || !$session) return 0
|
||||
return countLiveVisualFeeds($session)
|
||||
},
|
||||
)
|
||||
|
||||
export const toggleCamera = async () => {
|
||||
const session = get(currentVoiceSession)
|
||||
if (!session) return
|
||||
|
||||
const cameraOn = !session.cameraOn
|
||||
if (!cameraOn) {
|
||||
session.room.localParticipant.setCameraEnabled(false)
|
||||
currentVoiceSession.set({...session, cameraOn})
|
||||
bumpVideoCallLayoutRevision()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await session.room.localParticipant.setCameraEnabled(true)
|
||||
currentVoiceSession.set({...session, cameraOn})
|
||||
bumpVideoCallLayoutRevision()
|
||||
} catch (e) {
|
||||
pushToast({theme: "error", message: "Could not access camera"})
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleScreenShare = async () => {
|
||||
const session = get(currentVoiceSession)
|
||||
if (!session) return
|
||||
|
||||
const screenShareOn = !session.screenShareOn
|
||||
if (!screenShareOn) {
|
||||
session.room.localParticipant.setScreenShareEnabled(false)
|
||||
currentVoiceSession.set({...session, screenShareOn})
|
||||
bumpVideoCallLayoutRevision()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await session.room.localParticipant.setScreenShareEnabled(true)
|
||||
currentVoiceSession.set({...session, screenShareOn})
|
||||
bumpVideoCallLayoutRevision()
|
||||
} catch (e) {
|
||||
pushToast({theme: "error", message: "Could not start screen sharing"})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,14 @@
|
||||
interface Props {
|
||||
element?: Element
|
||||
children?: Snippet
|
||||
/** Desktop voice: chat occupies the right half in split view. */
|
||||
contentFrame?: "default" | "split-right"
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {children, element = $bindable(), contentFrame = "default", ...props}: Props = $props()
|
||||
let {children, element = $bindable(), ...props}: Props = $props()
|
||||
|
||||
const className = $derived(
|
||||
cx(
|
||||
props.class,
|
||||
"scroll-container cb ct fixed z-feature overflow-y-auto overflow-x-hidden",
|
||||
contentFrame === "split-right" ? "cw-split-chat" : "cw",
|
||||
),
|
||||
const className = cx(
|
||||
props.class,
|
||||
"scroll-container cw cb ct fixed z-feature overflow-y-auto overflow-x-hidden",
|
||||
)
|
||||
</script>
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
} from "@app/core/state"
|
||||
import {setSpaceMembershipOrder} from "@app/core/commands"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
import {goToSpace} from "@app/util/routes"
|
||||
import {goToSpace, makeSpacePath} from "@app/util/routes"
|
||||
import {notifications} from "@app/util/notifications"
|
||||
|
||||
const addSpace = () => pushModal(SpaceAdd)
|
||||
|
||||
@@ -254,9 +255,12 @@
|
||||
ondrop={e => onDrop(e, url)}
|
||||
ondragend={onDragEnd}>
|
||||
<Button
|
||||
class="card2 bg-alt shadow-md transition-all hover:shadow-lg hover:dark:brightness-[1.1] w-full"
|
||||
class="card2 bg-alt shadow-md transition-all hover:shadow-lg hover:dark:brightness-[1.1] w-full relative"
|
||||
onclick={() => openSpace(url)}>
|
||||
<RelaySummary hideFavorites {url} />
|
||||
{#if $notifications.has(makeSpacePath(url))}
|
||||
<div class="absolute right-3 top-3 h-2 w-2 rounded-full bg-primary"></div>
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type {Snippet} from "svelte"
|
||||
<script>
|
||||
import {page} from "$app/stores"
|
||||
|
||||
type Props = {
|
||||
children?: Snippet
|
||||
}
|
||||
|
||||
const {children}: Props = $props()
|
||||
</script>
|
||||
|
||||
{#key $page.url.searchParams.get("at")}
|
||||
{@render children?.()}
|
||||
<slot />
|
||||
{/key}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
import ClockCircle from "@assets/icons/clock-circle.svg?dataurl"
|
||||
import InfoCircle from "@assets/icons/info-circle.svg?dataurl"
|
||||
import Login2 from "@assets/icons/login-3.svg?dataurl"
|
||||
import cx from "classnames"
|
||||
import {slide, fade, fly} from "@lib/transition"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import Divider from "@lib/components/Divider.svelte"
|
||||
@@ -51,8 +50,7 @@
|
||||
userSettingsValues,
|
||||
} from "@app/core/state"
|
||||
import VoiceWidget from "@app/components/VoiceWidget.svelte"
|
||||
import VideoCallContent from "@app/components/VideoCallContent.svelte"
|
||||
import {VoiceState, currentVoiceRoom, videoTileCount, voiceState} from "@app/voice"
|
||||
import {VoiceState, voiceState} from "@app/voice"
|
||||
import {makeFeed} from "@app/core/requests"
|
||||
import {popKey} from "@lib/implicit"
|
||||
import {checked} from "@app/util/notifications"
|
||||
@@ -65,53 +63,6 @@
|
||||
const url = decodeRelay(relay)
|
||||
const room = deriveRoom(url, h)
|
||||
const isVoiceRoom = $derived(getRoomType($room) === RoomType.Voice)
|
||||
|
||||
const voiceConnectedHere = $derived(
|
||||
isVoiceRoom &&
|
||||
$voiceState === VoiceState.Connected &&
|
||||
$currentVoiceRoom?.url === url &&
|
||||
$currentVoiceRoom?.h === h,
|
||||
)
|
||||
|
||||
let mobileRoomPanel = $state<"chat" | "video">("chat")
|
||||
let voiceDesktopPanel = $state<"chat" | "video" | "split">("split")
|
||||
|
||||
const showMobileVideoPanel = $derived(
|
||||
isVoiceRoom && $voiceState === VoiceState.Connected && mobileRoomPanel === "video",
|
||||
)
|
||||
|
||||
const pageContentFrame = $derived<"default" | "split-right">(
|
||||
voiceConnectedHere && voiceDesktopPanel === "split" ? "split-right" : "default",
|
||||
)
|
||||
|
||||
const pageContentHiddenDesktopVideoOnly = $derived(
|
||||
voiceConnectedHere && voiceDesktopPanel === "video",
|
||||
)
|
||||
|
||||
let prevVideoTileCount = $state(0)
|
||||
|
||||
$effect(() => {
|
||||
if ($voiceState !== VoiceState.Connected) {
|
||||
mobileRoomPanel = "chat"
|
||||
voiceDesktopPanel = "chat"
|
||||
prevVideoTileCount = 0
|
||||
return
|
||||
}
|
||||
|
||||
const here = isVoiceRoom && $currentVoiceRoom?.url === url && $currentVoiceRoom?.h === h
|
||||
const n = $videoTileCount
|
||||
|
||||
if (!here) {
|
||||
prevVideoTileCount = 0
|
||||
return
|
||||
}
|
||||
|
||||
if (prevVideoTileCount === 0 && n >= 1) {
|
||||
voiceDesktopPanel = "video"
|
||||
mobileRoomPanel = "video"
|
||||
}
|
||||
prevVideoTileCount = n
|
||||
})
|
||||
const shouldProtect = canEnforceNip70(url)
|
||||
const membershipStatus = deriveUserRoomMembershipStatus(url, h)
|
||||
const at = $derived(parseInt($page.url.searchParams.get("at")!))
|
||||
@@ -418,40 +369,6 @@
|
||||
<RoomName {url} {h} />
|
||||
{/snippet}
|
||||
{#snippet action()}
|
||||
{#if voiceConnectedHere}
|
||||
<div class="flex gap-1 md:hidden">
|
||||
<Button
|
||||
class={cx("btn btn-sm", mobileRoomPanel === "chat" && "btn-primary")}
|
||||
onclick={() => (mobileRoomPanel = "chat")}>
|
||||
Chat
|
||||
</Button>
|
||||
<Button
|
||||
class={cx("btn btn-sm", mobileRoomPanel === "video" && "btn-primary")}
|
||||
onclick={() => (mobileRoomPanel = "video")}>
|
||||
Video
|
||||
</Button>
|
||||
</div>
|
||||
<div class="hidden flex-wrap gap-1 md:flex">
|
||||
<Button
|
||||
data-tip="Messages only"
|
||||
class={cx("btn btn-sm", voiceDesktopPanel === "chat" && "btn-primary")}
|
||||
onclick={() => (voiceDesktopPanel = "chat")}>
|
||||
Chat
|
||||
</Button>
|
||||
<Button
|
||||
data-tip="Video only"
|
||||
class={cx("btn btn-sm", voiceDesktopPanel === "video" && "btn-primary")}
|
||||
onclick={() => (voiceDesktopPanel = "video")}>
|
||||
Video
|
||||
</Button>
|
||||
<Button
|
||||
data-tip="Video and chat side by side"
|
||||
class={cx("btn btn-sm", voiceDesktopPanel === "split" && "btn-primary")}
|
||||
onclick={() => (voiceDesktopPanel = "split")}>
|
||||
Video + Chat
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
<SpaceSearch {url} {h} />
|
||||
<Button class="btn btn-neutral btn-sm btn-square" onclick={showRoomDetail}>
|
||||
<Icon size={4} icon={InfoCircle} />
|
||||
@@ -459,16 +376,7 @@
|
||||
{/snippet}
|
||||
</SpaceBar>
|
||||
|
||||
<PageContent
|
||||
bind:element
|
||||
onscroll={onScroll}
|
||||
contentFrame={pageContentFrame}
|
||||
class={cx(
|
||||
showMobileVideoPanel
|
||||
? "hidden flex-col-reverse pt-4 md:flex md:flex-col-reverse"
|
||||
: "flex flex-col-reverse pt-4",
|
||||
pageContentHiddenDesktopVideoOnly && "md:hidden",
|
||||
)}>
|
||||
<PageContent bind:element onscroll={onScroll} class="flex flex-col-reverse pt-4">
|
||||
<div bind:this={dynamicPadding}></div>
|
||||
{#if $room.isPrivate && $membershipStatus !== MembershipStatus.Granted}
|
||||
<div class="py-20">
|
||||
@@ -538,22 +446,8 @@
|
||||
{/if}
|
||||
</PageContent>
|
||||
|
||||
{#if voiceConnectedHere}
|
||||
<VideoCallContent variant="desktop-split" {url} {h} visible={voiceDesktopPanel === "split"} />
|
||||
<VideoCallContent variant="desktop-full" {url} {h} visible={voiceDesktopPanel === "video"} />
|
||||
{/if}
|
||||
|
||||
{#if isVoiceRoom && $voiceState === VoiceState.Connected}
|
||||
<VideoCallContent variant="mobile" {url} {h} visible={mobileRoomPanel === "video"} />
|
||||
{/if}
|
||||
|
||||
<div
|
||||
class={cx(
|
||||
"chat__compose-zone flex flex-col gap-1 bg-base-200 md:flex-row md:gap-0",
|
||||
voiceConnectedHere && voiceDesktopPanel === "split" && "cw-split-chat",
|
||||
pageContentHiddenDesktopVideoOnly && "md:hidden",
|
||||
showMobileVideoPanel && "max-md:hidden",
|
||||
)}
|
||||
class="chat__compose-zone flex flex-col gap-1 bg-base-200 md:flex-row md:gap-0"
|
||||
bind:this={chatCompose}>
|
||||
<div class="chat__compose-inner min-w-0 flex-1">
|
||||
{#if $room.isPrivate && $membershipStatus !== MembershipStatus.Granted}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {readable} from "svelte/store"
|
||||
import type {Readable} from "svelte/store"
|
||||
import {page} from "$app/stores"
|
||||
import {sortBy, partition, spec, pushToMapKey, max} from "@welshman/lib"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {getTagValue} from "@welshman/util"
|
||||
import {fly} from "@lib/transition"
|
||||
import PollIcon from "@assets/icons/revote.svg?dataurl"
|
||||
import Add from "@assets/icons/add.svg?dataurl"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import PageContent from "@lib/components/PageContent.svelte"
|
||||
import Spinner from "@lib/components/Spinner.svelte"
|
||||
import SpaceBar from "@app/components/SpaceBar.svelte"
|
||||
import PollItem from "@app/components/PollItem.svelte"
|
||||
import PollCreate from "@app/components/PollCreate.svelte"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
import {decodeRelay, makeCommentFilter} from "@app/core/state"
|
||||
import {makeFeed} from "@app/core/requests"
|
||||
import {pushModal} from "@app/util/modal"
|
||||
|
||||
const url = decodeRelay($page.params.relay!)
|
||||
|
||||
let loading = $state(true)
|
||||
let element: HTMLElement | undefined = $state()
|
||||
let events: Readable<TrustedEvent[]> = $state(readable([]))
|
||||
|
||||
const createPoll = () => pushModal(PollCreate, {url})
|
||||
|
||||
const items = $derived.by(() => {
|
||||
const scores = new Map<string, number[]>()
|
||||
const [polls, comments] = partition(spec({kind: Poll}), $events)
|
||||
|
||||
for (const comment of comments) {
|
||||
const id = getTagValue("E", comment.tags)
|
||||
|
||||
if (id) {
|
||||
pushToMapKey(scores, id, comment.created_at)
|
||||
}
|
||||
}
|
||||
|
||||
return sortBy(e => -max([...(scores.get(e.id) || []), e.created_at]), polls)
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
const feed = makeFeed({
|
||||
url,
|
||||
element: element!,
|
||||
filters: [{kinds: [Poll]}, makeCommentFilter([Poll])],
|
||||
onBackwardExhausted: () => {
|
||||
loading = false
|
||||
},
|
||||
})
|
||||
|
||||
events = feed.events
|
||||
|
||||
return () => {
|
||||
feed.cleanup()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<SpaceBar>
|
||||
{#snippet title()}
|
||||
<Icon icon={PollIcon} />
|
||||
<strong>Polls</strong>
|
||||
{/snippet}
|
||||
{#snippet action()}
|
||||
<Button class="btn btn-primary btn-sm" onclick={createPoll}>
|
||||
<Icon icon={Add} />
|
||||
Create
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SpaceBar>
|
||||
|
||||
<PageContent bind:element class="flex flex-col gap-2 p-2 pt-4">
|
||||
{#each items as event (event.id)}
|
||||
<div in:fly>
|
||||
<PollItem {url} event={$state.snapshot(event)} />
|
||||
</div>
|
||||
{/each}
|
||||
<p class="flex h-10 items-center justify-center py-20">
|
||||
<Spinner {loading}>
|
||||
{#if loading}
|
||||
Looking for polls...
|
||||
{:else if items.length === 0}
|
||||
No polls found.
|
||||
{:else}
|
||||
That's all!
|
||||
{/if}
|
||||
</Spinner>
|
||||
</p>
|
||||
</PageContent>
|
||||
@@ -0,0 +1,107 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {page} from "$app/stores"
|
||||
import {sleep} from "@welshman/lib"
|
||||
import type {MakeNonOptional} from "@welshman/lib"
|
||||
import {COMMENT} from "@welshman/util"
|
||||
import {repository} from "@welshman/app"
|
||||
import {request} from "@welshman/net"
|
||||
import {deriveEventsById, deriveEventsAsc} from "@welshman/store"
|
||||
import SortVertical from "@assets/icons/sort-vertical.svg?dataurl"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import PageContent from "@lib/components/PageContent.svelte"
|
||||
import Spinner from "@lib/components/Spinner.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import SpaceBar from "@app/components/SpaceBar.svelte"
|
||||
import NoteCard from "@app/components/NoteCard.svelte"
|
||||
import NoteContent from "@app/components/NoteContent.svelte"
|
||||
import CommentActions from "@app/components/CommentActions.svelte"
|
||||
import EventReply from "@app/components/EventReply.svelte"
|
||||
import {deriveEvent, decodeRelay} from "@app/core/state"
|
||||
import {Poll, PollResponse} from "nostr-tools/kinds"
|
||||
|
||||
const {relay, id} = $page.params as MakeNonOptional<typeof $page.params>
|
||||
const url = decodeRelay(relay)
|
||||
const event = deriveEvent(id, [url])
|
||||
const filters = [{kinds: [COMMENT], "#E": [id]}]
|
||||
const comments = deriveEventsAsc(deriveEventsById({repository, filters}))
|
||||
|
||||
const back = () => history.back()
|
||||
|
||||
const openReply = () => {
|
||||
showReply = true
|
||||
}
|
||||
|
||||
const closeReply = () => {
|
||||
showReply = false
|
||||
}
|
||||
|
||||
const expand = () => {
|
||||
showAll = true
|
||||
}
|
||||
|
||||
let showAll = $state(false)
|
||||
let showReply = $state(false)
|
||||
|
||||
onMount(() => {
|
||||
const controller = new AbortController()
|
||||
|
||||
request({
|
||||
relays: [url],
|
||||
filters: [{kinds: [Poll], ids: [id]}, {kinds: [PollResponse], "#e": [id]}, ...filters],
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
return () => {
|
||||
controller.abort()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<SpaceBar {back}>
|
||||
{#snippet title()}
|
||||
<h1 class="text-xl">{$event?.content || "Poll"}</h1>
|
||||
{/snippet}
|
||||
</SpaceBar>
|
||||
|
||||
<PageContent class="flex flex-col gap-3 p-2 pt-4">
|
||||
{#if $event}
|
||||
<div class="flex flex-col gap-3">
|
||||
<NoteCard event={$event} {url} class="card2 bg-alt z-feature w-full">
|
||||
<div class="col-3 ml-12 flex flex-col gap-3">
|
||||
<NoteContent showEntire event={$event} {url} />
|
||||
<CommentActions segment="polls" showActivity {url} event={$event} />
|
||||
</div>
|
||||
</NoteCard>
|
||||
{#if !showAll && $comments.length > 4}
|
||||
<div class="flex justify-center">
|
||||
<Button class="btn btn-link" onclick={expand}>
|
||||
<Icon icon={SortVertical} />
|
||||
Show all {$comments.length} comments
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{#each $comments.slice(0, showAll ? undefined : 4) as reply (reply.id)}
|
||||
<NoteCard event={reply} {url} class="card2 bg-alt z-feature w-full">
|
||||
<div class="col-3 ml-12">
|
||||
<NoteContent showEntire event={reply} {url} />
|
||||
<CommentActions segment="polls" event={reply} {url} />
|
||||
</div>
|
||||
</NoteCard>
|
||||
{/each}
|
||||
</div>
|
||||
{#if showReply}
|
||||
<EventReply {url} event={$event} onClose={closeReply} onSubmit={closeReply} />
|
||||
{:else}
|
||||
<div class="flex justify-end p-2">
|
||||
<Button class="btn btn-primary" onclick={openReply}>Comment on this poll</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
{#await sleep(5000)}
|
||||
<Spinner loading>Loading poll...</Spinner>
|
||||
{:then}
|
||||
<p>Failed to load poll.</p>
|
||||
{/await}
|
||||
{/if}
|
||||
</PageContent>
|
||||
@@ -1,8 +1,23 @@
|
||||
<script lang="ts">
|
||||
import {onMount} from "svelte"
|
||||
import {tick, onMount} from "svelte"
|
||||
import {derived} from "svelte/store"
|
||||
import {page} from "$app/stores"
|
||||
import {groupBy, ago, MONTH, first, sortBy, uniqBy} from "@welshman/lib"
|
||||
import {debounce} from "throttle-debounce"
|
||||
import {
|
||||
formatTimestampAsDate,
|
||||
groupBy,
|
||||
ago,
|
||||
now,
|
||||
MONTH,
|
||||
MINUTE,
|
||||
HOUR,
|
||||
DAY,
|
||||
WEEK,
|
||||
first,
|
||||
sortBy,
|
||||
uniqBy,
|
||||
} from "@welshman/lib"
|
||||
import {request} from "@welshman/net"
|
||||
import {
|
||||
MESSAGE,
|
||||
THREAD,
|
||||
@@ -13,12 +28,17 @@
|
||||
getTagValue,
|
||||
getTagValues,
|
||||
getIdAndAddress,
|
||||
sortEventsDesc,
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent} from "@welshman/util"
|
||||
import {repository} from "@welshman/app"
|
||||
import History from "@assets/icons/history.svg?dataurl"
|
||||
import Magnifier from "@assets/icons/magnifier.svg?dataurl"
|
||||
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
|
||||
import {createScroller} from "@lib/html"
|
||||
import {fly} from "@lib/transition"
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import Button from "@lib/components/Button.svelte"
|
||||
import PageContent from "@lib/components/PageContent.svelte"
|
||||
import SpaceBar from "@app/components/SpaceBar.svelte"
|
||||
import NoteItem from "@app/components/NoteItem.svelte"
|
||||
@@ -26,8 +46,11 @@
|
||||
import ClassifiedItem from "@app/components/ClassifiedItem.svelte"
|
||||
import GoalItem from "@app/components/GoalItem.svelte"
|
||||
import CalendarEventItem from "@app/components/CalendarEventItem.svelte"
|
||||
import PollItem from "@app/components/PollItem.svelte"
|
||||
import RecentConversation from "@app/components/RecentConversation.svelte"
|
||||
import {decodeRelay, deriveEventsForUrl, CONTENT_KINDS} from "@app/core/state"
|
||||
import {goToEvent} from "@app/util/routes"
|
||||
import {Poll} from "nostr-tools/kinds"
|
||||
|
||||
const url = decodeRelay($page.params.relay!)
|
||||
const since = ago(3, MONTH)
|
||||
@@ -88,9 +111,93 @@
|
||||
},
|
||||
)
|
||||
|
||||
let term = $state("")
|
||||
let showSearch = $state(false)
|
||||
let loading = $state(false)
|
||||
let searchResults: TrustedEvent[] = $state([])
|
||||
let searchInput: HTMLInputElement | undefined = $state()
|
||||
let controller: AbortController | undefined
|
||||
|
||||
let limit = $state(20)
|
||||
let element: Element | undefined = $state()
|
||||
|
||||
const resultsByAge = $derived(groupBy(e => getAgeSection(e.created_at), searchResults))
|
||||
|
||||
const getAgeSection = (createdAt: number) => {
|
||||
const age = now() - createdAt
|
||||
|
||||
if (age <= DAY) return "day"
|
||||
if (age <= WEEK) return "week"
|
||||
return "older"
|
||||
}
|
||||
|
||||
const getAgeLabel = (createdAt: number) => {
|
||||
const age = now() - createdAt
|
||||
|
||||
if (age < MINUTE) return "Just now"
|
||||
if (age < HOUR) return `${Math.floor(age / MINUTE)}m ago`
|
||||
if (age < DAY) return `${Math.floor(age / HOUR)}h ago`
|
||||
return `${Math.floor(age / DAY)}d ago`
|
||||
}
|
||||
|
||||
const openSearch = () => {
|
||||
showSearch = true
|
||||
tick().then(() => searchInput?.focus())
|
||||
}
|
||||
|
||||
const closeSearch = () => {
|
||||
showSearch = false
|
||||
}
|
||||
|
||||
const clearSearch = () => {
|
||||
term = ""
|
||||
showSearch = false
|
||||
loading = false
|
||||
searchResults = []
|
||||
controller?.abort()
|
||||
controller = undefined
|
||||
}
|
||||
|
||||
const search = debounce(300, async (searchTerm: string) => {
|
||||
controller?.abort()
|
||||
|
||||
if (!searchTerm.trim()) {
|
||||
loading = false
|
||||
searchResults = []
|
||||
return
|
||||
}
|
||||
|
||||
controller = new AbortController()
|
||||
loading = true
|
||||
|
||||
try {
|
||||
const events = await request({
|
||||
relays: [url],
|
||||
autoClose: true,
|
||||
signal: controller.signal,
|
||||
filters: [{kinds: [MESSAGE, ...CONTENT_KINDS], search: searchTerm.trim()}],
|
||||
})
|
||||
|
||||
searchResults = sortEventsDesc(uniqBy((e: TrustedEvent) => e.id, events))
|
||||
} catch (error) {
|
||||
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
||||
searchResults = []
|
||||
}
|
||||
} finally {
|
||||
loading = false
|
||||
}
|
||||
})
|
||||
|
||||
const onInput = () => {
|
||||
showSearch = true
|
||||
void search(term)
|
||||
}
|
||||
|
||||
const onResultClick = (event: TrustedEvent) => {
|
||||
closeSearch()
|
||||
goToEvent(event, {keepFocus: true})
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
const scroller = createScroller({
|
||||
element: element!,
|
||||
@@ -108,6 +215,81 @@
|
||||
<Icon icon={History} />
|
||||
<strong>Recent Activity</strong>
|
||||
{/snippet}
|
||||
{#snippet action()}
|
||||
<div>
|
||||
<button class="btn btn-neutral btn-sm btn-square" aria-label="Search" onclick={openSearch}>
|
||||
<Icon size={4} icon={Magnifier} />
|
||||
</button>
|
||||
{#if showSearch}
|
||||
<button class="fixed inset-0 z-feature" aria-label="Close search" onclick={closeSearch}
|
||||
></button>
|
||||
<div class="fixed cw top-0 right-0 z-feature p-2">
|
||||
<div
|
||||
class="card2 card2-sm bg-alt flex flex-col gap-2 shadow-md"
|
||||
transition:fly={{y: -40, duration: 150}}>
|
||||
<div class="flex justify-between">
|
||||
<strong>Search</strong>
|
||||
<Button onclick={clearSearch}>
|
||||
<Icon icon={CloseCircle} />
|
||||
</Button>
|
||||
</div>
|
||||
<label class="input input-sm input-bordered flex w-full items-center gap-2">
|
||||
<Icon size={4} icon={Magnifier} />
|
||||
<input
|
||||
bind:this={searchInput}
|
||||
bind:value={term}
|
||||
class="min-w-0 grow"
|
||||
type="text"
|
||||
placeholder="Search this space..."
|
||||
oninput={onInput} />
|
||||
</label>
|
||||
<div class="max-h-[65vh] overflow-y-auto">
|
||||
{#if !term}
|
||||
<p class="text-sm opacity-70">Search for content across this space.</p>
|
||||
{:else if loading}
|
||||
<p class="text-sm opacity-70">Searching...</p>
|
||||
{:else if resultsByAge.size === 0}
|
||||
<p class="text-sm opacity-70">No results found.</p>
|
||||
{:else}
|
||||
<div class="col-2">
|
||||
{#each resultsByAge as [key, events] (key)}
|
||||
<div class="col-2">
|
||||
<p class="text-xs uppercase tracking-wide opacity-60">
|
||||
{#if key === "day"}
|
||||
Last 24 Hours
|
||||
{:else if key === "week"}
|
||||
Last 7 Days
|
||||
{:else}
|
||||
Older
|
||||
{/if}
|
||||
</p>
|
||||
<div class="col-2">
|
||||
{#each events as event (event.id)}
|
||||
<button
|
||||
class="card2 bg-alt card2-sm col-2 transition-colors hover:bg-base-200 text-left"
|
||||
onclick={() => onResultClick(event)}>
|
||||
<p class="line-clamp-2 text-sm">
|
||||
{event.content.trim() ||
|
||||
getTagValue("title", event.tags) ||
|
||||
"(No text content)"}
|
||||
</p>
|
||||
<div class="row-2 text-xs opacity-70">
|
||||
<span>{getAgeLabel(event.created_at)}</span>
|
||||
<span>{formatTimestampAsDate(event.created_at)}</span>
|
||||
</div>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
</SpaceBar>
|
||||
|
||||
<div bind:this={element}>
|
||||
@@ -126,6 +308,8 @@
|
||||
<GoalItem {url} {event} />
|
||||
{:else if event.kind === EVENT_TIME}
|
||||
<CalendarEventItem {url} {event} />
|
||||
{:else if event.kind === Poll}
|
||||
<PollItem {url} {event} />
|
||||
{:else}
|
||||
<NoteItem {url} {event} />
|
||||
{/if}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import daisyui from "daisyui"
|
||||
import themes from "daisyui/src/theming/themes"
|
||||
|
||||
config({path: ".env.local"})
|
||||
config({path: ".env.template"})
|
||||
config({path: ".env"})
|
||||
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {sveltekit} from "@sveltejs/kit/vite"
|
||||
import svg from "@poppanator/sveltekit-svg"
|
||||
|
||||
config({path: ".env.local"})
|
||||
config({path: ".env.template"})
|
||||
config({path: ".env"})
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
|
||||
Reference in New Issue
Block a user