watchMessagesForTarget method

Stream<List<Message>> watchMessagesForTarget(
  1. String targetId
)

Watches all messages matching targetId — reactively.

This is the primary UI-facing query. It:

  1. Immediately emits all historical messages from the database.
  2. Emits updates whenever new messages arrive via sync.

targetId can be:

  • A specific group/role name to watch group messages
  • '*' to watch broadcast messages

Messages are ordered by creation time (newest last).

Implementation

Stream<List<Message>> watchMessagesForTarget(String targetId) {
  return (select(messages)
        ..where((t) => t.targetId.equals(targetId))
        ..orderBy([(t) => OrderingTerm.asc(t.createdAt)]))
      .watch();
}