mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
messge status
This commit is contained in:
+19
-8
@@ -1,13 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
|
||||
import { z } from 'zod';
|
||||
import { MessageInputDTO } from '../../dto/message/messageInputDtO';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
|
||||
const tableSchema = z.object({
|
||||
@@ -24,10 +19,12 @@ const tableSchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string()
|
||||
})
|
||||
userPhoto: z.string(),
|
||||
}),
|
||||
sending: z.boolean().optional()
|
||||
})
|
||||
|
||||
|
||||
export type TableMessage = z.infer<typeof tableSchema>
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
@@ -49,6 +46,20 @@ export class MessageLocalDataSourceService {
|
||||
constructor() {}
|
||||
|
||||
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
|
||||
(data as TableMessage).sending = true
|
||||
|
||||
try {
|
||||
const result = await messageDataSource.message.add(data)
|
||||
return ok(result as string)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
async createMessage(data: MessageInputDTO) {
|
||||
|
||||
try {
|
||||
@@ -62,7 +73,7 @@ export class MessageLocalDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
async update(data: TableMessage) {
|
||||
async update(data: TableMessage ) {
|
||||
|
||||
try {
|
||||
const result = await messageDataSource.message.update(data.id, data)
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ export class RoomLocalDataSourceService {
|
||||
return result
|
||||
} else {
|
||||
console.log(`No member found with $roomIdUserId ${$roomIdUserId}`);
|
||||
return
|
||||
return err('not Found')
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -25,7 +25,7 @@ export class MessageRepositoryService {
|
||||
wxUserId: SessionStore.user.UserId
|
||||
}
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.createMessage(data)
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(data)
|
||||
|
||||
if(localActionResult.isOk()) {
|
||||
const sendMessageResult = await this.messageRemoteDataSourceService.sendMessage(data)
|
||||
@@ -42,9 +42,11 @@ export class MessageRepositoryService {
|
||||
id : localActionResult.value
|
||||
}
|
||||
|
||||
return this.messageLocalDataSourceService.update(clone)
|
||||
return this.messageLocalDataSourceService.update({...clone, sending: false})
|
||||
}
|
||||
|
||||
} else {
|
||||
return this.messageLocalDataSourceService.update({sending: false})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +54,6 @@ export class MessageRepositoryService {
|
||||
const result = await this.messageRemoteDataSourceService.getMessagesFromRoom(id)
|
||||
|
||||
if(result.isOk()) {
|
||||
console.log({result})
|
||||
|
||||
for(const message of result.value.data) {
|
||||
let clone: TableMessage = message
|
||||
|
||||
Reference in New Issue
Block a user