remove method

  1. @override
Future<void> remove(
  1. ChatItemId itemId
)
override

Removes a ChatItem identified by its id.

Implementation

@override
Future<void> remove(ChatItemId itemId) async {
  Log.debug('remove($itemId)', '$runtimeType($id)');

  _pagination?.remove(itemId);
  for (var e in fragments) {
    e.pagination?.remove(itemId);
  }

  if (dto.value.lastItem?.id == itemId) {
    var lastItem = messages.lastWhereOrNull((e) => e.value.id != itemId);

    if (lastItem != null) {
      dto.value.lastItem = lastItem.value;
      dto.lastItemCursor =
          (await _driftItems.read(lastItem.value.id))?.cursor;
    } else {
      dto.value.lastItem = null;
      dto.lastItemCursor = null;
    }

    await _driftChat.upsert(dto);
  }
}