Skip to content

Commit

Permalink
Feat/add my msg (#61)
Browse files Browse the repository at this point in the history
* 채팅 가져오기 학생 오류 수정

* 채팅 가져오기 학생 오류 수정
  • Loading branch information
seongyunlee authored Sep 25, 2023
1 parent d12501e commit f4c6dbe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/chatting/chatting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export class ChattingService {
if (userInfo.role == 'student') {
const questions =
await this.questionRepository.getStudentPendingQuestions(userId);
const questionIds = [];
for (let i = 0; i < questions.count; i++) {
questionIds.push(questions[i].id);
}
chatLists.normalProposed = await this.groupNormalProposedForStudent(
chatLists.normalReserved,
questions.map((q) => q.id),
chatLists.normalProposed,
questionIds,
);
}

Expand Down Expand Up @@ -156,14 +160,20 @@ export class ChattingService {
id: roomInfo.id,
messages: roomInfo.messages.map((message) => {
const { body, ...rest } = message;
const isMyMsg = message.sender == userInfo.id;
try {
return { body: JSON.parse(body), ...rest };
return { body: JSON.parse(body), ...rest, isMyMsg: isMyMsg };
} catch (e) {
return { body: { text: body }, ...rest, format: 'text' };
return {
body: { text: body },
...rest,
isMyMsg: isMyMsg,
format: 'text',
};
}
}),
status: status,
roomImage: roomImage,
roomImage: opponentInfo.profileImage,
questionId: questionInfo.id,
schoolSubject: questionInfo.problem.schoolSubject,
schoolLevel: questionInfo.problem.schoolLevel,
Expand Down
10 changes: 9 additions & 1 deletion src/chatting/items/chat.list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Question } from '../../question/entities/question.interface';
import { Chatting, Message } from '../entities/chatting.interface';
import { Chatting } from '../entities/chatting.interface';
import { Item } from 'nestjs-dynamoose';

export interface ChatList {
Expand Down Expand Up @@ -35,3 +35,11 @@ export interface ChatRoom {
teachers?: ChatRoom[];
questionId: string;
}

export interface Message {
sender: string;
format: string;
body: string;
createdAt: string;
isMyMsg?: boolean;
}

0 comments on commit f4c6dbe

Please sign in to comment.