mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Improve
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatMessageService } from './chat-message.service';
|
||||
|
||||
describe('ChatMessageService', () => {
|
||||
let service: ChatMessageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChatMessageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { localstoreService } from './localstore.service'
|
||||
import { SHA1 } from 'crypto-js'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatMessageService {
|
||||
|
||||
private _message = []
|
||||
// local storage keyName
|
||||
private keyName: string;
|
||||
|
||||
constructor() {
|
||||
|
||||
this.keyName = (SHA1(this.constructor.name)).toString()
|
||||
|
||||
setTimeout(()=> {
|
||||
let restore = localstoreService.get(this.keyName, {})
|
||||
this._message = restore.message || {}
|
||||
}, 10)
|
||||
|
||||
}
|
||||
|
||||
getMessages(roomId) {
|
||||
return this._message[roomId] || []
|
||||
}
|
||||
|
||||
add(roomId, message) {
|
||||
this._message[roomId] = message
|
||||
|
||||
setTimeout(()=> {
|
||||
localstoreService.set(this.keyName, {
|
||||
message: this._message
|
||||
})
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export const ChatMessageStore = new ChatMessageService()
|
||||
Reference in New Issue
Block a user