KI-AGENT: Ungelesene Chat Badges in Mobile App anzeigen

This commit is contained in:
2026-05-22 18:51:33 +02:00
parent 00da371dfb
commit f150cfd740
3 changed files with 69 additions and 5 deletions

View File

@@ -185,6 +185,12 @@ export default function CommunicationScreen() {
return users.filter((user) => !existing.has(user.matrixUserId));
}, [members, users]);
const clearRoomUnread = useCallback((roomKey: string) => {
setRooms((current) =>
current.map((room) => (room.key === roomKey ? { ...room, unread: 0, mentions: 0 } : room))
);
}, []);
const loadRooms = useCallback(async () => {
if (!token) return;
const [nextStatus, identity, nextRooms, nextUsers] = await Promise.all([
@@ -221,7 +227,10 @@ export default function CommunicationScreen() {
setMembers(sync.members || nextMembers);
setSyncSince(sync.nextBatch);
const last = merged.at(-1);
if (last?.id) await markMatrixRoomRead(token, roomKeyToLoad, last.id);
if (last?.id) {
await markMatrixRoomRead(token, roomKeyToLoad, last.id);
clearRoomUnread(roomKeyToLoad);
}
requestAnimationFrame(() => messageListRef.current?.scrollToEnd({ animated: true }));
} catch (err) {
setError(err instanceof Error ? err.message : 'Kommunikation konnte nicht geladen werden.');
@@ -230,7 +239,7 @@ export default function CommunicationScreen() {
setRefreshing(false);
}
},
[token]
[clearRoomUnread, token]
);
const refreshAll = useCallback(
@@ -255,19 +264,25 @@ export default function CommunicationScreen() {
if (!token || !activeRoom?.exists || !syncSince) return;
try {
const sync = await syncMatrixRoom(token, activeRoom.key, syncSince);
const incomingMessages = sync.messages || [];
setSyncSince(sync.nextBatch || syncSince);
setMembers((current) => sync.members || current);
setMessages((current) => {
let next = mergeMessages(current, sync.messages || []);
let next = mergeMessages(current, incomingMessages);
next = applyReplacements(next, sync.replacements);
next = applyReactions(next, sync.reactions);
next = applyRedactions(next, sync.redactions);
return next;
});
const last = incomingMessages.at(-1);
if (last?.id) {
await markMatrixRoomRead(token, activeRoom.key, last.id);
clearRoomUnread(activeRoom.key);
}
} catch {
// Polling errors are surfaced by manual refresh to avoid noisy chat usage.
}
}, [activeRoom, syncSince, token]);
}, [activeRoom, clearRoomUnread, syncSince, token]);
useEffect(() => {
void refreshAll(true);