podchat-browser
Version:
Javascript SDK to use POD's Chat Service - Browser Only
58 lines (49 loc) • 1.76 kB
JavaScript
import {HistoryListManager} from "./historyList";
import {RequestParamsManager} from "./requestParams";
function HistoryCache() {
const config = {
historyList: new HistoryListManager()
}
function canSave(threadId, params) {
let history = config.historyList.get(threadId);
return history.params.canCacheTheRequest(params)
}
function canGetFromCache(threadId, params,lastMessageItem) {
let his = config.historyList.get(threadId);
if (his && publicized.isParamsValid(params)) {
return his?.cacheHasEnoughData(params,lastMessageItem)
}
return false;
}
let publicized= {
isParamsValid(params) {
const paramsValidator= new RequestParamsManager(params)
return paramsValidator.canCacheTheRequest(params);
},
saveList(threadId, params, list,hasNext=true) {
config.historyList.save(threadId, params, list,hasNext);
},
saveMessage: config.historyList.saveMessage,
canGetFromCache,
canSave,
hasNext(threadId) {
return config.historyList.hasNext(threadId);
},
updateSeen(threadId,lastSeenMessageTime) {
return config.historyList.updateSeen(threadId,lastSeenMessageTime);
},
get(threadId) {
return config.historyList.get(threadId);
},
remove(threadId) {
config.historyList.remove(threadId);
},
removeMessage: config.historyList.removeMessage,
reset() {
config.historyList.reset()
}
}
return publicized;
}
const historyCache = new HistoryCache();
export {historyCache}