add headers to options

This commit is contained in:
Peter Maquiran
2021-08-24 14:07:27 +01:00
parent 567209ed4b
commit 019b85d209
16 changed files with 184 additions and 32 deletions
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { localstoreService } from './localstore.service'
import { localstoreService } from '../localstore.service'
import { SHA1 } from 'crypto-js'
@Injectable({
@@ -13,7 +13,7 @@ export class ChatMessageService {
constructor() {
this.keyName = (SHA1(this.constructor.name)).toString()
this.keyName = ('chat'+SHA1(this.constructor.name)).toString()
setTimeout(()=> {
let restore = localstoreService.get(this.keyName, {})
@@ -22,18 +22,22 @@ export class ChatMessageService {
}
get message() {
return this._message
}
getMessages(roomId) {
return this._message[roomId] || []
}
add(roomId, message) {
add(roomId:string, message: any[]) {
this._message[roomId] = message
setTimeout(()=> {
localstoreService.set(this.keyName, {
message: this._message
})
}, 5000)
}, 10)
}
}
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ChatUserService } from './chat-user.service';
describe('ChatUserService', () => {
let service: ChatUserService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ChatUserService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+46
View File
@@ -0,0 +1,46 @@
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()