markMessagesAsRead function
Mark all messages in a teammate's inbox as read.
Implementation
Future<void> markMessagesAsRead(String agentName, {String? teamName}) async {
final inboxPath = getInboxPath(agentName, teamName: teamName);
final lockFilePath = '$inboxPath.lock';
final lock = File(lockFilePath);
try {
await _acquireLock(lock);
final messages = await readMailbox(agentName, teamName: teamName);
if (messages.isEmpty) return;
final updated = messages.map((m) => m.copyWith(read: true)).toList();
final encoder = const JsonEncoder.withIndent(' ');
await File(
inboxPath,
).writeAsString(encoder.convert(updated.map((m) => m.toJson()).toList()));
} on PathNotFoundException {
return;
} catch (_) {
// Silently fail.
} finally {
await _releaseLock(lock);
}
}