mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix chat bold
This commit is contained in:
@@ -36,7 +36,6 @@ import { DistributionLocalRepository } from './data/repository/destribution/dest
|
||||
import { DistributionService } from './domain/service/distribution.service'
|
||||
import { BoldLocalRepository } from './data/repository/bold/bold-local-repository';
|
||||
import { IBoldLocalRepository } from 'src/app/core/chat/repository/bold/bold-local-repository';
|
||||
import { BoldService } from 'src/app/module/chat/domain/service/bold.service'
|
||||
import { RoomLastMessageService } from 'src/app/module/chat/domain/service/room-last-message.service'
|
||||
@NgModule({
|
||||
imports: [HttpModule],
|
||||
@@ -119,7 +118,6 @@ export class ChatModule {
|
||||
private UserTypingRemoteRepositoryService: UserTypingRemoteRepositoryService,
|
||||
private RoomService: RoomService,
|
||||
private DistributionService: DistributionService,
|
||||
private BoldService: BoldService,
|
||||
private RoomLastMessageService: RoomLastMessageService
|
||||
) {
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@ import { Observable as DexieObservable, PromiseExtended } from 'Dexie';
|
||||
import { MessageTable, MessageTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { chatDatabase } from 'src/app/infra/database/dexie/service';
|
||||
import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
|
||||
import { combineLatest, from, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { BehaviorSubject, combineLatest, from, Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageLocalDataSourceService extends DexieRepository<MessageTable, MessageEntity> implements IMessageLocalRepository {
|
||||
|
||||
private creatingSubject : BehaviorSubject<MessageTable> = new BehaviorSubject<MessageTable>(null);
|
||||
|
||||
constructor() {
|
||||
super(chatDatabase.message, MessageTableSchema)
|
||||
@@ -21,6 +22,20 @@ export class MessageLocalDataSourceService extends DexieRepository<MessageTable,
|
||||
this.setAllSenderToFalse();
|
||||
}
|
||||
|
||||
private onCreatingHook() {
|
||||
chatDatabase.message.hook('creating', (primaryKey, obj, transaction) => {
|
||||
console.log('A new friend is being added:', obj);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// onCreateObservable() {
|
||||
// return this.creatingSubject.asObservable().pipe(
|
||||
// filter(e => e?.sender?.wxFullName)
|
||||
// )
|
||||
// }
|
||||
|
||||
async setAllSenderToFalse() {
|
||||
try {
|
||||
await chatDatabase.transaction('rw', chatDatabase.message, async () => {
|
||||
|
||||
@@ -40,7 +40,7 @@ import { MessageSocketRepositoryService } from 'src/app/module/chat/data/reposit
|
||||
import { MessageMarkAsReadInput } from "src/app/module/chat/domain/use-case/message/message-mark-as-read-use-case.service";
|
||||
import { BoldRemoveByRoomIdInput, BoldRemoveByRoomIdService } from 'src/app/module/chat/domain/use-case/bold/bold-remove-by-room-id.service';
|
||||
import { MemberListHttpSyncUseCase } from 'src/app/module/chat/domain/use-case/member/member-list-http-sync-use-case.ts.service'
|
||||
import { RoomSetLastMessageService } from 'src/app/module/chat/domain/use-case/room/room-set-last-message.service'
|
||||
import { RoomBoldSyncUseCaseService } from 'src/app/module/chat/domain/use-case/room/room-bold-sync-use-case.service'
|
||||
export const InstanceId = uuidv4();
|
||||
|
||||
@Injectable({
|
||||
@@ -82,7 +82,7 @@ export class ChatServiceService {
|
||||
private MessageSocketRepositoryService: MessageSocketRepositoryService,
|
||||
private BoldRemoveByRoomIdService: BoldRemoveByRoomIdService,
|
||||
private MemberListHttpSyncUseCase: MemberListHttpSyncUseCase,
|
||||
private RoomSetLastMessageService: RoomSetLastMessageService
|
||||
private RoomBoldSyncUseCaseService: RoomBoldSyncUseCaseService
|
||||
) {
|
||||
this.MessageSocketRepositoryService.listenToDeleteMessages()
|
||||
.pipe()
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
+16
-11
@@ -7,7 +7,8 @@ import { err, Result } from 'neverthrow';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { MessageEntity } from '../../../../../core/chat/entity/message';
|
||||
import { AttachmentTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
||||
import { XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { isHttpResponse } from 'src/app/infra/http/http.service';
|
||||
|
||||
const MessageAttachmentByMessageIdSchema = AttachmentTableSchema.pick({
|
||||
$messageId: true,
|
||||
@@ -27,7 +28,7 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
) { }
|
||||
|
||||
@XTracerAsync({name:'Message-Attachment-By-MessageIdUseCase', module:'chat', bugPrint: true, waitNThrow: 15000})
|
||||
async execute(input: MessageEntity): Promise<Result<string, any>> {
|
||||
async execute(input: MessageEntity, tracing?: TracingType): Promise<Result<string, any>> {
|
||||
|
||||
const getLocalAttachment = await this.AttachmentLocalDataSource.findOne({
|
||||
$messageId: input.$id
|
||||
@@ -47,7 +48,7 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
} else {
|
||||
// has data url
|
||||
return getLocalAttachment.map((e) => {
|
||||
|
||||
|
||||
// Logger.info('restored file .', {
|
||||
// data: e.base64.slice(0, 100)+'...'
|
||||
// })
|
||||
@@ -56,18 +57,22 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.log('donwload')
|
||||
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.attachments[0].id)
|
||||
|
||||
} else {
|
||||
tracing.setAttribute('download', 'true')
|
||||
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.attachments[0].id)
|
||||
tracing.setAttribute('attachmentId', input.attachments[0].id.toString())
|
||||
if(result.isErr()) {
|
||||
Logger.error('failed to download message attachment', {
|
||||
tracing.hasError('failed to download message attachment', {
|
||||
error: result.error,
|
||||
data: 'document id '+ input.attachments[0].id,
|
||||
messageId: input.id,
|
||||
$messageId: input.$id
|
||||
})
|
||||
|
||||
if(isHttpResponse(result.error)) {
|
||||
tracing.setAttribute('attachmentUrl', result.error.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +84,9 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
if(dataUrl.isOk()) {
|
||||
|
||||
//console.log('done convert')
|
||||
Logger.info('downloaded file .', {
|
||||
//Logger.info('downloaded file .', {
|
||||
// data: dataUrl.value.slice(0, 100)+'...'
|
||||
})
|
||||
//})
|
||||
|
||||
this.AttachmentLocalDataSource.insert({
|
||||
$messageId: input.$id,
|
||||
@@ -94,7 +99,7 @@ export class MessageAttachmentByMessageIdUseCase {
|
||||
mimeType: input.attachments[0].mimeType,
|
||||
}).then((e) => {
|
||||
if(e.isErr()) {
|
||||
Logger.error('failed to create attachment locally on send message', {
|
||||
tracing.hasError('failed to create attachment locally on send message', {
|
||||
error: e.error,
|
||||
// data: dataUrl.value.slice(0, 100)+'...'
|
||||
})
|
||||
|
||||
@@ -214,7 +214,7 @@ export class MessageCreateUseCaseService {
|
||||
|
||||
} else {
|
||||
Logger.error('failed to insert locally', {
|
||||
error: createMessageLocally.error
|
||||
error: createMessageLocally.error.message
|
||||
})
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -41,19 +41,19 @@ export class SyncAllRoomMessagesService {
|
||||
this.messageRemoteDataSourceService.getMessagesFromRoom(room.id),
|
||||
this.messageLocalDataSourceService.getItems(room.id)
|
||||
]);
|
||||
|
||||
|
||||
tracing.addEvent('async n ' + n);
|
||||
n++;
|
||||
|
||||
|
||||
if (result.isOk()) {
|
||||
const { addedItems, changedItems, deletedItems } = messageListDetermineChanges(result.value.data, localResult);
|
||||
|
||||
|
||||
for (const message of changedItems) {
|
||||
let clone: MessageTable = { ...message, roomId: room.id };
|
||||
await this.messageLocalDataSourceService.update(clone.$id, clone);
|
||||
|
||||
|
||||
const me = message.info.find(e => e.memberId === SessionStore.user.UserId && typeof e.deliverAt === 'string');
|
||||
|
||||
|
||||
if (!me) {
|
||||
this.MessageSocketRepositoryService.sendDeliverAt({
|
||||
memberId: SessionStore.user.UserId,
|
||||
@@ -61,22 +61,25 @@ export class SyncAllRoomMessagesService {
|
||||
roomId: message.roomId,
|
||||
requestId: uuidv4()
|
||||
});
|
||||
|
||||
|
||||
tracing.addEvent('send deliver roomId ' + room.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (const message of addedItems) {
|
||||
let clone: MessageTable = { ...message, roomId: room.id };
|
||||
// You can perform operations with addedItems here if needed
|
||||
}
|
||||
|
||||
await this.messageLocalDataSourceService.insertMany(addedItems.reverse());
|
||||
|
||||
await this.messageLocalDataSourceService.insertMany(addedItems.reverse().map(e => {
|
||||
e.origin = 'history'
|
||||
return e
|
||||
}));
|
||||
} else {
|
||||
Logger.error('failed to get room message ' + room.id);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Wait for all the promises to resolve
|
||||
await Promise.all(roomPromises);
|
||||
|
||||
|
||||
+29
-6
@@ -1,28 +1,33 @@
|
||||
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';
|
||||
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';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class BoldService {
|
||||
export class RoomBoldSyncUseCaseService {
|
||||
|
||||
constructor(
|
||||
private MessageSocketRepositoryService: IMessageSocketRepository,
|
||||
private boldLocalRepository: IBoldLocalRepository
|
||||
private boldLocalRepository: IBoldLocalRepository,
|
||||
private http: HttpAdapter,
|
||||
) {
|
||||
this.listenToIncomingMessage();
|
||||
}
|
||||
this.loadHistory()
|
||||
}
|
||||
|
||||
listenToIncomingMessage() {
|
||||
private 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) {
|
||||
@@ -32,6 +37,24 @@ export class BoldService {
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
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)=> {
|
||||
|
||||
if(data.data.length >= 1) {
|
||||
for(const message of data.data) {
|
||||
const haveSeen = MessageEntity.haveSeen(message.info)
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user