mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
validate user permision on chat
This commit is contained in:
@@ -3,7 +3,7 @@ import { z } from "zod"
|
||||
export const UserTypingDTOSchema = z.object({
|
||||
requestId: z.string(),
|
||||
roomId: z.string(),
|
||||
userId: z.string(),
|
||||
userId: z.number(),
|
||||
userName: z.string()
|
||||
})
|
||||
export type UserTypingDTO = z.infer<typeof UserTypingDTOSchema>
|
||||
|
||||
@@ -3,11 +3,27 @@ import { SignalRService } from '../../../infra/socket/signal-r.service';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { z } from 'zod';
|
||||
import { SocketMessage } from '../../../infra/socket/signalR';
|
||||
import { RoomInputDTO } from '../../dto/room/roomInputDTO';
|
||||
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
const listenToDeleteRoomInputSchema = z.object({
|
||||
roomId: z.string()
|
||||
})
|
||||
|
||||
|
||||
export const RoomSocketOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any().nullable(),
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(),
|
||||
roomType: z.any()
|
||||
});
|
||||
|
||||
export type RoomSocketOutPutDTO = z.infer<typeof RoomSocketOutPutDTOSchema>
|
||||
|
||||
|
||||
export type ListenToDeleteRoomInput = z.infer<typeof listenToDeleteRoomInputSchema>
|
||||
|
||||
@Injectable({
|
||||
@@ -19,6 +35,19 @@ export class RoomSocketRepositoryService {
|
||||
private socket: SignalRService
|
||||
) { }
|
||||
|
||||
|
||||
async CreateGroup(data: RoomInputDTO) {
|
||||
const result = await this.socket.sendData<RoomSocketOutPutDTO>({
|
||||
method: 'CreateGroup',
|
||||
data: {
|
||||
...data,
|
||||
requestId: uuidv4()
|
||||
} as any,
|
||||
})
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
listenToCreateRoom() {
|
||||
return this.socket.getData().pipe(
|
||||
filter((data) => data?.method == 'UserAddGroup')
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { SocketMessage } from '../../../infra/socket/signalR';
|
||||
import { UserTypingDTO } from '../../dto/typing/typingInputDTO';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserTypingRemoteRepositoryService {
|
||||
|
||||
constructor(
|
||||
private socket: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(roomId: string) {
|
||||
return this.socket.sendData({
|
||||
method: 'Typing',
|
||||
data: {
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId,
|
||||
requestId: '',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
listenToTyping() {
|
||||
return this.socket.getData().pipe(
|
||||
filter((e) : e is SocketMessage<UserTypingDTO>=> e?.method == 'TypingMessage'
|
||||
),
|
||||
map((e)=> e.data)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
+11
-4
@@ -2,8 +2,8 @@ import { Injectable } from '@angular/core';
|
||||
import { z } from 'zod';
|
||||
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { chatDatabase } from '../../infra/database/dexie/service';
|
||||
import { TypingTable } from '../../infra/database/dexie/schema/typing';
|
||||
import { chatDatabase } from '../../../infra/database/dexie/service';
|
||||
import { TypingTable } from '../../../infra/database/dexie/schema/typing';
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export class UserTypingLocalRepository {
|
||||
|
||||
async addUserTyping(data: TypingTable) {
|
||||
|
||||
data.id = data.chatRoomId + '@' + data.userName
|
||||
data.id = data.roomId + '@' + data.userName
|
||||
try {
|
||||
const result = await chatDatabase.typing.add(data)
|
||||
return ok(result)
|
||||
@@ -39,7 +39,7 @@ export class UserTypingLocalRepository {
|
||||
|
||||
async removeUserTyping(data: TypingTable) {
|
||||
|
||||
const id = data.chatRoomId + '@' + data.userName
|
||||
const id = data.roomId + '@' + data.userName
|
||||
try {
|
||||
const result = await chatDatabase.typing.delete(id)
|
||||
return ok(result)
|
||||
@@ -53,4 +53,11 @@ export class UserTypingLocalRepository {
|
||||
return liveQuery(() => chatDatabase.typing.toArray());
|
||||
}
|
||||
|
||||
getUserTypingLiveByRoomId(roomId: string) {
|
||||
return liveQuery(() => chatDatabase.typing
|
||||
.where('roomId')
|
||||
.equals(roomId)
|
||||
.sortBy('id')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SignalRService } from '../../infra/socket/signal-r.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserTypingRemoteRepositoryService {
|
||||
|
||||
constructor(
|
||||
private socket: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.socket.sendData({
|
||||
method: 'Typing',
|
||||
data: {
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user