fix(llc): fixed expired cdn attachment links

This commit is contained in:
Salvatore Giordano
2021-09-29 15:11:10 +02:00
parent 2ce209bed0
commit 0233c243f1
2 changed files with 10 additions and 5 deletions
+1
View File
@@ -3,6 +3,7 @@
🐞 Fixed
- [[#710]](https://github.com/GetStream/stream-chat-flutter/issues/710) Fixed JWT requiring using `String` as id.
- Fixed expired CDN attachment links not updating correctly.
## 3.0.0
@@ -1521,7 +1521,7 @@ class ChannelClientState {
}
}
void _checkExpiredAttachmentMessages(ChannelState channelState) {
void _checkExpiredAttachmentMessages(ChannelState channelState) async {
final expiredAttachmentMessagesId = channelState.messages
.where((m) =>
!_updatedMessagesIds.contains(m.id) &&
@@ -1532,20 +1532,24 @@ class ChannelClientState {
return false;
}
final uri = Uri.parse(url);
if (uri.host != 'stream-io-cdn.com' ||
if (!uri.host.endsWith('stream-io-cdn.com') ||
uri.queryParameters['Expires'] == null) {
return false;
}
final expiration =
DateTime.parse(uri.queryParameters['Expires']!);
final secondsFromEpoch =
int.parse(uri.queryParameters['Expires']!);
final expiration = DateTime.fromMillisecondsSinceEpoch(
secondsFromEpoch * 1000);
return expiration.isBefore(DateTime.now());
}) ==
true)
.map((e) => e.id)
.toList();
if (expiredAttachmentMessagesId.isNotEmpty == true) {
_channel.getMessagesById(expiredAttachmentMessagesId);
await _channel._initializedCompleter.future;
_updatedMessagesIds.addAll(expiredAttachmentMessagesId);
_channel.getMessagesById(expiredAttachmentMessagesId);
}
}