diff --git a/android/src/screens/ChatScreen.tsx b/android/src/screens/ChatScreen.tsx index c5a1ff0..b1cb1e2 100644 --- a/android/src/screens/ChatScreen.tsx +++ b/android/src/screens/ChatScreen.tsx @@ -1375,17 +1375,30 @@ const ChatScreen: React.FC = () => { { + onPress={async () => { if (!a.path) return; if (a.localUri) { - if (isImage) setFullscreenImage(a.localUri); - else openFileWithIntent(a.localUri.replace(/^file:\/\//, ''), a.mime || ''); - } else { - // Datei via Bridge nachladen — file_response hat den - // memorySaved-Match-Path und cached + zeigt direkt - autoOpenPaths.current.add(a.path); - rvs.send('file_request' as any, { serverPath: a.path, requestId: `memAtt_${item.id}_${idx}` }); + const localPath = a.localUri.replace(/^file:\/\//, ''); + const exists = await RNFS.exists(localPath).catch(() => false); + if (exists) { + if (isImage) setFullscreenImage(a.localUri); + else openFileWithIntent(localPath, a.mime || ''); + return; + } + // Cache weg → localUri leeren + neu laden + setMessages(prev => prev.map(mm => mm.id === item.id && mm.memorySaved + ? { ...mm, memorySaved: { ...mm.memorySaved, + attachments: mm.memorySaved.attachments?.map(x => + x.path === a.path ? { ...x, localUri: undefined } : x) } } + : mm)); + if (Platform.OS === 'android') { + ToastAndroid.show('Cache leer — lade nach...', ToastAndroid.SHORT); + } } + // Datei via Bridge nachladen — file_response hat den + // memorySaved-Match-Path und cached + zeigt direkt + autoOpenPaths.current.add(a.path); + rvs.send('file_request' as any, { serverPath: a.path, requestId: `memAtt_${item.id}_${idx}` }); }} > {icon} @@ -1489,17 +1502,32 @@ const ChatScreen: React.FC = () => { ) : ( { - // Lokal vorhanden \u2192 direkt mit System-Intent oeffnen + onPress={async () => { + // Lokal vorhanden? Cache koennte geleert worden sein \u2014 + // Datei-Existenz pruefen bevor wir den Intent feuern. if (att.uri) { - openFileWithIntent(att.uri.replace(/^file:\/\//, ''), att.mimeType || ''); - return; + const localPath = att.uri.replace(/^file:\/\//, ''); + const exists = await RNFS.exists(localPath).catch(() => false); + if (exists) { + openFileWithIntent(localPath, att.mimeType || ''); + return; + } + // Cache weg \u2192 uri im State leeren damit UI "tippen zum Laden" zeigt + setMessages(prev => prev.map(m => m.id === item.id + ? { ...m, attachments: m.attachments?.map(a => + a.serverPath === att.serverPath ? { ...a, uri: undefined } : a) } + : m)); + if (Platform.OS === 'android') { + ToastAndroid.show('Cache leer \u2014 lade nach...', ToastAndroid.SHORT); + } } - // Sonst: file_request \u2192 bei file_response wird die Datei - // gespeichert UND geoeffnet (autoOpenPaths-Tracking). + // Re-Download via file_request \u2192 bei file_response wird die + // Datei gespeichert UND geoeffnet (autoOpenPaths-Tracking). if (att.serverPath) { autoOpenPaths.current.add(att.serverPath); rvs.send('file_request' as any, { serverPath: att.serverPath, requestId: item.id }); + } else if (Platform.OS === 'android') { + ToastAndroid.show('Datei kann nicht nachgeladen werden (kein serverPath)', ToastAndroid.LONG); } }} >