mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add readAt functionality
This commit is contained in:
@@ -19,7 +19,6 @@ export class MessageAsyncService {
|
||||
private messageLocalDataSourceService: MessageLocalDataSourceService
|
||||
) {
|
||||
|
||||
|
||||
this.messageLiveSignalRDataSourceService.getMessage().pipe(
|
||||
filter((message: any) => {
|
||||
return !message?.requestId?.startsWith(InstanceId) && message?.requestId
|
||||
@@ -40,7 +39,6 @@ export class MessageAsyncService {
|
||||
|
||||
this.incomingMessage(incomingMessage)
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -21,17 +21,15 @@ export class UserTypingAsyncService {
|
||||
private signalR: SignalRService,
|
||||
) {
|
||||
|
||||
this.signalR.getTyping().subscribe(async (e:any) => {
|
||||
if(e?.chatRoomId) {
|
||||
|
||||
console.log('e', e)
|
||||
this.signalR.getTyping().subscribe(async (e) => {
|
||||
if(e?.roomId) {
|
||||
|
||||
this.memoryDataSource.dispatch(removeUserTyping({data: {...e} as any}))
|
||||
this.memoryDataSource.dispatch(addUserTyping({data: {...e} as any}))
|
||||
//
|
||||
const value = await this.localDataSource.addUserTyping(e);
|
||||
|
||||
const id = e.chatRoomId + '@' + e.userName
|
||||
const id = e.roomId + '@' + e.userName
|
||||
if(!this.typingCallback[id]) {
|
||||
this.typingCallback[id] = new Subject()
|
||||
this.typingCallback[id].pipe(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { err, ok, Result } from 'neverthrow';
|
||||
import { z } from 'zod';
|
||||
import { from, Observable, Subject } from 'rxjs';
|
||||
import { filter, switchMap } from 'rxjs/operators';
|
||||
@@ -73,6 +73,21 @@ export class MessageLocalDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
async getLastMessageByRoomId(roomId: string): Promise<Result<undefined|TableMessage, any>> {
|
||||
try {
|
||||
const lastMessage = await messageDataSource.message
|
||||
.where('roomId')
|
||||
.equals(roomId)
|
||||
.reverse()
|
||||
.sortBy('id');
|
||||
|
||||
return ok(lastMessage[0]); // Get the last message
|
||||
} catch (error) {
|
||||
return err(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async sendMessage(data: MessageInputDTO) {
|
||||
|
||||
(data as TableMessage).sending = true
|
||||
|
||||
+2
-2
@@ -11,8 +11,8 @@ export class UserTypingLiveDataSourceService {
|
||||
private SignalRLiveDataSourceService: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(ChatRoomId) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({ChatRoomId, UserName:SessionStore.user.FullName})
|
||||
sendTyping(roomId) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,4 +26,5 @@ export const MessageOutPutDTOSchema = z.object({
|
||||
data: DataSchema
|
||||
});
|
||||
|
||||
export type MessageOutPutDataDTO = z.infer<typeof DataSchema>
|
||||
export type MessageOutPutDTO = z.infer<typeof MessageOutPutDTOSchema>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const UserTypingDTOSchema = z.object({
|
||||
requestId: z.string(),
|
||||
roomId: z.string(),
|
||||
userId: z.string(),
|
||||
userName: z.string()
|
||||
})
|
||||
export type UserTypingDTO = z.infer<typeof UserTypingDTOSchema>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { SessionStore } from 'src/app/store/session.service';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { err, ok } from 'neverthrow';
|
||||
|
||||
export const InstanceId = uuidv4();
|
||||
|
||||
@@ -50,9 +51,6 @@ export class MessageRepositoryService {
|
||||
|
||||
if(localActionResult.isOk()) {
|
||||
|
||||
(await this.sendTyping(data.roomId)).map((e) => {
|
||||
console.log('map', e)
|
||||
})
|
||||
const sendMessageResult = await this.messageLiveSignalRDataSourceService.sendMessage(data)
|
||||
|
||||
|
||||
@@ -79,6 +77,18 @@ export class MessageRepositoryService {
|
||||
}
|
||||
}
|
||||
|
||||
async sendReadAt({roomId}) {
|
||||
const result = await this.messageLocalDataSourceService.getLastMessageByRoomId(roomId)
|
||||
if(result.isOk()) {
|
||||
if(result.value) {
|
||||
|
||||
return await this.messageLiveSignalRDataSourceService.sendReadAt({roomId, memberId: SessionStore.user.UserId, chatMessageId: result.value.messageId})
|
||||
}
|
||||
return ok(true)
|
||||
}
|
||||
return err(false)
|
||||
}
|
||||
|
||||
async listAllMessagesByRoomId(id: string) {
|
||||
const result = await this.messageRemoteDataSourceService.getMessagesFromRoom(id)
|
||||
|
||||
@@ -105,7 +115,7 @@ export class MessageRepositoryService {
|
||||
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
|
||||
}
|
||||
|
||||
sendTyping(ChatRoomId) {
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({ChatRoomId, UserName:SessionStore.user.FullName})
|
||||
sendTyping(roomId) {
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user