|
|
|
@ -1,6 +1,6 @@
@@ -1,6 +1,6 @@
|
|
|
|
|
import { Inject, Injectable } from '@nestjs/common' |
|
|
|
|
import * as _ from 'lodash' |
|
|
|
|
import { Chats, FilesStorage, WebSockets } from 'src/core' |
|
|
|
|
import { Chats, FilesStorage, Users, WebSockets } from 'src/core' |
|
|
|
|
import { |
|
|
|
|
CHATS_MEMBERS_SERVICE, |
|
|
|
|
CHATS_MESSAGES_SERVICE, |
|
|
|
@ -8,23 +8,24 @@ import {
@@ -8,23 +8,24 @@ import {
|
|
|
|
|
CHATS_SYSTEM_MESSAGES_SERVICE, |
|
|
|
|
GET_CHATS_LIST_ACTION, |
|
|
|
|
REAL_TIME_SERVICE, |
|
|
|
|
USERS_SERVICE, |
|
|
|
|
} from 'src/core/consts' |
|
|
|
|
import { IPagination } from 'src/core/interfaces' |
|
|
|
|
import { transformFileUrl } from 'src/shared/transforms' |
|
|
|
|
import { SetChatMutedDto, StoreGroupChatDto, StorePersonalChatDto, UpdateChatDto } from '../dto' |
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
|
|
export class AppChatsService { |
|
|
|
|
constructor( |
|
|
|
|
@Inject(CHATS_SERVICE) private readonly chatsService: Chats.IChatsService, |
|
|
|
|
@Inject(CHATS_MESSAGES_SERVICE) |
|
|
|
|
private readonly chatsMessagesService: Chats.IChatsMessagesService, |
|
|
|
|
@Inject(CHATS_SYSTEM_MESSAGES_SERVICE) |
|
|
|
|
private readonly chatsSystemMessagesService: Chats.IChatsSystemMessagesService, |
|
|
|
|
@Inject(CHATS_MEMBERS_SERVICE) |
|
|
|
|
private readonly chatsMembersService: Chats.IChatsMembersService, |
|
|
|
|
@Inject(REAL_TIME_SERVICE) private wsService: WebSockets.Service, |
|
|
|
|
@Inject(GET_CHATS_LIST_ACTION) private getChatsListAction: Chats.IGetChatsListAction, |
|
|
|
|
) {} |
|
|
|
|
@Inject(CHATS_SERVICE) private readonly chatsService: Chats.IChatsService |
|
|
|
|
@Inject(CHATS_MESSAGES_SERVICE) |
|
|
|
|
private readonly chatsMessagesService: Chats.IChatsMessagesService |
|
|
|
|
@Inject(CHATS_SYSTEM_MESSAGES_SERVICE) |
|
|
|
|
private readonly chatsSystemMessagesService: Chats.IChatsSystemMessagesService |
|
|
|
|
@Inject(CHATS_MEMBERS_SERVICE) |
|
|
|
|
private readonly chatsMembersService: Chats.IChatsMembersService |
|
|
|
|
@Inject(REAL_TIME_SERVICE) private wsService: WebSockets.Service |
|
|
|
|
@Inject(GET_CHATS_LIST_ACTION) private getChatsListAction: Chats.IGetChatsListAction |
|
|
|
|
@Inject(USERS_SERVICE) private readonly usersService: Users.IUsersService |
|
|
|
|
|
|
|
|
|
public async storeGroupChat( |
|
|
|
|
userId: number, |
|
|
|
@ -103,6 +104,24 @@ export class AppChatsService {
@@ -103,6 +104,24 @@ export class AppChatsService {
|
|
|
|
|
chatUsersIds.map(it => this.wsService.emitToUser(it, 'chat/delete-chat', { chatId })) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async getUsersForChat(pagination: IPagination) { |
|
|
|
|
const { items, count } = await this.usersService.getList(pagination, {}) |
|
|
|
|
|
|
|
|
|
const reducedUsers = items.map(user => { |
|
|
|
|
const reducedUser = _.pick(user.info, ['userId', 'firstName', 'middleName', 'lastName']) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
...reducedUser, |
|
|
|
|
avatarUrl: transformFileUrl(user.info.avatarUrl), |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
items: reducedUsers, |
|
|
|
|
count, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async restoreMemberIfDeleted(userId: number, members: Chats.IChatMember[]) { |
|
|
|
|
const member = _.find(members, member => member.userId === userId) |
|
|
|
|
if (!member.isDeleted) return |
|
|
|
|