Files
doneit-web/src/app/store/chat/chat-user.service.ts
T
Peter Maquiran 75a714a03a Improve
2021-08-25 13:04:15 +01:00

48 lines
897 B
TypeScript

import { Injectable } from '@angular/core';
import { localstoreService } from '../localstore.service';
import { SHA1 } from 'crypto-js';
@Injectable({
providedIn: 'root'
})
export class ChatUserService {
// main data
private _userList = {}
// local storage keyName
private keyName: string;
constructor() {
this.keyName = (SHA1('chat'+this.constructor.name)).toString()
setTimeout(()=> {
let restore = localstoreService.get(this.keyName, {})
this._userList = restore.userList || {}
}, 10)
}
get userList() {
return this._userList
}
add(roomId:string, userList: any[] = []) {
this._userList[roomId] = userList
this.save()
}
private save() {
setTimeout(()=> {
localstoreService.set(this.keyName, {
userList: this._userList
})
}, 10)
}
}
export const ChatUserStorage = new ChatUserService()