Files
dchain/client-app/components/chat/PostRefCard.tsx
vsecoder 0bb5780a5d feat(feed/chat): VK-style share post to chats + list breathing room
Feed list padding
  FlatList had no inner padding so the first post bumped against the
  tab strip and the last post against the NavBar. Added paddingTop: 8
  / paddingBottom: 24 on contentContainerStyle in both /feed and
  /feed/tag/[tag] — first card now has a clear top gap, last card
  doesn't get hidden behind the FAB or NavBar.

Share-to-chat flow
  Replaces the placeholder share button (which showed an Alert with
  the post URL) with a real "forward to chats" flow modeled on VK's
  shared-wall-post embed.

  New modules
    lib/forwardPost.ts       — encodePostRef / tryParsePostRef +
                               forwardPostToContacts(). Serialises a
                               feed post into a tiny JSON payload that
                               rides the same encrypted envelope as any
                               chat message; decode side distinguishes
                               "post_ref" payloads from regular text by
                               trying JSON.parse on decrypted text.
                               Mirrors the sent message into the sender's
                               local history so they see "you shared
                               this" in the chat they forwarded to.

    components/feed/ShareSheet.tsx
                             — bottom-sheet picker. Multi-select
                               contacts via tick-box, search by
                               username / alias / address prefix.
                               "Send (N)" dispatches N parallel
                               encrypted envelopes. Contacts with no
                               X25519 key are filtered out (can't
                               encrypt for them).

    components/chat/PostRefCard.tsx
                             — compact embedded-post card for chat
                               bubbles. Ribbon "ПОСТ" label +
                               author + 3-line excerpt + "с фото"
                               indicator. Tap → /(app)/feed/{id} full
                               post detail. Palette switches between
                               blue-bubble-friendly and peer-bubble-
                               friendly depending on bubble side.

  Message pipeline
    lib/types.ts           — Message.postRef optional field added.
                             text stays "" when the message is a
                             post-ref (nothing to render as plain text).
    hooks/useMessages.ts   + hooks/useGlobalInbox.ts
                           — post decryption of every inbound envelope
                             runs through tryParsePostRef; matching
                             messages get the postRef attached instead
                             of the raw JSON in .text.
    components/chat/MessageBubble.tsx
                           — renders PostRefCard inside the bubble when
                             msg.postRef is set. Other bubble features
                             (reply quote, attachment preview, text)
                             still work around it.

  PostCard
    - share icon now opens <ShareSheet>; the full-URL placeholder is
      gone. ShareSheet is embedded at the PostCard level so each card
      owns its own sheet state (avoids modal-stacking issues).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 21:26:43 +03:00

144 lines
4.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* PostRefCard — renders a shared feed post inside a chat bubble.
*
* Visually distinct from plain messages so the user sees at-a-glance
* that this came from the feed, not a direct-typed text. Matches
* VK's "shared wall post" embed pattern:
*
* [newspaper icon] ПОСТ
* @author · 2 строки excerpt'а
* [📷 Фото in this post]
*
* Tap → /(app)/feed/{postID}. The full post (with image + stats +
* like button) is displayed in the standard post-detail screen.
*/
import React from 'react';
import { View, Text, Pressable } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { router } from 'expo-router';
import { useStore } from '@/lib/store';
import { Avatar } from '@/components/Avatar';
export interface PostRefCardProps {
postID: string;
author: string;
excerpt: string;
hasImage?: boolean;
/** True when the card appears inside the sender's own bubble (our own
* share). Adjusts colour contrast so it reads on the blue bubble
* background. */
own: boolean;
}
function shortAddr(a: string, n = 6): string {
if (!a) return '—';
return a.length <= n * 2 + 1 ? a : `${a.slice(0, n)}${a.slice(-n)}`;
}
export function PostRefCard({ postID, author, excerpt, hasImage, own }: PostRefCardProps) {
const contacts = useStore(s => s.contacts);
// Resolve author name the same way the feed does.
const contact = contacts.find(c => c.address === author);
const displayName = contact?.username
? `@${contact.username}`
: contact?.alias ?? shortAddr(author);
const onOpen = () => {
router.push(`/(app)/feed/${postID}` as never);
};
// Tinted palette based on bubble side — inside an "own" (blue) bubble
// the card uses a deeper blue so it reads as a distinct nested block,
// otherwise we use the standard card colours.
const bg = own ? 'rgba(0, 0, 0, 0.22)' : '#0a0a0a';
const border = own ? 'rgba(255, 255, 255, 0.15)' : '#1f1f1f';
const labelColor = own ? 'rgba(255, 255, 255, 0.75)' : '#1d9bf0';
const bodyColor = own ? '#ffffff' : '#ffffff';
const subColor = own ? 'rgba(255, 255, 255, 0.65)' : '#8b8b8b';
return (
<Pressable
onPress={onOpen}
style={({ pressed }) => ({
marginBottom: 6,
borderRadius: 14,
backgroundColor: pressed ? 'rgba(0,0,0,0.35)' : bg,
borderWidth: 1,
borderColor: border,
overflow: 'hidden',
})}
>
{/* Top ribbon: "ПОСТ" label — makes the shared nature unmistakable. */}
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 6,
paddingHorizontal: 10,
paddingTop: 8,
paddingBottom: 4,
}}
>
<Ionicons name="newspaper-outline" size={11} color={labelColor} />
<Text
style={{
color: labelColor,
fontSize: 10,
fontWeight: '700',
letterSpacing: 1.2,
}}
>
ПОСТ
</Text>
</View>
{/* Author + excerpt */}
<View style={{ flexDirection: 'row', paddingHorizontal: 10, paddingBottom: 10 }}>
<Avatar name={displayName} address={author} size={28} />
<View style={{ flex: 1, marginLeft: 8, minWidth: 0, overflow: 'hidden' }}>
<Text
numberOfLines={1}
style={{
color: bodyColor,
fontWeight: '700',
fontSize: 13,
}}
>
{displayName}
</Text>
{excerpt.length > 0 && (
<Text
numberOfLines={3}
style={{
color: subColor,
fontSize: 12,
lineHeight: 16,
marginTop: 2,
}}
>
{excerpt}
</Text>
)}
{hasImage && (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
gap: 4,
marginTop: 6,
}}
>
<Ionicons name="image-outline" size={11} color={subColor} />
<Text style={{ color: subColor, fontSize: 11 }}>
с фото
</Text>
</View>
)}
</View>
</View>
</Pressable>
);
}