Миграции, сборка
This commit is contained in:
@@ -79,13 +79,13 @@ public sealed class AdminEndpoints : ICarterModule
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.NotFound("User not found");
|
||||
});
|
||||
|
||||
group.MapGet("clean/dry-run", async (IFileStorageService fileStorage, AuthDbContext identityDb, ISender sender, CancellationToken ct) =>
|
||||
group.MapGet("clean/dry-run", async ([FromServices] IFileStorageService fileStorage, [FromServices] AuthDbContext identityDb, ISender sender, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new CleanDryRunQuery(fileStorage, identityDb), ct);
|
||||
return Results.Ok(result.Value);
|
||||
});
|
||||
|
||||
group.MapPost("clean/run", async (IFileStorageService fileStorage, AuthDbContext identityDb, ISender sender, CancellationToken ct) =>
|
||||
group.MapPost("clean/run", async ([FromServices] IFileStorageService fileStorage, [FromServices] AuthDbContext identityDb, ISender sender, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new CleanRunCommand(fileStorage, identityDb), ct);
|
||||
return Results.Ok(result.Value);
|
||||
|
||||
92
backend/src/Modules/Auth/Migrations/20270327140400_AddUserExtendedFields.Designer.cs
generated
Normal file
92
backend/src/Modules/Auth/Migrations/20270327140400_AddUserExtendedFields.Designer.cs
generated
Normal file
@@ -0,0 +1,92 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
using Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Knot.Modules.Auth.Migrations
|
||||
{
|
||||
[DbContext(typeof(AuthDbContext))]
|
||||
[Migration("20270327140400_AddUserExtendedFields")]
|
||||
partial class AddUserExtendedFields
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasDefaultSchema("identity")
|
||||
.HasAnnotation("ProductVersion", "10.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Knot.Modules.Auth.Domain.User", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<string>("Avatar")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Bio")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("Birthday")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Domain")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("HideStatus")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("HideStoryViews")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsExternal")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsOnline")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime?>("LastSeen")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users", "identity");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Knot.Modules.Auth.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddUserExtendedFields : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsExternal",
|
||||
schema: "identity",
|
||||
table: "Users",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Domain",
|
||||
schema: "identity",
|
||||
table: "Users",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsOnline",
|
||||
schema: "identity",
|
||||
table: "Users",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastSeen",
|
||||
schema: "identity",
|
||||
table: "Users",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "HideStatus",
|
||||
schema: "identity",
|
||||
table: "Users",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsExternal",
|
||||
schema: "identity",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Domain",
|
||||
schema: "identity",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsOnline",
|
||||
schema: "identity",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LastSeen",
|
||||
schema: "identity",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HideStatus",
|
||||
schema: "identity",
|
||||
table: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -45,12 +45,27 @@ namespace Knot.Modules.Auth.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Domain")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("HideStatus")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("HideStoryViews")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsExternal")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsOnline")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime?>("LastSeen")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
@@ -41,7 +41,7 @@ public sealed class FederationEndpoints : ICarterModule
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.NotFound(new { error = result.Error.Description });
|
||||
});
|
||||
|
||||
group.MapGet("/proxy/{id}", async (string id, [FromHeader(Name = "X-Knot-Signature")] string signature, [FromHeader(Name = "X-Knot-Domain")] string senderDomain, IFileStorageService storage, ISettingsService settingsService, CancellationToken ct) =>
|
||||
group.MapGet("/proxy/{id}", async (string id, [FromHeader(Name = "X-Knot-Signature")] string signature, [FromHeader(Name = "X-Knot-Domain")] string senderDomain, [FromServices] IFileStorageService storage, [FromServices] ISettingsService settingsService, CancellationToken ct) =>
|
||||
{
|
||||
// 1. Валидация подписи (упрощенно)
|
||||
var settings = await settingsService.GetSettingsAsync(ct);
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для хранения аватаров в S3 (MinIO).
|
||||
/// Отдельный от IFileStorageService модуля Storage,
|
||||
/// чтобы не создавать прямой зависимости на Storage модуль.
|
||||
/// </summary>
|
||||
public interface IAvatarStorageService
|
||||
{
|
||||
/// <summary>
|
||||
/// Загружает файл в S3-бакет аватаров и возвращает fileId (ключ объекта).
|
||||
/// </summary>
|
||||
Task<string> UploadAsync(System.IO.Stream stream, string fileName, string contentType, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Удаляет файл аватара из S3 по fileId.
|
||||
/// </summary>
|
||||
Task DeleteAsync(string fileId, CancellationToken ct = default);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
namespace Knot.Modules.Profiles.Application.Abstractions;
|
||||
|
||||
public interface IProfilesDbContext
|
||||
{
|
||||
DbSet<Profile> Profiles { get; }
|
||||
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
@@ -34,10 +34,10 @@ internal sealed class CropAvatarCommandHandler : ICommandHandler<CropAvatarComma
|
||||
if (profile is null)
|
||||
return Result.Failure<UserProfileDto>(ProfilesErrors.ProfileNotFound);
|
||||
|
||||
// Обрезать и ресайзнуть изображение до 400×400
|
||||
// Обрезать и ресайзнуть изображение до 400×400
|
||||
using var ms = await CropAndResizeAsync(request, cancellationToken);
|
||||
|
||||
// Удалить старый аватар из S3
|
||||
// Удалить старый аватар из S3
|
||||
if (!string.IsNullOrEmpty(profile.AvatarUrl))
|
||||
await _avatarStorage.DeleteAsync(profile.AvatarUrl, cancellationToken);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Profiles.Avatar;
|
||||
|
||||
// ─── Upload ────────────────────────────────────────────────────────────────
|
||||
// в”Ђв”Ђв”Ђ Upload в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
||||
|
||||
public sealed record UploadAvatarCommand(
|
||||
Guid UserId,
|
||||
@@ -33,7 +33,7 @@ internal sealed class UploadAvatarCommandHandler : ICommandHandler<UploadAvatarC
|
||||
if (profile is null)
|
||||
return Result.Failure<UserProfileDto>(ProfilesErrors.ProfileNotFound);
|
||||
|
||||
// Удалить старый аватар из S3, если был
|
||||
// Удалить старый аватар из S3, если был
|
||||
if (!string.IsNullOrEmpty(profile.AvatarUrl))
|
||||
await _avatarStorage.DeleteAsync(profile.AvatarUrl, cancellationToken);
|
||||
|
||||
@@ -47,7 +47,7 @@ internal sealed class UploadAvatarCommandHandler : ICommandHandler<UploadAvatarC
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Delete ────────────────────────────────────────────────────────────────
|
||||
// в”Ђв”Ђв”Ђ Delete в”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђв”Ђ
|
||||
|
||||
public sealed record DeleteAvatarCommand(Guid UserId) : ICommand<UserProfileDto>;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
using MediatR;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Shared.Kernel.Events;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Profiles.Integration;
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик события из модуля Auth.
|
||||
/// Создаёт пустой профиль при регистрации пользователя.
|
||||
/// Обработчик события из модуля Auth.
|
||||
/// Создаёт пустой профиль при регистрации пользователя.
|
||||
/// </summary>
|
||||
public class UserRegisteredDomainEventHandler : INotificationHandler<UserRegisteredDomainEvent>
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Abstractions;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Application.Profiles.DTOs;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Modules.Profiles.Infrastructure.Database;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Knot.Modules.Profiles;
|
||||
|
||||
public static class DependencyInjection
|
||||
@@ -11,10 +17,11 @@ public static class DependencyInjection
|
||||
// MongoDB Registration
|
||||
var mongoConnection = configuration.GetConnectionString("MongoConnection")
|
||||
?? configuration["MONGO_URL"]
|
||||
?? "mongodb://localhost:27017";
|
||||
?? "mongodb://mongo:27017";
|
||||
|
||||
var mongoClient = new MongoClient(mongoConnection);
|
||||
var database = mongoClient.GetDatabase("knot_messager");
|
||||
var databaseName = new MongoUrl(mongoConnection).DatabaseName ?? "knot_messager";
|
||||
var database = mongoClient.GetDatabase(databaseName);
|
||||
services.AddSingleton<IMongoDatabase>(database);
|
||||
|
||||
services.AddMediatR(config =>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace Knot.Modules.Profiles.Domain.Events;
|
||||
namespace Knot.Modules.Profiles.Domain.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Профиль пользователя создан.
|
||||
/// Профиль пользователя создан.
|
||||
/// </summary>
|
||||
public record ProfileCreatedDomainEvent(Guid ProfileId) : IDomainEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Профиль пользователя обновлен.
|
||||
/// Профиль пользователя обновлен.
|
||||
/// </summary>
|
||||
public record ProfileUpdatedDomainEvent(Guid ProfileId) : IDomainEvent;
|
||||
|
||||
11
backend/src/Modules/Profiles/Domain/IAvatarStorageService.cs
Normal file
11
backend/src/Modules/Profiles/Domain/IAvatarStorageService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
public interface IAvatarStorageService
|
||||
{
|
||||
Task<string> UploadAsync(Stream content, string fileName, string contentType, CancellationToken ct = default);
|
||||
Task DeleteAsync(string fileId, CancellationToken ct = default);
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
namespace Knot.Modules.Profiles.Application.Abstractions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
public interface IProfileRepository
|
||||
{
|
||||
Task<ProfileDocument?> GetByIdAsync(Guid userId, CancellationToken ct = default);
|
||||
Task<ProfileDocument?> GetByIdAsync(Guid id, CancellationToken ct = default);
|
||||
Task<ProfileDocument?> GetByUsernameAsync(string username, CancellationToken ct = default);
|
||||
Task AddAsync(ProfileDocument profile, CancellationToken ct = default);
|
||||
Task UpdateAsync(ProfileDocument profile, CancellationToken ct = default);
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Knot.Modules.Profiles.Application.Abstractions;
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
public interface IProfilesUnitOfWork
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
public sealed class Profile : AggregateRoot<Guid>
|
||||
{
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// MongoDB-документ профиля пользователя.
|
||||
/// Id совпадает с UserId из модуля Auth (Postgres).
|
||||
/// MongoDB-документ профиля пользователя.
|
||||
/// Id совпадает с UserId из модуля Auth (Postgres).
|
||||
/// </summary>
|
||||
public sealed class ProfileDocument
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
namespace Knot.Modules.Profiles.Domain;
|
||||
using Knot.Shared.Kernel;
|
||||
public static class ProfilesErrors
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
global using Knot.Shared.Kernel;
|
||||
global using Knot.Shared.Kernel.Events;
|
||||
global using Knot.Shared.Kernel.Storage;
|
||||
global using Knot.Modules.Profiles.Application.Abstractions;
|
||||
global using Knot.Modules.Profiles.Domain;
|
||||
global using Knot.Modules.Profiles.Domain.Events;
|
||||
global using Knot.Modules.Profiles.Infrastructure.Database;
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using Knot.Shared.Kernel.Storage;
|
||||
|
||||
namespace Knot.Modules.Profiles.Infrastructure.Database;
|
||||
|
||||
public class AvatarStorageService : IAvatarStorageService
|
||||
@@ -11,13 +17,13 @@ public class AvatarStorageService : IAvatarStorageService
|
||||
|
||||
public async Task<string> UploadAsync(Stream content, string fileName, string contentType, CancellationToken ct = default)
|
||||
{
|
||||
// IFileStorageService не принимает CancellationToken в UploadFileAsync
|
||||
// IFileStorageService не принимает CancellationToken в UploadFileAsync
|
||||
return await _fileStorage.UploadFileAsync(content, fileName, contentType);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string fileId, CancellationToken ct = default)
|
||||
{
|
||||
// IFileStorageService не принимает CancellationToken в DeleteFileAsync
|
||||
// IFileStorageService не принимает CancellationToken в DeleteFileAsync
|
||||
await _fileStorage.DeleteFileAsync(fileId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Knot.Modules.Profiles.Infrastructure.Database;
|
||||
|
||||
public class ProfileRepository : IProfileRepository
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Knot.Modules.Profiles.Domain;
|
||||
|
||||
namespace Knot.Modules.Profiles.Infrastructure.Database;
|
||||
|
||||
public class ProfilesUnitOfWork : IProfilesUnitOfWork
|
||||
{
|
||||
// MongoDB не поддерживает транзакции без репликации в простом виде,
|
||||
// поэтому UnitOfWork здесь формальный для соответствия интерфейсу.
|
||||
public Task SaveChangesAsync(CancellationToken ct = default) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Carter;
|
||||
using Carter;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Modules.Profiles.Application.Profiles.Avatar;
|
||||
using Knot.Modules.Profiles.Application.Profiles.GetProfile;
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed class FilesEndpoints : ICarterModule
|
||||
{
|
||||
var group = app.MapGroup("api/files");
|
||||
|
||||
group.MapGet("{id}", async (string id, [FromQuery] bool download, IFileStorageService fileStorage, IMemoryCache cache, CancellationToken ct) =>
|
||||
group.MapGet("{id}", async (string id, [FromQuery] bool download, [FromServices] IFileStorageService fileStorage, [FromServices] IMemoryCache cache, CancellationToken ct) =>
|
||||
{
|
||||
// (Текущая логика локальных файлов остается без изменений)
|
||||
try
|
||||
|
||||
@@ -95,7 +95,14 @@ export interface Message {
|
||||
isDeleted?: boolean;
|
||||
quote?: string | null;
|
||||
media?: MediaItem[];
|
||||
sender: { id: string; username: string; displayName: string };
|
||||
sender: {
|
||||
id: string;
|
||||
username: string;
|
||||
userName?: string;
|
||||
displayName: string;
|
||||
avatar?: string | null;
|
||||
avatarUrl?: string | null;
|
||||
};
|
||||
} | null;
|
||||
forwardedFrom?: UserBasic | null;
|
||||
media: MediaItem[];
|
||||
|
||||
@@ -135,7 +135,7 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
||||
onClose();
|
||||
};
|
||||
|
||||
const initials = (user?.displayName || user?.username || '??')
|
||||
const initials = (user?.displayName || user?.userName || user?.username || '??')
|
||||
.split(' ')
|
||||
.map((w: string) => w[0])
|
||||
.join('')
|
||||
@@ -193,11 +193,11 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
||||
</div>
|
||||
{/* Name & username */}
|
||||
<h3 className="text-xl font-bold text-transparent bg-clip-text bg-gradient-to-b from-white to-white/70 tracking-tight leading-tight">
|
||||
{user?.displayName || user?.username}
|
||||
{user?.displayName || user?.userName || user?.username || ''}
|
||||
</h3>
|
||||
<div className="flex items-center gap-1.5 mt-1.5">
|
||||
<AtSign size={12} className="text-knot-400" />
|
||||
<span className="text-sm font-medium text-knot-100/70">{user?.username}</span>
|
||||
<span className="text-sm font-medium text-knot-100/70">{user?.userName || user?.username || ''}</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* Bottom fade line */}
|
||||
@@ -526,8 +526,8 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-white truncate">{u.displayName || u.username}</p>
|
||||
<p className="text-xs text-zinc-500">@{u.username}</p>
|
||||
<p className="text-sm font-medium text-white truncate">{u.displayName || u.userName || u.username || ''}</p>
|
||||
<p className="text-xs text-zinc-500">@{u.userName || u.username || ''}</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => handleSendFriendRequest(u.id)}
|
||||
@@ -561,8 +561,8 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-white truncate">{req.user.displayName || req.user.username}</p>
|
||||
<p className="text-xs text-zinc-500">@{req.user.username}</p>
|
||||
<p className="text-sm font-medium text-white truncate">{req.user.displayName || req.user.userName || req.user.username || ''}</p>
|
||||
<p className="text-xs text-zinc-500">@{req.user.userName || req.user.username || ''}</p>
|
||||
</div>
|
||||
<div className="flex gap-1.5">
|
||||
<button
|
||||
@@ -610,9 +610,9 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm font-medium text-white truncate">{friend.displayName || friend.username}</p>
|
||||
<p className="text-sm font-medium text-white truncate">{friend.displayName || friend.userName || friend.username || ''}</p>
|
||||
<p className="text-xs text-zinc-500">
|
||||
{friend.isOnline ? t('online') : `@${friend.username}`}
|
||||
{friend.isOnline ? t('online') : `@${friend.userName || friend.username || ''}`}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
|
||||
@@ -74,7 +74,7 @@ export default function Sidebar() {
|
||||
(m) =>
|
||||
m.user.id !== user?.id &&
|
||||
((m.user.username || m.user.userName || '').toLowerCase().includes(q) ||
|
||||
m.user.displayName.toLowerCase().includes(q))
|
||||
(m.user.displayName || '').toLowerCase().includes(q))
|
||||
);
|
||||
}).sort((a, b) => {
|
||||
// 1. Favorites chat always on top
|
||||
@@ -82,8 +82,8 @@ export default function Sidebar() {
|
||||
if (b.type === 'favorites') return 1;
|
||||
|
||||
// 2. Pinned chats next
|
||||
const aPinned = a.members.find(m => m.user.id === user?.id)?.isPinned;
|
||||
const bPinned = b.members.find(m => m.user.id === user?.id)?.isPinned;
|
||||
const aPinned = a.members.find(m => m.user.id === user?.id)?.isPinned ?? false;
|
||||
const bPinned = b.members.find(m => m.user.id === user?.id)?.isPinned ?? false;
|
||||
if (aPinned && !bPinned) return -1;
|
||||
if (!aPinned && bPinned) return 1;
|
||||
|
||||
@@ -182,13 +182,13 @@ export default function Sidebar() {
|
||||
<div className="w-[44px] h-[44px] rounded-full flex items-center justify-center overflow-hidden">
|
||||
<Avatar
|
||||
src={avatarUrl}
|
||||
name={group.user.displayName || group.user.username}
|
||||
name={group.user.displayName || group.user.userName || group.user.username || '?'}
|
||||
size="md"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<span className="text-[11px] text-zinc-400 truncate w-full text-center">
|
||||
{isMine ? t('myStory') : (group.user.displayName || group.user.userName || group.user.username || '').split(' ')[0]}
|
||||
{isMine ? t('myStory') : (group.user.displayName || group.user.userName || group.user.username || '?').split(' ')[0]}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
@@ -218,7 +218,7 @@ export default function Sidebar() {
|
||||
{showNewChat && <NewChatModal onClose={() => setShowNewChat(false)} />}
|
||||
</AnimatePresence>
|
||||
<AnimatePresence>
|
||||
{showProfile && <UserProfile userId={user!.id} onClose={() => setShowProfile(false)} isSelf />}
|
||||
{showProfile && user && <UserProfile userId={user.id} onClose={() => setShowProfile(false)} isSelf />}
|
||||
</AnimatePresence>
|
||||
<SideMenu
|
||||
isOpen={showSideMenu}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { Settings, Shield, Activity, Users, Database, Globe, Search, Trash2, Plus, Download, Upload, Loader2, User, CheckCircle, XCircle } from 'lucide-react';
|
||||
import { httpClient } from '../../../core/infrastructure/httpClient';
|
||||
import { deepNormalize } from '../../../core/utils/normalize';
|
||||
import { httpClient } from '../../../../core/infrastructure/httpClient';
|
||||
import { deepNormalize } from '../../../../core/utils/normalize';
|
||||
|
||||
interface Stats {
|
||||
storageUsedBytes: number;
|
||||
@@ -894,47 +894,47 @@ export default function AdminPage() {
|
||||
{isSearching && <Loader2 className="absolute right-4 top-1/2 -translate-y-1/2 text-accent w-5 h-5 animate-spin" />}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 auto-rows-max">
|
||||
{users.length === 0 && !isSearching && (
|
||||
<div className="col-span-full text-center py-20 text-gray-500">
|
||||
{t.noUsersFound}
|
||||
</div>
|
||||
)}
|
||||
{users.map(u => (
|
||||
<div key={u.id} className="bg-surface border border-white/10 p-5 rounded-2xl flex items-center gap-4 hover:border-accent/50 transition-colors cursor-pointer" onClick={() => fetchUserDetails(u.id)}>
|
||||
{u.avatar ? (
|
||||
<img src={u.avatar} alt="avatar" className="w-14 h-14 rounded-full object-cover border border-white/10" />
|
||||
) : (
|
||||
<div className="w-14 h-14 rounded-full bg-white/10 flex items-center justify-center border border-white/5">
|
||||
<User className="text-gray-400 w-6 h-6" />
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 auto-rows-max">
|
||||
{users.length === 0 && !isSearching && (
|
||||
<div className="col-span-full text-center py-20 text-gray-500">
|
||||
{t.noUsersFound}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-semibold text-white truncate">{u.displayName}</h4>
|
||||
<div className="text-sm text-gray-400 truncate">@{u.username}</div>
|
||||
</div>
|
||||
{users.map(u => (
|
||||
<div key={u.id} className="bg-surface border border-white/10 p-5 rounded-2xl flex items-center gap-4 hover:border-accent/50 transition-colors cursor-pointer" onClick={() => fetchUserDetails(u.id)}>
|
||||
{u.avatarUrl || u.avatar ? (
|
||||
<img src={u.avatarUrl || u.avatar || undefined} alt="avatar" className="w-14 h-14 rounded-full object-cover border border-white/10" />
|
||||
) : (
|
||||
<div className="w-14 h-14 rounded-full bg-white/10 flex items-center justify-center border border-white/5">
|
||||
<User className="text-gray-400 w-6 h-6" />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-semibold text-white truncate">{u.displayName || u.userName || u.username || ''}</h4>
|
||||
<div className="text-sm text-gray-400 truncate">@{u.userName || u.username || ''}</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<motion.div initial={{ opacity: 0, scale: 0.95 }} animate={{ opacity: 1, scale: 1 }} className="flex flex-col gap-6 max-w-2xl">
|
||||
<button onClick={() => setSelectedUser(null)} className="text-accent hover:underline self-start flex items-center gap-2">
|
||||
← {t.backToList}
|
||||
</button>
|
||||
|
||||
<div className="bg-surface border border-white/10 rounded-2xl p-8 flex flex-col items-center relative overflow-hidden">
|
||||
<div className="absolute top-0 left-0 w-full h-32 bg-gradient-to-b from-accent/20 to-transparent" />
|
||||
{selectedUser.avatar ? (
|
||||
<img src={selectedUser.avatar} className="w-32 h-32 rounded-full object-cover border-4 border-surface shadow-2xl relative z-10 z-10" alt="Avatar" />
|
||||
) : (
|
||||
<div className="w-32 h-32 rounded-full bg-black border-4 border-surface shadow-2xl relative z-10 flex items-center justify-center">
|
||||
<User className="text-gray-400 w-12 h-12" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h2 className="text-3xl font-bold text-white mt-4 relative z-10">{selectedUser.displayName}</h2>
|
||||
<p className="text-gray-400 text-lg relative z-10">@{selectedUser.username}</p>
|
||||
</>
|
||||
) : (
|
||||
<motion.div initial={{ opacity: 0, scale: 0.95 }} animate={{ opacity: 1, scale: 1 }} className="flex flex-col gap-6 max-w-2xl">
|
||||
<button onClick={() => setSelectedUser(null)} className="text-accent hover:underline self-start flex items-center gap-2">
|
||||
← {t.backToList}
|
||||
</button>
|
||||
|
||||
<div className="bg-surface border border-white/10 rounded-2xl p-8 flex flex-col items-center relative overflow-hidden">
|
||||
<div className="absolute top-0 left-0 w-full h-32 bg-gradient-to-b from-accent/20 to-transparent" />
|
||||
{selectedUser.avatarUrl || selectedUser.avatar ? (
|
||||
<img src={selectedUser.avatarUrl || selectedUser.avatar || undefined} className="w-32 h-32 rounded-full object-cover border-4 border-surface shadow-2xl relative z-10" alt="Avatar" />
|
||||
) : (
|
||||
<div className="w-32 h-32 rounded-full bg-black border-4 border-surface shadow-2xl relative z-10 flex items-center justify-center">
|
||||
<User className="text-gray-400 w-12 h-12" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h2 className="text-3xl font-bold text-white mt-4 relative z-10">{selectedUser.displayName || selectedUser.userName || selectedUser.username || ''}</h2>
|
||||
<p className="text-gray-400 text-lg relative z-10">@{selectedUser.userName || selectedUser.username || ''}</p>
|
||||
|
||||
<div className="w-full mt-8 flex flex-col gap-4 relative z-10">
|
||||
<div className="bg-black/30 p-4 rounded-xl border border-white/5 flex flex-col gap-1">
|
||||
|
||||
@@ -11,7 +11,7 @@ type CallState = 'idle' | 'calling' | 'incoming' | 'connected' | 'ended';
|
||||
interface CallModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
targetUser: { id: string; displayName?: string; username: string; avatar?: string | null } | null;
|
||||
targetUser: { id: string; displayName?: string; username?: string; avatar?: string | null } | null;
|
||||
callType: 'voice' | 'video';
|
||||
incoming?: {
|
||||
from: string;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getSocket, disconnectSocket } from '../../../core/infrastructure/socket
|
||||
import { ChatApi } from '../infrastructure/chatApi';
|
||||
import { playNotificationSound, isChatMuted, playCallRingtone, stopCallRingtone } from '../../../core/utils/sounds';
|
||||
import { useLang } from '../../../core/infrastructure/i18n';
|
||||
import type { Message, UserBasic, CallInfo } from '../../../core/domain/types';
|
||||
import type { Message, UserBasic, CallInfo, ChatMember } from '../../../core/domain/types';
|
||||
import { Send, Check, Phone, PhoneOff } from 'lucide-react';
|
||||
import Sidebar from '../../../core/presentation/layouts/Sidebar';
|
||||
import ChatView from './components/ChatView';
|
||||
|
||||
@@ -32,19 +32,19 @@ function ChatListItem({ chat, isActive }: ChatListItemProps) {
|
||||
|
||||
const otherMember = chat.members.find((m) => m.user.id !== user?.id);
|
||||
const isFavorites = chat.type === 'favorites';
|
||||
const chatName = isFavorites
|
||||
const chatName = (isFavorites
|
||||
? t('favorites')
|
||||
: chat.type === 'personal'
|
||||
? otherMember?.user.displayName || otherMember?.user.userName || otherMember?.user.username || t('chat')
|
||||
: chat.name || t('group');
|
||||
: chat.name || t('group')) || '??';
|
||||
|
||||
const chatAvatar = isFavorites
|
||||
const chatAvatar: string | null = isFavorites
|
||||
? null
|
||||
: chat.type === 'personal'
|
||||
? otherMember?.user.avatarUrl || otherMember?.user.avatar
|
||||
: chat.avatarUrl || chat.avatar;
|
||||
? otherMember?.user.avatarUrl || otherMember?.user.avatar || null
|
||||
: chat.avatarUrl || chat.avatar || null;
|
||||
|
||||
const isOnline = chat.type === 'personal' && otherMember?.user.isOnline;
|
||||
const isOnline = chat.type === 'personal' && !!otherMember?.user.isOnline;
|
||||
|
||||
// Check if someone is typing in this chat
|
||||
const typingInChat = typingUsers.filter((t) => t.chatId === chat.id && t.userId !== user?.id);
|
||||
@@ -128,8 +128,9 @@ function ChatListItem({ chat, isActive }: ChatListItemProps) {
|
||||
} catch (e) { console.error(e); }
|
||||
};
|
||||
|
||||
const initials = chatName
|
||||
const initials = (chatName || '??')
|
||||
.split(' ')
|
||||
.filter(Boolean)
|
||||
.map((w: string) => w[0])
|
||||
.join('')
|
||||
.slice(0, 2)
|
||||
@@ -151,7 +152,7 @@ function ChatListItem({ chat, isActive }: ChatListItemProps) {
|
||||
<Bookmark size={22} className="text-white" />
|
||||
</div>
|
||||
) : (
|
||||
<Avatar src={chatAvatar} name={chatName} size="lg" online={isOnline ? true : undefined} />
|
||||
<Avatar src={chatAvatar || undefined} name={chatName || '??'} size="lg" online={isOnline ? true : false} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -93,13 +93,13 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
||||
const chatName = isFavorites
|
||||
? t('favorites')
|
||||
: chat?.type === 'personal'
|
||||
? otherMember?.user.displayName || otherMember?.user.username || t('chat')
|
||||
? otherMember?.user.displayName || otherMember?.user.userName || otherMember?.user.username || t('chat')
|
||||
: chat?.name || t('group');
|
||||
const chatAvatar = isFavorites
|
||||
? null
|
||||
: chat?.type === 'personal'
|
||||
? otherMember?.user.avatar
|
||||
: chat?.avatar;
|
||||
? otherMember?.user.avatarUrl || otherMember?.user.avatar || null
|
||||
: chat?.avatarUrl || chat?.avatar || null;
|
||||
const isOnline = chat?.type === 'personal' && otherMember?.user.isOnline;
|
||||
|
||||
const typingInChat = typingUsers.filter((t) => t.chatId === activeChat && t.userId !== user?.id);
|
||||
@@ -422,7 +422,7 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
||||
);
|
||||
}
|
||||
|
||||
const initials = chatName
|
||||
const initials = (chatName || '??')
|
||||
.split(' ')
|
||||
.map((w: string) => w[0])
|
||||
.join('')
|
||||
|
||||
@@ -151,10 +151,9 @@ function MessageBubble({
|
||||
};
|
||||
|
||||
const chatForDelete = chats.find(c => c.id === message.chatId);
|
||||
const otherMember = chatForDelete?.members.find(m => m.user.id !== user?.id);
|
||||
const otherMemberName = chatForDelete?.type === 'personal'
|
||||
? chatForDelete.members.find(m => m.user.id !== user?.id)?.user.displayName
|
||||
|| chatForDelete.members.find(m => m.user.id !== user?.id)?.user.username
|
||||
|| ''
|
||||
? otherMember?.user.displayName || otherMember?.user.userName || otherMember?.user.username || ''
|
||||
: '';
|
||||
|
||||
const isPinned = pinnedMessages[message.chatId]?.id === message.id;
|
||||
@@ -306,7 +305,7 @@ function MessageBubble({
|
||||
reactionGroups[r.emoji] = { count: 0, users: [], isMine: false, avatars: [] };
|
||||
}
|
||||
reactionGroups[r.emoji].count++;
|
||||
const displayName = r.user?.displayName || r.user?.username || '?';
|
||||
const displayName = r.user?.displayName || r.user?.userName || r.user?.username || '?';
|
||||
reactionGroups[r.emoji].users.push(displayName);
|
||||
if (reactionGroups[r.emoji].avatars.length < 3) {
|
||||
reactionGroups[r.emoji].avatars.push({
|
||||
@@ -318,8 +317,8 @@ function MessageBubble({
|
||||
if (r.userId === user?.id) reactionGroups[r.emoji].isMine = true;
|
||||
});
|
||||
|
||||
const senderName = message.sender?.displayName || message.sender?.username || '';
|
||||
const senderAvatar = message.sender?.avatar;
|
||||
const senderName = message.sender?.displayName || message.sender?.userName || message.sender?.username || '';
|
||||
const senderAvatar = message.sender?.avatarUrl || message.sender?.avatar;
|
||||
|
||||
const firstUrlMatch = message.content?.match(/https?:\/\/[^\s]+/);
|
||||
const firstUrl = firstUrlMatch ? firstUrlMatch[0] : null;
|
||||
@@ -453,7 +452,7 @@ function MessageBubble({
|
||||
}}
|
||||
>
|
||||
<p className={`text-[13.5px] font-semibold mb-0.5 truncate ${isMine ? 'text-white' : 'text-knot-500'}`}>
|
||||
{message.replyTo.sender?.displayName || message.replyTo.sender?.username}
|
||||
{message.replyTo.sender?.displayName || message.replyTo.sender?.userName || message.replyTo.sender?.username || ''}
|
||||
</p>
|
||||
<div className="flex items-center gap-1.5">
|
||||
{message.replyTo.isDeleted ? (
|
||||
@@ -536,7 +535,7 @@ function MessageBubble({
|
||||
onClick={() => onViewProfile?.(message.forwardedFromId!)}
|
||||
>
|
||||
<div className={`font-medium ${isMine ? 'text-white/90' : 'text-knot-500'}`}>
|
||||
{(t('forwardedFrom' as any) === 'forwardedFrom' ? 'Переслано от' : t('forwardedFrom' as any))} <span className="font-semibold">{message.forwardedFrom.displayName || message.forwardedFrom.username}</span>
|
||||
{(t('forwardedFrom' as any) === 'forwardedFrom' ? 'Переслано от' : t('forwardedFrom' as any))} <span className="font-semibold">{message.forwardedFrom.displayName || message.forwardedFrom.userName || message.forwardedFrom.username || ''}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { useAuthStore } from '../../../auth/application/authStore';
|
||||
import { ChatApi } from '../../infrastructure/chatApi';
|
||||
import { getSocket } from '../../../../core/infrastructure/socket';
|
||||
import { useLang } from '../../../../core/infrastructure/i18n';
|
||||
import { AUDIO_EXTENSIONS, MAX_FILE_SIZE } from '../../../../core/domain/types';
|
||||
import { AUDIO_EXTENSIONS, MAX_FILE_SIZE, type ChatMember } from '../../../../core/domain/types';
|
||||
import { useNotificationStore } from '../../../../core/application/stores/notificationStore';
|
||||
import EmojiPicker from './EmojiPicker';
|
||||
|
||||
@@ -70,27 +70,31 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
||||
const filteredMembers = mentionQuery !== null && isGroup
|
||||
? chatMembers.filter((m) => {
|
||||
const q = mentionQuery.toLowerCase();
|
||||
return m.user.displayName.toLowerCase().includes(q) || m.user.username.toLowerCase().includes(q);
|
||||
return (m.user.displayName || '').toLowerCase().includes(q)
|
||||
|| (m.user.userName || '').toLowerCase().includes(q)
|
||||
|| (m.user.username || '').toLowerCase().includes(q);
|
||||
}).slice(0, 6)
|
||||
: [];
|
||||
|
||||
const insertMention = (member: { user: { username: string } }) => {
|
||||
const insertMention = (member: ChatMember) => {
|
||||
const el = inputRef.current;
|
||||
if (!el) return;
|
||||
const username = member.user.userName || member.user.username;
|
||||
if (!username) return;
|
||||
const cursorPos = el.selectionStart;
|
||||
const before = text.substring(0, cursorPos);
|
||||
const after = text.substring(cursorPos);
|
||||
// Find the @ that started this mention
|
||||
const atIdx = before.lastIndexOf('@');
|
||||
if (atIdx === -1) return;
|
||||
const newText = before.substring(0, atIdx) + `@${member.user.username} ` + after;
|
||||
const newText = before.substring(0, atIdx) + `@${username} ` + after;
|
||||
setText(newText);
|
||||
setDraft(chatId, newText);
|
||||
setMentionQuery(null);
|
||||
setMentionIndex(0);
|
||||
setTimeout(() => {
|
||||
el.focus();
|
||||
const newPos = atIdx + member.user.username.length + 2;
|
||||
const newPos = atIdx + username.length + 2;
|
||||
el.setSelectionRange(newPos, newPos);
|
||||
}, 0);
|
||||
};
|
||||
@@ -617,7 +621,7 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
||||
<p className="text-xs font-semibold text-knot-400 mb-0.5">
|
||||
{editingMessage
|
||||
? t('editing')
|
||||
: `${t('replyTo')} ${replyTo?.sender?.displayName || replyTo?.sender?.username || ''}`}
|
||||
: `${t('replyTo')} ${replyTo?.sender?.displayName || replyTo?.sender?.userName || replyTo?.sender?.username || ''}`}
|
||||
</p>
|
||||
<div className="text-xs text-zinc-300 truncate opacity-80 border-l border-white/20 pl-2 ml-1">
|
||||
{replyTo?.quote ? `«${replyTo.quote}»` : (editingMessage || replyTo)?.content || t('media') || 'Медиа'}
|
||||
@@ -813,16 +817,16 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
||||
i === mentionIndex ? 'bg-accent/20 text-white' : 'text-zinc-300 hover:bg-white/5'
|
||||
}`}
|
||||
>
|
||||
{m.user.avatar ? (
|
||||
<img src={m.user.avatar} className="w-7 h-7 rounded-full object-cover" alt="" />
|
||||
{m.user.avatarUrl || m.user.avatar ? (
|
||||
<img src={m.user.avatarUrl || m.user.avatar || ''} className="w-7 h-7 rounded-full object-cover" alt="" />
|
||||
) : (
|
||||
<div className="w-7 h-7 rounded-full bg-gradient-to-br from-knot-500 to-purple-600 flex items-center justify-center text-white text-xs font-semibold">
|
||||
{(m.user.displayName || m.user.username)[0]?.toUpperCase()}
|
||||
{(m.user.displayName || m.user.userName || m.user.username || '?')[0]?.toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div className="min-w-0">
|
||||
<p className="text-sm font-medium truncate">{m.user.displayName || m.user.username}</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{m.user.username}</p>
|
||||
<p className="text-sm font-medium truncate">{m.user.displayName || m.user.userName || m.user.username || '??'}</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{m.user.userName || m.user.username || '??'}</p>
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
|
||||
@@ -171,10 +171,10 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
<img src={u.avatar} alt="" className="w-5 h-5 rounded-full object-cover" />
|
||||
) : (
|
||||
<div className="w-5 h-5 rounded-full bg-gradient-to-br from-knot-500 to-purple-600 flex items-center justify-center text-white text-[9px] font-semibold">
|
||||
{(u.displayName || u.username)?.[0]?.toUpperCase()}
|
||||
{(u.displayName || u.userName || u.username || '?')[0]?.toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<span className="text-xs text-white">{u.displayName || u.username}</span>
|
||||
<span className="text-xs text-white">{u.displayName || u.userName || u.username || ''}</span>
|
||||
<button
|
||||
onClick={() => setSelectedUsers((prev) => prev.filter((p) => p.id !== u.id))}
|
||||
className="text-zinc-500 hover:text-zinc-300"
|
||||
@@ -230,7 +230,7 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
onClick={() => setSelectedUsers((prev) => prev.filter((p) => p.id !== u.id))}
|
||||
className="flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-knot-500/20 border border-knot-500/30 text-xs text-white hover:bg-knot-500/30 transition-colors"
|
||||
>
|
||||
{(u.displayName || u.username)}
|
||||
{(u.displayName || u.userName || u.username || '')}
|
||||
<X size={11} />
|
||||
</button>
|
||||
))}
|
||||
@@ -276,7 +276,7 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
<img src={u.avatar} alt="" className="w-10 h-10 rounded-full object-cover" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-knot-500 to-purple-600 flex items-center justify-center text-white font-semibold text-sm">
|
||||
{(u.displayName || u.username)?.[0]?.toUpperCase() || '?'}
|
||||
{(u.displayName || u.userName || u.username || '?')[0]?.toUpperCase() || '?'}
|
||||
</div>
|
||||
)}
|
||||
{u.isOnline && (
|
||||
@@ -285,9 +285,9 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
</div>
|
||||
<div className="min-w-0 text-left flex-1">
|
||||
<p className="text-sm font-medium text-white truncate">
|
||||
{u.displayName || u.username}
|
||||
{u.displayName || u.userName || u.username || ''}
|
||||
</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{u.username}</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{u.userName || u.username || ''}</p>
|
||||
</div>
|
||||
{mode === 'group-select' && (
|
||||
<div className={`w-5 h-5 rounded-full border-2 flex items-center justify-center flex-shrink-0 transition-colors ${
|
||||
@@ -326,7 +326,7 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
<img src={u.avatar} alt="" className="w-10 h-10 rounded-full object-cover" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-knot-500 to-purple-600 flex items-center justify-center text-white font-semibold text-sm">
|
||||
{(u.displayName || u.username)?.[0]?.toUpperCase() || '?'}
|
||||
{(u.displayName || u.userName || u.username || '?')[0]?.toUpperCase() || '?'}
|
||||
</div>
|
||||
)}
|
||||
{u.isOnline && (
|
||||
@@ -335,9 +335,9 @@ export default function NewChatModal({ onClose }: NewChatModalProps) {
|
||||
</div>
|
||||
<div className="min-w-0 text-left flex-1">
|
||||
<p className="text-sm font-medium text-white truncate">
|
||||
{u.displayName || u.username}
|
||||
{u.displayName || u.userName || u.username || ''}
|
||||
</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{u.username}</p>
|
||||
<p className="text-xs text-zinc-500 truncate">@{u.userName || u.username || ''}</p>
|
||||
</div>
|
||||
{mode === 'group-select' && (
|
||||
<div className={`w-5 h-5 rounded-full border-2 flex items-center justify-center flex-shrink-0 transition-colors ${
|
||||
|
||||
@@ -45,7 +45,7 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
const TICK = 50;
|
||||
|
||||
const [showViewers, setShowViewers] = useState(false);
|
||||
const [viewers, setViewers] = useState<Array<{ userId: string; username: string; displayName: string; avatar: string | null; viewedAt: string }>>([]);
|
||||
const [viewers, setViewers] = useState<Array<{ userId: string; username: string; userName?: string; displayName: string; avatar: string | null; viewedAt: string }>>([]);
|
||||
const [viewersLoading, setViewersLoading] = useState(false);
|
||||
|
||||
const [showReplyInput, setShowReplyInput] = useState(false);
|
||||
@@ -207,7 +207,7 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
|
||||
const socket = getSocket();
|
||||
|
||||
const handleStoryViewed = (data: { storyId: string; userId: string; username: string; displayName: string; avatar: string | null; viewedAt: string; viewCount: number; ownerId: string }) => {
|
||||
const handleStoryViewed = (data: { storyId: string; userId: string; username: string; userName?: string; displayName: string; avatar: string | null; viewedAt: string; viewCount: number; ownerId: string }) => {
|
||||
// console.log('[StoryViewer] story_viewed received:', data);
|
||||
if (!currentStory || data.storyId !== currentStory.id) return;
|
||||
// Only process if this user is the owner
|
||||
@@ -227,6 +227,7 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
return [...prev, {
|
||||
userId: data.userId,
|
||||
username: data.username,
|
||||
userName: data.userName,
|
||||
displayName: data.displayName,
|
||||
avatar: data.avatar,
|
||||
viewedAt: data.viewedAt
|
||||
@@ -235,14 +236,14 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
}
|
||||
};
|
||||
|
||||
const handleStoryReply = (data: { storyId: string; userId: string; username: string; displayName: string; avatar: string | null; content: string; createdAt: string; ownerId: string }) => {
|
||||
const handleStoryReply = (data: { storyId: string; userId: string; username: string; userName?: string; displayName: string; avatar: string | null; content: string; createdAt: string; ownerId: string }) => {
|
||||
// console.log('[StoryViewer] story_reply received:', data);
|
||||
// Only process if this user is the owner
|
||||
if (data.ownerId !== user?.id) return;
|
||||
// Could show notification or update UI
|
||||
};
|
||||
|
||||
const handleStoryReaction = (data: { storyId: string; userId: string; username: string; displayName: string; avatar: string | null; emoji: string; createdAt: string; ownerId: string }) => {
|
||||
const handleStoryReaction = (data: { storyId: string; userId: string; username: string; userName?: string; displayName: string; avatar: string | null; emoji: string; createdAt: string; ownerId: string }) => {
|
||||
// console.log('[StoryViewer] story_reaction received:', data);
|
||||
// Only process if this user is the owner
|
||||
if (data.ownerId !== user?.id) return;
|
||||
@@ -408,13 +409,13 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
<div className="absolute top-4 left-0 right-0 flex items-center gap-3 px-4 pt-2 z-10">
|
||||
<Avatar
|
||||
src={avatarUrl}
|
||||
name={currentUser.user.displayName || currentUser.user.username}
|
||||
name={currentUser.user.displayName || currentUser.user.userName || currentUser.user.username || '?'}
|
||||
size="sm"
|
||||
className="ring-2 ring-white/20 rounded-full"
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-white text-sm font-semibold truncate drop-shadow">
|
||||
{currentUser.user.id === user?.id ? t('myStory') : currentUser.user.displayName || currentUser.user.username}
|
||||
{currentUser.user.id === user?.id ? t('myStory') : currentUser.user.displayName || currentUser.user.userName || currentUser.user.username || ''}
|
||||
</p>
|
||||
<p className="text-white/60 text-xs drop-shadow">{timeAgo(currentStory.createdAt)}</p>
|
||||
</div>
|
||||
@@ -600,12 +601,12 @@ export default function StoryViewer({ stories, initialUserIndex, initialStoryInd
|
||||
<div key={v.userId} className="flex items-center gap-3 py-1.5">
|
||||
<Avatar
|
||||
src={v.avatar ? getMediaUrl(v.avatar) : null}
|
||||
name={v.displayName || v.username}
|
||||
name={v.displayName || v.username || '?'}
|
||||
size="sm"
|
||||
className="rounded-full"
|
||||
/>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-white text-sm truncate">{v.displayName || v.username}</p>
|
||||
<p className="text-white text-sm truncate">{v.displayName || v.username || ''}</p>
|
||||
<p className="text-white/40 text-xs">@{v.username}</p>
|
||||
</div>
|
||||
<span className="text-white/30 text-xs">{timeAgo(v.viewedAt)}</span>
|
||||
|
||||
@@ -501,14 +501,14 @@ export default function UserProfile({ userId, chatId, onClose, onGoToMessage, is
|
||||
</div>
|
||||
) : (
|
||||
<h3 className="mt-5 text-[24px] font-semibold text-white tracking-tight text-center px-4">
|
||||
{profile.displayName || profile.userName || profile.username}
|
||||
{profile.displayName || profile.userName || profile.username || ''}
|
||||
</h3>
|
||||
)}
|
||||
|
||||
{/* Username (неизменяемый) */}
|
||||
<div className="flex items-center gap-1.5 mt-2 bg-accent/10 px-4 py-1.5 rounded-full border border-accent/20 cursor-default">
|
||||
<AtSign size={14} className="text-accent" />
|
||||
<span className="text-sm font-medium text-accent">{profile.userName || profile.username}</span>
|
||||
<span className="text-sm font-medium text-accent">{profile.userName || profile.username || ''}</span>
|
||||
</div>
|
||||
|
||||
{/* Онлайн статус */}
|
||||
@@ -985,10 +985,10 @@ export default function UserProfile({ userId, chatId, onClose, onGoToMessage, is
|
||||
user: {
|
||||
id: profile.id,
|
||||
userName: profile.userName || profile.username || '',
|
||||
username: profile.username,
|
||||
displayName: profile.displayName,
|
||||
avatar: profile.avatar,
|
||||
avatarUrl: profile.avatarUrl || profile.avatar
|
||||
username: profile.username || '',
|
||||
displayName: profile.displayName || '',
|
||||
avatar: profile.avatar ?? null,
|
||||
avatarUrl: (profile.avatarUrl || profile.avatar) ?? null
|
||||
},
|
||||
stories: sortedStories,
|
||||
hasUnviewed: false
|
||||
|
||||
Reference in New Issue
Block a user