mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix message
This commit is contained in:
@@ -24,7 +24,6 @@ export class BoldRemoveByRoomIdService {
|
||||
const validation = zodSafeValidation<any>(BoldRemoveByRoomIdInputSchema, input)
|
||||
|
||||
if(validation.isOk()) {
|
||||
console.log('remove buld============================')
|
||||
return await this.boldLocalRepository.delete(input.roomId)
|
||||
} else {
|
||||
tracing.hasError("invalid parameter")
|
||||
|
||||
@@ -8,6 +8,8 @@ import { InstanceId } from '../../chat-service.service';
|
||||
import { IMessageGetAllByRoomIdOutPut } from 'src/app/core/chat/usecase/message/message-get-all-by-room-Id';
|
||||
import { HttpAdapter } from 'src/app/infra/http/adapter';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { IRoomLocalRepository } from 'src/app/core/chat/repository/room/room-local-repository';
|
||||
|
||||
|
||||
@Injectable({
|
||||
@@ -19,17 +21,20 @@ export class RoomBoldSyncUseCaseService {
|
||||
private MessageSocketRepositoryService: IMessageSocketRepository,
|
||||
private boldLocalRepository: IBoldLocalRepository,
|
||||
private http: HttpAdapter,
|
||||
private messageLocalRepository: IMessageLocalRepository
|
||||
private messageLocalRepository: IMessageLocalRepository,
|
||||
private roomLocalDataSourceService: IRoomLocalRepository,
|
||||
) {
|
||||
this.listenToIncomingMessage();
|
||||
// this.loadHistory()
|
||||
this.onInsertToDB()
|
||||
this.listenToUpdateMessages();
|
||||
}
|
||||
|
||||
private listenToIncomingMessage() {
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
map(message => Object.assign(new MessageEntity(), message)),
|
||||
filter((message) => !message.meSender())
|
||||
).subscribe(async (message) => {
|
||||
|
||||
const result = await this.boldLocalRepository.findOne({roomId: message.roomId})
|
||||
@@ -43,32 +48,40 @@ export class RoomBoldSyncUseCaseService {
|
||||
});
|
||||
}
|
||||
|
||||
// private loadHistory() {
|
||||
// const regex = new RegExp("Room\\/([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})\\/Messages");
|
||||
private listenToUpdateMessages() {
|
||||
return this.MessageSocketRepositoryService.listenToUpdateMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
|
||||
// return this.http.listen().pipe(
|
||||
// filter((response: any)=> {
|
||||
// return response?.isOk() && regex.test(response.value.url)
|
||||
// }),
|
||||
// map((response: any) => response.value.data as IMessageGetAllByRoomIdOutPut)
|
||||
// ).subscribe(async (data)=> {
|
||||
const haveSeen = MessageEntity.haveSeen(message.info)
|
||||
|
||||
// if(data.data.length >= 1) {
|
||||
// for(const message of data.data) {
|
||||
// const haveSeen = MessageEntity.haveSeen(message.info)
|
||||
// }
|
||||
// }
|
||||
if(haveSeen) {
|
||||
|
||||
// })
|
||||
// }
|
||||
const result = await this.boldLocalRepository.findOne({roomId: message.roomId})
|
||||
|
||||
private onInsertToDB() {
|
||||
if(result.isOk() && result.value?.bold == 1) {
|
||||
const lastMessage = await this.roomLocalDataSourceService.findOne({id: message.roomId})
|
||||
if(lastMessage.isOk()) {
|
||||
if(lastMessage.value.messages[0].id == message.id) {
|
||||
const result = await this.boldLocalRepository.update(message.roomId, {bold: 0})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
console.log(message.info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1, '', message)
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@XTracerAsync({name:'RoomBoldSyncUseCaseService/onInsertToDB', module:'chat', bugPrint: true})
|
||||
private onInsertToDB(tracing?: TracingType) {
|
||||
|
||||
this.messageLocalRepository.onCreateObservable().pipe(
|
||||
filter(e => {
|
||||
console.log('onInsertToDB', e)
|
||||
return e?.origin == 'history'
|
||||
}),
|
||||
filter(e => e?.origin == 'history'),
|
||||
filter(e => e.sender.wxUserId != SessionStore.user.UserId)
|
||||
).subscribe(async (newMessage)=> {
|
||||
const haveSeen = MessageEntity.haveSeen(newMessage.info)
|
||||
@@ -82,6 +95,8 @@ export class RoomBoldSyncUseCaseService {
|
||||
const result = await this.boldLocalRepository.insert({roomId: newMessage.roomId, bold: 1})
|
||||
} else if(result.isOk() && result.value.bold == 0) {
|
||||
const result = await this.boldLocalRepository.update(newMessage.roomId, {bold: 1})
|
||||
} else {
|
||||
tracing.hasError("failed to set bold",{})
|
||||
}
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user