messge status

This commit is contained in:
Peter Maquiran
2024-06-11 08:37:52 +01:00
parent 1bfe617bfd
commit f3232c835d
3 changed files with 24 additions and 12 deletions
@@ -1,13 +1,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto';
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
import { Dexie, EntityTable, liveQuery } from 'Dexie'; import { Dexie, EntityTable, liveQuery } from 'Dexie';
import { err, ok } from 'neverthrow'; import { err, ok } from 'neverthrow';
import { Observable } from 'rxjs';
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
import { z } from 'zod'; import { z } from 'zod';
import { MessageInputDTO } from '../../dto/message/messageInputDtO'; import { MessageInputDTO } from '../../dto/message/messageInputDtO';
import { SessionStore } from 'src/app/store/session.service';
const tableSchema = z.object({ const tableSchema = z.object({
@@ -24,10 +19,12 @@ const tableSchema = z.object({
wxUserId: z.number(), wxUserId: z.number(),
wxFullName: z.string(), wxFullName: z.string(),
wxeMail: z.string(), wxeMail: z.string(),
userPhoto: z.string() userPhoto: z.string(),
}) }),
sending: z.boolean().optional()
}) })
export type TableMessage = z.infer<typeof tableSchema> export type TableMessage = z.infer<typeof tableSchema>
// Database declaration (move this to its own module also) // Database declaration (move this to its own module also)
@@ -49,6 +46,20 @@ export class MessageLocalDataSourceService {
constructor() {} 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) { async createMessage(data: MessageInputDTO) {
try { try {
@@ -62,7 +73,7 @@ export class MessageLocalDataSourceService {
} }
async update(data: TableMessage) { async update(data: TableMessage ) {
try { try {
const result = await messageDataSource.message.update(data.id, data) const result = await messageDataSource.message.update(data.id, data)
@@ -101,7 +101,7 @@ export class RoomLocalDataSourceService {
return result return result
} else { } else {
console.log(`No member found with $roomIdUserId ${$roomIdUserId}`); console.log(`No member found with $roomIdUserId ${$roomIdUserId}`);
return return err('not Found')
} }
} catch (e) { } catch (e) {
@@ -25,7 +25,7 @@ export class MessageRepositoryService {
wxUserId: SessionStore.user.UserId wxUserId: SessionStore.user.UserId
} }
const localActionResult = await this.messageLocalDataSourceService.createMessage(data) const localActionResult = await this.messageLocalDataSourceService.sendMessage(data)
if(localActionResult.isOk()) { if(localActionResult.isOk()) {
const sendMessageResult = await this.messageRemoteDataSourceService.sendMessage(data) const sendMessageResult = await this.messageRemoteDataSourceService.sendMessage(data)
@@ -42,9 +42,11 @@ export class MessageRepositoryService {
id : localActionResult.value 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) const result = await this.messageRemoteDataSourceService.getMessagesFromRoom(id)
if(result.isOk()) { if(result.isOk()) {
console.log({result})
for(const message of result.value.data) { for(const message of result.value.data) {
let clone: TableMessage = message let clone: TableMessage = message