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:
@@ -102,7 +102,11 @@ export class MessageEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static haveSeen(info: typeof MessageEntitySchema._type.info) {
|
static haveSeen(info: typeof MessageEntitySchema._type.info) {
|
||||||
return info.filter(e => typeof e.readAt != 'string' && e.memberId == SessionStore.user.UserId).length == 1
|
return info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
meSender() {
|
||||||
|
return this.sender.wxUserId == SessionStore.user.UserId
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ export class BoldRemoveByRoomIdService {
|
|||||||
const validation = zodSafeValidation<any>(BoldRemoveByRoomIdInputSchema, input)
|
const validation = zodSafeValidation<any>(BoldRemoveByRoomIdInputSchema, input)
|
||||||
|
|
||||||
if(validation.isOk()) {
|
if(validation.isOk()) {
|
||||||
console.log('remove buld============================')
|
|
||||||
return await this.boldLocalRepository.delete(input.roomId)
|
return await this.boldLocalRepository.delete(input.roomId)
|
||||||
} else {
|
} else {
|
||||||
tracing.hasError("invalid parameter")
|
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 { IMessageGetAllByRoomIdOutPut } from 'src/app/core/chat/usecase/message/message-get-all-by-room-Id';
|
||||||
import { HttpAdapter } from 'src/app/infra/http/adapter';
|
import { HttpAdapter } from 'src/app/infra/http/adapter';
|
||||||
import { SessionStore } from 'src/app/store/session.service';
|
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({
|
@Injectable({
|
||||||
@@ -19,17 +21,20 @@ export class RoomBoldSyncUseCaseService {
|
|||||||
private MessageSocketRepositoryService: IMessageSocketRepository,
|
private MessageSocketRepositoryService: IMessageSocketRepository,
|
||||||
private boldLocalRepository: IBoldLocalRepository,
|
private boldLocalRepository: IBoldLocalRepository,
|
||||||
private http: HttpAdapter,
|
private http: HttpAdapter,
|
||||||
private messageLocalRepository: IMessageLocalRepository
|
private messageLocalRepository: IMessageLocalRepository,
|
||||||
|
private roomLocalDataSourceService: IRoomLocalRepository,
|
||||||
) {
|
) {
|
||||||
this.listenToIncomingMessage();
|
this.listenToIncomingMessage();
|
||||||
// this.loadHistory()
|
// this.loadHistory()
|
||||||
this.onInsertToDB()
|
this.onInsertToDB()
|
||||||
|
this.listenToUpdateMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private listenToIncomingMessage() {
|
private listenToIncomingMessage() {
|
||||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
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) => {
|
).subscribe(async (message) => {
|
||||||
|
|
||||||
const result = await this.boldLocalRepository.findOne({roomId: message.roomId})
|
const result = await this.boldLocalRepository.findOne({roomId: message.roomId})
|
||||||
@@ -43,32 +48,40 @@ export class RoomBoldSyncUseCaseService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// private loadHistory() {
|
private listenToUpdateMessages() {
|
||||||
// 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");
|
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(
|
const haveSeen = MessageEntity.haveSeen(message.info)
|
||||||
// filter((response: any)=> {
|
|
||||||
// return response?.isOk() && regex.test(response.value.url)
|
|
||||||
// }),
|
|
||||||
// map((response: any) => response.value.data as IMessageGetAllByRoomIdOutPut)
|
|
||||||
// ).subscribe(async (data)=> {
|
|
||||||
|
|
||||||
// if(data.data.length >= 1) {
|
if(haveSeen) {
|
||||||
// for(const message of data.data) {
|
|
||||||
// const haveSeen = MessageEntity.haveSeen(message.info)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// })
|
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(
|
this.messageLocalRepository.onCreateObservable().pipe(
|
||||||
filter(e => {
|
filter(e => e?.origin == 'history'),
|
||||||
console.log('onInsertToDB', e)
|
|
||||||
return e?.origin == 'history'
|
|
||||||
}),
|
|
||||||
filter(e => e.sender.wxUserId != SessionStore.user.UserId)
|
filter(e => e.sender.wxUserId != SessionStore.user.UserId)
|
||||||
).subscribe(async (newMessage)=> {
|
).subscribe(async (newMessage)=> {
|
||||||
const haveSeen = MessageEntity.haveSeen(newMessage.info)
|
const haveSeen = MessageEntity.haveSeen(newMessage.info)
|
||||||
@@ -82,6 +95,8 @@ export class RoomBoldSyncUseCaseService {
|
|||||||
const result = await this.boldLocalRepository.insert({roomId: newMessage.roomId, bold: 1})
|
const result = await this.boldLocalRepository.insert({roomId: newMessage.roomId, bold: 1})
|
||||||
} else if(result.isOk() && result.value.bold == 0) {
|
} else if(result.isOk() && result.value.bold == 0) {
|
||||||
const result = await this.boldLocalRepository.update(newMessage.roomId, {bold: 1})
|
const result = await this.boldLocalRepository.update(newMessage.roomId, {bold: 1})
|
||||||
|
} else {
|
||||||
|
tracing.hasError("failed to set bold",{})
|
||||||
}
|
}
|
||||||
}, 2000)
|
}, 2000)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user