isAttachmentInLocalStore method

Future<bool> isAttachmentInLocalStore({
  1. bool getThumbnail = false,
})

Returns if an attachment is in the local store

Implementation

Future<bool> isAttachmentInLocalStore({bool getThumbnail = false}) async {
  if (![EventTypes.Message, EventTypes.Sticker].contains(type)) {
    throw ("This event has the type '$type' and so it can't contain an attachment.");
  }
  final mxcUrl = attachmentOrThumbnailMxcUrl(getThumbnail: getThumbnail);
  if (mxcUrl == null) {
    throw "This event hasn't any attachment or thumbnail.";
  }
  getThumbnail = mxcUrl != attachmentMxcUrl;
  // Is this file storeable?
  final thisInfoMap = getThumbnail ? thumbnailInfoMap : infoMap;
  final database = room.client.database;
  if (database == null) {
    return false;
  }

  final storeable = thisInfoMap['size'] is int &&
      thisInfoMap['size'] <= database.maxFileSize;

  Uint8List? uint8list;
  if (storeable) {
    uint8list = await database.getFile(mxcUrl);
  }
  return uint8list != null;
}