mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
set bold
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { BoldService } from './bold.service';
|
||||
|
||||
describe('BoldService', () => {
|
||||
let service: BoldService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(BoldService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { IMessageSocketRepository } from 'src/app/core/chat/repository/message/message-socket-repository';
|
||||
import { InstanceId } from '../chat-service.service';
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { IBoldLocalRepository } from 'src/app/core/chat/repository/bold/bold-local-repository';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BoldService {
|
||||
|
||||
constructor(
|
||||
private MessageSocketRepositoryService: IMessageSocketRepository,
|
||||
private boldLocalRepository: IBoldLocalRepository
|
||||
) {
|
||||
this.listenToIncomingMessage();
|
||||
}
|
||||
|
||||
listenToIncomingMessage() {
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
|
||||
const result = await this.boldLocalRepository.findOne({roomId: message.roomId})
|
||||
|
||||
if(result.isOk() && !result.value) {
|
||||
const result = await this.boldLocalRepository.insert({roomId: message.roomId, bold: 1})
|
||||
} else if(result.isOk() && result.value.bold == 0) {
|
||||
const result = await this.boldLocalRepository.update(message.roomId, {bold: 1})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DistributionService } from './distribution.service';
|
||||
|
||||
describe('DistributionService', () => {
|
||||
let service: DistributionService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(DistributionService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { IMessageGetAllByRoomIdOutPut } from 'src/app/core/chat/usecase/message/message-get-all-by-room-Id';
|
||||
import { HttpAdapter } from 'src/app/infra/http/adapter';
|
||||
import { IDistributionLocalRepository } from 'src/app/core/chat/repository/distribution/distribution-local-repository'
|
||||
import { z } from 'zod';
|
||||
import { distributionListDetermineChanges } from '../../data/async/list/rooms/distributionListChangedetector';
|
||||
import { DistributionEntity } from 'src/app/core/chat/entity/distribution';
|
||||
|
||||
export const DistributionOutPutDTOSchema = z.object({
|
||||
$messageIdMemberId: z.string(),
|
||||
memberId: z.number(),
|
||||
readAt: z.string().nullable(),
|
||||
deliverAt: z.string().nullable()
|
||||
})
|
||||
export type DistributionOutPutDTO = z.infer<typeof DistributionOutPutDTOSchema>
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DistributionService {
|
||||
|
||||
constructor(
|
||||
private http: HttpAdapter,
|
||||
private distributionLocalRepository: IDistributionLocalRepository
|
||||
) {
|
||||
// this.listenToLoadHistory()
|
||||
}
|
||||
|
||||
listenToLoadHistory() {
|
||||
return this.http.listen().pipe(
|
||||
filter((response)=> {
|
||||
if(response?.isOk()) {
|
||||
return response.value.url.endsWith('Messages')
|
||||
}
|
||||
|
||||
return false
|
||||
}),
|
||||
map((response: any) => response.value.data as IMessageGetAllByRoomIdOutPut)
|
||||
)
|
||||
.subscribe(async (data) => {
|
||||
|
||||
const localList = await this.distributionLocalRepository.find({roomId: data.data[0].roomId})
|
||||
|
||||
data.data.map(async (message) => {
|
||||
const serverList = message.info
|
||||
|
||||
if(localList.isOk() && localList.value) {
|
||||
|
||||
// const localListForCurrentMessage = localList.value.filter((e) => e.messageId == message.id)
|
||||
|
||||
// console.log('localListForCurrentMessage', localListForCurrentMessage)
|
||||
|
||||
// const { distributionToInsert, distributionToUpdate, distributionToDelete } = await distributionListDetermineChanges(serverList, localListForCurrentMessage, message.id)
|
||||
// console.log({distributionToInsert, distributionToUpdate, distributionToDelete})
|
||||
|
||||
// const map = distributionToInsert.map((e) => {
|
||||
// e.
|
||||
// })
|
||||
|
||||
// this.distributionLocalRepository.insertMany(distributionToInsert)
|
||||
|
||||
// const distributionEntityToInsert = distributionToInsert.map((ee)=> {
|
||||
// return new DistributionEntity({
|
||||
// roomId: message.roomId,
|
||||
// deliverAt: ee.deliverAt,
|
||||
// memberId: ee.memberId,
|
||||
// messageId: message.roomId,
|
||||
// readAt: ee.readAt,
|
||||
// })
|
||||
|
||||
// console.log('create')
|
||||
// })
|
||||
|
||||
// if(distributionEntityToInsert.length >= 0) {
|
||||
// // console.log('distributionEntityToInsert', distributionEntityToInsert)
|
||||
// //this.distributionLocalRepository.insertMany(distributionEntityToInsert)
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user