watchMessagesForTarget method
Watches all messages matching targetId — reactively.
This is the primary UI-facing query. It:
- Immediately emits all historical messages from the database.
- 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();
}