Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add my msg #61

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}