mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
set last message
This commit is contained in:
@@ -13,6 +13,20 @@ export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> i
|
||||
|
||||
constructor() {
|
||||
super(chatDatabase.room, RoomTableSchema)
|
||||
// chatDatabase.room.hook('creating', (primaryKey, obj, transaction) => {
|
||||
// if(obj.messages?.[0].attachments?.[0]) {
|
||||
// delete obj.messages[0].attachments[0].file
|
||||
// }
|
||||
// });
|
||||
|
||||
// chatDatabase.room.hook('updating', (modifications, primKey, obj, transaction) => {
|
||||
|
||||
// if((modifications as Partial<RoomTable>).messages?.[0].attachments?.[0]) {
|
||||
// delete (modifications as Partial<RoomTable>).messages[0].attachments[0].file
|
||||
// }
|
||||
|
||||
// return modifications
|
||||
// });
|
||||
}
|
||||
|
||||
getItemsLive() {
|
||||
|
||||
@@ -39,7 +39,7 @@ export const MessageInputDTOSchema = z.object({
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
mimeType: z.string().optional(),
|
||||
mimeType: z.string().nullable().optional(),
|
||||
description: z.string().optional()
|
||||
}).optional()
|
||||
});
|
||||
@@ -80,7 +80,7 @@ export const MessageCreatePutDataDTOSchema = z.object({
|
||||
file: z.string().optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.string().optional(),
|
||||
docId: z.number().optional(),
|
||||
id: z.string().optional()
|
||||
}))
|
||||
});
|
||||
@@ -181,6 +181,8 @@ export class MessageCreateUseCaseService {
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
message.id = sendMessageResult.value.id
|
||||
|
||||
console.log('sendMessageResult', sendMessageResult.value.id)
|
||||
|
||||
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ export class MessageDeleteLiveUseCaseService {
|
||||
public repository: MessageSocketRepositoryService
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'MessageDeleteLiveUseCaseService', module:'chat', bugPrint: true, waitNThrow: 2000})
|
||||
@XTracerAsync({name:'MessageDeleteLiveUseCaseService', module:'chat', bugPrint: true, waitNThrow: 5000})
|
||||
async execute(data: MessageDeleteInputDTO, tracing?: TracingType) {
|
||||
tracing.log('MessageDeleteLiveUseCaseService payload', {
|
||||
data: data
|
||||
|
||||
@@ -22,8 +22,12 @@ export class RoomSetLastMessageService {
|
||||
this.listenToIncomingMessage()
|
||||
this.listenToOnSendDataToSocket()
|
||||
this.loadHistory()
|
||||
this.listenToUpdateMessage()
|
||||
|
||||
}
|
||||
|
||||
private listenToUpdateMessage() {}
|
||||
|
||||
private listenToIncomingMessage() {
|
||||
return this.messageSocketRepository.listenToMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)), // get all message not send by me
|
||||
@@ -46,15 +50,24 @@ export class RoomSetLastMessageService {
|
||||
private listenToOnSendDataToSocket() {
|
||||
this.messageSocketRepository.listenToSendMessage().subscribe(async (e) => {
|
||||
|
||||
e.data['sender'] = {
|
||||
const message = Object.assign(new MessageEntity(), e.data)
|
||||
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
e.data['sentAt'] = new Date().toISOString()
|
||||
message.sentAt = new Date().toISOString()
|
||||
|
||||
if(e.data.attachment?.fileType) {
|
||||
message.attachments = [ e.data.attachment ]
|
||||
} else {
|
||||
message.attachments = []
|
||||
}
|
||||
|
||||
const result = await this.roomLocalRepository.update(e.data.roomId, {
|
||||
messages: [e.data]
|
||||
messages: [message]
|
||||
})
|
||||
|
||||
if(result.isErr()) {
|
||||
@@ -91,7 +104,6 @@ export class RoomSetLastMessageService {
|
||||
const loadHistoryLastMessageDate = new Date(loadHistoryFirstMessage.sentAt).getTime()
|
||||
|
||||
if(loadHistoryLastMessageDate>localLastMessageDate) {
|
||||
console.log('update by load history')
|
||||
await this.roomLocalRepository.update(loadHistoryFirstMessage.roomId, {
|
||||
messages: [loadHistoryFirstMessage]
|
||||
})
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ export class SocketMessageDeleteUseCaseService {
|
||||
const result = await this.messageLocalDataSourceService.update(input.id, { isDeleted: true})
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
console.log('deleled', result.value)
|
||||
} else {
|
||||
console.log(result.error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user