improve chat

This commit is contained in:
Peter Maquiran
2024-08-17 22:05:57 +01:00
parent eb615d4335
commit 650c772084
43 changed files with 712 additions and 1540 deletions
@@ -1,16 +0,0 @@
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();
});
});
@@ -1,46 +0,0 @@
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('chat'+"ChatMessageService")).toString()
setTimeout(()=> {
let restore = localstoreService.get(this.keyName, {})
this._message = restore.message || {}
}, 10)
}
get message() {
return this._message
}
getMessages(roomId) {
return this._message[roomId] || []
}
add(roomId:string, message: any[]) {
this._message[roomId] = message
setTimeout(()=> {
localstoreService.set(this.keyName, {
message: this._message
})
}, 10)
}
}
export const ChatMessageStore = new ChatMessageService()
@@ -1,16 +0,0 @@
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();
});
});
-47
View File
@@ -1,47 +0,0 @@
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'+"ToDayEventStorageService")).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()