readMailbox function

Future<List<TeammateMessage>> readMailbox(
  1. String agentName, {
  2. String? teamName,
})

Read all messages from a teammate's inbox.

Implementation

Future<List<TeammateMessage>> readMailbox(
  String agentName, {
  String? teamName,
}) async {
  final inboxPath = getInboxPath(agentName, teamName: teamName);
  try {
    final content = await File(inboxPath).readAsString();
    final List<dynamic> decoded = jsonDecode(content) as List<dynamic>;
    return decoded
        .map((e) => TeammateMessage.fromJson(e as Map<String, dynamic>))
        .toList();
  } on PathNotFoundException {
    return [];
  } catch (e) {
    // Log but don't crash.
    return [];
  }
}