Flesh out recent activity component

This commit is contained in:
Jon Staab
2025-06-05 10:16:05 -07:00
parent 0b8c6c4a49
commit d8b87db784
3 changed files with 102 additions and 158 deletions
+5 -66
View File
@@ -6,28 +6,6 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
Flotilla is a Discord-like Nostr client that operates on the concept of "relays as groups/spaces." Built with SvelteKit 2.5 and Svelte 5, it provides messaging, threads, calendar events, and social features across Nostr relays. Flotilla is a Discord-like Nostr client that operates on the concept of "relays as groups/spaces." Built with SvelteKit 2.5 and Svelte 5, it provides messaging, threads, calendar events, and social features across Nostr relays.
## Development Commands
```bash
# Development
pnpm run dev # Start dev server on port 1847
pnpm run check # TypeScript checking
pnpm run check:watch # Watch mode TypeScript checking
# Production
pnpm run build # Custom build with env processing
./build.sh # Main build script with PWA assets
pnpm run sourcemaps # Build with sourcemap upload
# Code Quality
pnpm run lint # ESLint + Prettier checking
pnpm run format # Auto-format with Prettier
# Mobile
pnpm run release:android # Android APK build
npx cap sync # Sync web assets to native
```
## Architecture ## Architecture
### Core Technology Stack ### Core Technology Stack
@@ -37,58 +15,18 @@ npx cap sync # Sync web assets to native
- **Capacitor 7** - Cross-platform mobile deployment - **Capacitor 7** - Cross-platform mobile deployment
- **TypeScript** - Full type safety throughout - **TypeScript** - Full type safety throughout
### Key Directories
- `/src/app/state.ts` - Global state management, stores, derived values
- `/src/app/components/` - 80+ feature-specific Svelte components
- `/src/lib/components/` - Shared/generic UI components
- `/src/routes/` - SvelteKit file-based routing with dynamic relay/room routes
- `/src/app/commands.ts` - User actions and business logic
- `/src/assets/icons/` - 60+ custom SVG icons
### State Management Patterns ### State Management Patterns
- Svelte stores with Welshman reactive patterns - Svelte stores with Welshman reactive patterns
- Repository pattern for Nostr event storage with 10k event limit - Repository pattern for Nostr event storage with 10k event limit
- Derived stores for computed values and real-time updates - Derived stores for computed values and real-time updates
- Event-based architecture with reactive data flow - Event-based architecture with reactive data flow
### Nostr Integration Architecture
- **NIP-29 support** - Group chat functionality via relays
- **NIP-46 support** - Remote signing (Nostr Connect/Bunker)
- **Event unwrapping** - Handles gift-wrapped messages for privacy
- **Real-time relay management** - Automatic connection and authentication
- **Web of trust calculations** - User reputation and content filtering
### Mobile & PWA Features
- Responsive navigation (drawer on mobile, sidebar on desktop)
- Capacitor integration for native mobile apps
- PWA with offline support and auto-updating
- Safe area handling for iOS/Android
## Environment Configuration
All environment variables are optional and enable platform customization:
```bash
# Branding
VITE_PLATFORM_NAME="Custom Name"
VITE_PLATFORM_LOGO="/custom-logo.png"
VITE_PLATFORM_DESCRIPTION="Custom description"
# Platform Mode (single-relay instance)
VITE_PLATFORM_RELAYS="wss://relay.example.com"
# Bootstrap and Discovery
VITE_DEFAULT_PUBKEYS="npub1...,npub2..." # Web of trust seed
VITE_INDEXER_RELAYS="wss://indexer1.com,wss://indexer2.com"
# Monitoring
VITE_GLITCHTIP_API_KEY="..." # Error reporting
```
The `build.sh` script processes these variables and generates theme files.
## Important Patterns ## Important Patterns
### Finding Code
- Prefer navigating from one file to the next following imports when possible
- If search is necessary, use `ack`, not `grep` or `rg`.
### Component Organization ### Component Organization
- Components are organized by feature (Chat, Calendar, Profile, Space) - Components are organized by feature (Chat, Calendar, Profile, Space)
- Use existing components from `/lib/components/` before creating new ones - Use existing components from `/lib/components/` before creating new ones
@@ -103,6 +41,7 @@ The `build.sh` script processes these variables and generates theme files.
- Events flow through the repository pattern in `state.ts` - Events flow through the repository pattern in `state.ts`
- Use Welshman utilities for event validation and parsing - Use Welshman utilities for event validation and parsing
- Handle both plain and gift-wrapped events for privacy - Handle both plain and gift-wrapped events for privacy
- Prefer seconds to milliseconds when handling nostr events.
### Styling Conventions ### Styling Conventions
- TailwindCSS with DaisyUI components - TailwindCSS with DaisyUI components
+1 -1
View File
@@ -130,7 +130,7 @@
</div> </div>
{:else} {:else}
<div <div
class="flex flex-col overflow-hidden text-ellipsis break-words" class="overflow-hidden text-ellipsis break-words"
style={expandBlock ? "mask-image: linear-gradient(0deg, transparent 0px, black 100px)" : ""}> style={expandBlock ? "mask-image: linear-gradient(0deg, transparent 0px, black 100px)" : ""}>
{#each shortContent as parsed, i} {#each shortContent as parsed, i}
{#if isNewline(parsed) && !isBlock(i - 1)} {#if isNewline(parsed) && !isBlock(i - 1)}
+96 -91
View File
@@ -1,70 +1,70 @@
<script lang="ts"> <script lang="ts">
import {derived} from "svelte/store"
import {groupBy, first, last, uniq, avg, overlappingPairs} from "@welshman/lib"
import {formatTimestamp} from "@welshman/lib"
import {MESSAGE, getTagValue} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import Content from "@app/components/Content.svelte"
import ProfileCircle from "@app/components/ProfileCircle.svelte" import ProfileCircle from "@app/components/ProfileCircle.svelte"
import ProfileCircles from "@app/components/ProfileCircles.svelte" import ProfileCircles from "@app/components/ProfileCircles.svelte"
import {formatTimestamp} from "@welshman/lib" import {deriveEventsForUrl} from "@app/state"
interface Props { type Props = {
url: string url: string
} }
const {url}: Props = $props() const {url}: Props = $props()
// Mock conversation data similar to Slack's threads view const messages = deriveEventsForUrl(url, [{kinds: [MESSAGE]}])
const mockConversations = [
{ const conversations = derived(messages, $messages => {
id: "conv1", const convs = []
starter: {
pubkey: "npub1xyz123", for (const [room, messages] of groupBy(e => getTagValue("h", e.tags), $messages).entries()) {
content: const avgTime = avg(overlappingPairs(messages).map(([a, b]) => a.created_at - b.created_at))
"What's everyone's thoughts on the new relay implementation? I'm seeing some interesting performance improvements...", const groups: TrustedEvent[][] = []
timestamp: Date.now() - 3600000, // 1 hour ago const group: TrustedEvent[] = []
},
room: "general", // Group conversations by time between messages
replyCount: 12, let prevCreatedAt = messages[0].created_at
lastActivity: Date.now() - 900000, // 15 minutes ago for (const message of messages) {
participants: ["npub1abc", "npub1def", "npub1ghi", "npub1jkl"], if (prevCreatedAt - message.created_at < avgTime) {
latestReply: { group.push(message)
pubkey: "npub1abc", } else {
content: "The latency improvements are definitely noticeable in my tests", groups.push(group.splice(0))
}, }
},
{ prevCreatedAt = message.created_at
id: "conv2", }
starter: {
pubkey: "npub2abc456", if (group.length > 0) {
content: groups.push(group.splice(0))
"Has anyone tried the new calendar integration? Looking for feedback before we roll it out to more spaces", }
timestamp: Date.now() - 7200000, // 2 hours ago
}, // Convert each group into a conversation
room: "development", for (const events of groups) {
replyCount: 8, if (events.length < 2) {
lastActivity: Date.now() - 1800000, // 30 minutes ago continue
participants: ["npub2def", "npub2ghi", "npub2jkl"], }
latestReply: {
pubkey: "npub2def", const latest = first(events)!
content: "Works great on mobile, had one small sync issue but figured it out", const earliest = last(events)!
}, const participants = uniq(events.map(msg => msg.pubkey))
},
{ convs.push({room, events, latest, earliest, participants})
id: "conv3", }
starter: { }
pubkey: "npub3def789",
content: return convs
"Quick question about zap splitting - should we implement this at the relay level or client level?", })
timestamp: Date.now() - 10800000, // 3 hours ago
}, const viewMore = () => {
room: "random", limit += 3
replyCount: 5, }
lastActivity: Date.now() - 3600000, // 1 hour ago
participants: ["npub3abc", "npub3ghi"], let limit = $state(3)
latestReply: {
pubkey: "npub3abc",
content: "I think client level makes more sense for privacy",
},
},
]
</script> </script>
<div class="card2 bg-alt"> <div class="card2 bg-alt">
@@ -74,53 +74,58 @@
Recent Conversations Recent Conversations
</h3> </h3>
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
{#each mockConversations as conversation (conversation.id)} {#if $conversations.length === 0}
<div class="card2 bg-alt"> <div class="py-8 text-center opacity-70">
<div class="flex flex-col gap-3"> <p>No recent conversations</p>
<div class="flex items-start gap-3"> </div>
<ProfileCircle pubkey={conversation.starter.pubkey} size={10} /> {:else}
<div class="min-w-0 flex-1"> {#each $conversations.slice(0, limit) as { room, events, latest, earliest, participants } (latest.id)}
<div class="flex items-center gap-2 text-sm opacity-70"> <div class="card2 bg-alt">
<span class="font-medium text-blue-400">#{conversation.room}</span> <div class="flex flex-col gap-3">
<span class="opacity-50"></span> <div class="flex items-start gap-3">
<span>{formatTimestamp(conversation.starter.timestamp)}</span> <ProfileCircle pubkey={earliest.pubkey} size={10} />
</div> <div class="min-w-0 flex-1">
<div class="flex flex-col gap-2"> <div class="flex items-center gap-2 text-sm opacity-70">
<p class="text-base leading-relaxed">{conversation.starter.content}</p> <span class="font-medium text-blue-400">#{room}</span>
<span class="opacity-50"></span>
<span>{formatTimestamp(earliest.created_at)}</span>
</div>
<Content minimalQuote minLength={100} maxLength={200} event={earliest} />
</div> </div>
</div> </div>
</div> <div class="ml-13 flex items-center justify-between">
<div class="ml-13 flex items-center justify-between"> <div class="flex items-center gap-4">
<div class="flex items-center gap-4"> <span class="flex items-center gap-2 text-sm opacity-70">
<span class="flex items-center gap-2 text-sm opacity-70"> <Icon icon="alt-arrow-left" size={4} />
<Icon icon="alt-arrow-left" size={4} /> {events.length} messages
{conversation.replyCount} replies </span>
<div class="flex -space-x-2">
<ProfileCircles pubkeys={participants} size={6} />
</div>
</div>
<span class="text-sm opacity-50">
{formatTimestamp(latest.created_at)}
</span> </span>
<div class="flex -space-x-2">
<ProfileCircles pubkeys={conversation.participants} size={6} />
</div>
</div> </div>
<span class="text-sm opacity-50">
{formatTimestamp(conversation.lastActivity)}
</span>
</div>
{#if conversation.latestReply}
<div class="card2 bg-alt"> <div class="card2 bg-alt">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<div class="flex items-center gap-2 text-sm opacity-70"> <div class="flex items-center gap-2 text-sm opacity-70">
<ProfileCircle pubkey={conversation.latestReply.pubkey} size={5} /> <ProfileCircle pubkey={latest.pubkey} size={5} />
<span class="font-medium">Latest reply:</span> <span class="font-medium">Latest reply:</span>
</div> </div>
<p class="text-sm leading-relaxed opacity-90"> <Content minimalQuote minLength={100} maxLength={200} event={latest} />
{conversation.latestReply.content}
</p>
</div> </div>
</div> </div>
{/if} </div>
</div> </div>
</div> {/each}
{/each} {#if $conversations.length > limit}
<Button class="btn btn-primary btn-sm">View all conversations →</Button> <Button class="btn btn-primary" onclick={viewMore}>
View more conversations
<Icon icon="alt-arrow-down" />
</Button>
{/if}
{/if}
</div> </div>
</div> </div>
</div> </div>