unreadThreads method

List<JsonMap> unreadThreads(
  1. String principalId
)

The API UnreadThreads of principalId: every visible thread with unread messages, with the counts after its read state (04 14).

Implementation

List<JsonMap> unreadThreads(String principalId) => [
  for (final t in threads.values)
    if (seesThread(principalId, t['id']! as String))
      ...() {
        final id = t['id']! as String;
        final lastRead =
            (readStates['$principalId|$id']?['last_read_seq'] as int?) ?? 0;
        final unread = _unread(principalId, id, lastRead);
        return [
          if (unread.isNotEmpty)
            {
              'thread_id': id,
              'channel_id': t['channel_id'],
              'unread_count': unread.length,
              'mention_count': _mentions(principalId, unread),
              'last_message_seq': t['last_message_seq'],
              'last_read_seq': lastRead,
            },
        ];
      }(),
];