updateAttachments method
- ChatItem item
override
Updates the Attachments of the specified item
to be up-to-date.
Intended to be used to update the StorageFile.relativeRef links.
Implementation
@override
Future<void> updateAttachments(ChatItem item) async {
Log.debug('updateAttachments($item)', '$runtimeType($id)');
if (item.id.isLocal) {
return;
}
Mutex? mutex = _attachmentGuards[item.id];
if (mutex == null) {
mutex = Mutex();
_attachmentGuards[item.id] = mutex;
}
final bool isLocked = mutex.isLocked;
await mutex.protect(() async {
if (isLocked) {
// Mutex has been already locked when tried to obtain it, thus the
// [Attachment]s of the [item] were already updated, so no action is
// required.
return;
}
await _updateAttachments(item);
_attachmentGuards.remove(item.id);
});
}