mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
47 lines
857 B
TypeScript
47 lines
857 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 = ('chat'+SHA1(this.constructor.name)).toString()
|
||
|
|
|
||
|
|
setTimeout(()=>{
|
||
|
|
let restore = localstoreService.get(this.keyName, [])
|
||
|
|
this._userList = restore.userList
|
||
|
|
}, 10)
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
get userList() {
|
||
|
|
return this._userList
|
||
|
|
}
|
||
|
|
|
||
|
|
reset(userList: any[]) {
|
||
|
|
this._userList = userList
|
||
|
|
|
||
|
|
this.save()
|
||
|
|
}
|
||
|
|
|
||
|
|
private save() {
|
||
|
|
setTimeout(()=> {
|
||
|
|
localstoreService.set(this.keyName, {
|
||
|
|
userList: this._userList
|
||
|
|
})
|
||
|
|
}, 10)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
export const ChatUserStorage = new ChatUserService()
|