added folder select dialog, fixed chat loading
This commit is contained in:
@@ -101,22 +101,28 @@ const ChatScreen: React.FC = () => {
|
||||
};
|
||||
|
||||
// Chat-Verlauf aus AsyncStorage laden
|
||||
const isInitialLoad = useRef(true);
|
||||
useEffect(() => {
|
||||
const loadMessages = async () => {
|
||||
try {
|
||||
const stored = await AsyncStorage.getItem(CHAT_STORAGE_KEY);
|
||||
console.log('[Chat] AsyncStorage geladen:', stored ? `${stored.length} Bytes` : 'leer');
|
||||
if (stored) {
|
||||
const parsed: ChatMessage[] = JSON.parse(stored);
|
||||
setMessages(parsed);
|
||||
// ID-Counter auf hoechsten Wert setzen um Kollisionen zu vermeiden
|
||||
const maxId = parsed.reduce((max, msg) => {
|
||||
const num = parseInt(msg.id.split('_').pop() || '0', 10);
|
||||
return num > max ? num : max;
|
||||
}, 0);
|
||||
messageIdCounter.current = maxId;
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
console.log('[Chat] ${parsed.length} Nachrichten geladen');
|
||||
setMessages(parsed);
|
||||
const maxId = parsed.reduce((max, msg) => {
|
||||
const num = parseInt(msg.id.split('_').pop() || '0', 10);
|
||||
return num > max ? num : max;
|
||||
}, 0);
|
||||
messageIdCounter.current = maxId;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Chat] Fehler beim Laden des Verlaufs:', err);
|
||||
} finally {
|
||||
isInitialLoad.current = false;
|
||||
}
|
||||
};
|
||||
loadMessages();
|
||||
@@ -278,7 +284,7 @@ const ChatScreen: React.FC = () => {
|
||||
|
||||
// Chat-Verlauf in AsyncStorage speichern (letzte N Nachrichten)
|
||||
useEffect(() => {
|
||||
if (messages.length === 0) return;
|
||||
if (messages.length === 0 || isInitialLoad.current) return;
|
||||
// Nur file:// URIs speichern, data: URIs rausfiltern (zu gross)
|
||||
const toStore = messages.slice(-MAX_STORED_MESSAGES).map(msg => ({
|
||||
...msg,
|
||||
|
||||
Reference in New Issue
Block a user