mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
receive error when sending message on offline
This commit is contained in:
@@ -9,7 +9,7 @@ import { MessageEntity } from '../../../domain/entity/message';
|
||||
|
||||
|
||||
const tableSchema = z.object({
|
||||
$id: z.any().optional(),
|
||||
$id: z.number().optional(),
|
||||
id: z.string().optional(),
|
||||
roomId: z.string().uuid(),
|
||||
message: z.string(),
|
||||
@@ -117,7 +117,7 @@ export class MessageLocalDataSourceService {
|
||||
try {
|
||||
const result = await messageDataSource.message.add(data)
|
||||
this.messageSubject.next({roomId: data.roomId});
|
||||
return ok(result as string)
|
||||
return ok(result as number)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export class MessageLocalDataSourceService {
|
||||
try {
|
||||
const result = await messageDataSource.message.add(data)
|
||||
this.messageSubject.next({roomId: data.roomId});
|
||||
return ok(result as string)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
@@ -179,11 +179,11 @@ export class MessageLocalDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
// not used
|
||||
async updateByMessageId(data: TableMessage ) {
|
||||
|
||||
try {
|
||||
console.log('update sdfsdfsd')
|
||||
const result = await messageDataSource.message.update(data.id, data)
|
||||
const result = await messageDataSource.message.update(data.id as any, data)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
|
||||
@@ -8,6 +8,7 @@ export const MessageInputDTOSchema = z.object({
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
requestId: z.string()
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
|
||||
import { MessageInputDTO } from '../dto/message/messageInputDtO';
|
||||
import { MessageLocalDataSourceService, TableMessage } from '../data-source/message/message-local-data-source.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
@@ -10,8 +9,10 @@ import { err, ok } from 'neverthrow';
|
||||
import { MessageDeleteInputDTO } from '../../domain/use-case/message-delete-live-use-case.service';
|
||||
import { MessageUpdateInput } from '../../domain/use-case/message-update-use-case.service';
|
||||
import { messageListDetermineChanges } from '../async/list/rooms/messageListChangedetector';
|
||||
import { MessageEntity } from '../../domain/entity/message';
|
||||
import { InstanceId } from '../../domain/chat-service.service';
|
||||
import { MessageMapper } from '../../domain/mapper/messageMapper';
|
||||
|
||||
export const InstanceId = uuidv4();
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -25,36 +26,21 @@ export class MessageRepositoryService {
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService
|
||||
) {}
|
||||
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
async sendMessage(entity: MessageEntity) {
|
||||
|
||||
(data as TableMessage).sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
const requestId = InstanceId +'@'+ uuidv4();
|
||||
const roomId = entity.roomId
|
||||
|
||||
data['requestId'] = InstanceId +'@'+ uuidv4();
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage({...data})
|
||||
console.log('create message', data)
|
||||
|
||||
// this.messageLiveDataSourceService.sendMessage({
|
||||
// type: 'sendMessage',
|
||||
// payload: data
|
||||
// })
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(entity)
|
||||
|
||||
if(localActionResult.isOk()) {
|
||||
|
||||
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(data)
|
||||
|
||||
|
||||
//const sendMessageResult = await this.messageRemoteDataSourceService.sendMessage(data)
|
||||
const DTO = MessageMapper.fromDomain(entity, requestId)
|
||||
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(DTO)
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
|
||||
console.log({sendMessageResult})
|
||||
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
|
||||
@@ -64,12 +50,12 @@ export class MessageRepositoryService {
|
||||
$id : localActionResult.value
|
||||
}
|
||||
|
||||
// console.log({clone})
|
||||
console.log('update message 11111')
|
||||
return this.messageLocalDataSourceService.update({...clone, sending: false, roomId: data.roomId})
|
||||
return this.messageLocalDataSourceService.update({...clone, sending: false, roomId: entity.roomId})
|
||||
return ok(true)
|
||||
} else {
|
||||
console.log('no message to upload')
|
||||
console.log('no message to upload', sendMessageResult.error)
|
||||
return this.messageLocalDataSourceService.update({sending: false, $id: localActionResult.value})
|
||||
return err(false)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user