mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
remove expired room
This commit is contained in:
@@ -105,31 +105,25 @@ export class RoomBoldSyncUseCaseService {
|
||||
|
||||
const room = await this.roomLocalDataSourceService.findOne({id: roomId})
|
||||
|
||||
if(room.isOk() && room.value) {
|
||||
const roomEntity = new RoomEntity(room.value)
|
||||
if (roomEntity.hasLastMessage()) {
|
||||
const message = Object.assign(new MessageEntity(), loadHistoryFirstMessage)
|
||||
const haveSeen = message.haveSeen()
|
||||
|
||||
const message = Object.assign(new MessageEntity(), roomEntity.messages[0])
|
||||
const haveSeen = message.haveSeen()
|
||||
if(haveSeen ===false && message.meSender() == false) {
|
||||
await this.boldLocalRepository.open()
|
||||
const result = await this.boldLocalRepository.findOne({roomId: roomId})
|
||||
|
||||
if(!haveSeen && !message.meSender()) {
|
||||
await this.boldLocalRepository.open()
|
||||
const result = await this.boldLocalRepository.findOne({roomId: roomEntity.id})
|
||||
|
||||
if(result.isOk() && !result.value) {
|
||||
const result = await this.boldLocalRepository.insert({roomId: roomEntity.id, bold: 1})
|
||||
} else if(result.isOk() && result.value.bold == 0) {
|
||||
const result = await this.boldLocalRepository.update(roomEntity.id, {bold: 1})
|
||||
} else {
|
||||
// tracing.hasError("failed to set bold",{})
|
||||
}
|
||||
} else {
|
||||
const result = await this.boldLocalRepository.update(roomEntity.id, {bold: 0})
|
||||
}
|
||||
if(result.isOk() && !result.value) {
|
||||
const result = await this.boldLocalRepository.insert({roomId: roomId, bold: 1})
|
||||
} else if(result.isOk() && result.value.bold == 0) {
|
||||
const result = await this.boldLocalRepository.update(roomId, {bold: 1})
|
||||
} else {
|
||||
// tracing.hasError("failed to set bold",{})
|
||||
}
|
||||
|
||||
} else {
|
||||
const result = await this.boldLocalRepository.update(roomId, {bold: 0})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { GetRoomByIdMapper } from 'src/app/core/chat/mapper/getRoomByIdMapper';
|
||||
import { RoomEntity, RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { diff, addedDiff, deletedDiff, updatedDiff, detailedDiff } from 'deep-object-diff';
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
import { CronJobService } from 'src/app/utils/task-scheduler'
|
||||
|
||||
const UserSchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
@@ -54,13 +55,13 @@ export class GetRoomByIdUseCaseService {
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: IRoomRemoteRepository,
|
||||
private roomLocalDataSourceService: IRoomLocalRepository,
|
||||
private MemberListLocalRepository: IMemberLocalRepository
|
||||
private MemberListLocalRepository: IMemberLocalRepository,
|
||||
private CronJobService: CronJobService
|
||||
) { }
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/getRoomById')
|
||||
async execute(id: RoomByIdInputDTO) {
|
||||
|
||||
console.log('iiiiiiiiiiii', id)
|
||||
const result = await this.roomRemoteDataSourceService.getRoom(id)
|
||||
|
||||
if(result.isOk()) {
|
||||
@@ -92,16 +93,30 @@ export class GetRoomByIdUseCaseService {
|
||||
|
||||
} else if (getRoomById.isOk() && !getRoomById.value) {
|
||||
const room = GetRoomByIdMapper.toDomain(validData.value)
|
||||
this.roomLocalDataSourceService.insert(room)
|
||||
const createResult = await this.roomLocalDataSourceService.insert(room)
|
||||
|
||||
if(createResult.isErr()) {
|
||||
console.error('createResultErr', createResult.error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(validData.value.data.expirationDate) {
|
||||
this.CronJobService.createCronJob(`remove expired room ${id}`, new Date(validData.value.data.expirationDate), () => {
|
||||
setTimeout(() => {
|
||||
this.execute(id);
|
||||
}, 60000);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (isHttpResponse(result.error) ) {
|
||||
if(result.error.status == 404) {
|
||||
await this.roomLocalDataSourceService.delete(id)
|
||||
|
||||
+19
-5
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { GetRoomListUseCaseService } from './room-get-list-use-case.service'
|
||||
import { RoomSocketRepositoryService } from '../../../data/repository/room/room-socket-repository.service'
|
||||
import { IRoomLocalRepository } from 'src/app/core/chat/repository/room/room-local-repository';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -9,7 +10,8 @@ export class RoomGetListOnCreateUseCaseService {
|
||||
|
||||
constructor(
|
||||
private RoomSocketRepositoryService: RoomSocketRepositoryService,
|
||||
private getRoomListUseCaseService: GetRoomListUseCaseService
|
||||
private getRoomListUseCaseService: GetRoomListUseCaseService,
|
||||
private roomLocalDataSourceService: IRoomLocalRepository,
|
||||
) {
|
||||
this.init()
|
||||
}
|
||||
@@ -21,10 +23,22 @@ export class RoomGetListOnCreateUseCaseService {
|
||||
}
|
||||
|
||||
|
||||
private OnReceiveCreateRoom() {
|
||||
this.RoomSocketRepositoryService.listenToCreateRoom().subscribe((data)=> {
|
||||
console.log('OnReceiveCreateRoom', data)
|
||||
this.getRoomListUseCaseService.execute()
|
||||
private async OnReceiveCreateRoom() {
|
||||
this.RoomSocketRepositoryService.listenToCreateRoom().subscribe(async(data)=> {
|
||||
|
||||
setTimeout(async () => {
|
||||
const findLocally = await this.roomLocalDataSourceService.findOne({id:(data.data as any).id})
|
||||
|
||||
if(findLocally.isOk() && !findLocally.value) {
|
||||
this.getRoomListUseCaseService.execute()
|
||||
}
|
||||
|
||||
}, 1000);
|
||||
|
||||
|
||||
// const result = await this.roomRemoteDataSourceService.getRoom(id)
|
||||
// console.log('OnReceiveCreateRoom', data)
|
||||
//this.getRoomListUseCaseService.execute()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ export class GetRoomListUseCaseService {
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
async execute() {
|
||||
console.log('update===============')
|
||||
const result = await this.roomRemoteDataSourceService.getRoomList()
|
||||
|
||||
const localList = await this.roomLocalDataSourceService.findAll()
|
||||
@@ -108,22 +109,44 @@ export class GetRoomListUseCaseService {
|
||||
}
|
||||
|
||||
} else {
|
||||
this.roomLocalDataSourceService.insert(room)
|
||||
const createResult = this.roomLocalDataSourceService.insert(room)
|
||||
|
||||
createResult.then((result) => {
|
||||
if(result.isErr()) {
|
||||
console.log('error', result.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if(room.expirationDate) {
|
||||
this.CronJobService.createCronJob('remove expired room', new Date(room.expirationDate), this.execute)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const roomsToUpdateEntity = GetRoomListMapper.toDomain(roomsToUpdate)
|
||||
this.roomLocalDataSourceService.updateMany(roomsToUpdateEntity)
|
||||
if(roomsToUpdate.length >= 1) {
|
||||
const roomsToUpdateEntity = GetRoomListMapper.toDomain(roomsToUpdate)
|
||||
this.roomLocalDataSourceService.updateMany(roomsToUpdateEntity)
|
||||
}
|
||||
|
||||
for( const room of roomsToDelete) {
|
||||
if(room.local == IDBoolean.false) {
|
||||
this.roomLocalDataSourceService.delete(room.id)
|
||||
const findResult = this.roomLocalDataSourceService.findOne({id:room.id})
|
||||
findResult.then((result) => {
|
||||
if(result.isOk() && result.value) {
|
||||
this.roomLocalDataSourceService.delete(result.value.$id)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for(const room of filterValidateRooms) {
|
||||
if(room.chatRoom.expirationDate) {
|
||||
|
||||
|
||||
this.CronJobService.createCronJob('remove expired room list', new Date(room.chatRoom.expirationDate), () => {
|
||||
setTimeout(() => {
|
||||
this.execute();
|
||||
}, 60000);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user