reload method
- Post post
Fetches the ChatItem of the provided post
to update its Attachments.
Should be invoked in case some of those Attachments are expired.
Implementation
Future<void> reload(Post post) async {
Log.debug('reload($post)', '$runtimeType');
final ChatItem? item = post.item;
if (item != null) {
final RxChat? chat = await _chatService?.get(item.chatId);
final Paginated<ChatItemId, Rx<ChatItem>>? single = await chat?.single(
item.id,
);
await single?.around();
final Rx<ChatItem>? node = single?.values.firstOrNull;
if (chat != null && single != null && node != null) {
await chat.updateAttachments(node.value);
final ChatItem message = node.value;
if (message is ChatMessage) {
post.items.value = message.attachments
.map((e) => PostItem(e))
.toList();
} else if (message is ChatForward) {
final quote = message.quote;
if (quote is ChatMessageQuote) {
post.items.value = quote.attachments
.map((e) => PostItem(e))
.toList();
}
}
}
}
}