import { useRef, useEffect, useState, useCallback } from 'react'; import { avatar } from '../constants/Icons' import { Pressable, View, Image } from 'react-native'; import {Icon, Text, IconButton, Surface, Divider} from 'react-native-paper'; import { Topic, Card, Profile } from 'databag-client-sdk'; import { ImageAsset } from './imageAsset/ImageAsset'; import { AudioAsset } from './audioAsset/AudioAsset'; import { VideoAsset } from './videoAsset/VideoAsset'; import { BinaryAsset } from './binaryAsset/BinaryAsset'; import { useMessage } from './useMessage.hook'; import {styles} from './Message.styled'; export function Message({ topic, card, profile, host, select, selected }: { topic: Topic, card: Card | null, profile: Profile | null, host: boolean, select: (id: string)=>void, selected: string }) { const { state, actions } = useMessage(); const { locked, data, created, topicId, status, transform } = topic; const { name, handle, node } = profile || card || { name: null, handle: null, node: null } const { text, textColor, textSize, assets } = data || { text: null, textColor: null, textSize: null } const textStyle = textColor && textSize ? { fontSize: textSize, color: textColor } : textColor ? { color: textColor } : textSize ? { fontSize: textSize } : {} const logoUrl = profile ? profile.imageUrl : card ? card.imageUrl : avatar; const timestamp = actions.getTimestamp(created); const [message, setMessage] = useState(''); const [editing, setEditing] = useState(false); const [editText, setEditText] = useState(''); const [saving, setSaving] = useState(false); return ( select(topicId)}> { name && ( { name } )} { !name && handle && ( { `${handle}${node ? '/' + node : ''}` } )} { !name && !handle && ( { state.strings.unknownContact } )} { timestamp } {! locked && status === 'confirmed' && editing && ( )} { !locked && status === 'confirmed' && text && !editing && ( { text } )} { !locked && status !== 'confirmed' && ( )} { locked && ( { state.strings.encrypted } )} { topicId === selected && ( {}} /> {}} /> {}} /> {}} /> {}} /> )} ); }