watchArchive method

Stream<List<DtoChat>> watchArchive({
  1. int? limit,
})

Returns the Stream of archived DtoChats being in a historical order.

Implementation

Stream<List<DtoChat>> watchArchive({int? limit}) {
  return stream((db) {
    final stmt = db.select(db.chats);

    stmt.where(
      (u) =>
          u.isHidden.equals(false) &
          u.isArchived.equals(true) &
          u.id.like('local__%', escapeChar: '_').not() &
          u.id.like('d__%', escapeChar: '_').not(),
    );
    stmt.orderBy([(u) => OrderingTerm.desc(u.updatedAt)]);

    if (limit != null) {
      stmt.limit(limit);
    }

    return stmt.watch().map((rows) {
      return rows.map(_ChatDb.fromDb).toList();
    });
  });
}