From eb6ee3bdd2a62fd065bc279da3c87769e476f0f7 Mon Sep 17 00:00:00 2001 From: soomanbaek Date: Fri, 2 Dec 2022 18:18:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B1=84=EB=84=90=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EC=8B=9C=20=EB=B4=87=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/apps/api/src/channel/channel.module.ts | 13 ++++++++++++- server/apps/api/src/channel/channel.service.ts | 12 ++++++++++++ .../api/src/channel/helper/getChannelBasicInfo.ts | 1 + server/apps/api/src/chat-list/chat-list.module.ts | 5 +++-- server/utils/def.ts | 1 + 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/server/apps/api/src/channel/channel.module.ts b/server/apps/api/src/channel/channel.module.ts index cf8ffca2..088f5c5f 100644 --- a/server/apps/api/src/channel/channel.module.ts +++ b/server/apps/api/src/channel/channel.module.ts @@ -10,15 +10,26 @@ import { CommunityModule } from '@community/community.module'; import { UserRepository } from '@repository/user.repository'; import { UserModule } from '@user/user.module'; import { ChannelsController } from '@channel/channels.controller'; +import { ChatListModule } from '@chat-list/chat-list.module'; +import { ChatListService } from '@chat-list/chat-list.service'; +import { ChatListRespository } from '@repository/chat-list.respository'; @Module({ imports: [ MongooseModule.forFeature([{ name: Channel.name, schema: ChannelSchema }]), forwardRef(() => CommunityModule), UserModule, + forwardRef(() => ChatListModule), ], controllers: [ChannelController, ChannelsController], - providers: [ChannelService, ChannelRepository, CommunityRepository, UserRepository], + providers: [ + ChannelService, + ChannelRepository, + CommunityRepository, + UserRepository, + ChatListService, + ChatListRespository, + ], exports: [MongooseModule], }) export class ChannelModule {} diff --git a/server/apps/api/src/channel/channel.service.ts b/server/apps/api/src/channel/channel.service.ts index 9772fbb2..553dc9cb 100644 --- a/server/apps/api/src/channel/channel.service.ts +++ b/server/apps/api/src/channel/channel.service.ts @@ -13,6 +13,8 @@ import { import { ExitChannelDto } from '@channel/dto/exit-channel.dto'; import { getChannelBasicInfo, getChannelToUserForm } from '@channel/helper'; import { getUserBasicInfo } from '@user/helper/getUserBasicInfo'; +import { ChatListService } from '@chat-list/chat-list.service'; +import { BOT_ID } from '@utils/def'; @Injectable() export class ChannelService { @@ -20,6 +22,7 @@ export class ChannelService { private readonly channelRepository: ChannelRepository, private readonly communityRepository: CommunityRepository, private readonly userRepository: UserRepository, + private readonly chatListService: ChatListService, ) {} async createChannel(createChannelDto: CreateChannelDto) { @@ -42,6 +45,15 @@ export class ChannelService { // 공개 채널일 경우 : 채널 유저에 커뮤니티 사용자 모두 존재 await this.addUserToChannel(community._id, channel._id, community.users); } + const user = await this.userRepository.findById(managerId); + // TODO: 봇 메세지 content 수정 필요 + await this.chatListService.restoreMessage({ + channel_id: channel.id, + type: 'TEXT', + content: `${user.nickname}님이 이 채널을 ${new Date()}에 생성했습니다.`, + senderId: BOT_ID, + }); + return getChannelBasicInfo(channel); } diff --git a/server/apps/api/src/channel/helper/getChannelBasicInfo.ts b/server/apps/api/src/channel/helper/getChannelBasicInfo.ts index d435f3ee..067e2f35 100644 --- a/server/apps/api/src/channel/helper/getChannelBasicInfo.ts +++ b/server/apps/api/src/channel/helper/getChannelBasicInfo.ts @@ -10,5 +10,6 @@ export const getChannelBasicInfo = (channel) => { users: channel.users, createdAt: channel.createdAt, deletedAt: channel.deletedAt, + lastRead: channel.lastRead, }; }; diff --git a/server/apps/api/src/chat-list/chat-list.module.ts b/server/apps/api/src/chat-list/chat-list.module.ts index 81a25d42..e9506cae 100644 --- a/server/apps/api/src/chat-list/chat-list.module.ts +++ b/server/apps/api/src/chat-list/chat-list.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import { forwardRef, Module } from '@nestjs/common'; import { ChatListController } from '@chat-list/chat-list.controller'; import { ChatListService } from '@chat-list/chat-list.service'; import { ChatListRespository } from '@repository/chat-list.respository'; @@ -12,10 +12,11 @@ import { UserModule } from '@user/user.module'; @Module({ imports: [ MongooseModule.forFeature([{ name: ChatList.name, schema: ChatListSchema }]), - ChannelModule, + forwardRef(() => ChannelModule), UserModule, ], controllers: [ChatListController], providers: [ChatListService, ChatListRespository, ChannelRepository, UserRepository], + exports: [MongooseModule], }) export class ChatListModule {} diff --git a/server/utils/def.ts b/server/utils/def.ts index 6e187320..c42b55b9 100644 --- a/server/utils/def.ts +++ b/server/utils/def.ts @@ -2,3 +2,4 @@ export const STATUS = ['ONLINE', 'OFFLINE', 'AFK']; export const PROVIDER = ['ASNITY', 'GITHUB']; export const CHANNEL_TYPE = ['CHANNEL', 'DM']; export const CHAT_TYPE = ['TEXT', 'IMAGE']; +export const BOT_ID = '63888e5a55ab39cc98bfee3c';