mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
fix last message
This commit is contained in:
+12
-12
@@ -15,20 +15,20 @@ export class MemberListHttpSyncUseCase {
|
||||
private memberLocalRepository: IMemberLocalRepository
|
||||
) {
|
||||
|
||||
// this.http.listen().pipe(
|
||||
// filter((response)=> {
|
||||
// if(response?.isOk()) {
|
||||
// return response.value.url.includes('/Room/') && typeof response.value?.data?.data?.roomName == 'string'
|
||||
// }
|
||||
this.http.listen().pipe(
|
||||
filter((response)=> {
|
||||
if(response?.isOk()) {
|
||||
return response.value.url.includes('/Room/') && typeof response.value?.data?.data?.roomName == 'string'
|
||||
}
|
||||
|
||||
// return false
|
||||
// }),
|
||||
// map((response: any) => response.value.data as RoomByIdOutputDTO)
|
||||
// )
|
||||
// .subscribe(async (data) => {
|
||||
return false
|
||||
}),
|
||||
map((response: any) => response.value.data as RoomByIdOutputDTO)
|
||||
)
|
||||
.subscribe(async (data) => {
|
||||
|
||||
// this.syncMembers(data)
|
||||
// })
|
||||
this.syncMembers(data)
|
||||
})
|
||||
}
|
||||
|
||||
private async syncMembers(roomData: RoomByIdOutputDTO): Promise<void> {
|
||||
|
||||
@@ -19,12 +19,31 @@ import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/me
|
||||
import { IMessageSocketRepository } from 'src/app/core/chat/repository/message/message-socket-repository';
|
||||
import { IMemberLocalRepository } from 'src/app/core/chat/repository/member/member-local-repository';
|
||||
import { IAttachmentLocalRepository } from 'src/app/core/chat/repository/typing/typing-local-repository';
|
||||
import { base64Schema } from 'src/app/utils/zod';
|
||||
|
||||
|
||||
export enum MessageEnum {
|
||||
Direct = 1,
|
||||
group = 2
|
||||
}
|
||||
export const MessageInputDTOSchema = z.object({
|
||||
roomId: z.string().uuid().optional(),
|
||||
receiverId: z.number().optional(),
|
||||
senderId: z.number(),
|
||||
message: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
requestId: z.string(),
|
||||
attachment: z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: base64Schema.optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
mimeType: z.string().optional()
|
||||
}).optional()
|
||||
});
|
||||
export type MessageInputDTO = z.infer<typeof MessageInputDTOSchema>
|
||||
|
||||
|
||||
|
||||
export const MessageCreatePutDataDTOSchema = z.object({
|
||||
|
||||
@@ -6,7 +6,6 @@ import { z } from "zod";
|
||||
import { IRoomRemoteRepository } from 'src/app/core/chat/repository/room/room-remote-repository';
|
||||
import { IRoomLocalRepository } from 'src/app/core/chat/repository/room/room-local-repository';
|
||||
import { MessageEntitySchema } from 'src/app/core/chat/entity/message';
|
||||
import { RoomEntity, RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { GetRoomListMapper } from 'src/app/core/chat/mapper/getRoomListMapper';
|
||||
|
||||
|
||||
@@ -52,7 +51,6 @@ export class GetRoomListUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: IRoomRemoteRepository,
|
||||
// private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: IRoomLocalRepository,
|
||||
private CronJobService: CronJobService
|
||||
) { }
|
||||
@@ -65,7 +63,7 @@ export class GetRoomListUseCaseService {
|
||||
|
||||
if(localList.isOk()) {
|
||||
if(result.isOk()) {
|
||||
|
||||
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges(result.value.data, localList.value)
|
||||
|
||||
if(roomsToInsert) {
|
||||
@@ -73,12 +71,11 @@ export class GetRoomListUseCaseService {
|
||||
for( const room of roomsToInsertEntity) {
|
||||
this.roomLocalDataSourceService.insert(room)
|
||||
if(room.expirationDate) {
|
||||
console.log('room expiration date schedule')
|
||||
this.CronJobService.createCronJob('remove expired room', new Date(room.expirationDate), this.execute)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const roomsToUpdateEntity = GetRoomListMapper.toDomain(roomsToUpdate)
|
||||
this.roomLocalDataSourceService.updateMany(roomsToUpdateEntity)
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomSetLastMessageService } from './room-set-last-message.service';
|
||||
|
||||
describe('RoomSetLastMessageService', () => {
|
||||
let service: RoomSetLastMessageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomSetLastMessageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { IRoomLocalRepository } from 'src/app/core/chat/repository/room/room-loc
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { InstanceId } from '../../chat-service.service';
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -11,14 +12,15 @@ import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
export class RoomSetLastMessageService {
|
||||
|
||||
constructor(
|
||||
private MessageSocketRepositoryService: IMessageSocketRepository,
|
||||
private roomLocalRepository: IRoomLocalRepository
|
||||
private roomLocalRepository: IRoomLocalRepository,
|
||||
private messageSocketRepository: IMessageSocketRepository
|
||||
) {
|
||||
// this.listenToIncomingMessage()
|
||||
this.listenToIncomingMessage()
|
||||
this.listenToOnSendDataToSocket()
|
||||
}
|
||||
|
||||
listenToIncomingMessage() {
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
return this.messageSocketRepository.listenToMessages().pipe(
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
@@ -31,6 +33,23 @@ export class RoomSetLastMessageService {
|
||||
}
|
||||
|
||||
listenToOnSendDataToSocket() {
|
||||
this.messageSocketRepository.listenToSendMessage().subscribe(async (e) => {
|
||||
|
||||
e.data['sender'] = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
e.data['sentAt'] = new Date().toISOString()
|
||||
const result = await this.roomLocalRepository.update(e.data.roomId, {
|
||||
messages: [e.data]
|
||||
})
|
||||
|
||||
if(result.isErr()) {
|
||||
console.log(result.error)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user