UNPKG

podchat-browser

Version:

Javascript SDK to use POD's Chat Service - Browser Only

49 lines (41 loc) 1.22 kB
class UsersNotSeenDuration { constructor(app) { this._users = {}; } get(id) { return this._users[id]; } set(data) { if(!this._users[data.id]) { this._users[data.id] = new NotSeenDuration(data); } else { this._users[data.id].set(data); } } saveMany(users, timeout) { if(users) { Object.keys(users).forEach(item => { this.set({id: item, notSeenDuration: users[item], timeout}); }); } } } class NotSeenDuration { constructor(data) { this._notSeenDuration = data.notSeenDuration; this._lastUpdateTime = new Date().getTime(); this._timeoutTime = data.timeout; } getDuration() { return this._notSeenDuration; } set(data) { this._notSeenDuration = data.notSeenDuration; this._lastUpdateTime = new Date().getTime(); this._timeoutTime = data.timeout; } isDataValid() { return this._lastUpdateTime && this._notSeenDuration && (this._lastUpdateTime > new Date().getTime() - this._timeoutTime); } } export {UsersNotSeenDuration};