Added support for force refresh without caching, using this system on chatList.dart
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChat.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/chat/getChatParams.dart';
|
||||
@ -14,10 +15,13 @@ class GetChatCache extends RequestCache<GetChatResponse> {
|
||||
|
||||
@override
|
||||
Future<GetChatResponse> onLoad() {
|
||||
log("LOAD");
|
||||
return GetChat(
|
||||
chatToken,
|
||||
GetChatParams(
|
||||
lookIntoFuture: GetChatParamsSwitch.off
|
||||
lookIntoFuture: GetChatParamsSwitch.off,
|
||||
setReadMarker: GetChatParamsSwitch.on,
|
||||
limit: 200,
|
||||
)
|
||||
).run();
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
||||
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomResponse.dart';
|
||||
@ -8,7 +7,7 @@ import 'package:marianum_mobile/api/requestCache.dart';
|
||||
import 'getRoom.dart';
|
||||
|
||||
class GetRoomCache extends RequestCache<GetRoomResponse> {
|
||||
GetRoomCache({onUpdate}) : super(RequestCache.cacheMinute, onUpdate) {
|
||||
GetRoomCache({onUpdate, renew}) : super(RequestCache.cacheMinute, onUpdate, renew: renew) {
|
||||
start("MarianumMobile", "nc-rooms");
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,9 @@ abstract class RequestCache<T> {
|
||||
|
||||
int maxCacheTime;
|
||||
Function(T) onUpdate;
|
||||
bool? renew;
|
||||
|
||||
RequestCache(this.maxCacheTime, this.onUpdate);
|
||||
RequestCache(this.maxCacheTime, this.onUpdate, {this.renew = false});
|
||||
|
||||
void start(String file, String document) async {
|
||||
Map<String, dynamic>? tableData = await Localstore.instance.collection(file).doc(document).get();
|
||||
@ -20,7 +21,7 @@ abstract class RequestCache<T> {
|
||||
}
|
||||
|
||||
if(DateTime.now().millisecondsSinceEpoch - (maxCacheTime * 1000) < (tableData?['lastupdate'] ?? 0)) {
|
||||
return;
|
||||
if(renew == null || !renew!) return;
|
||||
}
|
||||
|
||||
T newValue = await onLoad();
|
||||
|
Reference in New Issue
Block a user