Skip to content

Commit

Permalink
fix: 채널 생성 시 채널 입장과 동일한 response로 변경 #16
Browse files Browse the repository at this point in the history
  • Loading branch information
yubinquitous committed Dec 4, 2023
1 parent 8d482d4 commit 99d3681
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/channels/channels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ export class ChannelsService {
userId,
channelInfo.userId!,
);
// 이미 DM 채널이 존재한다면 해당 채널에 대한 정보를 반환한다.
if (channelId) {
// 이미 DM 채널이 존재하는 경우
return { channelId };
const channelUserInfoList =
await this.channelUsersRepository.findChannelUserInfoList(
userId,
channelId,
);
const myChannelUserType = channelUserInfoList.find(
(channelUser) => channelUser.userId === userId,
)?.channelUserType;
return { channelUser: channelUserInfoList, myChannelUserType };
}
}

Expand All @@ -61,6 +69,7 @@ export class ChannelsService {

let userCount = 1;

// DM 일 경우 상대방도 channelUsers에 추가
if (channel.channelType === ChannelType.DM) {
const targetChannelUser = this.channelUsersRepository.create({
channelId: channel.id,
Expand All @@ -73,13 +82,23 @@ export class ChannelsService {
++userCount;
}

// channelUserList 조회
const channelUserInfoList =
await this.channelUsersRepository.findChannelUserInfoList(
userId,
channel.id,
);

// TODO: 채널에 소환된 유저에게 알림 전송. DM의 경우에만 해당
// TODO: cache에 user count 저장
this.logger.log(
`channel ${channel.id} is created. user count: ${userCount}`,
);

return { channelId: channel.id };
return {
channelUser: channelUserInfoList,
myChannelUserType: ChannelUserType.OWNER,
};
}

async enterChannel(userId: number, channelId: number) {
Expand Down

0 comments on commit 99d3681

Please sign in to comment.