added p2pinvite event and added group update
This commit is contained in:
parent
bc7b4cd272
commit
b885159784
@ -158,6 +158,8 @@ export class ChatGateway
|
|||||||
//verify memebership, store chat and return event's data
|
//verify memebership, store chat and return event's data
|
||||||
const data = await this.chatService.handleRoomMessage(body, sender);
|
const data = await this.chatService.handleRoomMessage(body, sender);
|
||||||
|
|
||||||
|
if(!data) return;
|
||||||
|
|
||||||
// send everone in the room(including the sender)
|
// send everone in the room(including the sender)
|
||||||
this.server.to(body.roomId).emit('roomMessage', data);
|
this.server.to(body.roomId).emit('roomMessage', data);
|
||||||
}
|
}
|
||||||
@ -169,6 +171,6 @@ export class ChatGateway
|
|||||||
@ConnectedSocket() client: Socket,
|
@ConnectedSocket() client: Socket,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return this.chatService.handleStartP2P(body.targetUserId, client);
|
return this.chatService.handleStartP2P(body.targetUserId, client, this.server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { ConversationsService } from './../conversations/conversations.service';
|
|||||||
import { MessagesService } from './../messages/messages.service';
|
import { MessagesService } from './../messages/messages.service';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { RoomMessageDto } from './dto/room-message.dto';
|
import { RoomMessageDto } from './dto/room-message.dto';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket, Server } from 'socket.io';
|
||||||
import { ConversationType } from 'src/conversations/schemas/conversation.schema';
|
import { ConversationType } from 'src/conversations/schemas/conversation.schema';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -38,7 +38,7 @@ export class ChatService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleStartP2P(targetUserId: string, client: Socket) {
|
async handleStartP2P(targetUserId: string, client: Socket, server:Server) {
|
||||||
const senderId = client.data.user.id;
|
const senderId = client.data.user.id;
|
||||||
|
|
||||||
if (senderId === targetUserId) {
|
if (senderId === targetUserId) {
|
||||||
@ -67,8 +67,19 @@ export class ChatService {
|
|||||||
message: `P2P room ready`,
|
message: `P2P room ready`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// find target user's socket and notify him/her
|
||||||
|
const targetSockets=await server.in('/chat').fetchSockets();
|
||||||
|
const targetSocket=targetSockets.find(s=>s.data.user?.id===targetUserId)
|
||||||
|
if(targetSocket){
|
||||||
|
targetSocket.join(roomId);
|
||||||
|
targetSocket.emit("p2pInvite",{
|
||||||
|
roomId,
|
||||||
|
fromUserId:senderId,
|
||||||
|
message: 'You have been added to a P2P conversation',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return { roomId };
|
return { roomId };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,19 @@ import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/commo
|
|||||||
import { ConversationsService } from './conversations.service';
|
import { ConversationsService } from './conversations.service';
|
||||||
import { CreateConversationDto } from './dto/create-conversation.dto';
|
import { CreateConversationDto } from './dto/create-conversation.dto';
|
||||||
import { UpdateConversationDto } from './dto/update-conversation.dto';
|
import { UpdateConversationDto } from './dto/update-conversation.dto';
|
||||||
|
import { ApiOperation } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('conversations')
|
@Controller('conversations')
|
||||||
export class ConversationsController {
|
export class ConversationsController {
|
||||||
constructor(private readonly conversationsService: ConversationsService) {}
|
constructor(private readonly conversationsService: ConversationsService) {}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: 'Create a conversation'})
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() createConversationDto: CreateConversationDto) {
|
async create(@Body() createConversationDto: CreateConversationDto) {
|
||||||
return await this.conversationsService.create(createConversationDto);
|
return await this.conversationsService.create(createConversationDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation({ summary: 'Get all conversations' })
|
||||||
@Get()
|
@Get()
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return await this.conversationsService.findAll();
|
return await this.conversationsService.findAll();
|
||||||
@ -24,7 +27,7 @@ export class ConversationsController {
|
|||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateConversationDto: UpdateConversationDto) {
|
update(@Param('id') id: string, @Body() updateConversationDto: UpdateConversationDto) {
|
||||||
return this.conversationsService.update(+id, updateConversationDto);
|
return this.conversationsService.update(id, updateConversationDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
|||||||
@ -31,8 +31,12 @@ export class ConversationsService {
|
|||||||
// return `This action returns a #${id} conversation`;
|
// return `This action returns a #${id} conversation`;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
update(id: number, updateConversationDto: UpdateConversationDto) {
|
async update(id: string, updateConversationDto: UpdateConversationDto) {
|
||||||
return `This action updates a #${id} conversation`;
|
await this.conversationModel.findByIdAndUpdate(
|
||||||
|
{_id:id},
|
||||||
|
updateConversationDto,
|
||||||
|
{new:true}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
remove(id: number) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user