family update

This commit is contained in:
lendry
2026-06-24 23:17:24 +03:00
parent 9727cf3f35
commit f2366a69a0
18 changed files with 1374 additions and 103 deletions

View File

@@ -1,4 +1,4 @@
import { Body, Controller, Get, Headers, Param, Patch, Post, Query } from '@nestjs/common';
import { Body, Controller, Delete, Get, Headers, Param, Patch, Post, Query } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { firstValueFrom } from 'rxjs';
@@ -6,7 +6,10 @@ import { map } from 'rxjs/operators';
import { CoreGrpcService } from '../core-grpc.service';
import { getAuthorizedUserId } from '../document-access';
import {
AddChatRoomMemberDto,
CreateChatRoomDto,
EditChatMessageDto,
MarkRoomReadDto,
SendChatMessageDto,
SetRoomNotificationsMutedDto,
UpdateChatRoomDto,
@@ -71,6 +74,28 @@ export class ChatController {
);
}
@Post('rooms/:roomId/members')
@ApiOperation({ summary: 'Добавить участника в чат' })
async addMember(
@Headers('authorization') authorization: string | undefined,
@Param('roomId') roomId: string,
@Body() dto: AddChatRoomMemberDto
) {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.chat.AddRoomMember({ userId, roomId, memberUserId: dto.memberUserId }));
}
@Delete('rooms/:roomId/members/:memberUserId')
@ApiOperation({ summary: 'Удалить участника из чата' })
async removeMember(
@Headers('authorization') authorization: string | undefined,
@Param('roomId') roomId: string,
@Param('memberUserId') memberUserId: string
) {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.chat.RemoveRoomMember({ userId, roomId, memberUserId }));
}
@Get('rooms/:roomId/messages')
@ApiOperation({ summary: 'Сообщения чата' })
async listMessages(
@@ -139,4 +164,35 @@ export class ChatController {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.chat.SetRoomNotificationsMuted({ userId, roomId, muted: dto.muted }));
}
@Patch('messages/:messageId')
@ApiOperation({ summary: 'Редактировать сообщение' })
async editMessage(
@Headers('authorization') authorization: string | undefined,
@Param('messageId') messageId: string,
@Body() dto: EditChatMessageDto
) {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.chat.EditMessage({ userId, messageId, content: dto.content }));
}
@Delete('messages/:messageId')
@ApiOperation({ summary: 'Удалить сообщение' })
async deleteMessage(@Headers('authorization') authorization: string | undefined, @Param('messageId') messageId: string) {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.chat.DeleteMessage({ userId, messageId }));
}
@Post('rooms/:roomId/read')
@ApiOperation({ summary: 'Отметить сообщения чата прочитанными' })
async markRoomRead(
@Headers('authorization') authorization: string | undefined,
@Param('roomId') roomId: string,
@Body() dto: MarkRoomReadDto
) {
const userId = await this.auth(authorization);
return firstValueFrom(
this.core.chat.MarkRoomRead({ userId, roomId, lastMessageId: dto.lastMessageId })
);
}
}

View File

@@ -144,5 +144,12 @@ export class FamilyController {
const userId = await this.auth(authorization);
return firstValueFrom(this.core.family.RespondFamilyInvite({ userId, inviteId, accept: dto.accept }));
}
@Get('groups/:groupId/presence')
@ApiOperation({ summary: 'Онлайн-статус участников семьи' })
async getPresence(@Headers('authorization') authorization: string | undefined, @Param('groupId') groupId: string) {
const requesterId = await this.auth(authorization);
return firstValueFrom(this.core.family.GetFamilyPresence({ requesterId, groupId }));
}
}

View File

@@ -256,4 +256,37 @@ export class MediaController {
this.core.media.GetChatMediaAccessUrl({ requesterId, roomId, storageKey, fileName })
);
}
@Post('chat/:roomId/avatar/upload-url')
@ApiBearerAuth()
async createChatRoomAvatarUploadUrl(
@Headers('authorization') authorization: string | undefined,
@Param('roomId') roomId: string,
@Body() dto: AvatarUploadDto
) {
const requesterId = await this.authUserId(authorization);
return firstValueFrom(
this.core.media.CreateChatRoomAvatarUploadUrl({ requesterId, roomId, contentType: dto.contentType })
);
}
@Post('chat/:roomId/avatar/confirm')
@ApiBearerAuth()
async confirmChatRoomAvatar(
@Headers('authorization') authorization: string | undefined,
@Param('roomId') roomId: string,
@Body() dto: ConfirmAvatarDto
) {
const requesterId = await this.authUserId(authorization);
return firstValueFrom(
this.core.media.ConfirmChatRoomAvatar({ requesterId, roomId, storageKey: dto.storageKey })
);
}
@Get('chat/:roomId/avatar/url')
@ApiBearerAuth()
async getChatRoomAvatarUrl(@Headers('authorization') authorization: string | undefined, @Param('roomId') roomId: string) {
const requesterId = await this.authUserId(authorization);
return firstValueFrom(this.core.media.GetChatRoomAvatarAccessUrl({ requesterId, roomId }));
}
}

View File

@@ -66,3 +66,20 @@ export class SetRoomNotificationsMutedDto {
@IsBoolean()
muted!: boolean;
}
export class AddChatRoomMemberDto {
@IsString()
memberUserId!: string;
}
export class EditChatMessageDto {
@IsString()
@MinLength(1)
content!: string;
}
export class MarkRoomReadDto {
@IsOptional()
@IsString()
lastMessageId?: string;
}