Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
refactor(summary): refactor code to get messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffael Di Pietro committed Dec 1, 2023
1 parent 868b43a commit 54180ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/meetings/meetings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export class MeetingsController {
}

@Get('testservice')
public testService(@Query('bubbleId') bubbleId: string): Promise<any[]> {
return this.meetingsService.getBubbleHistory(bubbleId);
public testService(@Query('bubbleId') meetingId: number): Promise<any[]> {

Check failure on line 64 in src/meetings/meetings.controller.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check failure on line 64 in src/meetings/meetings.controller.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.meetingsService.getMessages(meetingId);
}

@Get('attendees')
Expand Down
15 changes: 11 additions & 4 deletions src/meetings/meetings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RainbowService } from 'src/rainbow/rainbow.service';
import { Observable, Subject } from 'rxjs';
import { ApplicationEvent } from 'src/types/MeetingEvents';
import { Bubble } from 'rainbow-node-sdk/lib/common/models/Bubble';
import { Conversation } from 'rainbow-node-sdk/lib/common/models/Conversation';
import { Message } from 'src/types/message';

export type MeetingEvent =
| { type: 'bubbleCreated'; id: number; meeting: MeetingWithAttendees }
Expand Down Expand Up @@ -166,9 +166,16 @@ export class MeetingsService {
return meeting;
}

public async getBubbleHistory(bubbleId: string): Promise<Conversation[]> {
this.rainbow.getBubbleMessagesHistory(bubbleId);
return;
public async getMessages(meetingId: number): Promise<Message[]> {
// TODO: create function
const bubbleId = (
await this.database.meeting.findUnique({
where: {
id: meetingId,
},
})
).bubbleId;
return await this.rainbow.getBubbleMessages(bubbleId);
}

public async delete(id: number): Promise<Meeting> {
Expand Down
24 changes: 13 additions & 11 deletions src/rainbow/rainbow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { ApplicationEvent } from 'src/types/MeetingEvents';
import { ConversationsService } from 'rainbow-node-sdk/lib/services/ConversationsService';
import { ImsService } from 'rainbow-node-sdk/lib/services/ImsService';
import { Message } from 'rainbow-node-sdk/lib/common/models/Message';
import { Message } from 'src/types/message';

@Injectable()
export class RainbowService implements OnApplicationShutdown {
Expand Down Expand Up @@ -167,19 +167,21 @@ export class RainbowService implements OnApplicationShutdown {
return url;
}

public async getBubbleMessagesHistory(bubbleId: string): Promise<any[]> {
const convService = this.rainbowSDK.conversations as ConversationsService;
public async getBubbleMessages(bubbleId: string): Promise<Message[]> {
const conversationService = this.rainbowSDK
.conversations as ConversationsService;
const imService = this.rainbowSDK.im as ImsService;
const conversation = await convService.getConversationByBubbleId(bubbleId);
const conversation =
await conversationService.getConversationByBubbleId(bubbleId);
const conversationMessages =
await imService.getMessagesFromConversation(conversation);

const messages = conversationMessages.messages as Message[];

messages.map((message) => {
console.log('content', message.content);
console.log('from', message.from.displayName);
});
return;
return conversationMessages.messages.map(
(message) =>
({
content: message.content,
senderName: message.from.displayName,
}) as Message,
);
}
}
4 changes: 4 additions & 0 deletions src/types/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type Message = {
content: string;
senderName: string;
};

0 comments on commit 54180ed

Please sign in to comment.