mirror of
https://github.com/dergigi/boris.git
synced 2026-02-23 16:04:29 +01:00
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a89c87819a | ||
|
|
b09ae3bae3 | ||
|
|
6ea8c0d40e | ||
|
|
079501337c | ||
|
|
5bf0382227 | ||
|
|
0199c59014 | ||
|
|
44fb63fc59 | ||
|
|
13a28d2dbd | ||
|
|
f87a7da32e | ||
|
|
8fdf9938c2 | ||
|
|
ee4d480961 | ||
|
|
bd866549a0 | ||
|
|
7c39f1d821 | ||
|
|
e6a7bb4c98 | ||
|
|
14cf3189b8 | ||
|
|
66b060627a | ||
|
|
d9bcf14baa | ||
|
|
c571e6ebf7 | ||
|
|
fb06a1aec3 | ||
|
|
5a0d08641b | ||
|
|
8a8419385e | ||
|
|
0d5dc6e785 | ||
|
|
1d90333803 | ||
|
|
91e6e62688 | ||
|
|
619a8a9753 | ||
|
|
0fe38e94d3 | ||
|
|
722e8adbdf | ||
|
|
886d5ac08c | ||
|
|
89d5ba4c37 | ||
|
|
b8b9f82d91 | ||
|
|
b3fc9bb5c3 | ||
|
|
d2ebcd8fbe | ||
|
|
68c9623c35 | ||
|
|
496d1df404 | ||
|
|
ea1046fe13 | ||
|
|
6d58d6e7f3 | ||
|
|
e1420140d1 | ||
|
|
484c2e0c2f | ||
|
|
31f7d53829 | ||
|
|
e3debfa5df | ||
|
|
a1305fba81 | ||
|
|
ca95d6c7f4 | ||
|
|
5513fc9850 | ||
|
|
86de98e644 |
75
CHANGELOG.md
75
CHANGELOG.md
@@ -7,6 +7,77 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.5.2] - 2025-10-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Three-dot menu to highlight cards for more compact UI
|
||||||
|
- Combines "Open on Nostr" and "Delete" actions into dropdown menu
|
||||||
|
- Uses horizontal ellipsis icon (⋯)
|
||||||
|
- Click-outside functionality to close menu
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Switch Nostr gateway from njump.me/search.dergigi.com to ants.sh
|
||||||
|
- Centralized gateway URLs in config file
|
||||||
|
- All profile and event links now use ants.sh
|
||||||
|
- Automatic detection of identifier type (profile vs event) for proper routing
|
||||||
|
- Remove loading text from Explore and Me pages (spinner only)
|
||||||
|
- "Open on Nostr" now links to the highlight event itself instead of the article
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Gateway URL routing for ants.sh requirements (/p/ for profiles, /e/ for events)
|
||||||
|
- Linting errors in HighlightItem component
|
||||||
|
|
||||||
|
## [0.5.1] - 2025-10-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Highlight color customization to UI elements
|
||||||
|
- Apply user's "my highlights" color to highlight creation buttons
|
||||||
|
- Apply highlight group colors to highlight count indicators
|
||||||
|
- Apply "my highlights" color to collapsed highlights panel button
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Highlight count indicator styling to match reading-time element
|
||||||
|
- Brightness and border styling for highlight count indicator
|
||||||
|
- User highlight color now applies to both marker and arrow icons
|
||||||
|
- Highlight group color properly applied to count indicator background
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- MOBILE_IMPLEMENTATION.md documentation file
|
||||||
|
|
||||||
|
## [0.5.0] - 2025-10-12
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Upgrade to full PWA with `vite-plugin-pwa`
|
||||||
|
- Replace placeholder icons with branded favicons
|
||||||
|
- Author info card for nostr-native articles
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Explore: shrink refresh spinner footprint; inline-sized loading row
|
||||||
|
- Explore: preserve posts across navigations; seed from cache; merge streamed and final results
|
||||||
|
- Explore: keep posts visible during refresh; inline spinner; no list wipe
|
||||||
|
- Bookmarks: keep list visible during refresh; show spinner only; no wipe
|
||||||
|
- Bookmarks: avoid clearing list when no new events; decouple refetch from route changes
|
||||||
|
- Highlights: split service into smaller modules to keep files under 210 lines
|
||||||
|
- Lint/TypeScript: satisfy react-hooks dependencies; fix worker typings; clear ESLint/TS issues
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Highlights: merge remote results after local for article/url
|
||||||
|
- Explore: always query remote relays after local; stream merge into UI
|
||||||
|
- Improve mobile touch targets for highlight icons
|
||||||
|
- Color `/me` highlights with "my highlights" color setting
|
||||||
|
|
||||||
|
### Performance
|
||||||
|
- Local-first then remote follow-up across services (titles, bookmarks, highlights)
|
||||||
|
- Run local and remote fetches concurrently; stream and dedupe results
|
||||||
|
- Stream contacts and early posts from local; merge remote later
|
||||||
|
- Relay queries use local-first with short timeouts; fallback to remote when needed
|
||||||
|
- Stream results to UI; display cached/local immediately (articles, highlights, explore)
|
||||||
|
|
||||||
|
### Documentation
|
||||||
|
- PWA implementation summary and launch checklist updates
|
||||||
|
- Update docs to reflect branded icons and final steps
|
||||||
|
- Remove temporary PWA launch checklist and implementation summary
|
||||||
|
|
||||||
## [0.4.3] - 2025-10-11
|
## [0.4.3] - 2025-10-11
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -658,6 +729,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Optimize relay usage following applesauce-relay best practices
|
- Optimize relay usage following applesauce-relay best practices
|
||||||
- Use applesauce-react event models for better profile handling
|
- Use applesauce-react event models for better profile handling
|
||||||
|
|
||||||
|
[Unreleased]: https://github.com/dergigi/boris/compare/v0.5.2...HEAD
|
||||||
|
[0.5.2]: https://github.com/dergigi/boris/compare/v0.5.1...v0.5.2
|
||||||
|
[0.5.1]: https://github.com/dergigi/boris/compare/v0.5.0...v0.5.1
|
||||||
|
[0.5.0]: https://github.com/dergigi/boris/compare/v0.4.3...v0.5.0
|
||||||
[0.4.0]: https://github.com/dergigi/boris/compare/v0.3.8...v0.4.0
|
[0.4.0]: https://github.com/dergigi/boris/compare/v0.3.8...v0.4.0
|
||||||
[0.3.8]: https://github.com/dergigi/boris/compare/v0.3.7...v0.3.8
|
[0.3.8]: https://github.com/dergigi/boris/compare/v0.3.7...v0.3.8
|
||||||
[0.3.7]: https://github.com/dergigi/boris/compare/v0.3.6...v0.3.7
|
[0.3.7]: https://github.com/dergigi/boris/compare/v0.3.6...v0.3.7
|
||||||
|
|||||||
@@ -1,156 +0,0 @@
|
|||||||
# Mobile Implementation Summary
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
Boris is now mobile-friendly! The app now works seamlessly on mobile devices with a responsive design that includes:
|
|
||||||
- Auto-collapsing sidebar that opens as an overlay drawer on small screens
|
|
||||||
- Touch-optimized UI with proper touch target sizes (44x44px minimum)
|
|
||||||
- Safe area insets for notched devices (iPhone X+, etc.)
|
|
||||||
- Focus trap and keyboard navigation in the mobile sidebar
|
|
||||||
- Mobile-optimized modals, toasts, and other UI elements
|
|
||||||
|
|
||||||
## Changes Made
|
|
||||||
|
|
||||||
### 1. Viewport & Base Setup
|
|
||||||
**File: `index.html`**
|
|
||||||
- Updated viewport meta tag to include `viewport-fit=cover` for proper safe area handling
|
|
||||||
|
|
||||||
### 2. Media Query Hooks
|
|
||||||
**File: `src/hooks/useMediaQuery.ts` (NEW)**
|
|
||||||
- `useMediaQuery(query)` - Generic hook for any media query
|
|
||||||
- `useIsMobile()` - Detects mobile viewport (≤768px)
|
|
||||||
- `useIsTablet()` - Detects tablet viewport (≤1024px)
|
|
||||||
- `useIsCoarsePointer()` - Detects touch devices
|
|
||||||
|
|
||||||
### 3. Mobile CSS Styles
|
|
||||||
**File: `src/index.css`**
|
|
||||||
- Added CSS custom properties for mobile breakpoints and safe areas
|
|
||||||
- Mobile-specific three-pane layout that stacks into single column
|
|
||||||
- Overlay sidebar with backdrop and transitions
|
|
||||||
- Touch target improvements (44x44px minimum)
|
|
||||||
- Disabled hover effects on touch devices
|
|
||||||
- Mobile-optimized modals (full-screen sheet style)
|
|
||||||
- Mobile-optimized toasts (bottom position with safe area)
|
|
||||||
- Dynamic viewport height support (`100dvh`)
|
|
||||||
- Overscroll behavior and body scroll locking
|
|
||||||
|
|
||||||
### 4. Sidebar State Management
|
|
||||||
**File: `src/hooks/useBookmarksUI.ts`**
|
|
||||||
- Added `isMobile` state from media query
|
|
||||||
- Added `isSidebarOpen` state for mobile overlay
|
|
||||||
- Added `toggleSidebar()` function
|
|
||||||
- Auto-collapse logic based on `autoCollapseSidebarOnMobile` setting
|
|
||||||
- Mobile sidebar defaults to closed, desktop defaults to open
|
|
||||||
|
|
||||||
### 5. Three-Pane Layout Mobile Support
|
|
||||||
**File: `src/components/ThreePaneLayout.tsx`**
|
|
||||||
- Mobile hamburger button (visible only on mobile)
|
|
||||||
- Mobile backdrop for closing sidebar
|
|
||||||
- Body scroll locking when sidebar is open
|
|
||||||
- ESC key handler to close sidebar
|
|
||||||
- Focus trap in sidebar (Tab navigation stays within sidebar)
|
|
||||||
- Focus restoration when closing sidebar
|
|
||||||
- Accessibility attributes (`aria-hidden`, `aria-expanded`, etc.)
|
|
||||||
|
|
||||||
### 6. Sidebar Header Mobile Controls
|
|
||||||
**File: `src/components/SidebarHeader.tsx`**
|
|
||||||
- Close button (X) visible on mobile instead of collapse chevron
|
|
||||||
- Hamburger button hidden in header (shown in layout instead)
|
|
||||||
|
|
||||||
### 7. Bookmark List Mobile Props
|
|
||||||
**File: `src/components/BookmarkList.tsx`**
|
|
||||||
- Added `isMobile` prop support
|
|
||||||
- Passes mobile state to SidebarHeader
|
|
||||||
|
|
||||||
### 8. Main Bookmarks Component
|
|
||||||
**File: `src/components/Bookmarks.tsx`**
|
|
||||||
- Uses mobile state from `useBookmarksUI`
|
|
||||||
- Auto-closes sidebar when selecting bookmark on mobile
|
|
||||||
- Closes sidebar when opening settings on mobile
|
|
||||||
- Proper desktop/mobile toggle behavior
|
|
||||||
|
|
||||||
### 9. Icon Button Enhancement
|
|
||||||
**File: `src/components/IconButton.tsx`**
|
|
||||||
- Added optional `className` prop for additional styling
|
|
||||||
|
|
||||||
### 10. Mobile Settings
|
|
||||||
**File: `src/services/settingsService.ts`**
|
|
||||||
- Added `autoCollapseSidebarOnMobile?: boolean` setting (default: true)
|
|
||||||
|
|
||||||
**File: `src/components/Settings/StartupPreferencesSettings.tsx`**
|
|
||||||
- Added UI toggle for "Auto-collapse sidebar on small screens"
|
|
||||||
|
|
||||||
## Accessibility Features
|
|
||||||
- Focus trap in mobile sidebar (Tab key navigation stays within drawer)
|
|
||||||
- ESC key closes mobile sidebar
|
|
||||||
- Backdrop click closes mobile sidebar
|
|
||||||
- Proper ARIA attributes (`aria-hidden`, `aria-expanded`, `aria-controls`)
|
|
||||||
- Touch target minimum size enforcement (44x44px)
|
|
||||||
- Focus restoration when closing sidebar
|
|
||||||
|
|
||||||
## Mobile Behaviors
|
|
||||||
1. **Sidebar**: Slides in from left as overlay drawer with backdrop
|
|
||||||
2. **Hamburger Menu**: Fixed position top-left when sidebar closed
|
|
||||||
3. **Selecting Content**: Auto-closes sidebar on mobile
|
|
||||||
4. **Opening Settings**: Auto-closes sidebar on mobile
|
|
||||||
5. **Highlights Panel**: Hidden on mobile (content takes full width)
|
|
||||||
6. **Modals**: Full-screen sheet style from bottom
|
|
||||||
7. **Toasts**: Bottom position with safe area padding
|
|
||||||
|
|
||||||
## Responsive Breakpoints
|
|
||||||
- **Mobile**: ≤768px (sidebar overlay, single column)
|
|
||||||
- **Tablet**: ≤1024px (defined but not actively used yet)
|
|
||||||
- **Desktop**: >768px (three-pane layout as before)
|
|
||||||
|
|
||||||
## Browser Support
|
|
||||||
- Modern browsers with CSS Grid support
|
|
||||||
- iOS Safari (including safe area insets)
|
|
||||||
- Chrome for Android
|
|
||||||
- Firefox Mobile
|
|
||||||
- Safari on iPadOS
|
|
||||||
|
|
||||||
## Safe Area Support
|
|
||||||
The app respects device safe areas (notches, home indicators) through CSS environment variables:
|
|
||||||
- `env(safe-area-inset-top)`
|
|
||||||
- `env(safe-area-inset-bottom)`
|
|
||||||
- `env(safe-area-inset-left)`
|
|
||||||
- `env(safe-area-inset-right)`
|
|
||||||
|
|
||||||
## Future Enhancements
|
|
||||||
Potential improvements for future iterations:
|
|
||||||
- Swipe gesture to open/close sidebar
|
|
||||||
- Pull-to-refresh on mobile
|
|
||||||
- Bottom sheet for highlights panel on mobile
|
|
||||||
- Optimized font sizes for mobile reading
|
|
||||||
- Mobile-specific view mode (perhaps auto-switch to compact on mobile)
|
|
||||||
- Haptic feedback on interactions (iOS/Android)
|
|
||||||
- Share sheet integration
|
|
||||||
- Install prompt for PWA
|
|
||||||
|
|
||||||
## Testing Checklist
|
|
||||||
- [x] Sidebar opens/closes on mobile
|
|
||||||
- [x] Hamburger button visible on mobile
|
|
||||||
- [x] Backdrop closes sidebar
|
|
||||||
- [x] ESC key closes sidebar
|
|
||||||
- [x] Focus trap works in sidebar
|
|
||||||
- [x] Selecting bookmark closes sidebar
|
|
||||||
- [x] No horizontal scroll
|
|
||||||
- [x] Touch targets ≥ 44px
|
|
||||||
- [x] Modals are full-screen on mobile
|
|
||||||
- [x] Toasts appear at bottom with safe area
|
|
||||||
- [x] Build completes without errors
|
|
||||||
- [ ] Test on actual iOS device (iPhone)
|
|
||||||
- [ ] Test on actual Android device
|
|
||||||
- [ ] Test with keyboard navigation
|
|
||||||
- [ ] Test with screen reader
|
|
||||||
- [ ] Test landscape orientation
|
|
||||||
- [ ] Test on various screen sizes (320px, 375px, 414px, 768px)
|
|
||||||
|
|
||||||
## Commit History
|
|
||||||
1. `feat: update viewport meta for mobile support`
|
|
||||||
2. `feat: add media query hooks for responsive design`
|
|
||||||
3. `feat: add mobile sidebar state management to useBookmarksUI`
|
|
||||||
4. `feat: add mobile-responsive CSS with breakpoints and safe areas`
|
|
||||||
5. `feat: implement mobile overlay sidebar with focus trap and ESC handling`
|
|
||||||
6. `feat: add mobile auto-collapse setting`
|
|
||||||
7. `fix: resolve TypeScript errors for mobile implementation`
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "boris",
|
"name": "boris",
|
||||||
"version": "0.4.3",
|
"version": "0.5.3",
|
||||||
"description": "A minimal nostr client for bookmark management",
|
"description": "A minimal nostr client for bookmark management",
|
||||||
"homepage": "https://read.withboris.com/",
|
"homepage": "https://read.withboris.com/",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -111,16 +111,18 @@ export const BookmarkList: React.FC<BookmarkListProps> = ({
|
|||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{loading ? (
|
{allIndividualBookmarks.length === 0 ? (
|
||||||
<div className="loading">
|
loading ? (
|
||||||
<FontAwesomeIcon icon={faSpinner} spin />
|
<div className="loading">
|
||||||
</div>
|
<FontAwesomeIcon icon={faSpinner} spin />
|
||||||
) : allIndividualBookmarks.length === 0 ? (
|
</div>
|
||||||
<div className="empty-state">
|
) : (
|
||||||
<p>No bookmarks found.</p>
|
<div className="empty-state">
|
||||||
<p>Add bookmarks using your nostr client to see them here.</p>
|
<p>No bookmarks found.</p>
|
||||||
<p>If you aren't on nostr yet, start here: <a href="https://nstart.me/" target="_blank" rel="noopener noreferrer">nstart.me</a></p>
|
<p>Add bookmarks using your nostr client to see them here.</p>
|
||||||
</div>
|
<p>If you aren't on nostr yet, start here: <a href="https://nstart.me/" target="_blank" rel="noopener noreferrer">nstart.me</a></p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<div className="bookmarks-list">
|
<div className="bookmarks-list">
|
||||||
<div className={`bookmarks-grid bookmarks-${viewMode}`}>
|
<div className={`bookmarks-grid bookmarks-${viewMode}`}>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { classifyUrl } from '../../utils/helpers'
|
|||||||
import { IconGetter } from './shared'
|
import { IconGetter } from './shared'
|
||||||
import { useImageCache } from '../../hooks/useImageCache'
|
import { useImageCache } from '../../hooks/useImageCache'
|
||||||
import { UserSettings } from '../../services/settingsService'
|
import { UserSettings } from '../../services/settingsService'
|
||||||
|
import { getProfileUrl, getEventUrl } from '../../config/nostrGateways'
|
||||||
|
|
||||||
interface CardViewProps {
|
interface CardViewProps {
|
||||||
bookmark: IndividualBookmark
|
bookmark: IndividualBookmark
|
||||||
@@ -79,7 +80,7 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
|
|
||||||
{eventNevent ? (
|
{eventNevent ? (
|
||||||
<a
|
<a
|
||||||
href={`https://search.dergigi.com/e/${eventNevent}`}
|
href={getEventUrl(eventNevent)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="bookmark-date-link"
|
className="bookmark-date-link"
|
||||||
@@ -159,7 +160,7 @@ export const CardView: React.FC<CardViewProps> = ({
|
|||||||
<div className="bookmark-footer">
|
<div className="bookmark-footer">
|
||||||
<div className="bookmark-meta-minimal">
|
<div className="bookmark-meta-minimal">
|
||||||
<a
|
<a
|
||||||
href={`https://search.dergigi.com/p/${authorNpub}`}
|
href={getProfileUrl(authorNpub)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="author-link-minimal"
|
className="author-link-minimal"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import ContentWithResolvedProfiles from '../ContentWithResolvedProfiles'
|
|||||||
import { IconGetter } from './shared'
|
import { IconGetter } from './shared'
|
||||||
import { useImageCache } from '../../hooks/useImageCache'
|
import { useImageCache } from '../../hooks/useImageCache'
|
||||||
import { UserSettings } from '../../services/settingsService'
|
import { UserSettings } from '../../services/settingsService'
|
||||||
|
import { getProfileUrl, getEventUrl } from '../../config/nostrGateways'
|
||||||
|
|
||||||
interface LargeViewProps {
|
interface LargeViewProps {
|
||||||
bookmark: IndividualBookmark
|
bookmark: IndividualBookmark
|
||||||
@@ -79,7 +80,7 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
<div className="large-footer">
|
<div className="large-footer">
|
||||||
<span className="large-author">
|
<span className="large-author">
|
||||||
<a
|
<a
|
||||||
href={`https://search.dergigi.com/p/${authorNpub}`}
|
href={getProfileUrl(authorNpub)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="author-link-minimal"
|
className="author-link-minimal"
|
||||||
@@ -90,7 +91,7 @@ export const LargeView: React.FC<LargeViewProps> = ({
|
|||||||
|
|
||||||
{eventNevent && (
|
{eventNevent && (
|
||||||
<a
|
<a
|
||||||
href={`https://search.dergigi.com/e/${eventNevent}`}
|
href={getEventUrl(eventNevent)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="bookmark-date-link"
|
className="bookmark-date-link"
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
|||||||
hasHighlights={hasHighlights}
|
hasHighlights={hasHighlights}
|
||||||
highlightCount={relevantHighlights.length}
|
highlightCount={relevantHighlights.length}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
|
highlights={relevantHighlights}
|
||||||
|
highlightVisibility={highlightVisibility}
|
||||||
/>
|
/>
|
||||||
{markdown || html ? (
|
{markdown || html ? (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { nip19 } from 'nostr-tools'
|
|||||||
import { fetchContacts } from '../services/contactService'
|
import { fetchContacts } from '../services/contactService'
|
||||||
import { fetchBlogPostsFromAuthors, BlogPostPreview } from '../services/exploreService'
|
import { fetchBlogPostsFromAuthors, BlogPostPreview } from '../services/exploreService'
|
||||||
import BlogPostCard from './BlogPostCard'
|
import BlogPostCard from './BlogPostCard'
|
||||||
|
import { getCachedPosts, upsertCachedPost, setCachedPosts } from '../services/exploreCache'
|
||||||
|
|
||||||
interface ExploreProps {
|
interface ExploreProps {
|
||||||
relayPool: RelayPool
|
relayPool: RelayPool
|
||||||
@@ -27,11 +28,59 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// show spinner but keep existing posts
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
||||||
|
// Seed from in-memory cache if available to avoid empty flash
|
||||||
|
const cached = getCachedPosts(activeAccount.pubkey)
|
||||||
|
if (cached && cached.length > 0 && blogPosts.length === 0) {
|
||||||
|
setBlogPosts(cached)
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch the user's contacts (friends)
|
// Fetch the user's contacts (friends)
|
||||||
const contacts = await fetchContacts(relayPool, activeAccount.pubkey)
|
const contacts = await fetchContacts(
|
||||||
|
relayPool,
|
||||||
|
activeAccount.pubkey,
|
||||||
|
(partial) => {
|
||||||
|
// When local contacts are available, kick off early posts fetch
|
||||||
|
if (partial.size > 0) {
|
||||||
|
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
||||||
|
fetchBlogPostsFromAuthors(
|
||||||
|
relayPool,
|
||||||
|
Array.from(partial),
|
||||||
|
relayUrls,
|
||||||
|
(post) => {
|
||||||
|
// merge into UI and cache as we stream
|
||||||
|
setBlogPosts((prev) => {
|
||||||
|
const exists = prev.some(p => p.event.id === post.event.id)
|
||||||
|
if (exists) return prev
|
||||||
|
const next = [...prev, post]
|
||||||
|
return next.sort((a, b) => {
|
||||||
|
const timeA = a.published || a.event.created_at
|
||||||
|
const timeB = b.published || b.event.created_at
|
||||||
|
return timeB - timeA
|
||||||
|
})
|
||||||
|
})
|
||||||
|
setCachedPosts(activeAccount.pubkey, upsertCachedPost(activeAccount.pubkey, post))
|
||||||
|
}
|
||||||
|
).then((all) => {
|
||||||
|
// Ensure union of streamed + final is displayed
|
||||||
|
setBlogPosts((prev) => {
|
||||||
|
const byId = new Map(prev.map(p => [p.event.id, p]))
|
||||||
|
for (const post of all) byId.set(post.event.id, post)
|
||||||
|
const merged = Array.from(byId.values()).sort((a, b) => {
|
||||||
|
const timeA = a.published || a.event.created_at
|
||||||
|
const timeB = b.published || b.event.created_at
|
||||||
|
return timeB - timeA
|
||||||
|
})
|
||||||
|
setCachedPosts(activeAccount.pubkey, merged)
|
||||||
|
return merged
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if (contacts.size === 0) {
|
if (contacts.size === 0) {
|
||||||
setError('You are not following anyone yet. Follow some people to see their blog posts!')
|
setError('You are not following anyone yet. Follow some people to see their blog posts!')
|
||||||
@@ -39,21 +88,25 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get relay URLs from pool
|
// After full contacts, do a final pass for completeness
|
||||||
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
||||||
|
const posts = await fetchBlogPostsFromAuthors(relayPool, Array.from(contacts), relayUrls)
|
||||||
// Fetch blog posts from friends
|
|
||||||
const posts = await fetchBlogPostsFromAuthors(
|
|
||||||
relayPool,
|
|
||||||
Array.from(contacts),
|
|
||||||
relayUrls
|
|
||||||
)
|
|
||||||
|
|
||||||
if (posts.length === 0) {
|
if (posts.length === 0) {
|
||||||
setError('No blog posts found from your friends yet')
|
setError('No blog posts found from your friends yet')
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlogPosts(posts)
|
setBlogPosts((prev) => {
|
||||||
|
const byId = new Map(prev.map(p => [p.event.id, p]))
|
||||||
|
for (const post of posts) byId.set(post.event.id, post)
|
||||||
|
const merged = Array.from(byId.values()).sort((a, b) => {
|
||||||
|
const timeA = a.published || a.event.created_at
|
||||||
|
const timeB = b.published || b.event.created_at
|
||||||
|
return timeB - timeA
|
||||||
|
})
|
||||||
|
setCachedPosts(activeAccount.pubkey, merged)
|
||||||
|
return merged
|
||||||
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to load blog posts:', err)
|
console.error('Failed to load blog posts:', err)
|
||||||
setError('Failed to load blog posts. Please try again.')
|
setError('Failed to load blog posts. Please try again.')
|
||||||
@@ -63,7 +116,7 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadBlogPosts()
|
loadBlogPosts()
|
||||||
}, [relayPool, activeAccount])
|
}, [relayPool, activeAccount, blogPosts.length])
|
||||||
|
|
||||||
const getPostUrl = (post: BlogPostPreview) => {
|
const getPostUrl = (post: BlogPostPreview) => {
|
||||||
// Get the d-tag identifier
|
// Get the d-tag identifier
|
||||||
@@ -79,17 +132,6 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
return `/a/${naddr}`
|
return `/a/${naddr}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loading) {
|
|
||||||
return (
|
|
||||||
<div className="explore-container">
|
|
||||||
<div className="explore-loading">
|
|
||||||
<FontAwesomeIcon icon={faSpinner} spin size="2x" />
|
|
||||||
<p>Loading blog posts from your friends...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className="explore-container">
|
<div className="explore-container">
|
||||||
@@ -112,6 +154,11 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
Discover blog posts from your friends on Nostr
|
Discover blog posts from your friends on Nostr
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
{loading && (
|
||||||
|
<div className="explore-loading" style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', padding: '0.5rem 0' }}>
|
||||||
|
<FontAwesomeIcon icon={faSpinner} spin />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="explore-grid">
|
<div className="explore-grid">
|
||||||
{blogPosts.map((post) => (
|
{blogPosts.map((post) => (
|
||||||
<BlogPostCard
|
<BlogPostCard
|
||||||
@@ -120,6 +167,11 @@ const Explore: React.FC<ExploreProps> = ({ relayPool }) => {
|
|||||||
href={getPostUrl(post)}
|
href={getPostUrl(post)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
{!loading && blogPosts.length === 0 && (
|
||||||
|
<div className="explore-empty" style={{ gridColumn: '1/-1', textAlign: 'center', color: 'var(--text-secondary)' }}>
|
||||||
|
<p>No blog posts found yet.</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react'
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faQuoteLeft, faExternalLinkAlt, faPlane, faSpinner, faServer, faTrash } from '@fortawesome/free-solid-svg-icons'
|
import { faQuoteLeft, faExternalLinkAlt, faPlane, faSpinner, faServer, faTrash, faEllipsisH } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { Highlight } from '../types/highlights'
|
import { Highlight } from '../types/highlights'
|
||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models, IEventStore } from 'applesauce-core'
|
import { Models, IEventStore } from 'applesauce-core'
|
||||||
@@ -13,6 +13,7 @@ import { nip19 } from 'nostr-tools'
|
|||||||
import { formatDateCompact } from '../utils/bookmarkUtils'
|
import { formatDateCompact } from '../utils/bookmarkUtils'
|
||||||
import { createDeletionRequest } from '../services/deletionService'
|
import { createDeletionRequest } from '../services/deletionService'
|
||||||
import ConfirmDialog from './ConfirmDialog'
|
import ConfirmDialog from './ConfirmDialog'
|
||||||
|
import { getNostrUrl } from '../config/nostrGateways'
|
||||||
|
|
||||||
interface HighlightWithLevel extends Highlight {
|
interface HighlightWithLevel extends Highlight {
|
||||||
level?: 'mine' | 'friends' | 'nostrverse'
|
level?: 'mine' | 'friends' | 'nostrverse'
|
||||||
@@ -31,7 +32,7 @@ interface HighlightItemProps {
|
|||||||
|
|
||||||
export const HighlightItem: React.FC<HighlightItemProps> = ({
|
export const HighlightItem: React.FC<HighlightItemProps> = ({
|
||||||
highlight,
|
highlight,
|
||||||
onSelectUrl,
|
// onSelectUrl is not used but kept in props for API compatibility
|
||||||
isSelected,
|
isSelected,
|
||||||
onHighlightClick,
|
onHighlightClick,
|
||||||
relayPool,
|
relayPool,
|
||||||
@@ -40,11 +41,13 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
onHighlightDelete
|
onHighlightDelete
|
||||||
}) => {
|
}) => {
|
||||||
const itemRef = useRef<HTMLDivElement>(null)
|
const itemRef = useRef<HTMLDivElement>(null)
|
||||||
|
const menuRef = useRef<HTMLDivElement>(null)
|
||||||
const [isSyncing, setIsSyncing] = useState(() => isEventSyncing(highlight.id))
|
const [isSyncing, setIsSyncing] = useState(() => isEventSyncing(highlight.id))
|
||||||
const [showOfflineIndicator, setShowOfflineIndicator] = useState(() => highlight.isOfflineCreated && !isSyncing)
|
const [showOfflineIndicator, setShowOfflineIndicator] = useState(() => highlight.isOfflineCreated && !isSyncing)
|
||||||
const [isRebroadcasting, setIsRebroadcasting] = useState(false)
|
const [isRebroadcasting, setIsRebroadcasting] = useState(false)
|
||||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
|
||||||
const [isDeleting, setIsDeleting] = useState(false)
|
const [isDeleting, setIsDeleting] = useState(false)
|
||||||
|
const [showMenu, setShowMenu] = useState(false)
|
||||||
|
|
||||||
const activeAccount = Hooks.useActiveAccount()
|
const activeAccount = Hooks.useActiveAccount()
|
||||||
|
|
||||||
@@ -97,61 +100,45 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
}
|
}
|
||||||
}, [isSelected])
|
}, [isSelected])
|
||||||
|
|
||||||
|
// Close menu when clicking outside
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
||||||
|
setShowMenu(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showMenu) {
|
||||||
|
document.addEventListener('mousedown', handleClickOutside)
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [showMenu])
|
||||||
|
|
||||||
const handleItemClick = () => {
|
const handleItemClick = () => {
|
||||||
if (onHighlightClick) {
|
if (onHighlightClick) {
|
||||||
onHighlightClick(highlight.id)
|
onHighlightClick(highlight.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLinkClick = (url: string, e: React.MouseEvent) => {
|
const getHighlightLink = () => {
|
||||||
if (onSelectUrl) {
|
// Encode the highlight event itself (kind 9802) as a nevent
|
||||||
e.preventDefault()
|
// Get non-local relays for the hint
|
||||||
onSelectUrl(url)
|
const relayHints = RELAYS.filter(r =>
|
||||||
}
|
!r.includes('localhost') && !r.includes('127.0.0.1')
|
||||||
|
).slice(0, 3) // Include up to 3 relay hints
|
||||||
|
|
||||||
|
const nevent = nip19.neventEncode({
|
||||||
|
id: highlight.id,
|
||||||
|
relays: relayHints,
|
||||||
|
author: highlight.pubkey,
|
||||||
|
kind: 9802
|
||||||
|
})
|
||||||
|
return getNostrUrl(nevent)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSourceLink = () => {
|
const highlightLink = getHighlightLink()
|
||||||
if (highlight.eventReference) {
|
|
||||||
// Check if it's a coordinate string (kind:pubkey:identifier) or a simple event ID
|
|
||||||
if (highlight.eventReference.includes(':')) {
|
|
||||||
// It's an addressable event coordinate, encode as naddr
|
|
||||||
const parts = highlight.eventReference.split(':')
|
|
||||||
if (parts.length === 3) {
|
|
||||||
const [kindStr, pubkey, identifier] = parts
|
|
||||||
const kind = parseInt(kindStr, 10)
|
|
||||||
|
|
||||||
// Get non-local relays for the hint
|
|
||||||
const relayHints = RELAYS.filter(r =>
|
|
||||||
!r.includes('localhost') && !r.includes('127.0.0.1')
|
|
||||||
).slice(0, 3) // Include up to 3 relay hints
|
|
||||||
|
|
||||||
const naddr = nip19.naddrEncode({
|
|
||||||
kind,
|
|
||||||
pubkey,
|
|
||||||
identifier,
|
|
||||||
relays: relayHints
|
|
||||||
})
|
|
||||||
return `https://njump.me/${naddr}`
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// It's a simple event ID, encode as nevent
|
|
||||||
// Get non-local relays for the hint
|
|
||||||
const relayHints = RELAYS.filter(r =>
|
|
||||||
!r.includes('localhost') && !r.includes('127.0.0.1')
|
|
||||||
).slice(0, 3) // Include up to 3 relay hints
|
|
||||||
|
|
||||||
const nevent = nip19.neventEncode({
|
|
||||||
id: highlight.eventReference,
|
|
||||||
relays: relayHints,
|
|
||||||
author: highlight.author
|
|
||||||
})
|
|
||||||
return `https://njump.me/${nevent}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return highlight.urlReference
|
|
||||||
}
|
|
||||||
|
|
||||||
const sourceLink = getSourceLink()
|
|
||||||
|
|
||||||
// Handle rebroadcast to all relays
|
// Handle rebroadcast to all relays
|
||||||
const handleRebroadcast = async (e: React.MouseEvent) => {
|
const handleRebroadcast = async (e: React.MouseEvent) => {
|
||||||
@@ -255,11 +242,6 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
// Check if current user can delete this highlight
|
// Check if current user can delete this highlight
|
||||||
const canDelete = activeAccount && highlight.pubkey === activeAccount.pubkey
|
const canDelete = activeAccount && highlight.pubkey === activeAccount.pubkey
|
||||||
|
|
||||||
const handleDeleteClick = (e: React.MouseEvent) => {
|
|
||||||
e.stopPropagation()
|
|
||||||
setShowDeleteConfirm(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleConfirmDelete = async () => {
|
const handleConfirmDelete = async () => {
|
||||||
if (!activeAccount || !relayPool) {
|
if (!activeAccount || !relayPool) {
|
||||||
console.warn('Cannot delete: no account or relay pool')
|
console.warn('Cannot delete: no account or relay pool')
|
||||||
@@ -295,6 +277,23 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
setShowDeleteConfirm(false)
|
setShowDeleteConfirm(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleMenuToggle = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
setShowMenu(!showMenu)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenExternal = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
window.open(highlightLink, '_blank', 'noopener,noreferrer')
|
||||||
|
setShowMenu(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleMenuDeleteClick = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
setShowMenu(false)
|
||||||
|
setShowDeleteConfirm(true)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -316,15 +315,6 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
<FontAwesomeIcon icon={relayIndicator.icon} spin={relayIndicator.spin} />
|
<FontAwesomeIcon icon={relayIndicator.icon} spin={relayIndicator.spin} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{canDelete && (
|
|
||||||
<div
|
|
||||||
className="highlight-delete-btn"
|
|
||||||
title="Delete highlight"
|
|
||||||
onClick={handleDeleteClick}
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={isDeleting ? faSpinner : faTrash} spin={isDeleting} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="highlight-content">
|
<div className="highlight-content">
|
||||||
@@ -348,18 +338,37 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({
|
|||||||
{formatDateCompact(highlight.created_at)}
|
{formatDateCompact(highlight.created_at)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{sourceLink && (
|
<div className="highlight-menu-wrapper" ref={menuRef}>
|
||||||
<a
|
<button
|
||||||
href={sourceLink}
|
className="highlight-menu-btn"
|
||||||
target="_blank"
|
onClick={handleMenuToggle}
|
||||||
rel="noopener noreferrer"
|
title="More options"
|
||||||
onClick={(e) => highlight.urlReference && onSelectUrl ? handleLinkClick(highlight.urlReference, e) : undefined}
|
|
||||||
className="highlight-source"
|
|
||||||
title={highlight.eventReference ? 'Open on Nostr' : 'Open source'}
|
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
<FontAwesomeIcon icon={faEllipsisH} />
|
||||||
</a>
|
</button>
|
||||||
)}
|
|
||||||
|
{showMenu && (
|
||||||
|
<div className="highlight-menu">
|
||||||
|
<button
|
||||||
|
className="highlight-menu-item"
|
||||||
|
onClick={handleOpenExternal}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={faExternalLinkAlt} />
|
||||||
|
<span>Open on Nostr</span>
|
||||||
|
</button>
|
||||||
|
{canDelete && (
|
||||||
|
<button
|
||||||
|
className="highlight-menu-item highlight-menu-item-danger"
|
||||||
|
onClick={handleMenuDeleteClick}
|
||||||
|
disabled={isDeleting}
|
||||||
|
>
|
||||||
|
<FontAwesomeIcon icon={isDeleting ? faSpinner : faTrash} spin={isDeleting} />
|
||||||
|
<span>Delete</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import HighlightsPanelCollapsed from './HighlightsPanel/HighlightsPanelCollapsed
|
|||||||
import HighlightsPanelHeader from './HighlightsPanel/HighlightsPanelHeader'
|
import HighlightsPanelHeader from './HighlightsPanel/HighlightsPanelHeader'
|
||||||
import { RelayPool } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { IEventStore } from 'applesauce-core'
|
import { IEventStore } from 'applesauce-core'
|
||||||
|
import { UserSettings } from '../services/settingsService'
|
||||||
|
|
||||||
export interface HighlightVisibility {
|
export interface HighlightVisibility {
|
||||||
nostrverse: boolean
|
nostrverse: boolean
|
||||||
@@ -32,6 +33,7 @@ interface HighlightsPanelProps {
|
|||||||
followedPubkeys?: Set<string>
|
followedPubkeys?: Set<string>
|
||||||
relayPool?: RelayPool | null
|
relayPool?: RelayPool | null
|
||||||
eventStore?: IEventStore | null
|
eventStore?: IEventStore | null
|
||||||
|
settings?: UserSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
||||||
@@ -50,7 +52,8 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
|||||||
onHighlightVisibilityChange,
|
onHighlightVisibilityChange,
|
||||||
followedPubkeys = new Set(),
|
followedPubkeys = new Set(),
|
||||||
relayPool,
|
relayPool,
|
||||||
eventStore
|
eventStore,
|
||||||
|
settings
|
||||||
}) => {
|
}) => {
|
||||||
const [showHighlights, setShowHighlights] = useState(true)
|
const [showHighlights, setShowHighlights] = useState(true)
|
||||||
const [localHighlights, setLocalHighlights] = useState(highlights)
|
const [localHighlights, setLocalHighlights] = useState(highlights)
|
||||||
@@ -90,6 +93,7 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
|
|||||||
<HighlightsPanelCollapsed
|
<HighlightsPanelCollapsed
|
||||||
hasHighlights={filteredHighlights.length > 0}
|
hasHighlights={filteredHighlights.length > 0}
|
||||||
onToggleCollapse={onToggleCollapse}
|
onToggleCollapse={onToggleCollapse}
|
||||||
|
settings={settings}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faHighlighter, faChevronRight } from '@fortawesome/free-solid-svg-icons'
|
import { faHighlighter, faChevronRight } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
import { UserSettings } from '../../services/settingsService'
|
||||||
|
|
||||||
interface HighlightsPanelCollapsedProps {
|
interface HighlightsPanelCollapsedProps {
|
||||||
hasHighlights: boolean
|
hasHighlights: boolean
|
||||||
onToggleCollapse: () => void
|
onToggleCollapse: () => void
|
||||||
|
settings?: UserSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
const HighlightsPanelCollapsed: React.FC<HighlightsPanelCollapsedProps> = ({
|
const HighlightsPanelCollapsed: React.FC<HighlightsPanelCollapsedProps> = ({
|
||||||
hasHighlights,
|
hasHighlights,
|
||||||
onToggleCollapse
|
onToggleCollapse,
|
||||||
|
settings
|
||||||
}) => {
|
}) => {
|
||||||
|
const highlightColor = settings?.highlightColorMine || '#ffff00'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="highlights-container collapsed">
|
<div className="highlights-container collapsed">
|
||||||
<button
|
<button
|
||||||
@@ -19,8 +24,12 @@ const HighlightsPanelCollapsed: React.FC<HighlightsPanelCollapsedProps> = ({
|
|||||||
title="Expand highlights panel"
|
title="Expand highlights panel"
|
||||||
aria-label="Expand highlights panel"
|
aria-label="Expand highlights panel"
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} className={hasHighlights ? 'glow' : ''} />
|
<FontAwesomeIcon
|
||||||
<FontAwesomeIcon icon={faChevronRight} />
|
icon={faHighlighter}
|
||||||
|
className={hasHighlights ? 'glow' : ''}
|
||||||
|
style={{ color: highlightColor }}
|
||||||
|
/>
|
||||||
|
<FontAwesomeIcon icon={faChevronRight} style={{ color: highlightColor }} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ const Me: React.FC<MeProps> = ({ relayPool }) => {
|
|||||||
<div className="explore-container">
|
<div className="explore-container">
|
||||||
<div className="explore-loading">
|
<div className="explore-loading">
|
||||||
<FontAwesomeIcon icon={faSpinner} spin size="2x" />
|
<FontAwesomeIcon icon={faSpinner} spin size="2x" />
|
||||||
<p>Loading your highlights...</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import React from 'react'
|
import React, { useMemo } from 'react'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faHighlighter, faClock } from '@fortawesome/free-solid-svg-icons'
|
import { faHighlighter, faClock } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { useImageCache } from '../hooks/useImageCache'
|
import { useImageCache } from '../hooks/useImageCache'
|
||||||
import { UserSettings } from '../services/settingsService'
|
import { UserSettings } from '../services/settingsService'
|
||||||
|
import { Highlight, HighlightLevel } from '../types/highlights'
|
||||||
|
import { HighlightVisibility } from './HighlightsPanel'
|
||||||
|
import { hexToRgb } from '../utils/colorHelpers'
|
||||||
|
|
||||||
interface ReaderHeaderProps {
|
interface ReaderHeaderProps {
|
||||||
title?: string
|
title?: string
|
||||||
@@ -14,6 +17,8 @@ interface ReaderHeaderProps {
|
|||||||
hasHighlights: boolean
|
hasHighlights: boolean
|
||||||
highlightCount: number
|
highlightCount: number
|
||||||
settings?: UserSettings
|
settings?: UserSettings
|
||||||
|
highlights?: Highlight[]
|
||||||
|
highlightVisibility?: HighlightVisibility
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
||||||
@@ -24,12 +29,46 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
readingTimeText,
|
readingTimeText,
|
||||||
hasHighlights,
|
hasHighlights,
|
||||||
highlightCount,
|
highlightCount,
|
||||||
settings
|
settings,
|
||||||
|
highlights = [],
|
||||||
|
highlightVisibility = { nostrverse: true, friends: true, mine: true }
|
||||||
}) => {
|
}) => {
|
||||||
const cachedImage = useImageCache(image, settings)
|
const cachedImage = useImageCache(image, settings)
|
||||||
const formattedDate = published ? format(new Date(published * 1000), 'MMM d, yyyy') : null
|
const formattedDate = published ? format(new Date(published * 1000), 'MMM d, yyyy') : null
|
||||||
const isLongSummary = summary && summary.length > 150
|
const isLongSummary = summary && summary.length > 150
|
||||||
|
|
||||||
|
// Determine the dominant highlight color based on visibility and priority
|
||||||
|
const highlightIndicatorStyles = useMemo(() => {
|
||||||
|
if (!highlights.length) return undefined
|
||||||
|
|
||||||
|
// Count highlights by level that are visible
|
||||||
|
const visibleLevels = new Set<HighlightLevel>()
|
||||||
|
highlights.forEach(h => {
|
||||||
|
if (h.level && highlightVisibility[h.level]) {
|
||||||
|
visibleLevels.add(h.level)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
let hexColor: string | undefined
|
||||||
|
// Priority: nostrverse > friends > mine
|
||||||
|
if (visibleLevels.has('nostrverse') && highlightVisibility.nostrverse) {
|
||||||
|
hexColor = settings?.highlightColorNostrverse || '#9333ea'
|
||||||
|
} else if (visibleLevels.has('friends') && highlightVisibility.friends) {
|
||||||
|
hexColor = settings?.highlightColorFriends || '#f97316'
|
||||||
|
} else if (visibleLevels.has('mine') && highlightVisibility.mine) {
|
||||||
|
hexColor = settings?.highlightColorMine || '#ffff00'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hexColor) return undefined
|
||||||
|
|
||||||
|
const rgb = hexToRgb(hexColor)
|
||||||
|
return {
|
||||||
|
backgroundColor: `rgba(${rgb}, 0.1)`,
|
||||||
|
borderColor: `rgba(${rgb}, 0.3)`,
|
||||||
|
color: '#fff'
|
||||||
|
}
|
||||||
|
}, [highlights, highlightVisibility, settings])
|
||||||
|
|
||||||
if (cachedImage) {
|
if (cachedImage) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -52,7 +91,10 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{hasHighlights && (
|
{hasHighlights && (
|
||||||
<div className="highlight-indicator">
|
<div
|
||||||
|
className="highlight-indicator"
|
||||||
|
style={highlightIndicatorStyles}
|
||||||
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -89,7 +131,10 @@ const ReaderHeader: React.FC<ReaderHeaderProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{hasHighlights && (
|
{hasHighlights && (
|
||||||
<div className="highlight-indicator">
|
<div
|
||||||
|
className="highlight-indicator"
|
||||||
|
style={highlightIndicatorStyles}
|
||||||
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
<span>{highlightCount} highlight{highlightCount !== 1 ? 's' : ''}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ import { useIsMobile } from '../hooks/useMediaQuery'
|
|||||||
|
|
||||||
interface RelayStatusIndicatorProps {
|
interface RelayStatusIndicatorProps {
|
||||||
relayPool: RelayPool | null
|
relayPool: RelayPool | null
|
||||||
|
showOnMobile?: boolean // Control visibility based on scroll
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RelayStatusIndicator: React.FC<RelayStatusIndicatorProps> = ({ relayPool }) => {
|
export const RelayStatusIndicator: React.FC<RelayStatusIndicatorProps> = ({
|
||||||
|
relayPool,
|
||||||
|
showOnMobile = true
|
||||||
|
}) => {
|
||||||
// Poll frequently for responsive offline indicator (5s instead of default 20s)
|
// Poll frequently for responsive offline indicator (5s instead of default 20s)
|
||||||
const relayStatuses = useRelayStatus({ relayPool, pollingInterval: 5000 })
|
const relayStatuses = useRelayStatus({ relayPool, pollingInterval: 5000 })
|
||||||
const [isConnecting, setIsConnecting] = useState(true)
|
const [isConnecting, setIsConnecting] = useState(true)
|
||||||
@@ -70,7 +74,7 @@ export const RelayStatusIndicator: React.FC<RelayStatusIndicatorProps> = ({ rela
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`relay-status-indicator ${isConnecting ? 'connecting' : ''} ${isMobile ? 'mobile' : ''} ${isExpanded ? 'expanded' : ''}`}
|
className={`relay-status-indicator ${isConnecting ? 'connecting' : ''} ${isMobile ? 'mobile' : ''} ${isExpanded ? 'expanded' : ''} ${isMobile && !showOnMobile ? 'hidden' : 'visible'}`}
|
||||||
title={
|
title={
|
||||||
!isMobile ? (
|
!isMobile ? (
|
||||||
isConnecting
|
isConnecting
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React from 'react'
|
|||||||
import { useEventModel } from 'applesauce-react/hooks'
|
import { useEventModel } from 'applesauce-react/hooks'
|
||||||
import { Models, Helpers } from 'applesauce-core'
|
import { Models, Helpers } from 'applesauce-core'
|
||||||
import { decode, npubEncode } from 'nostr-tools/nip19'
|
import { decode, npubEncode } from 'nostr-tools/nip19'
|
||||||
|
import { getProfileUrl } from '../config/nostrGateways'
|
||||||
|
|
||||||
const { getPubkeyFromDecodeResult } = Helpers
|
const { getPubkeyFromDecodeResult } = Helpers
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ const ResolvedMention: React.FC<ResolvedMentionProps> = ({ encoded }) => {
|
|||||||
if (npub) {
|
if (npub) {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
href={`https://search.dergigi.com/p/${npub}`}
|
href={getProfileUrl(npub)}
|
||||||
className="nostr-mention"
|
className="nostr-mention"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
|
|||||||
@@ -241,6 +241,10 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
onClick={props.onToggleHighlightsPanel}
|
onClick={props.onToggleHighlightsPanel}
|
||||||
aria-label="Open highlights"
|
aria-label="Open highlights"
|
||||||
aria-expanded={!props.isHighlightsCollapsed}
|
aria-expanded={!props.isHighlightsCollapsed}
|
||||||
|
style={{
|
||||||
|
backgroundColor: props.settings.highlightColorMine || '#ffff00',
|
||||||
|
color: '#000'
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faHighlighter} />
|
<FontAwesomeIcon icon={faHighlighter} />
|
||||||
</button>
|
</button>
|
||||||
@@ -351,6 +355,7 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
followedPubkeys={props.followedPubkeys}
|
followedPubkeys={props.followedPubkeys}
|
||||||
relayPool={props.relayPool}
|
relayPool={props.relayPool}
|
||||||
eventStore={props.eventStore}
|
eventStore={props.eventStore}
|
||||||
|
settings={props.settings}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -358,10 +363,13 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
|
|||||||
<HighlightButton
|
<HighlightButton
|
||||||
ref={props.highlightButtonRef}
|
ref={props.highlightButtonRef}
|
||||||
onHighlight={props.onCreateHighlight}
|
onHighlight={props.onCreateHighlight}
|
||||||
highlightColor={props.settings.highlightColor || '#ffff00'}
|
highlightColor={props.settings.highlightColorMine || '#ffff00'}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<RelayStatusIndicator relayPool={props.relayPool} />
|
<RelayStatusIndicator
|
||||||
|
relayPool={props.relayPool}
|
||||||
|
showOnMobile={showMobileButtons}
|
||||||
|
/>
|
||||||
{props.toastMessage && (
|
{props.toastMessage && (
|
||||||
<Toast
|
<Toast
|
||||||
message={props.toastMessage}
|
message={props.toastMessage}
|
||||||
|
|||||||
34
src/config/nostrGateways.ts
Normal file
34
src/config/nostrGateways.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Nostr gateway URLs for viewing events and profiles on the web
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const NOSTR_GATEWAY = 'https://ants.sh' as const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a profile URL on the gateway
|
||||||
|
*/
|
||||||
|
export function getProfileUrl(npub: string): string {
|
||||||
|
return `${NOSTR_GATEWAY}/p/${npub}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an event URL on the gateway
|
||||||
|
*/
|
||||||
|
export function getEventUrl(nevent: string): string {
|
||||||
|
return `${NOSTR_GATEWAY}/e/${nevent}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a general nostr link on the gateway
|
||||||
|
* Automatically detects if it's a profile (npub/nprofile) or event (note/nevent/naddr)
|
||||||
|
*/
|
||||||
|
export function getNostrUrl(identifier: string): string {
|
||||||
|
// Check the prefix to determine if it's a profile or event
|
||||||
|
if (identifier.startsWith('npub') || identifier.startsWith('nprofile')) {
|
||||||
|
return `${NOSTR_GATEWAY}/p/${identifier}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything else (note, nevent, naddr) goes to /e/
|
||||||
|
return `${NOSTR_GATEWAY}/e/${identifier}`
|
||||||
|
}
|
||||||
|
|
||||||
@@ -44,10 +44,14 @@ export const useBookmarksData = ({
|
|||||||
|
|
||||||
const handleFetchBookmarks = useCallback(async () => {
|
const handleFetchBookmarks = useCallback(async () => {
|
||||||
if (!relayPool || !activeAccount) return
|
if (!relayPool || !activeAccount) return
|
||||||
|
// don't clear existing bookmarks: we keep UI stable and show spinner unobtrusively
|
||||||
setBookmarksLoading(true)
|
setBookmarksLoading(true)
|
||||||
try {
|
try {
|
||||||
const fullAccount = accountManager.getActive()
|
const fullAccount = accountManager.getActive()
|
||||||
await fetchBookmarks(relayPool, fullAccount || activeAccount, setBookmarks, settings)
|
// merge-friendly: updater form that preserves visible list until replacement
|
||||||
|
await fetchBookmarks(relayPool, fullAccount || activeAccount, (next) => {
|
||||||
|
setBookmarks(() => next)
|
||||||
|
}, settings)
|
||||||
} finally {
|
} finally {
|
||||||
setBookmarksLoading(false)
|
setBookmarksLoading(false)
|
||||||
}
|
}
|
||||||
@@ -102,15 +106,21 @@ export const useBookmarksData = ({
|
|||||||
}
|
}
|
||||||
}, [relayPool, activeAccount, isRefreshing, handleFetchBookmarks, handleFetchHighlights, handleFetchContacts])
|
}, [relayPool, activeAccount, isRefreshing, handleFetchBookmarks, handleFetchHighlights, handleFetchContacts])
|
||||||
|
|
||||||
// Load initial data
|
// Load initial data (avoid clearing on route-only changes)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!relayPool || !activeAccount) return
|
if (!relayPool || !activeAccount) return
|
||||||
|
// Only (re)fetch bookmarks when account or relayPool changes, not on naddr route changes
|
||||||
handleFetchBookmarks()
|
handleFetchBookmarks()
|
||||||
|
}, [relayPool, activeAccount, handleFetchBookmarks])
|
||||||
|
|
||||||
|
// Fetch highlights/contacts independently to avoid disturbing bookmarks
|
||||||
|
useEffect(() => {
|
||||||
|
if (!relayPool || !activeAccount) return
|
||||||
if (!naddr) {
|
if (!naddr) {
|
||||||
handleFetchHighlights()
|
handleFetchHighlights()
|
||||||
}
|
}
|
||||||
handleFetchContacts()
|
handleFetchContacts()
|
||||||
}, [relayPool, activeAccount, naddr, handleFetchBookmarks, handleFetchHighlights, handleFetchContacts])
|
}, [relayPool, activeAccount, naddr, handleFetchHighlights, handleFetchContacts])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bookmarks,
|
bookmarks,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ interface UseExternalUrlLoaderProps {
|
|||||||
setReaderContent: (content: ReadableContent | undefined) => void
|
setReaderContent: (content: ReadableContent | undefined) => void
|
||||||
setReaderLoading: (loading: boolean) => void
|
setReaderLoading: (loading: boolean) => void
|
||||||
setIsCollapsed: (collapsed: boolean) => void
|
setIsCollapsed: (collapsed: boolean) => void
|
||||||
setHighlights: (highlights: Highlight[]) => void
|
setHighlights: (highlights: Highlight[] | ((prev: Highlight[]) => Highlight[])) => void
|
||||||
setHighlightsLoading: (loading: boolean) => void
|
setHighlightsLoading: (loading: boolean) => void
|
||||||
setCurrentArticleCoordinate: (coord: string | undefined) => void
|
setCurrentArticleCoordinate: (coord: string | undefined) => void
|
||||||
setCurrentArticleEventId: (id: string | undefined) => void
|
setCurrentArticleEventId: (id: string | undefined) => void
|
||||||
@@ -57,7 +57,21 @@ export function useExternalUrlLoader({
|
|||||||
|
|
||||||
// Check if fetchHighlightsForUrl exists, otherwise skip
|
// Check if fetchHighlightsForUrl exists, otherwise skip
|
||||||
if (typeof fetchHighlightsForUrl === 'function') {
|
if (typeof fetchHighlightsForUrl === 'function') {
|
||||||
const highlightsList = await fetchHighlightsForUrl(relayPool, url)
|
const seen = new Set<string>()
|
||||||
|
const highlightsList = await fetchHighlightsForUrl(
|
||||||
|
relayPool,
|
||||||
|
url,
|
||||||
|
(highlight) => {
|
||||||
|
if (seen.has(highlight.id)) return
|
||||||
|
seen.add(highlight.id)
|
||||||
|
setHighlights((prev) => {
|
||||||
|
if (prev.some(h => h.id === highlight.id)) return prev
|
||||||
|
const next = [...prev, highlight]
|
||||||
|
return next.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// Ensure final list is sorted and contains all items
|
||||||
setHighlights(highlightsList.sort((a, b) => b.created_at - a.created_at))
|
setHighlights(highlightsList.sort((a, b) => b.created_at - a.created_at))
|
||||||
console.log(`📌 Found ${highlightsList.length} highlights for URL`)
|
console.log(`📌 Found ${highlightsList.length} highlights for URL`)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
158
src/index.css
158
src/index.css
@@ -221,7 +221,7 @@ body.mobile-sidebar-open {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-avatar svg {
|
.profile-avatar svg {
|
||||||
font-size: 1rem;
|
font-size: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-header-bar .toggle-sidebar-btn {
|
.sidebar-header-bar .toggle-sidebar-btn {
|
||||||
@@ -1783,6 +1783,35 @@ body.mobile-sidebar-open {
|
|||||||
.highlight-text {
|
.highlight-text {
|
||||||
color: #213547;
|
color: #213547;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.highlight-menu-btn {
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-btn:hover {
|
||||||
|
color: #646cff;
|
||||||
|
background: rgba(100, 108, 255, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu {
|
||||||
|
background: #fff;
|
||||||
|
border-color: #ddd;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item {
|
||||||
|
color: #213547;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item:hover {
|
||||||
|
background: rgba(100, 108, 255, 0.08);
|
||||||
|
color: #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item-danger:hover {
|
||||||
|
background: rgba(255, 68, 68, 0.08);
|
||||||
|
color: #cc0000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Highlights Panel Styles */
|
/* Highlights Panel Styles */
|
||||||
@@ -1836,17 +1865,17 @@ body.mobile-sidebar-open {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.highlights-container.collapsed .toggle-highlights-btn .glow {
|
.highlights-container.collapsed .toggle-highlights-btn .glow {
|
||||||
color: #ffff00;
|
|
||||||
filter: drop-shadow(0 0 4px rgba(255, 255, 0, 0.6));
|
|
||||||
animation: pulse-glow 2s ease-in-out infinite;
|
animation: pulse-glow 2s ease-in-out infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes pulse-glow {
|
@keyframes pulse-glow {
|
||||||
0%, 100% {
|
0%, 100% {
|
||||||
filter: drop-shadow(0 0 4px rgba(255, 255, 0, 0.6));
|
opacity: 0.8;
|
||||||
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
filter: drop-shadow(0 0 8px rgba(255, 255, 0, 0.9));
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2236,25 +2265,77 @@ body.mobile-sidebar-open {
|
|||||||
line-height: 1;
|
line-height: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.highlight-source {
|
.highlight-menu-wrapper {
|
||||||
|
position: relative;
|
||||||
|
margin-left: auto;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #888;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.375rem;
|
|
||||||
color: #646cff;
|
|
||||||
text-decoration: none;
|
|
||||||
transition: color 0.2s ease;
|
transition: color 0.2s ease;
|
||||||
flex-shrink: 0;
|
border-radius: 4px;
|
||||||
margin-left: auto;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.highlight-source:hover {
|
.highlight-menu-btn:hover {
|
||||||
color: #535bf2;
|
color: #646cff;
|
||||||
text-decoration: underline;
|
background: rgba(100, 108, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.highlight-source svg {
|
.highlight-menu {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
top: calc(100% + 4px);
|
||||||
|
background: #2a2a2a;
|
||||||
|
border: 1px solid #444;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||||
|
z-index: 1000;
|
||||||
|
min-width: 160px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item {
|
||||||
|
width: 100%;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #ddd;
|
||||||
|
padding: 0.625rem 0.875rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.625rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item:hover {
|
||||||
|
background: rgba(100, 108, 255, 0.15);
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item-danger:hover {
|
||||||
|
background: rgba(255, 68, 68, 0.15);
|
||||||
|
color: #ff4444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight-menu-item svg {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inline content highlights - fluorescent marker style */
|
/* Inline content highlights - fluorescent marker style */
|
||||||
@@ -3101,13 +3182,13 @@ body.mobile-sidebar-open {
|
|||||||
/* Relay Status Indicator */
|
/* Relay Status Indicator */
|
||||||
.relay-status-indicator {
|
.relay-status-indicator {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 1.5rem;
|
bottom: 1rem;
|
||||||
left: 1.5rem;
|
left: 1rem;
|
||||||
z-index: 999;
|
z-index: 999;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.75rem;
|
gap: 0.5rem;
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.5rem 0.75rem;
|
||||||
background: rgba(245, 158, 11, 0.95);
|
background: rgba(245, 158, 11, 0.95);
|
||||||
border: 1px solid rgba(245, 158, 11, 0.4);
|
border: 1px solid rgba(245, 158, 11, 0.4);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
@@ -3115,12 +3196,13 @@ body.mobile-sidebar-open {
|
|||||||
backdrop-filter: blur(10px);
|
backdrop-filter: blur(10px);
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
font-size: 0.875rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mobile compact mode - just show icon */
|
/* Mobile compact mode - just show icon, match sidebar button size */
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.relay-status-indicator.mobile {
|
.relay-status-indicator.mobile {
|
||||||
padding: 0.5rem;
|
padding: 0;
|
||||||
width: var(--min-touch-target);
|
width: var(--min-touch-target);
|
||||||
height: var(--min-touch-target);
|
height: var(--min-touch-target);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -3128,12 +3210,13 @@ body.mobile-sidebar-open {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
bottom: 1rem;
|
bottom: 1rem;
|
||||||
left: 1rem;
|
left: 1rem;
|
||||||
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-indicator.mobile.expanded {
|
.relay-status-indicator.mobile.expanded {
|
||||||
width: auto;
|
width: auto;
|
||||||
padding: 0.75rem 1rem;
|
padding: 0.5rem 0.75rem;
|
||||||
gap: 0.75rem;
|
gap: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-indicator.mobile .relay-status-icon {
|
.relay-status-indicator.mobile .relay-status-icon {
|
||||||
@@ -3143,6 +3226,18 @@ body.mobile-sidebar-open {
|
|||||||
.relay-status-indicator.mobile:active {
|
.relay-status-indicator.mobile:active {
|
||||||
transform: scale(0.95);
|
transform: scale(0.95);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hide/show on scroll */
|
||||||
|
.relay-status-indicator.mobile.hidden {
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relay-status-indicator.mobile.visible {
|
||||||
|
opacity: 1;
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-indicator.connecting {
|
.relay-status-indicator.connecting {
|
||||||
@@ -3169,7 +3264,7 @@ body.mobile-sidebar-open {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-icon {
|
.relay-status-icon {
|
||||||
font-size: 1.25rem;
|
font-size: 1rem;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -3179,18 +3274,18 @@ body.mobile-sidebar-open {
|
|||||||
.relay-status-text {
|
.relay-status-text {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.15rem;
|
gap: 0.1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-title {
|
.relay-status-title {
|
||||||
font-size: 0.875rem;
|
font-size: 0.8125rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: #1a1a1a;
|
color: #1a1a1a;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relay-status-subtitle {
|
.relay-status-subtitle {
|
||||||
font-size: 0.75rem;
|
font-size: 0.6875rem;
|
||||||
color: rgba(26, 26, 26, 0.8);
|
color: rgba(26, 26, 26, 0.8);
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
}
|
}
|
||||||
@@ -3260,10 +3355,15 @@ body.mobile-sidebar-open {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
min-height: 50vh;
|
|
||||||
color: rgba(255, 255, 255, 0.7);
|
color: rgba(255, 255, 255, 0.7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compact, inline loading row for Explore refresh */
|
||||||
|
.explore-loading {
|
||||||
|
min-height: 0;
|
||||||
|
padding: 0.25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
.explore-error {
|
.explore-error {
|
||||||
color: #ff6b6b;
|
color: #ff6b6b;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, take } from 'rxjs'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { AddressPointer } from 'nostr-tools/nip19'
|
import { AddressPointer } from 'nostr-tools/nip19'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
import { RELAYS } from '../config/relays'
|
import { RELAYS } from '../config/relays'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays, createParallelReqStreams } from '../utils/helpers'
|
||||||
|
import { merge, toArray as rxToArray } from 'rxjs'
|
||||||
import { UserSettings } from './settingsService'
|
import { UserSettings } from './settingsService'
|
||||||
import { rebroadcastEvents } from './rebroadcastService'
|
import { rebroadcastEvents } from './rebroadcastService'
|
||||||
|
|
||||||
@@ -98,9 +100,11 @@ export async function fetchArticleByNaddr(
|
|||||||
const pointer = decoded.data as AddressPointer
|
const pointer = decoded.data as AddressPointer
|
||||||
|
|
||||||
// Define relays to query - prefer relays from naddr, fallback to configured relays (including local)
|
// Define relays to query - prefer relays from naddr, fallback to configured relays (including local)
|
||||||
const relays = pointer.relays && pointer.relays.length > 0
|
const baseRelays = pointer.relays && pointer.relays.length > 0
|
||||||
? pointer.relays
|
? pointer.relays
|
||||||
: RELAYS
|
: RELAYS
|
||||||
|
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
||||||
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||||
|
|
||||||
// Fetch the article event
|
// Fetch the article event
|
||||||
const filter = {
|
const filter = {
|
||||||
@@ -109,12 +113,10 @@ export async function fetchArticleByNaddr(
|
|||||||
'#d': [pointer.identifier]
|
'#d': [pointer.identifier]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use applesauce relay pool pattern
|
// Parallel local+remote, stream immediate, collect up to first from each
|
||||||
const events = await lastValueFrom(
|
const { local$, remote$ } = createParallelReqStreams(relayPool, localRelays, remoteRelays, filter, 1200, 6000)
|
||||||
relayPool
|
const collected = await lastValueFrom(merge(local$.pipe(take(1)), remote$.pipe(take(1))).pipe(rxToArray()))
|
||||||
.req(relays, filter)
|
const events = collected as NostrEvent[]
|
||||||
.pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
|
|
||||||
)
|
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
throw new Error('Article not found')
|
throw new Error('Article not found')
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, take } from 'rxjs'
|
||||||
import { nip19 } from 'nostr-tools'
|
import { nip19 } from 'nostr-tools'
|
||||||
import { AddressPointer } from 'nostr-tools/nip19'
|
import { AddressPointer } from 'nostr-tools/nip19'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
import { RELAYS } from '../config/relays'
|
import { RELAYS } from '../config/relays'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays, createParallelReqStreams } from '../utils/helpers'
|
||||||
|
import { merge, toArray as rxToArray } from 'rxjs'
|
||||||
|
|
||||||
const { getArticleTitle } = Helpers
|
const { getArticleTitle } = Helpers
|
||||||
|
|
||||||
@@ -25,9 +27,11 @@ export async function fetchArticleTitle(
|
|||||||
const pointer = decoded.data as AddressPointer
|
const pointer = decoded.data as AddressPointer
|
||||||
|
|
||||||
// Define relays to query
|
// Define relays to query
|
||||||
const relays = pointer.relays && pointer.relays.length > 0
|
const baseRelays = pointer.relays && pointer.relays.length > 0
|
||||||
? pointer.relays
|
? pointer.relays
|
||||||
: RELAYS
|
: RELAYS
|
||||||
|
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
||||||
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||||
|
|
||||||
// Fetch the article event
|
// Fetch the article event
|
||||||
const filter = {
|
const filter = {
|
||||||
@@ -36,11 +40,11 @@ export async function fetchArticleTitle(
|
|||||||
'#d': [pointer.identifier]
|
'#d': [pointer.identifier]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parallel local+remote: collect up to one event from each
|
||||||
|
const { local$, remote$ } = createParallelReqStreams(relayPool, localRelays, remoteRelays, filter, 1200, 5000)
|
||||||
const events = await lastValueFrom(
|
const events = await lastValueFrom(
|
||||||
relayPool
|
merge(local$.pipe(take(1)), remote$.pipe(take(1))).pipe(rxToArray())
|
||||||
.req(relays, filter)
|
) as unknown as { created_at: number }[]
|
||||||
.pipe(completeOnEose(), takeUntil(timer(5000)), toArray())
|
|
||||||
)
|
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
return null
|
return null
|
||||||
@@ -48,7 +52,7 @@ export async function fetchArticleTitle(
|
|||||||
|
|
||||||
// Sort by created_at and take the most recent
|
// Sort by created_at and take the most recent
|
||||||
events.sort((a, b) => b.created_at - a.created_at)
|
events.sort((a, b) => b.created_at - a.created_at)
|
||||||
const article = events[0]
|
const article = events[0] as unknown as Parameters<typeof getArticleTitle>[0]
|
||||||
|
|
||||||
return getArticleTitle(article) || null
|
return getArticleTitle(article) || null
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -60,8 +60,27 @@ export const processApplesauceBookmarks = (
|
|||||||
if (applesauceBookmarks.articles) allItems.push(...applesauceBookmarks.articles)
|
if (applesauceBookmarks.articles) allItems.push(...applesauceBookmarks.articles)
|
||||||
if (applesauceBookmarks.hashtags) allItems.push(...applesauceBookmarks.hashtags)
|
if (applesauceBookmarks.hashtags) allItems.push(...applesauceBookmarks.hashtags)
|
||||||
if (applesauceBookmarks.urls) allItems.push(...applesauceBookmarks.urls)
|
if (applesauceBookmarks.urls) allItems.push(...applesauceBookmarks.urls)
|
||||||
return allItems.map((bookmark: BookmarkData) => ({
|
return allItems
|
||||||
id: bookmark.id || `${isPrivate ? 'private' : 'public'}-${Date.now()}`,
|
.filter((bookmark: BookmarkData) => bookmark.id) // Skip bookmarks without valid IDs
|
||||||
|
.map((bookmark: BookmarkData) => ({
|
||||||
|
id: bookmark.id!,
|
||||||
|
content: bookmark.content || '',
|
||||||
|
created_at: bookmark.created_at || Math.floor(Date.now() / 1000),
|
||||||
|
pubkey: activeAccount.pubkey,
|
||||||
|
kind: bookmark.kind || 30001,
|
||||||
|
tags: bookmark.tags || [],
|
||||||
|
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
||||||
|
type: 'event' as const,
|
||||||
|
isPrivate,
|
||||||
|
added_at: bookmark.created_at || Math.floor(Date.now() / 1000)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
const bookmarkArray = Array.isArray(bookmarks) ? bookmarks : [bookmarks]
|
||||||
|
return bookmarkArray
|
||||||
|
.filter((bookmark: BookmarkData) => bookmark.id) // Skip bookmarks without valid IDs
|
||||||
|
.map((bookmark: BookmarkData) => ({
|
||||||
|
id: bookmark.id!,
|
||||||
content: bookmark.content || '',
|
content: bookmark.content || '',
|
||||||
created_at: bookmark.created_at || Math.floor(Date.now() / 1000),
|
created_at: bookmark.created_at || Math.floor(Date.now() / 1000),
|
||||||
pubkey: activeAccount.pubkey,
|
pubkey: activeAccount.pubkey,
|
||||||
@@ -70,23 +89,8 @@ export const processApplesauceBookmarks = (
|
|||||||
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
||||||
type: 'event' as const,
|
type: 'event' as const,
|
||||||
isPrivate,
|
isPrivate,
|
||||||
added_at: Math.floor(Date.now() / 1000)
|
added_at: bookmark.created_at || Math.floor(Date.now() / 1000)
|
||||||
}))
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
const bookmarkArray = Array.isArray(bookmarks) ? bookmarks : [bookmarks]
|
|
||||||
return bookmarkArray.map((bookmark: BookmarkData) => ({
|
|
||||||
id: bookmark.id || `${isPrivate ? 'private' : 'public'}-${Date.now()}`,
|
|
||||||
content: bookmark.content || '',
|
|
||||||
created_at: bookmark.created_at || Math.floor(Date.now() / 1000),
|
|
||||||
pubkey: activeAccount.pubkey,
|
|
||||||
kind: bookmark.kind || 30001,
|
|
||||||
tags: bookmark.tags || [],
|
|
||||||
parsedContent: bookmark.content ? (getParsedContent(bookmark.content) as ParsedContent) : undefined,
|
|
||||||
type: 'event' as const,
|
|
||||||
isPrivate,
|
|
||||||
added_at: Math.floor(Date.now() / 1000)
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Types and guards around signer/decryption APIs
|
// Types and guards around signer/decryption APIs
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, merge, Observable, takeUntil, timer, toArray } from 'rxjs'
|
||||||
import {
|
import {
|
||||||
AccountWithExtension,
|
AccountWithExtension,
|
||||||
NostrEvent,
|
NostrEvent,
|
||||||
@@ -16,6 +16,7 @@ import { Bookmark } from '../types/bookmarks'
|
|||||||
import { collectBookmarksFromEvents } from './bookmarkProcessing.ts'
|
import { collectBookmarksFromEvents } from './bookmarkProcessing.ts'
|
||||||
import { UserSettings } from './settingsService'
|
import { UserSettings } from './settingsService'
|
||||||
import { rebroadcastEvents } from './rebroadcastService'
|
import { rebroadcastEvents } from './rebroadcastService'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -31,14 +32,22 @@ export const fetchBookmarks = async (
|
|||||||
throw new Error('Invalid account object provided')
|
throw new Error('Invalid account object provided')
|
||||||
}
|
}
|
||||||
// Get relay URLs from the pool
|
// Get relay URLs from the pool
|
||||||
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
const relayUrls = prioritizeLocalRelays(Array.from(relayPool.relays.values()).map(relay => relay.url))
|
||||||
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(relayUrls)
|
||||||
// Fetch bookmark events - NIP-51 standards, legacy formats, and web bookmarks (NIP-B0)
|
// Fetch bookmark events - NIP-51 standards, legacy formats, and web bookmarks (NIP-B0)
|
||||||
console.log('🔍 Fetching bookmark events from relays:', relayUrls)
|
console.log('🔍 Fetching bookmark events from relays:', relayUrls)
|
||||||
const rawEvents = await lastValueFrom(
|
// Try local-first quickly, then full set fallback
|
||||||
relayPool
|
const local$ = localRelays.length > 0
|
||||||
.req(relayUrls, { kinds: [10003, 30003, 30001, 39701], authors: [activeAccount.pubkey] })
|
? relayPool
|
||||||
.pipe(completeOnEose(), takeUntil(timer(20000)), toArray())
|
.req(localRelays, { kinds: [10003, 30003, 30001, 39701], authors: [activeAccount.pubkey] })
|
||||||
)
|
.pipe(completeOnEose(), takeUntil(timer(1200)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const remote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [10003, 30003, 30001, 39701], authors: [activeAccount.pubkey] })
|
||||||
|
.pipe(completeOnEose(), takeUntil(timer(6000)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const rawEvents = await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||||
console.log('📊 Raw events fetched:', rawEvents.length, 'events')
|
console.log('📊 Raw events fetched:', rawEvents.length, 'events')
|
||||||
|
|
||||||
// Rebroadcast bookmark events to local/all relays based on settings
|
// Rebroadcast bookmark events to local/all relays based on settings
|
||||||
@@ -64,7 +73,7 @@ export const fetchBookmarks = async (
|
|||||||
const bookmarkListEvents = dedupeNip51Events(rawEvents)
|
const bookmarkListEvents = dedupeNip51Events(rawEvents)
|
||||||
console.log('📋 After deduplication:', bookmarkListEvents.length, 'bookmark events')
|
console.log('📋 After deduplication:', bookmarkListEvents.length, 'bookmark events')
|
||||||
if (bookmarkListEvents.length === 0) {
|
if (bookmarkListEvents.length === 0) {
|
||||||
setBookmarks([])
|
// Keep existing bookmarks visible; do not clear list if nothing new found
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Aggregate across events
|
// Aggregate across events
|
||||||
@@ -102,9 +111,14 @@ export const fetchBookmarks = async (
|
|||||||
let idToEvent: Map<string, NostrEvent> = new Map()
|
let idToEvent: Map<string, NostrEvent> = new Map()
|
||||||
if (noteIds.length > 0) {
|
if (noteIds.length > 0) {
|
||||||
try {
|
try {
|
||||||
const events = await lastValueFrom(
|
const { local: localHydrate, remote: remoteHydrate } = partitionRelays(relayUrls)
|
||||||
relayPool.req(relayUrls, { ids: noteIds }).pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
|
const localHydrate$ = localHydrate.length > 0
|
||||||
)
|
? relayPool.req(localHydrate, { ids: noteIds }).pipe(completeOnEose(), takeUntil(timer(800)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const remoteHydrate$ = remoteHydrate.length > 0
|
||||||
|
? relayPool.req(remoteHydrate, { ids: noteIds }).pipe(completeOnEose(), takeUntil(timer(2500)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const events: NostrEvent[] = await lastValueFrom(merge(localHydrate$, remoteHydrate$).pipe(toArray()))
|
||||||
idToEvent = new Map(events.map((e: NostrEvent) => [e.id, e]))
|
idToEvent = new Map(events.map((e: NostrEvent) => [e.id, e]))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to fetch events for hydration:', error)
|
console.warn('Failed to fetch events for hydration:', error)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, merge, Observable, takeUntil, timer, toArray } from 'rxjs'
|
||||||
|
import { prioritizeLocalRelays } from '../utils/helpers'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the contact list (follows) for a specific user
|
* Fetches the contact list (follows) for a specific user
|
||||||
@@ -9,40 +10,49 @@ import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
|||||||
*/
|
*/
|
||||||
export const fetchContacts = async (
|
export const fetchContacts = async (
|
||||||
relayPool: RelayPool,
|
relayPool: RelayPool,
|
||||||
pubkey: string
|
pubkey: string,
|
||||||
|
onPartial?: (contacts: Set<string>) => void
|
||||||
): Promise<Set<string>> => {
|
): Promise<Set<string>> => {
|
||||||
try {
|
try {
|
||||||
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
const relayUrls = prioritizeLocalRelays(Array.from(relayPool.relays.values()).map(relay => relay.url))
|
||||||
|
|
||||||
console.log('🔍 Fetching contacts (kind 3) for user:', pubkey)
|
console.log('🔍 Fetching contacts (kind 3) for user:', pubkey)
|
||||||
|
|
||||||
|
// Local-first quick attempt
|
||||||
|
const localRelays = relayUrls.filter(url => url.includes('localhost') || url.includes('127.0.0.1'))
|
||||||
|
const remoteRelays = relayUrls.filter(url => !url.includes('localhost') && !url.includes('127.0.0.1'))
|
||||||
|
const local$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [3], authors: [pubkey] })
|
||||||
|
.pipe(completeOnEose(), takeUntil(timer(1200)))
|
||||||
|
: new Observable<{ created_at: number; tags: string[][] }>((sub) => sub.complete())
|
||||||
|
const remote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [3], authors: [pubkey] })
|
||||||
|
.pipe(completeOnEose(), takeUntil(timer(6000)))
|
||||||
|
: new Observable<{ created_at: number; tags: string[][] }>((sub) => sub.complete())
|
||||||
const events = await lastValueFrom(
|
const events = await lastValueFrom(
|
||||||
relayPool
|
merge(local$, remote$).pipe(toArray())
|
||||||
.req(relayUrls, { kinds: [3], authors: [pubkey] })
|
|
||||||
.pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
|
|
||||||
)
|
)
|
||||||
|
const followed = new Set<string>()
|
||||||
|
if (events.length > 0) {
|
||||||
|
// Get the most recent contact list
|
||||||
|
const sortedEvents = events.sort((a, b) => b.created_at - a.created_at)
|
||||||
|
const contactList = sortedEvents[0]
|
||||||
|
// Extract pubkeys from 'p' tags
|
||||||
|
for (const tag of contactList.tags) {
|
||||||
|
if (tag[0] === 'p' && tag[1]) {
|
||||||
|
followed.add(tag[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (onPartial) onPartial(new Set(followed))
|
||||||
|
}
|
||||||
|
// merged already via streams
|
||||||
|
|
||||||
console.log('📊 Contact events fetched:', events.length)
|
console.log('📊 Contact events fetched:', events.length)
|
||||||
|
|
||||||
if (events.length === 0) {
|
console.log('👥 Followed contacts:', followed.size)
|
||||||
return new Set()
|
return followed
|
||||||
}
|
|
||||||
|
|
||||||
// Get the most recent contact list
|
|
||||||
const sortedEvents = events.sort((a, b) => b.created_at - a.created_at)
|
|
||||||
const contactList = sortedEvents[0]
|
|
||||||
|
|
||||||
// Extract pubkeys from 'p' tags
|
|
||||||
const followedPubkeys = new Set<string>()
|
|
||||||
for (const tag of contactList.tags) {
|
|
||||||
if (tag[0] === 'p' && tag[1]) {
|
|
||||||
followedPubkeys.add(tag[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('👥 Followed contacts:', followedPubkeys.size)
|
|
||||||
|
|
||||||
return followedPubkeys
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch contacts:', error)
|
console.error('Failed to fetch contacts:', error)
|
||||||
return new Set()
|
return new Set()
|
||||||
|
|||||||
42
src/services/exploreCache.ts
Normal file
42
src/services/exploreCache.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
|
||||||
|
export interface CachedBlogPostPreview {
|
||||||
|
event: NostrEvent
|
||||||
|
title: string
|
||||||
|
summary?: string
|
||||||
|
image?: string
|
||||||
|
published?: number
|
||||||
|
author: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CacheValue = {
|
||||||
|
posts: CachedBlogPostPreview[]
|
||||||
|
timestamp: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const exploreCache = new Map<string, CacheValue>() // key: pubkey
|
||||||
|
|
||||||
|
export function getCachedPosts(pubkey: string): CachedBlogPostPreview[] | null {
|
||||||
|
const entry = exploreCache.get(pubkey)
|
||||||
|
if (!entry) return null
|
||||||
|
return entry.posts
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setCachedPosts(pubkey: string, posts: CachedBlogPostPreview[]): void {
|
||||||
|
exploreCache.set(pubkey, { posts, timestamp: Date.now() })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function upsertCachedPost(pubkey: string, post: CachedBlogPostPreview): CachedBlogPostPreview[] {
|
||||||
|
const current = exploreCache.get(pubkey)?.posts || []
|
||||||
|
const byId = new Map(current.map(p => [p.event.id, p]))
|
||||||
|
byId.set(post.event.id, post)
|
||||||
|
const merged = Array.from(byId.values()).sort((a, b) => {
|
||||||
|
const ta = a.published || a.event.created_at
|
||||||
|
const tb = b.published || b.event.created_at
|
||||||
|
return tb - ta
|
||||||
|
})
|
||||||
|
setCachedPosts(pubkey, merged)
|
||||||
|
return merged
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
import { RelayPool, completeOnEose } from 'applesauce-relay'
|
||||||
import { lastValueFrom, takeUntil, timer, toArray } from 'rxjs'
|
import { lastValueFrom, merge, Observable, takeUntil, timer, toArray } from 'rxjs'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays } from '../utils/helpers'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
import { NostrEvent } from 'nostr-tools'
|
||||||
import { Helpers } from 'applesauce-core'
|
import { Helpers } from 'applesauce-core'
|
||||||
|
|
||||||
@@ -24,7 +25,8 @@ export interface BlogPostPreview {
|
|||||||
export const fetchBlogPostsFromAuthors = async (
|
export const fetchBlogPostsFromAuthors = async (
|
||||||
relayPool: RelayPool,
|
relayPool: RelayPool,
|
||||||
pubkeys: string[],
|
pubkeys: string[],
|
||||||
relayUrls: string[]
|
relayUrls: string[],
|
||||||
|
onPost?: (post: BlogPostPreview) => void
|
||||||
): Promise<BlogPostPreview[]> => {
|
): Promise<BlogPostPreview[]> => {
|
||||||
try {
|
try {
|
||||||
if (pubkeys.length === 0) {
|
if (pubkeys.length === 0) {
|
||||||
@@ -34,42 +36,65 @@ export const fetchBlogPostsFromAuthors = async (
|
|||||||
|
|
||||||
console.log('📚 Fetching blog posts (kind 30023) from', pubkeys.length, 'authors')
|
console.log('📚 Fetching blog posts (kind 30023) from', pubkeys.length, 'authors')
|
||||||
|
|
||||||
const events = await lastValueFrom(
|
const prioritized = prioritizeLocalRelays(relayUrls)
|
||||||
relayPool
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(prioritized)
|
||||||
.req(relayUrls, {
|
|
||||||
kinds: [30023],
|
|
||||||
authors: pubkeys,
|
|
||||||
limit: 100 // Fetch up to 100 recent posts
|
|
||||||
})
|
|
||||||
.pipe(completeOnEose(), takeUntil(timer(15000)), toArray())
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log('📊 Blog post events fetched:', events.length)
|
|
||||||
|
|
||||||
// Deduplicate replaceable events by keeping the most recent version
|
// Deduplicate replaceable events by keeping the most recent version
|
||||||
// Group by author + d-tag identifier
|
// Group by author + d-tag identifier
|
||||||
const uniqueEvents = new Map<string, NostrEvent>()
|
const uniqueEvents = new Map<string, NostrEvent>()
|
||||||
|
|
||||||
for (const event of events) {
|
const processEvents = (incoming: NostrEvent[]) => {
|
||||||
const dTag = event.tags.find(t => t[0] === 'd')?.[1] || ''
|
for (const event of incoming) {
|
||||||
const key = `${event.pubkey}:${dTag}`
|
const dTag = event.tags.find(t => t[0] === 'd')?.[1] || ''
|
||||||
|
const key = `${event.pubkey}:${dTag}`
|
||||||
const existing = uniqueEvents.get(key)
|
const existing = uniqueEvents.get(key)
|
||||||
if (!existing || event.created_at > existing.created_at) {
|
if (!existing || event.created_at > existing.created_at) {
|
||||||
uniqueEvents.set(key, event)
|
uniqueEvents.set(key, event)
|
||||||
|
// Emit as we incorporate
|
||||||
|
if (onPost) {
|
||||||
|
const post: BlogPostPreview = {
|
||||||
|
event,
|
||||||
|
title: getArticleTitle(event) || 'Untitled',
|
||||||
|
summary: getArticleSummary(event),
|
||||||
|
image: getArticleImage(event),
|
||||||
|
published: getArticlePublished(event),
|
||||||
|
author: event.pubkey
|
||||||
|
}
|
||||||
|
onPost(post)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const local$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [30023], authors: pubkeys, limit: 100 })
|
||||||
|
.pipe(completeOnEose(), takeUntil(timer(1200)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const remote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [30023], authors: pubkeys, limit: 100 })
|
||||||
|
.pipe(completeOnEose(), takeUntil(timer(6000)))
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const events = await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||||
|
processEvents(events)
|
||||||
|
|
||||||
|
console.log('📊 Blog post events fetched (unique):', uniqueEvents.size)
|
||||||
|
|
||||||
// Convert to blog post previews and sort by published date (most recent first)
|
// Convert to blog post previews and sort by published date (most recent first)
|
||||||
const blogPosts: BlogPostPreview[] = Array.from(uniqueEvents.values())
|
const blogPosts: BlogPostPreview[] = Array.from(uniqueEvents.values())
|
||||||
.map(event => ({
|
.map(event => {
|
||||||
event,
|
const post: BlogPostPreview = {
|
||||||
title: getArticleTitle(event) || 'Untitled',
|
event,
|
||||||
summary: getArticleSummary(event),
|
title: getArticleTitle(event) || 'Untitled',
|
||||||
image: getArticleImage(event),
|
summary: getArticleSummary(event),
|
||||||
published: getArticlePublished(event),
|
image: getArticleImage(event),
|
||||||
author: event.pubkey
|
published: getArticlePublished(event),
|
||||||
}))
|
author: event.pubkey
|
||||||
|
}
|
||||||
|
if (onPost) onPost(post)
|
||||||
|
return post
|
||||||
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
const timeA = a.published || a.event.created_at
|
const timeA = a.published || a.event.created_at
|
||||||
const timeB = b.published || b.event.created_at
|
const timeB = b.published || b.event.created_at
|
||||||
|
|||||||
@@ -1,204 +1,5 @@
|
|||||||
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
export * from './highlights/fetchForArticle'
|
||||||
import { lastValueFrom, takeUntil, timer, tap, toArray } from 'rxjs'
|
export * from './highlights/fetchForUrl'
|
||||||
import { NostrEvent } from 'nostr-tools'
|
export * from './highlights/fetchByAuthor'
|
||||||
import { Highlight } from '../types/highlights'
|
|
||||||
import { RELAYS } from '../config/relays'
|
|
||||||
import { eventToHighlight, dedupeHighlights, sortHighlights } from './highlightEventProcessor'
|
|
||||||
import { UserSettings } from './settingsService'
|
|
||||||
import { rebroadcastEvents } from './rebroadcastService'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches highlights for a specific article by its address coordinate and/or event ID
|
|
||||||
* @param relayPool - The relay pool to query
|
|
||||||
* @param articleCoordinate - The article's address in format "kind:pubkey:identifier" (e.g., "30023:abc...def:my-article")
|
|
||||||
* @param eventId - Optional event ID to also query by 'e' tag
|
|
||||||
* @param onHighlight - Optional callback to receive highlights as they arrive
|
|
||||||
* @param settings - User settings for rebroadcast options
|
|
||||||
*/
|
|
||||||
export const fetchHighlightsForArticle = async (
|
|
||||||
relayPool: RelayPool,
|
|
||||||
articleCoordinate: string,
|
|
||||||
eventId?: string,
|
|
||||||
onHighlight?: (highlight: Highlight) => void,
|
|
||||||
settings?: UserSettings
|
|
||||||
): Promise<Highlight[]> => {
|
|
||||||
try {
|
|
||||||
console.log('🔍 Fetching highlights (kind 9802) for article:', articleCoordinate)
|
|
||||||
console.log('🔍 Event ID:', eventId || 'none')
|
|
||||||
console.log('🔍 From relays (including local):', RELAYS)
|
|
||||||
|
|
||||||
const seenIds = new Set<string>()
|
|
||||||
const processEvent = (event: NostrEvent): Highlight | null => {
|
|
||||||
if (seenIds.has(event.id)) return null
|
|
||||||
seenIds.add(event.id)
|
|
||||||
return eventToHighlight(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query for highlights that reference this article via the 'a' tag
|
|
||||||
const aTagEvents = await lastValueFrom(
|
|
||||||
relayPool
|
|
||||||
.req(RELAYS, { kinds: [9802], '#a': [articleCoordinate] })
|
|
||||||
.pipe(
|
|
||||||
onlyEvents(),
|
|
||||||
tap((event: NostrEvent) => {
|
|
||||||
const highlight = processEvent(event)
|
|
||||||
if (highlight && onHighlight) {
|
|
||||||
onHighlight(highlight)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
completeOnEose(),
|
|
||||||
takeUntil(timer(10000)),
|
|
||||||
toArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log('📊 Highlights via a-tag:', aTagEvents.length)
|
|
||||||
|
|
||||||
// If we have an event ID, also query for highlights that reference via the 'e' tag
|
|
||||||
let eTagEvents: NostrEvent[] = []
|
|
||||||
if (eventId) {
|
|
||||||
eTagEvents = await lastValueFrom(
|
|
||||||
relayPool
|
|
||||||
.req(RELAYS, { kinds: [9802], '#e': [eventId] })
|
|
||||||
.pipe(
|
|
||||||
onlyEvents(),
|
|
||||||
tap((event: NostrEvent) => {
|
|
||||||
const highlight = processEvent(event)
|
|
||||||
if (highlight && onHighlight) {
|
|
||||||
onHighlight(highlight)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
completeOnEose(),
|
|
||||||
takeUntil(timer(10000)),
|
|
||||||
toArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
console.log('📊 Highlights via e-tag:', eTagEvents.length)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Combine results from both queries
|
|
||||||
const rawEvents = [...aTagEvents, ...eTagEvents]
|
|
||||||
console.log('📊 Total raw highlight events fetched:', rawEvents.length)
|
|
||||||
|
|
||||||
// Rebroadcast highlight events to local/all relays based on settings
|
|
||||||
await rebroadcastEvents(rawEvents, relayPool, settings)
|
|
||||||
|
|
||||||
if (rawEvents.length > 0) {
|
|
||||||
console.log('📄 Sample highlight tags:', JSON.stringify(rawEvents[0].tags, null, 2))
|
|
||||||
} else {
|
|
||||||
console.log('❌ No highlights found. Article coordinate:', articleCoordinate)
|
|
||||||
console.log('❌ Event ID:', eventId || 'none')
|
|
||||||
console.log('💡 Try checking if there are any highlights on this article at https://highlighter.com')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deduplicate events by ID
|
|
||||||
const uniqueEvents = dedupeHighlights(rawEvents)
|
|
||||||
console.log('📊 Unique highlight events after deduplication:', uniqueEvents.length)
|
|
||||||
|
|
||||||
const highlights: Highlight[] = uniqueEvents.map(eventToHighlight)
|
|
||||||
return sortHighlights(highlights)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch highlights for article:', error)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches highlights for a specific URL
|
|
||||||
* @param relayPool - The relay pool to query
|
|
||||||
* @param url - The external URL to find highlights for
|
|
||||||
* @param settings - User settings for rebroadcast options
|
|
||||||
*/
|
|
||||||
export const fetchHighlightsForUrl = async (
|
|
||||||
relayPool: RelayPool,
|
|
||||||
url: string,
|
|
||||||
settings?: UserSettings
|
|
||||||
): Promise<Highlight[]> => {
|
|
||||||
try {
|
|
||||||
console.log('🔍 Fetching highlights (kind 9802) for URL:', url)
|
|
||||||
|
|
||||||
const seenIds = new Set<string>()
|
|
||||||
const rawEvents = await lastValueFrom(
|
|
||||||
relayPool
|
|
||||||
.req(RELAYS, { kinds: [9802], '#r': [url] })
|
|
||||||
.pipe(
|
|
||||||
onlyEvents(),
|
|
||||||
tap((event: NostrEvent) => {
|
|
||||||
seenIds.add(event.id)
|
|
||||||
}),
|
|
||||||
completeOnEose(),
|
|
||||||
takeUntil(timer(10000)),
|
|
||||||
toArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log('📊 Highlights for URL:', rawEvents.length)
|
|
||||||
|
|
||||||
// Rebroadcast highlight events to local/all relays based on settings
|
|
||||||
await rebroadcastEvents(rawEvents, relayPool, settings)
|
|
||||||
|
|
||||||
const uniqueEvents = dedupeHighlights(rawEvents)
|
|
||||||
const highlights: Highlight[] = uniqueEvents.map(eventToHighlight)
|
|
||||||
return sortHighlights(highlights)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch highlights for URL:', error)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches highlights created by a specific user
|
|
||||||
* @param relayPool - The relay pool to query
|
|
||||||
* @param pubkey - The user's public key
|
|
||||||
* @param onHighlight - Optional callback to receive highlights as they arrive
|
|
||||||
* @param settings - User settings for rebroadcast options
|
|
||||||
*/
|
|
||||||
export const fetchHighlights = async (
|
|
||||||
relayPool: RelayPool,
|
|
||||||
pubkey: string,
|
|
||||||
onHighlight?: (highlight: Highlight) => void,
|
|
||||||
settings?: UserSettings
|
|
||||||
): Promise<Highlight[]> => {
|
|
||||||
try {
|
|
||||||
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
|
||||||
|
|
||||||
console.log('🔍 Fetching highlights (kind 9802) by author:', pubkey)
|
|
||||||
|
|
||||||
const seenIds = new Set<string>()
|
|
||||||
const rawEvents = await lastValueFrom(
|
|
||||||
relayPool
|
|
||||||
.req(relayUrls, { kinds: [9802], authors: [pubkey] })
|
|
||||||
.pipe(
|
|
||||||
onlyEvents(),
|
|
||||||
tap((event: NostrEvent) => {
|
|
||||||
if (!seenIds.has(event.id)) {
|
|
||||||
seenIds.add(event.id)
|
|
||||||
const highlight = eventToHighlight(event)
|
|
||||||
if (onHighlight) {
|
|
||||||
onHighlight(highlight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
completeOnEose(),
|
|
||||||
takeUntil(timer(10000)),
|
|
||||||
toArray()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
console.log('📊 Raw highlight events fetched:', rawEvents.length)
|
|
||||||
|
|
||||||
// Rebroadcast highlight events to local/all relays based on settings
|
|
||||||
await rebroadcastEvents(rawEvents, relayPool, settings)
|
|
||||||
|
|
||||||
// Deduplicate and process events
|
|
||||||
const uniqueEvents = dedupeHighlights(rawEvents)
|
|
||||||
console.log('📊 Unique highlight events after deduplication:', uniqueEvents.length)
|
|
||||||
|
|
||||||
const highlights: Highlight[] = uniqueEvents.map(eventToHighlight)
|
|
||||||
return sortHighlights(highlights)
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to fetch highlights by author:', error)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
63
src/services/highlights/fetchByAuthor.ts
Normal file
63
src/services/highlights/fetchByAuthor.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
||||||
|
import { lastValueFrom, merge, Observable, takeUntil, timer, tap, toArray } from 'rxjs'
|
||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
import { Highlight } from '../../types/highlights'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays } from '../../utils/helpers'
|
||||||
|
import { eventToHighlight, dedupeHighlights, sortHighlights } from '../highlightEventProcessor'
|
||||||
|
import { UserSettings } from '../settingsService'
|
||||||
|
import { rebroadcastEvents } from '../rebroadcastService'
|
||||||
|
|
||||||
|
export const fetchHighlights = async (
|
||||||
|
relayPool: RelayPool,
|
||||||
|
pubkey: string,
|
||||||
|
onHighlight?: (highlight: Highlight) => void,
|
||||||
|
settings?: UserSettings
|
||||||
|
): Promise<Highlight[]> => {
|
||||||
|
try {
|
||||||
|
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
|
||||||
|
const ordered = prioritizeLocalRelays(relayUrls)
|
||||||
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(ordered)
|
||||||
|
|
||||||
|
const seenIds = new Set<string>()
|
||||||
|
const local$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [9802], authors: [pubkey] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
if (!seenIds.has(event.id)) {
|
||||||
|
seenIds.add(event.id)
|
||||||
|
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(1200))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const remote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [9802], authors: [pubkey] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
if (!seenIds.has(event.id)) {
|
||||||
|
seenIds.add(event.id)
|
||||||
|
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(6000))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const rawEvents: NostrEvent[] = await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||||
|
|
||||||
|
await rebroadcastEvents(rawEvents, relayPool, settings)
|
||||||
|
const uniqueEvents = dedupeHighlights(rawEvents)
|
||||||
|
const highlights = uniqueEvents.map(eventToHighlight)
|
||||||
|
return sortHighlights(highlights)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
98
src/services/highlights/fetchForArticle.ts
Normal file
98
src/services/highlights/fetchForArticle.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
||||||
|
import { lastValueFrom, merge, Observable, takeUntil, timer, tap, toArray } from 'rxjs'
|
||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
import { Highlight } from '../../types/highlights'
|
||||||
|
import { RELAYS } from '../../config/relays'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays } from '../../utils/helpers'
|
||||||
|
import { eventToHighlight, dedupeHighlights, sortHighlights } from '../highlightEventProcessor'
|
||||||
|
import { UserSettings } from '../settingsService'
|
||||||
|
import { rebroadcastEvents } from '../rebroadcastService'
|
||||||
|
|
||||||
|
export const fetchHighlightsForArticle = async (
|
||||||
|
relayPool: RelayPool,
|
||||||
|
articleCoordinate: string,
|
||||||
|
eventId?: string,
|
||||||
|
onHighlight?: (highlight: Highlight) => void,
|
||||||
|
settings?: UserSettings
|
||||||
|
): Promise<Highlight[]> => {
|
||||||
|
try {
|
||||||
|
const seenIds = new Set<string>()
|
||||||
|
const processEvent = (event: NostrEvent): Highlight | null => {
|
||||||
|
if (seenIds.has(event.id)) return null
|
||||||
|
seenIds.add(event.id)
|
||||||
|
return eventToHighlight(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderedRelays = prioritizeLocalRelays(RELAYS)
|
||||||
|
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||||
|
|
||||||
|
const aLocal$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [9802], '#a': [articleCoordinate] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
const highlight = processEvent(event)
|
||||||
|
if (highlight && onHighlight) onHighlight(highlight)
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(1200))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const aRemote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [9802], '#a': [articleCoordinate] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
const highlight = processEvent(event)
|
||||||
|
if (highlight && onHighlight) onHighlight(highlight)
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(6000))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const aTagEvents: NostrEvent[] = await lastValueFrom(merge(aLocal$, aRemote$).pipe(toArray()))
|
||||||
|
|
||||||
|
let eTagEvents: NostrEvent[] = []
|
||||||
|
if (eventId) {
|
||||||
|
const eLocal$ = localRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelays, { kinds: [9802], '#e': [eventId] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
const highlight = processEvent(event)
|
||||||
|
if (highlight && onHighlight) onHighlight(highlight)
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(1200))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const eRemote$ = remoteRelays.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelays, { kinds: [9802], '#e': [eventId] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
const highlight = processEvent(event)
|
||||||
|
if (highlight && onHighlight) onHighlight(highlight)
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(6000))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
eTagEvents = await lastValueFrom(merge(eLocal$, eRemote$).pipe(toArray()))
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawEvents = [...aTagEvents, ...eTagEvents]
|
||||||
|
await rebroadcastEvents(rawEvents, relayPool, settings)
|
||||||
|
const uniqueEvents = dedupeHighlights(rawEvents)
|
||||||
|
const highlights: Highlight[] = uniqueEvents.map(eventToHighlight)
|
||||||
|
return sortHighlights(highlights)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
57
src/services/highlights/fetchForUrl.ts
Normal file
57
src/services/highlights/fetchForUrl.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import { RelayPool, completeOnEose, onlyEvents } from 'applesauce-relay'
|
||||||
|
import { lastValueFrom, merge, Observable, takeUntil, timer, tap, toArray } from 'rxjs'
|
||||||
|
import { NostrEvent } from 'nostr-tools'
|
||||||
|
import { Highlight } from '../../types/highlights'
|
||||||
|
import { RELAYS } from '../../config/relays'
|
||||||
|
import { prioritizeLocalRelays, partitionRelays } from '../../utils/helpers'
|
||||||
|
import { eventToHighlight, dedupeHighlights, sortHighlights } from '../highlightEventProcessor'
|
||||||
|
import { UserSettings } from '../settingsService'
|
||||||
|
import { rebroadcastEvents } from '../rebroadcastService'
|
||||||
|
|
||||||
|
export const fetchHighlightsForUrl = async (
|
||||||
|
relayPool: RelayPool,
|
||||||
|
url: string,
|
||||||
|
onHighlight?: (highlight: Highlight) => void,
|
||||||
|
settings?: UserSettings
|
||||||
|
): Promise<Highlight[]> => {
|
||||||
|
try {
|
||||||
|
const seenIds = new Set<string>()
|
||||||
|
const orderedRelaysUrl = prioritizeLocalRelays(RELAYS)
|
||||||
|
const { local: localRelaysUrl, remote: remoteRelaysUrl } = partitionRelays(orderedRelaysUrl)
|
||||||
|
const local$ = localRelaysUrl.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(localRelaysUrl, { kinds: [9802], '#r': [url] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
seenIds.add(event.id)
|
||||||
|
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(1200))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const remote$ = remoteRelaysUrl.length > 0
|
||||||
|
? relayPool
|
||||||
|
.req(remoteRelaysUrl, { kinds: [9802], '#r': [url] })
|
||||||
|
.pipe(
|
||||||
|
onlyEvents(),
|
||||||
|
tap((event: NostrEvent) => {
|
||||||
|
seenIds.add(event.id)
|
||||||
|
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||||
|
}),
|
||||||
|
completeOnEose(),
|
||||||
|
takeUntil(timer(6000))
|
||||||
|
)
|
||||||
|
: new Observable<NostrEvent>((sub) => sub.complete())
|
||||||
|
const rawEvents: NostrEvent[] = await lastValueFrom(merge(local$, remote$).pipe(toArray()))
|
||||||
|
await rebroadcastEvents(rawEvents, relayPool, settings)
|
||||||
|
const uniqueEvents = dedupeHighlights(rawEvents)
|
||||||
|
const highlights: Highlight[] = uniqueEvents.map(eventToHighlight)
|
||||||
|
return sortHighlights(highlights)
|
||||||
|
} catch {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,3 +63,58 @@ export const hasRemoteRelay = (relayUrls: string[]): boolean => {
|
|||||||
return relayUrls.some(url => !isLocalRelay(url))
|
return relayUrls.some(url => !isLocalRelay(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits relay URLs into local and remote groups
|
||||||
|
*/
|
||||||
|
export const partitionRelays = (
|
||||||
|
relayUrls: string[]
|
||||||
|
): { local: string[]; remote: string[] } => {
|
||||||
|
const local: string[] = []
|
||||||
|
const remote: string[] = []
|
||||||
|
for (const url of relayUrls) {
|
||||||
|
if (isLocalRelay(url)) local.push(url)
|
||||||
|
else remote.push(url)
|
||||||
|
}
|
||||||
|
return { local, remote }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns relays ordered with local first while keeping uniqueness
|
||||||
|
*/
|
||||||
|
export const prioritizeLocalRelays = (relayUrls: string[]): string[] => {
|
||||||
|
const { local, remote } = partitionRelays(relayUrls)
|
||||||
|
const seen = new Set<string>()
|
||||||
|
const out: string[] = []
|
||||||
|
for (const url of [...local, ...remote]) {
|
||||||
|
if (!seen.has(url)) {
|
||||||
|
seen.add(url)
|
||||||
|
out.push(url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parallel request helper
|
||||||
|
import { completeOnEose, onlyEvents, RelayPool } from 'applesauce-relay'
|
||||||
|
import { Observable, takeUntil, timer } from 'rxjs'
|
||||||
|
|
||||||
|
export function createParallelReqStreams(
|
||||||
|
relayPool: RelayPool,
|
||||||
|
localRelays: string[],
|
||||||
|
remoteRelays: string[],
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
filter: any,
|
||||||
|
localTimeoutMs = 1200,
|
||||||
|
remoteTimeoutMs = 6000
|
||||||
|
): { local$: Observable<unknown>; remote$: Observable<unknown> } {
|
||||||
|
const local$ = (localRelays.length > 0)
|
||||||
|
? relayPool.req(localRelays, filter).pipe(onlyEvents(), completeOnEose(), takeUntil(timer(localTimeoutMs)))
|
||||||
|
: new Observable<unknown>((sub) => { sub.complete() })
|
||||||
|
|
||||||
|
const remote$ = (remoteRelays.length > 0)
|
||||||
|
? relayPool.req(remoteRelays, filter).pipe(onlyEvents(), completeOnEose(), takeUntil(timer(remoteTimeoutMs)))
|
||||||
|
: new Observable<unknown>((sub) => { sub.complete() })
|
||||||
|
|
||||||
|
return { local$, remote$ }
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { decode, npubEncode, noteEncode } from 'nostr-tools/nip19'
|
import { decode, npubEncode, noteEncode } from 'nostr-tools/nip19'
|
||||||
|
import { getNostrUrl } from '../config/nostrGateways'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regular expression to match nostr: URIs and bare NIP-19 identifiers
|
* Regular expression to match nostr: URIs and bare NIP-19 identifiers
|
||||||
@@ -39,7 +40,7 @@ export function extractNaddrUris(text: string): string[] {
|
|||||||
/**
|
/**
|
||||||
* Decode a NIP-19 identifier and return a human-readable link
|
* Decode a NIP-19 identifier and return a human-readable link
|
||||||
* For articles (naddr), returns an internal app link
|
* For articles (naddr), returns an internal app link
|
||||||
* For other types, returns an external njump.me link
|
* For other types, returns an external gateway link
|
||||||
*/
|
*/
|
||||||
export function createNostrLink(encoded: string): string {
|
export function createNostrLink(encoded: string): string {
|
||||||
try {
|
try {
|
||||||
@@ -53,13 +54,13 @@ export function createNostrLink(encoded: string): string {
|
|||||||
case 'nprofile':
|
case 'nprofile':
|
||||||
case 'note':
|
case 'note':
|
||||||
case 'nevent':
|
case 'nevent':
|
||||||
return `https://njump.me/${encoded}`
|
return getNostrUrl(encoded)
|
||||||
default:
|
default:
|
||||||
return `https://njump.me/${encoded}`
|
return getNostrUrl(encoded)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to decode nostr URI:', encoded, error)
|
console.warn('Failed to decode nostr URI:', encoded, error)
|
||||||
return `https://njump.me/${encoded}`
|
return getNostrUrl(encoded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user