2026-09-30 10:40:29 +03:30
|
|
|
import { Body, Controller, Delete, Get, Post, Query, UseGuards } from '@nestjs/common';
|
2026-09-29 10:34:01 +03:30
|
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
|
|
|
import { RequireOrgModule } from '../billing/org-module.decorator';
|
|
|
|
|
import { OrgModuleGuard } from '../billing/org-module.guard';
|
|
|
|
|
import {
|
|
|
|
|
CreateConversationDmDto,
|
|
|
|
|
CreateConversationGroupDto,
|
2026-09-29 21:46:41 +03:30
|
|
|
HideConversationMessagesDto,
|
2026-09-30 10:40:29 +03:30
|
|
|
PinConversationMessageDto,
|
|
|
|
|
PinConversationRoomDto,
|
|
|
|
|
UnpinConversationMessageDto,
|
2026-09-29 10:34:01 +03:30
|
|
|
} from './dto';
|
|
|
|
|
import { ConversationsService } from './conversations.service';
|
|
|
|
|
|
|
|
|
|
@Controller('conversations')
|
|
|
|
|
@UseGuards(JwtAuthGuard, OrgModuleGuard)
|
|
|
|
|
@RequireOrgModule('conversations')
|
|
|
|
|
export class ConversationsController {
|
|
|
|
|
constructor(private readonly conversations: ConversationsService) {}
|
|
|
|
|
|
|
|
|
|
@Get('access')
|
|
|
|
|
access(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
|
|
|
|
return this.conversations.getAccess(user.userId, user.organizationId, user.role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('session')
|
|
|
|
|
session(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
|
|
|
|
return this.conversations.getSession(user.userId, user.organizationId, user.role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('peers')
|
|
|
|
|
peers(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
|
|
|
|
return this.conversations.listPeers(user.userId, user.organizationId, user.role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('rooms')
|
|
|
|
|
rooms(@CurrentUser() user: { userId: string; organizationId: string; role: string }) {
|
|
|
|
|
return this.conversations.listRooms(user.userId, user.organizationId, user.role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('rooms/dm')
|
|
|
|
|
createDm(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: CreateConversationDmDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.createDm(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.peerUserId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('rooms/group')
|
|
|
|
|
createGroup(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: CreateConversationGroupDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.createGroup(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.name,
|
|
|
|
|
dto.memberUserIds,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-29 21:46:41 +03:30
|
|
|
|
2026-09-30 10:40:29 +03:30
|
|
|
@Post('rooms/pin')
|
|
|
|
|
pinRoom(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: PinConversationRoomDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.setRoomPinned(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.externalRoomId,
|
|
|
|
|
dto.pinned,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-29 21:46:41 +03:30
|
|
|
@Post('messages/hide')
|
|
|
|
|
hideMessages(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: HideConversationMessagesDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.hideMessages(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.externalRoomId,
|
|
|
|
|
dto.messageIds,
|
2026-09-30 09:19:36 +03:30
|
|
|
dto.forEveryone !== false,
|
2026-09-29 21:46:41 +03:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('messages/hidden')
|
|
|
|
|
listHidden(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Query('externalRoomId') externalRoomId: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.listHiddenMessageIds(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
externalRoomId || '',
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-30 10:40:29 +03:30
|
|
|
|
|
|
|
|
@Get('messages/pin')
|
|
|
|
|
getPinnedMessage(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Query('externalRoomId') externalRoomId: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.getPinnedMessage(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
externalRoomId || '',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('messages/pin')
|
|
|
|
|
pinMessage(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: PinConversationMessageDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.pinMessage(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.externalRoomId,
|
|
|
|
|
dto.messageId,
|
|
|
|
|
dto.preview,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('messages/unpin')
|
|
|
|
|
unpinMessage(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Body() dto: UnpinConversationMessageDto,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.unpinMessage(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
dto.externalRoomId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Delete('messages/pin')
|
|
|
|
|
unpinMessageDelete(
|
|
|
|
|
@CurrentUser() user: { userId: string; organizationId: string; role: string },
|
|
|
|
|
@Query('externalRoomId') externalRoomId: string,
|
|
|
|
|
) {
|
|
|
|
|
return this.conversations.unpinMessage(
|
|
|
|
|
user.userId,
|
|
|
|
|
user.organizationId,
|
|
|
|
|
user.role,
|
|
|
|
|
externalRoomId || '',
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-09-29 10:34:01 +03:30
|
|
|
}
|