Files
doneit-web/src/app/store/chat/chat-user.service.ts
T

48 lines
897 B
TypeScript
Raw Normal View History

2021-08-24 14:07:27 +01:00
import { Injectable } from '@angular/core';
2021-08-25 11:51:02 +01:00
import { localstoreService } from '../localstore.service';
import { SHA1 } from 'crypto-js';
2021-08-24 14:07:27 +01:00
@Injectable({
providedIn: 'root'
})
export class ChatUserService {
// main data
2021-08-25 09:38:13 +01:00
private _userList = {}
2021-08-24 14:07:27 +01:00
// local storage keyName
private keyName: string;
constructor() {
2021-08-25 13:04:15 +01:00
this.keyName = (SHA1('chat'+this.constructor.name)).toString()
2021-08-24 14:07:27 +01:00
2021-08-25 11:51:02 +01:00
setTimeout(()=> {
2021-08-25 09:38:13 +01:00
let restore = localstoreService.get(this.keyName, {})
this._userList = restore.userList || {}
2021-08-24 14:07:27 +01:00
}, 10)
}
get userList() {
return this._userList
}
2021-08-25 09:38:13 +01:00
add(roomId:string, userList: any[] = []) {
this._userList[roomId] = userList
2021-08-24 14:07:27 +01:00
this.save()
}
private save() {
setTimeout(()=> {
localstoreService.set(this.keyName, {
userList: this._userList
})
}, 10)
}
}
export const ChatUserStorage = new ChatUserService()