Ships the client side of the v2.0.0 feed feature. Folds client-app/
into the monorepo (was previously .gitignored as "tracked separately"
but no separate repo ever existed — for v2.0.0 the client is
first-class).
Feed screens
app/(app)/feed.tsx — Feed tab
- Three-way tab strip: Подписки / Для вас / В тренде backed by
/feed/timeline, /feed/foryou, /feed/trending respectively
- Default landing tab is "Для вас" — surfaces discovery without
requiring the user to follow anyone first
- FlatList with pull-to-refresh + viewability-driven view counter
bump (posts visible ≥ 60% for ≥ 1s trigger POST /feed/post/…/view)
- Floating blue compose button → /compose
- Per-post liked_by_me fetched in batches of 6 after list load
app/(app)/compose.tsx — post composer modal
- Fullscreen, Twitter-like header (✕ left, Опубликовать right)
- Auto-focused multiline TextInput, 4000 char cap
- Hashtag preview chips that auto-update as you type
- expo-image-picker + expo-image-manipulator pipeline: resize to
1080px max-dim, JPEG Q=50 (client-side first-pass compression
before the mandatory server-side scrub)
- Live fee estimate + balance guard with a confirmation modal
("Опубликовать пост? Цена: 0.00X T · Размер: N KB")
- Exif: false passed to ImagePicker as an extra privacy layer
app/(app)/feed/[id].tsx — post detail
- Full PostCard rendering + detailed info panel (views, likes,
size, fee, hosting relay, hashtags as tappable chips)
- Triggers bumpView on mount
- 410 (on-chain soft-delete) routes back to the feed
app/(app)/feed/tag/[tag].tsx — hashtag feed
app/(app)/profile/[address].tsx — rebuilt
- Twitter-ish profile: avatar, name, address short-form, post count
- Posts | Инфо tab strip
- Follow / Unfollow button for non-self profiles (optimistic UI)
- Edit button on self profile → settings
- Secondary actions (chat, copy address) when viewing a known contact
Supporting library
lib/feed.ts — HTTP wrappers + tx builders for every /feed/* endpoint:
- publishPost (POST /feed/publish, signed)
- publishAndCommit (publish → on-chain CREATE_POST)
- fetchPost / fetchStats / bumpView
- fetchAuthorPosts / fetchTimeline / fetchForYou / fetchTrending /
fetchHashtag
- buildCreatePostTx / buildDeletePostTx
- buildFollowTx / buildUnfollowTx
- buildLikePostTx / buildUnlikePostTx
- likePost / unlikePost / followUser / unfollowUser / deletePost
(high-level helpers that bundle build + submitTx)
- formatFee, formatRelativeTime, formatCount — Twitter-like display
helpers
components/feed/PostCard.tsx — core card component
- Memoised for performance (N-row re-render on every like elsewhere
would cost a lot otherwise)
- Optimistic like toggle with heart-bounce spring animation
- Hashtag highlighting in body text (tappable → hashtag feed)
- Long-press context menu (Delete, owner-only)
- Views / likes / share-link / reply icons in footer row
Navigation cleanup
- NavBar: removed the SOON pill on the Feed tab (it's shipped now)
- (app)/_layout: hide NavBar on /compose and /feed/* sub-routes
- AnimatedSlot: treat /feed/<id>, /feed/tag/<t>, /compose as
sub-routes so back-swipe-right closes them
Channel removal (client side)
- lib/types.ts: ContactKind stripped to 'direct' | 'group'; legacy
'channel' flag removed. `kind` field kept for backward compat with
existing AsyncStorage records.
- lib/devSeed.ts: dropped the 5 channel seed contacts.
- components/ChatTile.tsx: removed channel kindIcon branch.
Dependencies
- expo-image-manipulator added for client-side image compression.
- expo-file-system/legacy used for readAsStringAsync (SDK 54 moved
that API to the legacy sub-path; the new streaming API isn't yet
stable).
Type check
- npx tsc --noEmit — clean, 0 errors.
Next (not in this commit)
- Direct attachment-bytes endpoint on the server so post-detail can
actually render the image (currently shows placeholder with URL)
- Cross-relay body fetch via /api/relays + hosting_relay pubkey
- Mentions (@username) with notifications
- Full-text search
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
218 lines
7.2 KiB
TypeScript
218 lines
7.2 KiB
TypeScript
/**
|
||
* VideoCircleRecorder — full-screen Modal для записи круглого видео-
|
||
* сообщения (Telegram-style).
|
||
*
|
||
* UX:
|
||
* 1. Открывается Modal с CameraView (по умолчанию front-camera).
|
||
* 2. Превью — круглое (аналогично VideoCirclePlayer).
|
||
* 3. Большая красная кнопка внизу: tap-to-start, tap-to-stop.
|
||
* 4. Максимум 15 секунд — авто-стоп.
|
||
* 5. По stop'у возвращаем attachment { kind:'video', circle:true, uri, duration }.
|
||
* 6. Свайп вниз / close-icon → cancel (без отправки).
|
||
*/
|
||
import React, { useEffect, useRef, useState } from 'react';
|
||
import { View, Text, Pressable, Modal, Alert } from 'react-native';
|
||
import { Ionicons } from '@expo/vector-icons';
|
||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||
import { CameraView, useCameraPermissions, useMicrophonePermissions } from 'expo-camera';
|
||
|
||
import type { Attachment } from '@/lib/types';
|
||
|
||
export interface VideoCircleRecorderProps {
|
||
visible: boolean;
|
||
onClose: () => void;
|
||
onFinish: (att: Attachment) => void;
|
||
}
|
||
|
||
const MAX_DURATION_SEC = 15;
|
||
|
||
function formatClock(sec: number): string {
|
||
const m = Math.floor(sec / 60);
|
||
const s = Math.floor(sec % 60);
|
||
return `${m}:${String(s).padStart(2, '0')}`;
|
||
}
|
||
|
||
export function VideoCircleRecorder({ visible, onClose, onFinish }: VideoCircleRecorderProps) {
|
||
const insets = useSafeAreaInsets();
|
||
const camRef = useRef<CameraView>(null);
|
||
|
||
const [camPerm, requestCam] = useCameraPermissions();
|
||
const [micPerm, requestMic] = useMicrophonePermissions();
|
||
|
||
const [recording, setRecording] = useState(false);
|
||
const [elapsed, setElapsed] = useState(0);
|
||
const startedAt = useRef(0);
|
||
const facing: 'front' | 'back' = 'front';
|
||
|
||
// Timer + auto-stop at MAX_DURATION_SEC
|
||
useEffect(() => {
|
||
if (!recording) return;
|
||
const t = setInterval(() => {
|
||
const s = Math.floor((Date.now() - startedAt.current) / 1000);
|
||
setElapsed(s);
|
||
if (s >= MAX_DURATION_SEC) stopAndSend();
|
||
}, 250);
|
||
return () => clearInterval(t);
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [recording]);
|
||
|
||
// Permissions on mount of visible
|
||
useEffect(() => {
|
||
if (!visible) {
|
||
setRecording(false);
|
||
setElapsed(0);
|
||
return;
|
||
}
|
||
(async () => {
|
||
if (!camPerm?.granted) await requestCam();
|
||
if (!micPerm?.granted) await requestMic();
|
||
})();
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [visible]);
|
||
|
||
const start = async () => {
|
||
if (!camRef.current || recording) return;
|
||
try {
|
||
startedAt.current = Date.now();
|
||
setElapsed(0);
|
||
setRecording(true);
|
||
// recordAsync блокируется до stopRecording или maxDuration
|
||
const result = await camRef.current.recordAsync({ maxDuration: MAX_DURATION_SEC });
|
||
setRecording(false);
|
||
if (!result?.uri) return;
|
||
const seconds = Math.max(1, Math.floor((Date.now() - startedAt.current) / 1000));
|
||
onFinish({
|
||
kind: 'video',
|
||
circle: true,
|
||
uri: result.uri,
|
||
duration: seconds,
|
||
mime: 'video/mp4',
|
||
});
|
||
onClose();
|
||
} catch (e: any) {
|
||
setRecording(false);
|
||
Alert.alert('Recording failed', e?.message ?? 'Unknown error');
|
||
}
|
||
};
|
||
|
||
const stopAndSend = () => {
|
||
if (!recording) return;
|
||
camRef.current?.stopRecording();
|
||
// recordAsync promise выше resolve'нется с uri → onFinish
|
||
};
|
||
|
||
const cancel = () => {
|
||
if (recording) {
|
||
camRef.current?.stopRecording();
|
||
}
|
||
onClose();
|
||
};
|
||
|
||
const permOK = camPerm?.granted && micPerm?.granted;
|
||
|
||
return (
|
||
<Modal visible={visible} transparent animationType="slide" onRequestClose={cancel}>
|
||
<View
|
||
style={{
|
||
flex: 1,
|
||
backgroundColor: '#000000',
|
||
paddingTop: insets.top,
|
||
paddingBottom: Math.max(insets.bottom, 12),
|
||
}}
|
||
>
|
||
{/* Header */}
|
||
<View style={{ flexDirection: 'row', alignItems: 'center', padding: 12 }}>
|
||
<Pressable
|
||
onPress={cancel}
|
||
hitSlop={10}
|
||
style={{
|
||
width: 36, height: 36, borderRadius: 18,
|
||
backgroundColor: 'rgba(255,255,255,0.08)',
|
||
alignItems: 'center', justifyContent: 'center',
|
||
}}
|
||
>
|
||
<Ionicons name="close" size={20} color="#ffffff" />
|
||
</Pressable>
|
||
<Text style={{ color: '#ffffff', fontSize: 16, fontWeight: '700', flex: 1, textAlign: 'center' }}>
|
||
Video message
|
||
</Text>
|
||
<View style={{ width: 36 }} />
|
||
</View>
|
||
|
||
{/* Camera */}
|
||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', padding: 20 }}>
|
||
{permOK ? (
|
||
<View
|
||
style={{
|
||
width: '85%',
|
||
aspectRatio: 1,
|
||
maxWidth: 360, maxHeight: 360,
|
||
borderRadius: 9999,
|
||
overflow: 'hidden',
|
||
backgroundColor: '#0a0a0a',
|
||
borderWidth: recording ? 3 : 0,
|
||
borderColor: '#f4212e',
|
||
}}
|
||
>
|
||
<CameraView
|
||
ref={camRef}
|
||
style={{ flex: 1 }}
|
||
facing={facing}
|
||
mode="video"
|
||
/>
|
||
</View>
|
||
) : (
|
||
<View style={{ alignItems: 'center', paddingHorizontal: 24 }}>
|
||
<Ionicons name="videocam-off-outline" size={42} color="#8b8b8b" />
|
||
<Text style={{ color: '#ffffff', fontSize: 16, fontWeight: '700', marginTop: 12 }}>
|
||
Permissions needed
|
||
</Text>
|
||
<Text style={{ color: '#8b8b8b', fontSize: 13, marginTop: 4, textAlign: 'center' }}>
|
||
Camera + microphone access are required to record a video message.
|
||
</Text>
|
||
</View>
|
||
)}
|
||
|
||
{/* Timer */}
|
||
{recording && (
|
||
<Text
|
||
style={{
|
||
color: '#f4212e',
|
||
fontSize: 14, fontWeight: '700',
|
||
marginTop: 14,
|
||
}}
|
||
>
|
||
● {formatClock(elapsed)} / {formatClock(MAX_DURATION_SEC)}
|
||
</Text>
|
||
)}
|
||
</View>
|
||
|
||
{/* Record / Stop button */}
|
||
<View style={{ alignItems: 'center', paddingBottom: 16 }}>
|
||
<Pressable
|
||
onPress={recording ? stopAndSend : start}
|
||
disabled={!permOK}
|
||
style={({ pressed }) => ({
|
||
width: 72, height: 72, borderRadius: 36,
|
||
backgroundColor: !permOK ? '#1a1a1a' : recording ? '#f4212e' : '#1d9bf0',
|
||
alignItems: 'center', justifyContent: 'center',
|
||
opacity: pressed ? 0.85 : 1,
|
||
borderWidth: 4,
|
||
borderColor: 'rgba(255,255,255,0.2)',
|
||
})}
|
||
>
|
||
<Ionicons
|
||
name={recording ? 'stop' : 'videocam'}
|
||
size={30}
|
||
color="#ffffff"
|
||
/>
|
||
</Pressable>
|
||
<Text style={{ color: '#8b8b8b', fontSize: 12, marginTop: 10 }}>
|
||
{recording ? 'Tap to stop & send' : permOK ? 'Tap to record' : 'Grant permissions'}
|
||
</Text>
|
||
</View>
|
||
</View>
|
||
</Modal>
|
||
);
|
||
}
|