Импорт из телеграм
This commit is contained in:
@@ -0,0 +1,282 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using Knot.Modules.Chats.Application.Abstractions;
|
||||||
|
using Knot.Modules.Chats.Domain;
|
||||||
|
using Knot.Modules.Identity.Domain;
|
||||||
|
using Knot.Shared.Kernel;
|
||||||
|
using Knot.Shared.Kernel.Storage;
|
||||||
|
using Knot.Modules.Chats.Infrastructure.SignalR;
|
||||||
|
using Knot.Modules.Chats.Application.Chats.Create;
|
||||||
|
|
||||||
|
namespace Host.Controllers;
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/import/telegram")]
|
||||||
|
public sealed class TelegramImportController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ISender _sender;
|
||||||
|
private readonly IUserContext _userContext;
|
||||||
|
private readonly IChatsUnitOfWork _unitOfWork;
|
||||||
|
private readonly IChatRepository _chatRepository;
|
||||||
|
private readonly IMessageRepository _messageRepository;
|
||||||
|
private readonly IFileStorageService _fileStorage;
|
||||||
|
private readonly IHubContext<ChatHub> _hubContext;
|
||||||
|
|
||||||
|
// In-memory store for uploaded zips (good enough for typical cases, ideally should be removed after use or by timer)
|
||||||
|
private static readonly ConcurrentDictionary<Guid, string> _tempZips = new();
|
||||||
|
|
||||||
|
public TelegramImportController(
|
||||||
|
ISender sender,
|
||||||
|
IUserContext userContext,
|
||||||
|
IChatsUnitOfWork unitOfWork,
|
||||||
|
IChatRepository chatRepository,
|
||||||
|
IMessageRepository messageRepository,
|
||||||
|
IFileStorageService fileStorage,
|
||||||
|
IHubContext<ChatHub> hubContext)
|
||||||
|
{
|
||||||
|
_sender = sender;
|
||||||
|
_userContext = userContext;
|
||||||
|
_unitOfWork = unitOfWork;
|
||||||
|
_chatRepository = chatRepository;
|
||||||
|
_messageRepository = messageRepository;
|
||||||
|
_fileStorage = fileStorage;
|
||||||
|
_hubContext = hubContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("analyze")]
|
||||||
|
[DisableRequestSizeLimit]
|
||||||
|
[RequestFormLimits(MultipartBodyLengthLimit = 10L * 1024 * 1024 * 1024)] // 10GB for big exports
|
||||||
|
public async Task<IActionResult> Analyze(IFormFile file, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (file == null || file.Length == 0) return BadRequest("No file uploaded");
|
||||||
|
if (!file.FileName.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) return BadRequest("Must be a ZIP archive");
|
||||||
|
|
||||||
|
var token = Guid.NewGuid();
|
||||||
|
var tempPath = Path.Combine(Path.GetTempPath(), $"{token}.zip");
|
||||||
|
|
||||||
|
await using (var fs = new FileStream(tempPath, FileMode.Create))
|
||||||
|
{
|
||||||
|
await file.CopyToAsync(fs, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
var names = new HashSet<string>();
|
||||||
|
|
||||||
|
// Open zip and quickly scan messages.html
|
||||||
|
using (var archive = ZipFile.OpenRead(tempPath))
|
||||||
|
{
|
||||||
|
var htmlEntries = archive.Entries.Where(e => e.FullName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) && e.Name.StartsWith("messages", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
foreach (var entry in htmlEntries)
|
||||||
|
{
|
||||||
|
using var stream = entry.Open();
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.Load(stream);
|
||||||
|
|
||||||
|
var messageNodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'message ')]");
|
||||||
|
if (messageNodes == null) continue;
|
||||||
|
|
||||||
|
foreach (var node in messageNodes)
|
||||||
|
{
|
||||||
|
var fromNameNode = node.SelectSingleNode(".//div[contains(@class, 'from_name')]");
|
||||||
|
if (fromNameNode != null)
|
||||||
|
{
|
||||||
|
var name = fromNameNode.InnerText.Trim();
|
||||||
|
// Ignore standard system names if obvious (for now everything is recorded)
|
||||||
|
if (!string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
names.Add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_tempZips[token] = tempPath;
|
||||||
|
|
||||||
|
return Ok(new
|
||||||
|
{
|
||||||
|
token,
|
||||||
|
names = names.ToList()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed record ExecuteImportRequest(Guid Token, Dictionary<string, Guid> Mapping);
|
||||||
|
|
||||||
|
[HttpPost("execute")]
|
||||||
|
public async Task<IActionResult> Execute([FromBody] ExecuteImportRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
if (!_tempZips.TryGetValue(req.Token, out var tempPath))
|
||||||
|
return BadRequest("Session not found or expired");
|
||||||
|
|
||||||
|
if (!System.IO.File.Exists(tempPath))
|
||||||
|
return BadRequest("ZIP file lost");
|
||||||
|
|
||||||
|
var myId = _userContext.UserId;
|
||||||
|
// Collect targeted users to check whose chat it is. Find the friend.
|
||||||
|
// Usually, the mapping contains MyId and FriendId.
|
||||||
|
var targetUserIds = req.Mapping.Values.Distinct().Where(id => id != Guid.Empty).ToList();
|
||||||
|
if (!targetUserIds.Contains(myId)) targetUserIds.Add(myId);
|
||||||
|
|
||||||
|
Guid chatId = Guid.Empty;
|
||||||
|
var chatMembers = targetUserIds;
|
||||||
|
|
||||||
|
if (chatMembers.Count <= 2)
|
||||||
|
{
|
||||||
|
// Find existing personal chat
|
||||||
|
var existingChats = await _chatRepository.GetUserChatsAsync(myId, ct);
|
||||||
|
var personalChat = existingChats.FirstOrDefault(c => c.Type == ChatType.Personal && c.Members.All(m => chatMembers.Contains(m.UserId)) && c.Members.Count == chatMembers.Count);
|
||||||
|
|
||||||
|
if (personalChat != null)
|
||||||
|
{
|
||||||
|
chatId = personalChat.Id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create personal chat
|
||||||
|
var friendId = chatMembers.FirstOrDefault(id => id != myId);
|
||||||
|
if (friendId == Guid.Empty) friendId = myId; // Notes to self
|
||||||
|
var command = new CreateChatCommand(string.Empty, ChatType.Personal, new List<Guid> { myId, friendId });
|
||||||
|
var res = await _sender.Send(command, ct);
|
||||||
|
if (res.IsFailure) return BadRequest(res.Error);
|
||||||
|
chatId = res.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create a group
|
||||||
|
var command = new CreateChatCommand("Импортированный чат", ChatType.Group, chatMembers);
|
||||||
|
var res = await _sender.Send(command, ct);
|
||||||
|
if (res.IsFailure) return BadRequest(res.Error);
|
||||||
|
chatId = res.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int importedCount = 0;
|
||||||
|
|
||||||
|
using (var archive = ZipFile.OpenRead(tempPath))
|
||||||
|
{
|
||||||
|
var htmlEntries = archive.Entries
|
||||||
|
.Where(e => e.FullName.EndsWith(".html", StringComparison.OrdinalIgnoreCase) && e.Name.StartsWith("messages", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.OrderBy(e => e.FullName); // Read chronologically
|
||||||
|
|
||||||
|
foreach (var entry in htmlEntries)
|
||||||
|
{
|
||||||
|
using var stream = entry.Open();
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.Load(stream);
|
||||||
|
|
||||||
|
var messageNodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'message ')]");
|
||||||
|
if (messageNodes == null) continue;
|
||||||
|
|
||||||
|
var baseDir = Path.GetDirectoryName(entry.FullName)?.Replace("\\", "/") ?? "";
|
||||||
|
if (!string.IsNullOrEmpty(baseDir) && !baseDir.EndsWith("/")) baseDir += "/";
|
||||||
|
|
||||||
|
foreach (var node in messageNodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var fromNameNode = node.SelectSingleNode(".//div[contains(@class, 'from_name')]");
|
||||||
|
var textNode = node.SelectSingleNode(".//div[contains(@class, 'text')]");
|
||||||
|
var dateNode = node.SelectSingleNode(".//div[contains(@class, 'pull_right date')]");
|
||||||
|
|
||||||
|
// Default values
|
||||||
|
var senderGuid = myId; // Fallback
|
||||||
|
if (fromNameNode != null)
|
||||||
|
{
|
||||||
|
var name = fromNameNode.InnerText.Trim();
|
||||||
|
if (req.Mapping.TryGetValue(name, out var mappedId) && mappedId != Guid.Empty)
|
||||||
|
senderGuid = mappedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
var content = textNode?.InnerText?.Trim() ?? "";
|
||||||
|
|
||||||
|
DateTime createdAt = DateTime.UtcNow;
|
||||||
|
if (dateNode != null && dateNode.Attributes["title"] != null)
|
||||||
|
{
|
||||||
|
var dateStr = dateNode.Attributes["title"].Value;
|
||||||
|
if (DateTime.TryParse(dateStr, out var d))
|
||||||
|
createdAt = d.ToUniversalTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
var mediaNodes = node.SelectNodes(".//a[contains(@class, 'photo_wrap')] | .//video | .//a[contains(@class, 'document')] | .//a[contains(@class, 'media_voice_message')]");
|
||||||
|
|
||||||
|
var messageType = "text";
|
||||||
|
if (mediaNodes != null && mediaNodes.Count > 0)
|
||||||
|
{
|
||||||
|
var firstHref = mediaNodes[0].Attributes["href"]?.Value ?? mediaNodes[0].Attributes["src"]?.Value;
|
||||||
|
if (firstHref != null)
|
||||||
|
{
|
||||||
|
if (firstHref.EndsWith(".jpg") || firstHref.EndsWith(".png")) messageType = "image";
|
||||||
|
else if (firstHref.EndsWith(".mp4")) messageType = "video";
|
||||||
|
else if (firstHref.EndsWith(".ogg")) messageType = "voice";
|
||||||
|
else messageType = "file";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var newMessage = Message.Import(chatId, senderGuid, content, messageType, createdAt);
|
||||||
|
|
||||||
|
if (mediaNodes != null)
|
||||||
|
{
|
||||||
|
foreach (var mediaNode in mediaNodes)
|
||||||
|
{
|
||||||
|
string? href = mediaNode.Attributes["href"]?.Value ?? mediaNode.Attributes["src"]?.Value;
|
||||||
|
if (!string.IsNullOrEmpty(href) && !href.StartsWith("http"))
|
||||||
|
{
|
||||||
|
// Local file in zip
|
||||||
|
var zipPath = baseDir + href.Replace("\\", "/");
|
||||||
|
var zipEntry = archive.GetEntry(zipPath);
|
||||||
|
if (zipEntry != null)
|
||||||
|
{
|
||||||
|
using var ms = new MemoryStream();
|
||||||
|
using var zipfs = zipEntry.Open();
|
||||||
|
await zipfs.CopyToAsync(ms, ct);
|
||||||
|
ms.Position = 0;
|
||||||
|
|
||||||
|
string cType = "application/octet-stream";
|
||||||
|
var mType = "file";
|
||||||
|
if (href.EndsWith(".jpg") || href.EndsWith(".png")) { cType = "image/jpeg"; mType = "image"; messageType = "image"; }
|
||||||
|
else if (href.EndsWith(".mp4")) { cType = "video/mp4"; mType = "video"; messageType = "video"; }
|
||||||
|
else if (href.EndsWith(".ogg")) { cType = "audio/ogg"; mType = "voice"; messageType = "voice"; }
|
||||||
|
|
||||||
|
var fileId = await _fileStorage.UploadFileAsync(ms, Path.GetFileName(href), cType);
|
||||||
|
newMessage.AddMedia(mType, $"/api/files/{fileId}", Path.GetFileName(href), zipEntry.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save text message without media if content is just empty, but wait, if it's empty and has no media, it was probably a system message (like pinned, joined).
|
||||||
|
if (!string.IsNullOrEmpty(content) || newMessage.Media.Any())
|
||||||
|
{
|
||||||
|
_messageRepository.Add(newMessage);
|
||||||
|
importedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { /* ignore single message parse error */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await _unitOfWork.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
// Delete temp zip
|
||||||
|
try { System.IO.File.Delete(tempPath); _tempZips.TryRemove(req.Token, out _); } catch { }
|
||||||
|
|
||||||
|
// Notify UI for all members of the chat
|
||||||
|
await _hubContext.Clients.Users(chatMembers.Select(x => x.ToString())).SendAsync("history_updated", new { chatId });
|
||||||
|
|
||||||
|
return Ok(new { success = true, messagesImported = importedCount, chatId });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.4" />
|
||||||
<PackageReference Include="Mapster" Version="7.4.0" />
|
<PackageReference Include="Mapster" Version="7.4.0" />
|
||||||
<PackageReference Include="MediatR" Version="12.0.1" />
|
<PackageReference Include="MediatR" Version="12.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-preview.1.25120.3" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-preview.1.25120.3" />
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public sealed class Message : AggregateRoot<Guid>
|
|||||||
public string? StoryMediaUrl { get; private set; }
|
public string? StoryMediaUrl { get; private set; }
|
||||||
public string? StoryMediaType { get; private set; }
|
public string? StoryMediaType { get; private set; }
|
||||||
public DateTime CreatedAt { get; private set; }
|
public DateTime CreatedAt { get; private set; }
|
||||||
|
public bool IsImported { get; private set; }
|
||||||
|
|
||||||
private readonly List<Media> _media = new();
|
private readonly List<Media> _media = new();
|
||||||
public IReadOnlyCollection<Media> Media => _media.AsReadOnly();
|
public IReadOnlyCollection<Media> Media => _media.AsReadOnly();
|
||||||
@@ -35,7 +36,9 @@ public sealed class Message : AggregateRoot<Guid>
|
|||||||
private readonly List<Guid> _deletedByUsers = new();
|
private readonly List<Guid> _deletedByUsers = new();
|
||||||
public IReadOnlyCollection<Guid> DeletedByUsers => _deletedByUsers.AsReadOnly();
|
public IReadOnlyCollection<Guid> DeletedByUsers => _deletedByUsers.AsReadOnly();
|
||||||
|
|
||||||
private Message(Guid id, Guid chatId, Guid senderId, string? content, string type, Guid? replyToId = null, string? quote = null, Guid? forwardedFromId = null, Guid? storyId = null, string? storyMediaUrl = null, string? storyMediaType = null) : base(id)
|
private Message() : base(Guid.Empty) { Type = "text"; }
|
||||||
|
|
||||||
|
private Message(Guid id, Guid chatId, Guid senderId, string? content, string type, Guid? replyToId, string? quote, Guid? forwardedFromId, Guid? storyId, string? storyMediaUrl, string? storyMediaType, DateTime createdAt, bool isImported) : base(id)
|
||||||
{
|
{
|
||||||
ChatId = chatId;
|
ChatId = chatId;
|
||||||
SenderId = senderId;
|
SenderId = senderId;
|
||||||
@@ -47,14 +50,23 @@ public sealed class Message : AggregateRoot<Guid>
|
|||||||
StoryId = storyId;
|
StoryId = storyId;
|
||||||
StoryMediaUrl = storyMediaUrl;
|
StoryMediaUrl = storyMediaUrl;
|
||||||
StoryMediaType = storyMediaType;
|
StoryMediaType = storyMediaType;
|
||||||
CreatedAt = DateTime.UtcNow;
|
CreatedAt = createdAt;
|
||||||
|
IsImported = isImported;
|
||||||
|
|
||||||
RaiseDomainEvent(new MessageSentDomainEvent(Id, ChatId, SenderId, Content));
|
if (!isImported) // Don't trigger realtime events for historic messages
|
||||||
|
{
|
||||||
|
RaiseDomainEvent(new MessageSentDomainEvent(Id, ChatId, SenderId, Content));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message Create(Guid chatId, Guid senderId, string? content, string type, Guid? replyToId = null, string? quote = null, Guid? forwardedFromId = null, Guid? storyId = null, string? storyMediaUrl = null, string? storyMediaType = null)
|
public static Message Create(Guid chatId, Guid senderId, string? content, string type, Guid? replyToId = null, string? quote = null, Guid? forwardedFromId = null, Guid? storyId = null, string? storyMediaUrl = null, string? storyMediaType = null)
|
||||||
{
|
{
|
||||||
return new Message(Guid.NewGuid(), chatId, senderId, content, type, replyToId, quote, forwardedFromId, storyId, storyMediaUrl, storyMediaType);
|
return new Message(Guid.NewGuid(), chatId, senderId, content, type, replyToId, quote, forwardedFromId, storyId, storyMediaUrl, storyMediaType, DateTime.UtcNow, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Message Import(Guid chatId, Guid senderId, string? content, string type, DateTime createdAt, Guid? replyToId = null)
|
||||||
|
{
|
||||||
|
return new Message(Guid.NewGuid(), chatId, senderId, content, type, replyToId, null, null, null, null, null, createdAt, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddMedia(string type, string url, string? filename, long? size)
|
public void AddMedia(string type, string url, string? filename, long? size)
|
||||||
|
|||||||
+266
@@ -0,0 +1,266 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Knot.Modules.Chats.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.Chats.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ChatsDbContext))]
|
||||||
|
[Migration("20260316142303_AddIsImportedToMessage")]
|
||||||
|
partial class AddIsImportedToMessage
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("chats")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Chat", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Avatar")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Chats", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("ChatId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<Guid[]>("DeletedByUsers")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("uuid[]")
|
||||||
|
.HasColumnName("DeletedByUsers");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ForwardedFromId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<bool>("IsDeleted")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEdited")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsImported")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Quote")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ReplyToId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("SenderId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid?>("StoryId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("StoryMediaType")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("StoryMediaUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Messages", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Reaction", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Emoji")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId", "Emoji")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageReactions", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.ReadReceipt", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ReadAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("ReadReceipts", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Chat", b =>
|
||||||
|
{
|
||||||
|
b.OwnsMany("Knot.Modules.Chats.Domain.ChatMember", "Members", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<Guid>("ChatId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<bool>("IsMuted")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b1.Property<bool>("IsPinned")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b1.Property<DateTime>("JoinedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b1.Property<string>("Role")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.HasKey("Id");
|
||||||
|
|
||||||
|
b1.HasIndex("ChatId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b1.ToTable("ChatMembers", "chats");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ChatId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.OwnsMany("Knot.Modules.Chats.Domain.Media", "Media", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<string>("Filename")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<long?>("Size")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b1.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.HasKey("MessageId", "Id");
|
||||||
|
|
||||||
|
b1.ToTable("MessageMedia", "chats");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MessageId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Media");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Reaction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Knot.Modules.Chats.Domain.Message", null)
|
||||||
|
.WithMany("Reactions")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.ReadReceipt", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Knot.Modules.Chats.Domain.Message", null)
|
||||||
|
.WithMany("ReadBy")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Reactions");
|
||||||
|
|
||||||
|
b.Navigation("ReadBy");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Knot.Modules.Chats.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddIsImportedToMessage : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<bool>(
|
||||||
|
name: "IsImported",
|
||||||
|
schema: "chats",
|
||||||
|
table: "Messages",
|
||||||
|
type: "boolean",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "IsImported",
|
||||||
|
schema: "chats",
|
||||||
|
table: "Messages");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+266
@@ -0,0 +1,266 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Knot.Modules.Chats.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.Chats.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ChatsDbContext))]
|
||||||
|
[Migration("20260316143533_RemoveIsImportedDefault")]
|
||||||
|
partial class RemoveIsImportedDefault
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasDefaultSchema("chats")
|
||||||
|
.HasAnnotation("ProductVersion", "10.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Chat", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Avatar")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Chats", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("ChatId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.PrimitiveCollection<Guid[]>("DeletedByUsers")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("uuid[]")
|
||||||
|
.HasColumnName("DeletedByUsers");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ForwardedFromId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<bool>("IsDeleted")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsEdited")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsImported")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("Quote")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid?>("ReplyToId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("SenderId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid?>("StoryId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("StoryMediaType")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("StoryMediaUrl")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Messages", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Reaction", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Emoji")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId", "Emoji")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("MessageReactions", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.ReadReceipt", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ReadAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("MessageId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b.ToTable("ReadReceipts", "chats");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Chat", b =>
|
||||||
|
{
|
||||||
|
b.OwnsMany("Knot.Modules.Chats.Domain.ChatMember", "Members", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<Guid>("ChatId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<bool>("IsMuted")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b1.Property<bool>("IsPinned")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b1.Property<DateTime>("JoinedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b1.Property<string>("Role")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.HasKey("Id");
|
||||||
|
|
||||||
|
b1.HasIndex("ChatId", "UserId")
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
b1.ToTable("ChatMembers", "chats");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("ChatId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Members");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.OwnsMany("Knot.Modules.Chats.Domain.Media", "Media", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("MessageId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b1.Property<string>("Filename")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<long?>("Size")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b1.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.Property<string>("Url")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b1.HasKey("MessageId", "Id");
|
||||||
|
|
||||||
|
b1.ToTable("MessageMedia", "chats");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("MessageId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Media");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Reaction", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Knot.Modules.Chats.Domain.Message", null)
|
||||||
|
.WithMany("Reactions")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.ReadReceipt", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Knot.Modules.Chats.Domain.Message", null)
|
||||||
|
.WithMany("ReadBy")
|
||||||
|
.HasForeignKey("MessageId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Knot.Modules.Chats.Domain.Message", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Reactions");
|
||||||
|
|
||||||
|
b.Navigation("ReadBy");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Knot.Modules.Chats.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RemoveIsImportedDefault : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-2
@@ -1,10 +1,10 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
|
using Knot.Modules.Chats.Infrastructure.Persistence;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
using Knot.Modules.Chats.Infrastructure.Persistence;
|
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@@ -79,6 +79,9 @@ namespace Knot.Modules.Chats.Infrastructure.Persistence.Migrations
|
|||||||
b.Property<bool>("IsEdited")
|
b.Property<bool>("IsEdited")
|
||||||
.HasColumnType("boolean");
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("IsImported")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
b.Property<string>("Quote")
|
b.Property<string>("Quote")
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.12.4" />
|
||||||
<PackageReference Include="MediatR" Version="12.0.1" />
|
<PackageReference Include="MediatR" Version="12.0.1" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.4" />
|
||||||
|
|||||||
@@ -102,12 +102,25 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
|
|
||||||
const typingInChat = typingUsers.filter((t) => t.chatId === activeChat && t.userId !== user?.id);
|
const typingInChat = typingUsers.filter((t) => t.chatId === activeChat && t.userId !== user?.id);
|
||||||
|
|
||||||
|
// Refs and logic for tracking session's first unread message to show the divider exactly once per load
|
||||||
|
const sessionUnreadRef = useRef<{ chatId: string, msgId: string | null }>({ chatId: '', msgId: null });
|
||||||
|
|
||||||
|
if (activeChat && activeChat !== sessionUnreadRef.current.chatId && !isLoadingMessages) {
|
||||||
|
const firstUnreadMsg = chatMessages.find(
|
||||||
|
(m) => m.senderId !== user?.id && !m.readBy?.some((r) => r.userId === user?.id)
|
||||||
|
);
|
||||||
|
sessionUnreadRef.current = { chatId: activeChat, msgId: firstUnreadMsg ? firstUnreadMsg.id : null };
|
||||||
|
}
|
||||||
|
const firstUnreadId = activeChat === sessionUnreadRef.current.chatId ? sessionUnreadRef.current.msgId : null;
|
||||||
|
const lastObservedMessageIdRef = useRef<string | null>(null);
|
||||||
|
|
||||||
// Load muted state
|
// Load muted state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeChat) {
|
if (activeChat) {
|
||||||
setMuted(isChatMuted(activeChat));
|
setMuted(isChatMuted(activeChat));
|
||||||
setScrollReady(false);
|
setScrollReady(false);
|
||||||
setActiveGroupCallParticipants([]);
|
setActiveGroupCallParticipants([]);
|
||||||
|
lastObservedMessageIdRef.current = null;
|
||||||
}
|
}
|
||||||
}, [activeChat]);
|
}, [activeChat]);
|
||||||
|
|
||||||
@@ -167,7 +180,23 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
// Первичная прокрутка при открытии чата или после загрузки (layout effect — до отрисовки)
|
// Первичная прокрутка при открытии чата или после загрузки (layout effect — до отрисовки)
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!isLoadingMessages && messagesContainerRef.current) {
|
if (!isLoadingMessages && messagesContainerRef.current) {
|
||||||
messagesContainerRef.current.scrollTop = messagesContainerRef.current.scrollHeight;
|
const container = messagesContainerRef.current;
|
||||||
|
const unreadId = sessionUnreadRef.current.msgId;
|
||||||
|
|
||||||
|
if (unreadId && activeChat === sessionUnreadRef.current.chatId) {
|
||||||
|
const dividerEl = document.getElementById('unread-divider');
|
||||||
|
const unreadEl = document.getElementById(`msg-${unreadId}`);
|
||||||
|
const targetEl = dividerEl || unreadEl;
|
||||||
|
|
||||||
|
if (targetEl) {
|
||||||
|
// Вычитаем отступ сверху, чтобы начало непрочитанных было под шапкой
|
||||||
|
container.scrollTop = targetEl.offsetTop - 60;
|
||||||
|
} else {
|
||||||
|
container.scrollTop = container.scrollHeight;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
container.scrollTop = container.scrollHeight;
|
||||||
|
}
|
||||||
setScrollReady(true);
|
setScrollReady(true);
|
||||||
}
|
}
|
||||||
}, [activeChat, isLoadingMessages]);
|
}, [activeChat, isLoadingMessages]);
|
||||||
@@ -176,17 +205,25 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (chatMessages.length > 0) {
|
if (chatMessages.length > 0) {
|
||||||
const lastMsg = chatMessages[chatMessages.length - 1];
|
const lastMsg = chatMessages[chatMessages.length - 1];
|
||||||
if (lastMsg.senderId === user?.id) {
|
const prevId = lastObservedMessageIdRef.current;
|
||||||
setTimeout(() => scrollToBottom(true), 50);
|
lastObservedMessageIdRef.current = lastMsg.id;
|
||||||
} else {
|
|
||||||
// Если пользователь внизу — прокрутить
|
// Scroll ONLY if a genuinely new message was added (not during initial chat load)
|
||||||
const container = messagesContainerRef.current;
|
if (prevId && prevId !== lastMsg.id) {
|
||||||
if (container) {
|
if (lastMsg.senderId === user?.id) {
|
||||||
const isNearBottom =
|
setTimeout(() => scrollToBottom(true), 50);
|
||||||
container.scrollHeight - container.scrollTop - container.clientHeight < 250;
|
} else {
|
||||||
if (isNearBottom) setTimeout(() => scrollToBottom(true), 50);
|
// Если пользователь внизу — прокрутить
|
||||||
|
const container = messagesContainerRef.current;
|
||||||
|
if (container) {
|
||||||
|
const isNearBottom =
|
||||||
|
container.scrollHeight - container.scrollTop - container.clientHeight < 300;
|
||||||
|
if (isNearBottom) setTimeout(() => scrollToBottom(true), 50);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lastObservedMessageIdRef.current = null;
|
||||||
}
|
}
|
||||||
}, [chatMessages.length, user?.id, scrollToBottom]);
|
}, [chatMessages.length, user?.id, scrollToBottom]);
|
||||||
|
|
||||||
@@ -273,7 +310,7 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const container = messagesContainerRef.current;
|
const container = messagesContainerRef.current;
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
const isNearBottom =
|
const isNearBottom =
|
||||||
container.scrollHeight - container.scrollTop - container.clientHeight < 200;
|
container.scrollHeight - container.scrollTop - container.clientHeight < 300;
|
||||||
setShowScrollDown(!isNearBottom);
|
setShowScrollDown(!isNearBottom);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -321,29 +358,20 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
if (!activeChat || !chat) {
|
if (!activeChat || !chat) {
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 h-full flex items-center justify-center bg-surface-secondary/50 rounded-[2rem] overflow-hidden border border-white/5 shadow-2xl relative z-0 backdrop-blur-3xl group">
|
<div className="flex-1 h-full flex items-center justify-center bg-surface-secondary/50 rounded-[2rem] overflow-hidden border border-white/5 shadow-2xl relative z-0 backdrop-blur-3xl group">
|
||||||
{/* Slowly pulsing purple background as requested */}
|
|
||||||
<div className="absolute inset-0 pointer-events-none overflow-hidden transition-opacity duration-[10000ms]">
|
|
||||||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[60vw] h-[60vw] max-w-[800px] max-h-[800px] bg-accent/10 rounded-full blur-[120px] animate-[pulse_8s_ease-in-out_infinite]" />
|
|
||||||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[40vw] h-[40vw] max-w-[500px] max-h-[500px] bg-purple-600/15 rounded-full blur-[100px] animate-[pulse_12s_ease-in-out_infinite_reverse]" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="absolute inset-0 bg-[url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGNpcmNsZSBjeD0iMSIgY3k9IjEiIHI9IjEiIGZpbGw9InJnYmEoMjU1LDI1NSwyNTUsMC4wMSkvPjwvc3ZnPg==')] [mask-image:radial-gradient(ellipse_at_center,black_40%,transparent_100%)] opacity-20 pointer-events-none" />
|
|
||||||
|
|
||||||
<div className="text-center relative z-10 w-full max-w-sm px-6 mx-auto">
|
<div className="text-center relative z-10 w-full max-w-sm px-6 mx-auto">
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{ scale: 0.8, opacity: 0 }}
|
initial={{ scale: 0.8, opacity: 0 }}
|
||||||
animate={{ scale: 1, opacity: 1 }}
|
animate={{ scale: 1, opacity: 1 }}
|
||||||
transition={{ duration: 0.6, ease: [0.16, 1, 0.3, 1] }}
|
transition={{ duration: 0.6, ease: [0.16, 1, 0.3, 1] }}
|
||||||
className="w-28 h-28 mx-auto mb-8 rounded-[2rem] bg-gradient-to-br from-accent/20 to-purple-600/20 flex items-center justify-center shadow-[0_0_60px_-15px_var(--color-accent)] ring-1 ring-white/10 backdrop-blur-2xl relative"
|
className="w-24 h-24 mx-auto mb-6 rounded-full bg-surface-hover flex items-center justify-center border border-border/40 backdrop-blur-md relative"
|
||||||
>
|
>
|
||||||
<div className="absolute inset-0 rounded-[2rem] bg-gradient-to-br from-white/[0.05] to-transparent pointer-events-none" />
|
<MessageSquare className="w-10 h-10 text-zinc-500 transform hover:scale-105 transition-transform" />
|
||||||
<MessageSquare className="w-16 h-16 text-accent shadow-2xl transform hover:scale-105 transition-transform" />
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
<motion.h2
|
<motion.h2
|
||||||
initial={{ y: 20, opacity: 0 }}
|
initial={{ y: 20, opacity: 0 }}
|
||||||
animate={{ y: 0, opacity: 1 }}
|
animate={{ y: 0, opacity: 1 }}
|
||||||
transition={{ duration: 0.6, delay: 0.1, ease: [0.16, 1, 0.3, 1] }}
|
transition={{ duration: 0.6, delay: 0.1, ease: [0.16, 1, 0.3, 1] }}
|
||||||
className="text-3xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-accent via-fuchsia-400 to-indigo-400 mb-4 drop-shadow-lg tracking-tight"
|
className="text-2xl font-semibold text-white mb-2 tracking-tight"
|
||||||
>
|
>
|
||||||
Knot Messenger
|
Knot Messenger
|
||||||
</motion.h2>
|
</motion.h2>
|
||||||
@@ -351,7 +379,7 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
initial={{ y: 20, opacity: 0 }}
|
initial={{ y: 20, opacity: 0 }}
|
||||||
animate={{ y: 0, opacity: 1 }}
|
animate={{ y: 0, opacity: 1 }}
|
||||||
transition={{ duration: 0.6, delay: 0.2, ease: [0.16, 1, 0.3, 1] }}
|
transition={{ duration: 0.6, delay: 0.2, ease: [0.16, 1, 0.3, 1] }}
|
||||||
className="text-sm font-medium text-zinc-300 bg-white/5 backdrop-blur-lg py-2.5 px-6 rounded-full inline-flex border border-white/10 shadow-lg"
|
className="text-sm text-zinc-400 bg-surface-hover backdrop-blur-lg py-2 px-4 rounded-full inline-flex border border-border/50"
|
||||||
>
|
>
|
||||||
{t('selectChat')}
|
{t('selectChat')}
|
||||||
</motion.p>
|
</motion.p>
|
||||||
@@ -743,8 +771,8 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const el = document.getElementById(`msg-${msg.id}`);
|
const el = document.getElementById(`msg-${msg.id}`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
el.classList.add('bg-knot-500/20');
|
el.classList.add('highlight-message');
|
||||||
setTimeout(() => el.classList.remove('bg-knot-500/20'), 2000);
|
setTimeout(() => el.classList.remove('highlight-message'), 3000);
|
||||||
}
|
}
|
||||||
setShowSearch(false);
|
setShowSearch(false);
|
||||||
setSearchText('');
|
setSearchText('');
|
||||||
@@ -790,8 +818,8 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const el = document.getElementById(`msg-${pinnedMsg.id}`);
|
const el = document.getElementById(`msg-${pinnedMsg.id}`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
el.classList.add('bg-knot-500/20');
|
el.classList.add('highlight-message');
|
||||||
setTimeout(() => el.classList.remove('bg-knot-500/20'), 2000);
|
setTimeout(() => el.classList.remove('highlight-message'), 3000);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className="flex items-center gap-3 px-4 py-2 border-b border-border bg-surface-secondary/60 hover:bg-surface-hover transition-colors text-left w-full flex-shrink-0"
|
className="flex items-center gap-3 px-4 py-2 border-b border-border bg-surface-secondary/60 hover:bg-surface-hover transition-colors text-left w-full flex-shrink-0"
|
||||||
@@ -839,6 +867,8 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const showDate =
|
const showDate =
|
||||||
!prevMsg ||
|
!prevMsg ||
|
||||||
new Date(msg.createdAt).toDateString() !== new Date(prevMsg.createdAt).toDateString();
|
new Date(msg.createdAt).toDateString() !== new Date(prevMsg.createdAt).toDateString();
|
||||||
|
|
||||||
|
const isFirstUnread = firstUnreadId === msg.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -846,6 +876,15 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
data-message-id={msg.id}
|
data-message-id={msg.id}
|
||||||
className={`transition-colors duration-500 ${msg.senderId !== user?.id && !msg.readBy?.some(r => r.userId === user?.id) ? 'unread-detector' : ''}`}
|
className={`transition-colors duration-500 ${msg.senderId !== user?.id && !msg.readBy?.some(r => r.userId === user?.id) ? 'unread-detector' : ''}`}
|
||||||
>
|
>
|
||||||
|
{isFirstUnread && (
|
||||||
|
<div id="unread-divider" className="flex items-center justify-center my-4 opacity-80 select-none">
|
||||||
|
<div className="flex-1 h-px bg-border/50"></div>
|
||||||
|
<span className="px-4 text-[11px] font-semibold tracking-wider uppercase text-zinc-400">
|
||||||
|
{t('unreadMessages')}
|
||||||
|
</span>
|
||||||
|
<div className="flex-1 h-px bg-border/50"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{showDate && (
|
{showDate && (
|
||||||
<div className="flex justify-center my-4">
|
<div className="flex justify-center my-4">
|
||||||
<span className="px-3 py-1 rounded-full text-xs text-zinc-400 glass">
|
<span className="px-3 py-1 rounded-full text-xs text-zinc-400 glass">
|
||||||
@@ -886,9 +925,9 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
animate={{ scale: 1, opacity: 1 }}
|
animate={{ scale: 1, opacity: 1 }}
|
||||||
exit={{ scale: 0, opacity: 0 }}
|
exit={{ scale: 0, opacity: 0 }}
|
||||||
onClick={() => scrollToBottom()}
|
onClick={() => scrollToBottom()}
|
||||||
className="absolute bottom-24 right-6 w-11 h-11 rounded-full bg-surface-tertiary/90 backdrop-blur-md border border-border shadow-2xl flex items-center justify-center text-zinc-400 hover:text-white hover:bg-surface-hover hover:scale-105 transition-all z-10"
|
className="absolute bottom-24 right-5 w-12 h-12 rounded-full bg-surface-secondary/95 backdrop-blur-md border border-border shadow-xl flex items-center justify-center text-zinc-400 hover:text-white hover:bg-surface-hover hover:scale-105 transition-all z-10"
|
||||||
>
|
>
|
||||||
<ArrowDown size={20} />
|
<ArrowDown size={22} className="text-accent hover:text-accent-light transition-colors" />
|
||||||
{unreadCount > 0 && (
|
{unreadCount > 0 && (
|
||||||
<motion.span
|
<motion.span
|
||||||
initial={{ scale: 0 }}
|
initial={{ scale: 0 }}
|
||||||
@@ -923,8 +962,8 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const el = document.getElementById(`msg-${msgId}`);
|
const el = document.getElementById(`msg-${msgId}`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
el.classList.add('bg-knot-500/20');
|
el.classList.add('highlight-message');
|
||||||
setTimeout(() => el.classList.remove('bg-knot-500/20'), 2000);
|
setTimeout(() => el.classList.remove('highlight-message'), 3000);
|
||||||
setProfileUserId(null);
|
setProfileUserId(null);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -943,8 +982,8 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
|||||||
const el = document.getElementById(`msg-${msgId}`);
|
const el = document.getElementById(`msg-${msgId}`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||||
el.classList.add('bg-knot-500/20');
|
el.classList.add('highlight-message');
|
||||||
setTimeout(() => el.classList.remove('bg-knot-500/20'), 2000);
|
setTimeout(() => el.classList.remove('highlight-message'), 3000);
|
||||||
setShowGroupSettings(false);
|
setShowGroupSettings(false);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -141,28 +141,28 @@ export default function EmojiPicker({ onSelect, onSelectGif, onClose }: EmojiPic
|
|||||||
<>
|
<>
|
||||||
<div className="fixed inset-0 z-[9990]" onClick={onClose} />
|
<div className="fixed inset-0 z-[9990]" onClick={onClose} />
|
||||||
<div
|
<div
|
||||||
className="fixed z-[9991] rounded-2xl shadow-2xl border border-white/10"
|
className="fixed z-[9991] rounded-xl shadow-2xl border border-border/40"
|
||||||
style={{
|
style={{
|
||||||
width: pickerWidth,
|
width: pickerWidth,
|
||||||
height: tab === 'gif' ? 435 : undefined,
|
height: tab === 'gif' ? 435 : undefined,
|
||||||
bottom: pos ? `${window.innerHeight - pos.top}px` : undefined,
|
bottom: pos ? `${window.innerHeight - pos.top}px` : undefined,
|
||||||
left: pos ? pos.left : undefined,
|
left: pos ? pos.left : undefined,
|
||||||
background: 'rgb(17, 17, 19)',
|
background: '#17212b',
|
||||||
visibility: pos ? 'visible' : 'hidden',
|
visibility: pos ? 'visible' : 'hidden',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<div className="flex border-b border-white/10">
|
<div className="flex border-b border-border/40">
|
||||||
<button
|
<button
|
||||||
onClick={() => setTab('emoji')}
|
onClick={() => setTab('emoji')}
|
||||||
className={`flex-1 py-2.5 text-xs font-semibold tracking-wide transition-colors ${tab === 'emoji' ? 'text-white border-b-2 border-accent' : 'text-zinc-500 hover:text-zinc-300'}`}
|
className={`flex-1 py-3 text-[14px] font-medium transition-colors ${tab === 'emoji' ? 'text-accent border-b-[2px] border-accent' : 'text-zinc-500 hover:text-zinc-300'}`}
|
||||||
>
|
>
|
||||||
EMOJI
|
{lang === 'ru' ? 'Эмодзи' : 'Emoji'}
|
||||||
</button>
|
</button>
|
||||||
{config?.enableKlipy && onSelectGif && (
|
{config?.enableKlipy && onSelectGif && (
|
||||||
<button
|
<button
|
||||||
onClick={() => { setTab('gif'); setTimeout(() => gifSearchRef.current?.focus(), 100); }}
|
onClick={() => { setTab('gif'); setTimeout(() => gifSearchRef.current?.focus(), 100); }}
|
||||||
className={`flex-1 py-2.5 text-xs font-semibold tracking-wide transition-colors ${tab === 'gif' ? 'text-white border-b-2 border-accent' : 'text-zinc-500 hover:text-zinc-300'}`}
|
className={`flex-1 py-3 text-[14px] font-medium transition-colors ${tab === 'gif' ? 'text-accent border-b-[2px] border-accent' : 'text-zinc-500 hover:text-zinc-300'}`}
|
||||||
>
|
>
|
||||||
GIF
|
GIF
|
||||||
</button>
|
</button>
|
||||||
@@ -183,7 +183,7 @@ export default function EmojiPicker({ onSelect, onSelectGif, onClose }: EmojiPic
|
|||||||
emojiSize={28}
|
emojiSize={28}
|
||||||
emojiButtonSize={36}
|
emojiButtonSize={36}
|
||||||
maxFrequentRows={2}
|
maxFrequentRows={2}
|
||||||
navPosition="bottom"
|
navPosition="top"
|
||||||
dynamicWidth={false}
|
dynamicWidth={false}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -733,14 +733,14 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex items-end gap-1.5 bg-white/[0.04] backdrop-blur-[40px] rounded-[2rem] border border-white/[0.08] p-2 w-full max-w-3xl mx-auto transition-all duration-300 hover:bg-white/[0.06] focus-within:bg-white/[0.08] shadow-[0_8px_32px_rgba(0,0,0,0.3)] focus-within:shadow-[0_8px_40px_rgba(99,102,241,0.15)] focus-within:border-knot-500/30 group">
|
<div className="flex items-end gap-1.5 bg-surface-secondary rounded-2xl border border-border/40 px-2 py-1.5 w-full max-w-4xl mx-auto transition-all duration-200 focus-within:border-border/80">
|
||||||
{/* Attach */}
|
{/* Attach */}
|
||||||
<div className="relative mb-0.5 ml-1 flex-shrink-0 self-center">
|
<div className="relative mb-0 flex-shrink-0 self-center">
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowAttachMenu(!showAttachMenu)}
|
onClick={() => setShowAttachMenu(!showAttachMenu)}
|
||||||
className="p-2 rounded-full text-white/50 hover:text-white hover:bg-white/10 transition-colors group-focus-within:text-white/70"
|
className="p-2 rounded-full text-zinc-400 hover:text-accent hover:bg-surface-hover transition-colors"
|
||||||
>
|
>
|
||||||
<Paperclip size={20} />
|
<Paperclip size={22} strokeWidth={1.5} />
|
||||||
</button>
|
</button>
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{showAttachMenu && (
|
{showAttachMenu && (
|
||||||
@@ -852,17 +852,17 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
|||||||
onContextMenu={handleInputContextMenu}
|
onContextMenu={handleInputContextMenu}
|
||||||
placeholder={attachments.length > 0 ? t('addCaption') : t('message')}
|
placeholder={attachments.length > 0 ? t('addCaption') : t('message')}
|
||||||
rows={1}
|
rows={1}
|
||||||
className="w-full resize-none bg-transparent text-[15px] text-white placeholder-white/40 leading-relaxed py-2.5 px-2 border-none focus:ring-0 max-h-[150px] outline-none"
|
className="w-full resize-none bg-transparent text-[15px] text-white placeholder-zinc-500 leading-[22px] py-[10px] px-2 border-none focus:ring-0 max-h-[150px] outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Emoji */}
|
{/* Emoji */}
|
||||||
<div className="relative mb-0.5 flex-shrink-0 self-center">
|
<div className="relative mb-0 flex-shrink-0 self-center">
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowEmoji(!showEmoji)}
|
onClick={() => setShowEmoji(!showEmoji)}
|
||||||
className="p-2 rounded-full text-white/50 hover:text-white hover:bg-white/10 transition-colors"
|
className="p-2 rounded-full text-zinc-400 hover:text-accent hover:bg-surface-hover transition-colors"
|
||||||
>
|
>
|
||||||
<Smile size={20} />
|
<Smile size={22} strokeWidth={1.5} />
|
||||||
</button>
|
</button>
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
{showEmoji && (
|
{showEmoji && (
|
||||||
@@ -904,7 +904,7 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Send / Mic */}
|
{/* Send / Mic */}
|
||||||
<div className="flex-shrink-0 self-center mr-0.5 relative">
|
<div className="flex-shrink-0 self-center relative flex items-center">
|
||||||
{hasContent ? (
|
{hasContent ? (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
@@ -1031,9 +1031,9 @@ export default function MessageInput({ chatId }: MessageInputProps) {
|
|||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
onClick={startRecording}
|
onClick={startRecording}
|
||||||
className="w-10 h-10 flex items-center justify-center rounded-full bg-white/10 text-white/70 hover:text-white hover:bg-white/20 transition-all shadow-md transform hover:scale-105"
|
className="w-10 h-10 flex items-center justify-center rounded-full text-zinc-400 hover:text-accent hover:bg-surface-hover transition-colors"
|
||||||
>
|
>
|
||||||
<Mic size={18} />
|
<Mic size={22} strokeWidth={1.5} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import { getSocket } from '../lib/socket';
|
|||||||
import { useLang } from '../lib/i18n';
|
import { useLang } from '../lib/i18n';
|
||||||
import { useThemeStore, ChatTheme } from '../stores/themeStore';
|
import { useThemeStore, ChatTheme } from '../stores/themeStore';
|
||||||
import DatePicker from './DatePicker';
|
import DatePicker from './DatePicker';
|
||||||
|
import TelegramImportModal from './TelegramImportModal';
|
||||||
import type { User as UserType, UserPresence, FriendRequest, FriendWithId } from '../lib/types';
|
import type { User as UserType, UserPresence, FriendRequest, FriendWithId } from '../lib/types';
|
||||||
|
|
||||||
type SideView = 'main' | 'profile' | 'settings' | 'about' | 'themes' | 'friends';
|
type SideView = 'main' | 'profile' | 'settings' | 'about' | 'themes' | 'friends';
|
||||||
@@ -56,6 +57,8 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
|||||||
const [prevView, setPrevView] = useState<SideView>('main');
|
const [prevView, setPrevView] = useState<SideView>('main');
|
||||||
const [themeIndex, setThemeIndex] = useState(0);
|
const [themeIndex, setThemeIndex] = useState(0);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const [showImportModal, setShowImportModal] = useState(false);
|
||||||
|
|
||||||
// Friends state
|
// Friends state
|
||||||
const [friends, setFriends] = useState<FriendWithId[]>([]);
|
const [friends, setFriends] = useState<FriendWithId[]>([]);
|
||||||
@@ -425,6 +428,23 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="px-5 py-3 border-t border-border mt-2">
|
||||||
|
<h4 className="text-xs text-zinc-500 uppercase tracking-wide mb-3">Хранилище и данные</h4>
|
||||||
|
<button
|
||||||
|
onClick={() => { setShowImportModal(true); }}
|
||||||
|
className="w-full flex items-center gap-4 px-3 py-3 rounded-xl bg-surface-tertiary/50 hover:bg-surface-hover transition-colors"
|
||||||
|
>
|
||||||
|
<div className="w-8 h-8 rounded-lg bg-blue-500/20 flex items-center justify-center">
|
||||||
|
<MessageSquare size={16} className="text-blue-400" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1 min-w-0 text-left">
|
||||||
|
<p className="text-sm text-zinc-200">Импорт истории Telegram</p>
|
||||||
|
<p className="text-[11px] text-zinc-500 mt-0.5">Перенести сообщения и медиа</p>
|
||||||
|
</div>
|
||||||
|
<ChevronRight size={18} className="text-zinc-500 transition-colors" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="px-5 py-3">
|
<div className="px-5 py-3">
|
||||||
<h4 className="text-xs text-zinc-500 uppercase tracking-wide mb-3">{t('about')}</h4>
|
<h4 className="text-xs text-zinc-500 uppercase tracking-wide mb-3">{t('about')}</h4>
|
||||||
<div className="flex items-center gap-4 px-3 py-3 rounded-xl bg-surface-tertiary/50">
|
<div className="flex items-center gap-4 px-3 py-3 rounded-xl bg-surface-tertiary/50">
|
||||||
@@ -760,6 +780,7 @@ export default function SideMenu({ isOpen, onClose, onOpenProfile }: SideMenuPro
|
|||||||
{view === 'about' && renderAbout()}
|
{view === 'about' && renderAbout()}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
<TelegramImportModal isOpen={showImportModal} onClose={() => setShowImportModal(false)} friends={friends} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
|
|||||||
@@ -100,45 +100,47 @@ export default function Sidebar() {
|
|||||||
<>
|
<>
|
||||||
<div className="w-full h-full flex flex-col bg-surface-secondary sm:rounded-[2rem] overflow-hidden border-x sm:border border-border/50 shadow-2xl relative z-10">
|
<div className="w-full h-full flex flex-col bg-surface-secondary sm:rounded-[2rem] overflow-hidden border-x sm:border border-border/50 shadow-2xl relative z-10">
|
||||||
{/* Шапка */}
|
{/* Шапка */}
|
||||||
<div className="h-[76px] px-4 flex items-center gap-3 border-b border-border/40 bg-surface-secondary flex-shrink-0">
|
<div className="h-14 px-3 flex items-center justify-between border-b border-border/40 bg-surface-secondary flex-shrink-0">
|
||||||
<button
|
<div className="flex items-center gap-2">
|
||||||
onClick={() => setShowSideMenu(true)}
|
<button
|
||||||
className="p-2 rounded-lg hover:bg-surface-hover transition-colors text-zinc-400 hover:text-white"
|
onClick={() => setShowSideMenu(true)}
|
||||||
title={t('menu')}
|
className="p-1.5 rounded-lg hover:bg-surface-hover transition-colors text-zinc-400 hover:text-white"
|
||||||
>
|
title={t('menu')}
|
||||||
<Menu size={20} />
|
>
|
||||||
</button>
|
<Menu size={20} />
|
||||||
<div className="flex items-center gap-2.5 min-w-0">
|
</button>
|
||||||
<div className="flex items-center justify-center w-9 h-9 rounded-xl bg-gradient-to-br from-accent/20 to-purple-600/20 shadow-[0_0_15px_-3px_var(--color-accent)] ring-1 ring-white/10 relative overflow-hidden">
|
<div className="flex items-center gap-2.5 min-w-0">
|
||||||
<div className="absolute inset-0 rounded-xl bg-gradient-to-br from-white/[0.05] to-transparent pointer-events-none" />
|
<div className="flex items-center justify-center w-8 h-8 rounded-xl bg-accent text-white flex-shrink-0">
|
||||||
<MessageSquare size={18} className="text-accent drop-shadow-md relative z-10" />
|
<MessageSquare size={16} fill="currentColor" strokeWidth={0} />
|
||||||
|
</div>
|
||||||
|
<h1 className="text-[16px] font-semibold text-white truncate tracking-tight">Knot Messenger</h1>
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-lg font-bold gradient-text truncate">Knot Messenger</h1>
|
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowNewChat(true)}
|
onClick={() => setShowNewChat(true)}
|
||||||
className="p-2 rounded-lg hover:bg-surface-hover transition-colors text-zinc-400 hover:text-white"
|
className="p-1.5 rounded-lg hover:bg-surface-hover transition-colors text-zinc-400 hover:text-white"
|
||||||
title={t('newChat')}
|
title={t('newChat')}
|
||||||
>
|
>
|
||||||
<Plus size={20} />
|
<Plus size={22} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Поиск */}
|
{/* Поиск */}
|
||||||
<div className="p-4 bg-surface-secondary/50">
|
<div className="px-3 py-2 bg-surface-secondary">
|
||||||
<div className="relative group">
|
<div className="relative group">
|
||||||
<Search size={18} className="absolute left-4 top-1/2 -translate-y-1/2 text-zinc-500 group-focus-within:text-accent transition-colors" />
|
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-zinc-500 transition-colors" />
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder={t('searchChats')}
|
placeholder={t('searchChats')}
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
className="w-full pl-11 pr-10 py-3 rounded-2xl bg-surface-tertiary/80 text-[15px] font-medium text-white placeholder-zinc-500 border border-border/30 hover:border-border/60 focus:border-accent transition-all outline-none shadow-inner"
|
className="w-full pl-9 pr-8 py-1.5 rounded-[10px] bg-surface-tertiary text-[14px] text-white placeholder-zinc-500 border border-transparent focus:border-accent/50 hover:bg-surface-hover transition-all outline-none"
|
||||||
/>
|
/>
|
||||||
{searchQuery && (
|
{searchQuery && (
|
||||||
<button
|
<button
|
||||||
onClick={() => setSearchQuery('')}
|
onClick={() => setSearchQuery('')}
|
||||||
className="absolute right-3 top-1/2 -translate-y-1/2 p-1 rounded-full bg-surface-hover text-zinc-400 hover:text-white transition-colors"
|
className="absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded-full text-zinc-400 hover:text-white transition-colors"
|
||||||
|
title={t('clear')}
|
||||||
>
|
>
|
||||||
<X size={14} />
|
<X size={14} />
|
||||||
</button>
|
</button>
|
||||||
@@ -148,16 +150,16 @@ export default function Sidebar() {
|
|||||||
|
|
||||||
{/* Story circles */}
|
{/* Story circles */}
|
||||||
{(storyGroups.length > 0 || true) && (
|
{(storyGroups.length > 0 || true) && (
|
||||||
<div className="flex items-center gap-3 px-4 py-2 overflow-x-auto scrollbar-hide border-b border-border/20 flex-shrink-0">
|
<div className="flex items-center gap-2 px-3 py-2 overflow-x-auto scrollbar-hide border-b border-border/20 flex-shrink-0">
|
||||||
{/* Add story circle */}
|
{/* Add story circle */}
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowCreateStory(true)}
|
onClick={() => setShowCreateStory(true)}
|
||||||
className="flex flex-col items-center gap-1 flex-shrink-0 group"
|
className="flex flex-col items-center gap-1.5 flex-shrink-0 group w-[60px]"
|
||||||
>
|
>
|
||||||
<div className="w-12 h-12 sm:w-14 sm:h-14 rounded-full border-2 border-dashed border-zinc-600 flex items-center justify-center group-hover:border-accent transition-colors">
|
<div className="w-[50px] h-[50px] rounded-full border border-dashed border-zinc-600 flex items-center justify-center group-hover:border-accent group-hover:bg-accent/10 transition-colors">
|
||||||
<Plus size={18} className="text-zinc-400 group-hover:text-accent transition-colors" />
|
<Plus size={20} className="text-accent transition-colors" />
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] text-zinc-500 truncate w-12 sm:w-14 text-center">{t('newStory')}</span>
|
<span className="text-[11px] text-zinc-400 truncate w-full text-center">{t('newStory')}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{storyGroups.map((group, idx) => {
|
{storyGroups.map((group, idx) => {
|
||||||
@@ -167,25 +169,25 @@ export default function Sidebar() {
|
|||||||
<button
|
<button
|
||||||
key={group.user.id}
|
key={group.user.id}
|
||||||
onClick={() => openViewer(idx)}
|
onClick={() => openViewer(idx)}
|
||||||
className="flex flex-col items-center gap-1 flex-shrink-0 group"
|
className="flex flex-col items-center gap-1.5 flex-shrink-0 group w-[60px]"
|
||||||
>
|
>
|
||||||
<div className={`w-14 h-14 rounded-full p-[2.5px] transition-transform group-hover:scale-105 ${
|
<div className={`w-[50px] h-[50px] rounded-full flex items-center justify-center transition-transform group-hover:scale-[1.03] ${
|
||||||
group.hasUnviewed
|
group.hasUnviewed
|
||||||
? 'bg-gradient-to-tr from-accent via-purple-500 to-pink-500 shadow-lg shadow-accent/25'
|
? 'border-[2px] border-accent'
|
||||||
: isMine
|
: isMine
|
||||||
? 'bg-gradient-to-tr from-zinc-500 to-zinc-600'
|
? 'border border-zinc-600'
|
||||||
: 'bg-zinc-700'
|
: 'border border-zinc-700'
|
||||||
}`}>
|
}`}>
|
||||||
<div className="w-full h-full rounded-full overflow-hidden border-[2.5px] border-surface-secondary">
|
<div className="w-[44px] h-[44px] rounded-full overflow-hidden">
|
||||||
<Avatar
|
<Avatar
|
||||||
src={avatarUrl}
|
src={avatarUrl}
|
||||||
name={group.user.displayName || group.user.username}
|
name={group.user.displayName || group.user.username}
|
||||||
size="lg"
|
size="md"
|
||||||
className="w-full h-full"
|
className="w-full h-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] text-zinc-400 truncate w-14 text-center">
|
<span className="text-[11px] text-zinc-400 truncate w-full text-center">
|
||||||
{isMine ? t('myStory') : (group.user.displayName || group.user.username).split(' ')[0]}
|
{isMine ? t('myStory') : (group.user.displayName || group.user.username).split(' ')[0]}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -0,0 +1,249 @@
|
|||||||
|
import { useState, useRef } from 'react';
|
||||||
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
|
import { X, Upload, Check, Loader2, MessageSquare, AlertCircle } from 'lucide-react';
|
||||||
|
import { api } from '../lib/api';
|
||||||
|
import { useLang } from '../lib/i18n';
|
||||||
|
import type { User as UserType, FriendWithId } from '../lib/types';
|
||||||
|
import { useAuthStore } from '../stores/authStore';
|
||||||
|
|
||||||
|
interface TelegramImportModalProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
friends: FriendWithId[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TelegramImportModal({ isOpen, onClose, friends }: TelegramImportModalProps) {
|
||||||
|
const { t } = useLang();
|
||||||
|
const { user } = useAuthStore();
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
|
const [step, setStep] = useState<1 | 2 | 3>(1); // 1: upload, 2: map, 3: loading/done
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [token, setToken] = useState<string | null>(null);
|
||||||
|
const [names, setNames] = useState<string[]>([]);
|
||||||
|
const [mapping, setMapping] = useState<Record<string, string>>({});
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [importedState, setImportedState] = useState<{ count: number; text: string } | null>(null);
|
||||||
|
|
||||||
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const selectedFile = e.target.files?.[0];
|
||||||
|
if (!selectedFile) return;
|
||||||
|
|
||||||
|
if (!selectedFile.name.endsWith('.zip')) {
|
||||||
|
setError('Пожалуйста, выберите ZIP-архив экспорта Telegram.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setFile(selectedFile);
|
||||||
|
setError(null);
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await api.analyzeTelegramImport(selectedFile) as any;
|
||||||
|
setToken(data.token);
|
||||||
|
setNames(data.names);
|
||||||
|
|
||||||
|
// Auto-map if possible
|
||||||
|
const initialMap: Record<string, string> = {};
|
||||||
|
data.names.forEach((name: string) => {
|
||||||
|
initialMap[name] = '';
|
||||||
|
});
|
||||||
|
setMapping(initialMap);
|
||||||
|
setStep(2);
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
setError(err.message || 'Ошибка загрузки файла');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleExecute = async () => {
|
||||||
|
if (!token) return;
|
||||||
|
setLoading(true);
|
||||||
|
setError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await api.executeTelegramImport({ token, mapping }) as any;
|
||||||
|
setImportedState({ count: res.messagesImported, text: 'Успешно импортировано' });
|
||||||
|
setStep(3);
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error(err);
|
||||||
|
setError(err.message || 'Ошибка импорта');
|
||||||
|
setStep(1);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
setStep(1);
|
||||||
|
setFile(null);
|
||||||
|
setToken(null);
|
||||||
|
setNames([]);
|
||||||
|
setMapping({});
|
||||||
|
setError(null);
|
||||||
|
setImportedState(null);
|
||||||
|
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
reset();
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AnimatePresence>
|
||||||
|
{isOpen && (
|
||||||
|
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
className="absolute inset-0 bg-black/60 backdrop-blur-sm"
|
||||||
|
onClick={step === 3 && importedState ? handleClose : undefined}
|
||||||
|
/>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||||
|
animate={{ opacity: 1, scale: 1, y: 0 }}
|
||||||
|
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
||||||
|
className="relative w-full max-w-lg bg-surface-secondary border border-border shadow-2xl rounded-2xl overflow-hidden flex flex-col max-h-[90vh]"
|
||||||
|
>
|
||||||
|
{/* Header */}
|
||||||
|
<div className="h-14 px-4 flex items-center justify-between border-b border-border bg-surface-secondary/50 backdrop-blur-md shrink-0">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<MessageSquare size={20} className="text-knot-400" />
|
||||||
|
<h3 className="font-semibold text-white">Импорт из Telegram</h3>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleClose}
|
||||||
|
className="p-2 -mr-2 text-zinc-400 hover:text-white hover:bg-white/10 rounded-xl transition-all"
|
||||||
|
>
|
||||||
|
<X size={20} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex-1 overflow-y-auto p-6">
|
||||||
|
{error && (
|
||||||
|
<div className="mb-6 p-4 rounded-xl bg-red-500/10 border border-red-500/20 flex gap-3 text-red-400">
|
||||||
|
<AlertCircle size={20} className="shrink-0" />
|
||||||
|
<p className="text-sm">{error}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{step === 1 && (
|
||||||
|
<div className="text-center space-y-6">
|
||||||
|
<div className="w-20 h-20 mx-auto bg-surface-tertiary rounded-full flex items-center justify-center border border-border">
|
||||||
|
<Upload size={32} className="text-knot-400" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 className="text-lg font-medium text-white mb-2">Загрузите архив с историей</h4>
|
||||||
|
<p className="text-sm text-zinc-400 leading-relaxed max-w-sm mx-auto">
|
||||||
|
Скачайте историю чата из Telegram в формате HTML (сняв галочку с формата JSON). Убедитесь, что медиафайлы тоже скачаны, если хотите перенести их. Загрузите полученный ZIP архив.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileInputRef}
|
||||||
|
onChange={handleFileChange}
|
||||||
|
accept=".zip"
|
||||||
|
className="hidden"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => fileInputRef.current?.click()}
|
||||||
|
disabled={loading}
|
||||||
|
className="h-12 px-6 bg-knot-500 hover:bg-knot-600 active:bg-knot-700 text-white font-medium rounded-xl transition-colors inline-flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed mx-auto"
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<Loader2 size={18} className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Upload size={18} />
|
||||||
|
Выбрать ZIP-архив
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{step === 2 && (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div>
|
||||||
|
<h4 className="text-lg font-medium text-white mb-2">Кто есть кто?</h4>
|
||||||
|
<p className="text-sm text-zinc-400">
|
||||||
|
Мы нашли {names.length} имён в архиве. Укажите, какому контакту в Knot они соответствуют. Одно из имён должно принадлежать вам.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
{names.map((name) => (
|
||||||
|
<div key={name} className="flex flex-col gap-2 p-4 rounded-xl border border-border bg-surface-tertiary">
|
||||||
|
<span className="text-sm font-medium text-white">Сообщения от: "{name}"</span>
|
||||||
|
<select
|
||||||
|
value={mapping[name] || ''}
|
||||||
|
onChange={(e) => setMapping({ ...mapping, [name]: e.target.value })}
|
||||||
|
className="w-full h-11 px-3 bg-surface-secondary text-sm text-white rounded-lg border border-border focus:border-knot-500 outline-none transition-colors"
|
||||||
|
>
|
||||||
|
<option value="">-- Выберите пользователя --</option>
|
||||||
|
<option value={user?.id}>Это я ({user?.displayName || user?.username})</option>
|
||||||
|
<optgroup label="Мои контакты">
|
||||||
|
{friends.map(f => (
|
||||||
|
<option key={f.id} value={f.id}>
|
||||||
|
Контакт: {f.displayName || f.username}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</optgroup>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pt-4 flex items-center justify-end gap-3">
|
||||||
|
<button
|
||||||
|
onClick={reset}
|
||||||
|
disabled={loading}
|
||||||
|
className="px-5 py-2.5 text-sm font-medium text-zinc-400 hover:text-white transition-colors"
|
||||||
|
>
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleExecute}
|
||||||
|
disabled={loading || names.some(n => !mapping[n])}
|
||||||
|
className="px-6 py-2.5 bg-knot-500 hover:bg-knot-600 disabled:bg-surface-tertiary disabled:text-zinc-500 text-white text-sm font-medium rounded-xl transition-colors flex items-center gap-2"
|
||||||
|
>
|
||||||
|
{loading ? <Loader2 size={16} className="animate-spin" /> : <Check size={16} />}
|
||||||
|
Импортировать
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{step === 3 && importedState && (
|
||||||
|
<div className="text-center py-8 space-y-4">
|
||||||
|
<div className="w-16 h-16 mx-auto bg-green-500/20 text-green-400 rounded-full flex items-center justify-center border border-green-500/30">
|
||||||
|
<Check size={32} />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h4 className="text-xl font-medium text-white mb-2">Готово!</h4>
|
||||||
|
<p className="text-sm text-zinc-400">
|
||||||
|
Импорт завершен. Сообщений: <strong className="text-white">{importedState.count}</strong>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={handleClose}
|
||||||
|
className="mt-6 h-11 px-6 bg-surface-tertiary hover:bg-surface-hover active:bg-surface-secondary text-white font-medium rounded-xl transition-colors"
|
||||||
|
>
|
||||||
|
Закрыть
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -374,9 +374,8 @@ export default function UserProfile({ userId, chatId, onClose, onGoToMessage, is
|
|||||||
className="fixed right-3 top-3 bottom-3 w-[650px] max-w-[calc(100%-24px)] bg-surface-secondary/90 backdrop-blur-3xl shadow-2xl shadow-black/80 border border-white/5 rounded-[2rem] z-50 flex flex-col overflow-hidden ring-1 ring-white/10"
|
className="fixed right-3 top-3 bottom-3 w-[650px] max-w-[calc(100%-24px)] bg-surface-secondary/90 backdrop-blur-3xl shadow-2xl shadow-black/80 border border-white/5 rounded-[2rem] z-50 flex flex-col overflow-hidden ring-1 ring-white/10"
|
||||||
>
|
>
|
||||||
{/* Шапка */}
|
{/* Шапка */}
|
||||||
<div className="flex items-center justify-between p-5 border-b border-white/5 bg-white/5 relative overflow-hidden">
|
<div className="flex items-center justify-between p-5 border-b border-border/40 bg-surface-secondary relative overflow-hidden">
|
||||||
<div className="absolute inset-0 bg-gradient-to-r from-knot-500/20 to-purple-500/10 pointer-events-none" />
|
<h2 className="text-lg font-semibold tracking-tight text-white relative z-10 flex-1">
|
||||||
<h2 className="text-xl font-bold tracking-tight text-white drop-shadow-sm relative z-10 flex-1">
|
|
||||||
{(isSelf ? t('myProfile') : t('profileTitle')) as string}
|
{(isSelf ? t('myProfile') : t('profileTitle')) as string}
|
||||||
</h2>
|
</h2>
|
||||||
<div className="flex items-center gap-2 relative z-10">
|
<div className="flex items-center gap-2 relative z-10">
|
||||||
@@ -417,23 +416,18 @@ export default function UserProfile({ userId, chatId, onClose, onGoToMessage, is
|
|||||||
<div className="flex-shrink-0 overflow-y-auto max-h-[50%] custom-scrollbar">
|
<div className="flex-shrink-0 overflow-y-auto max-h-[50%] custom-scrollbar">
|
||||||
{/* Аватар */}
|
{/* Аватар */}
|
||||||
<div className="flex flex-col items-center pt-8 pb-4 px-6 relative overflow-visible">
|
<div className="flex flex-col items-center pt-8 pb-4 px-6 relative overflow-visible">
|
||||||
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[240px] h-[240px] bg-knot-500/10 rounded-full blur-[80px] pointer-events-none" />
|
<div className="relative group">
|
||||||
|
|
||||||
<div className="relative group">
|
|
||||||
{/* Spinning gradient glow ring */}
|
|
||||||
<div className="absolute -inset-1 bg-gradient-to-r from-accent via-purple-500 to-accent rounded-full opacity-50 blur group-hover:opacity-75 transition duration-500 animate-[spin_4s_linear_infinite]" />
|
|
||||||
|
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
{profile.avatar ? (
|
{profile.avatar ? (
|
||||||
<img
|
<img
|
||||||
src={getMediaUrl(profile.avatar)}
|
src={getMediaUrl(profile.avatar)}
|
||||||
alt=""
|
alt=""
|
||||||
className="w-32 h-32 rounded-full object-cover ring-4 ring-surface bg-surface"
|
className="w-32 h-32 rounded-full object-cover border-4 border-surface bg-surface"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="w-32 h-32 rounded-full bg-gradient-to-br from-surface to-surface-secondary flex items-center justify-center text-white font-bold text-4xl ring-4 ring-surface relative overflow-hidden">
|
<div className="w-32 h-32 rounded-full bg-accent flex items-center justify-center text-white font-bold text-4xl border-4 border-surface relative overflow-hidden">
|
||||||
<div className="absolute inset-0 bg-gradient-to-tr from-accent/20 to-purple-500/20" />
|
<span className="relative z-10 drop-shadow-sm">{initials}</span>
|
||||||
<span className="relative z-10 text-transparent bg-clip-text bg-gradient-to-br from-white to-zinc-400 drop-shadow-md">{initials}</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -477,15 +471,15 @@ export default function UserProfile({ userId, chatId, onClose, onGoToMessage, is
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<h3 className="mt-5 text-[28px] font-bold text-transparent bg-clip-text bg-gradient-to-b from-white to-white/70 tracking-tight text-center px-4">
|
<h3 className="mt-5 text-[24px] font-semibold text-white tracking-tight text-center px-4">
|
||||||
{profile.displayName || profile.username}
|
{profile.displayName || profile.username}
|
||||||
</h3>
|
</h3>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Username (неизменяемый) */}
|
{/* Username (неизменяемый) */}
|
||||||
<div className="flex items-center gap-1.5 mt-2.5 bg-knot-500/10 hover:bg-knot-500/20 transition-colors px-4 py-1.5 rounded-full border border-knot-500/20 backdrop-blur-sm cursor-default">
|
<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-knot-400" />
|
<AtSign size={14} className="text-accent" />
|
||||||
<span className="text-sm font-semibold text-knot-100">{profile.username}</span>
|
<span className="text-sm font-medium text-accent">{profile.username}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Онлайн статус */}
|
{/* Онлайн статус */}
|
||||||
|
|||||||
+28
-7
@@ -65,8 +65,8 @@ html, body, #root {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Roboto', 'Helvetica Neue', Arial, sans-serif);
|
||||||
background-color: #09090b;
|
background-color: var(--color-surface, #17212b);
|
||||||
color: #fafafa;
|
color: #fafafa;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
@@ -300,18 +300,39 @@ a:focus:not(:focus-visible) {
|
|||||||
|
|
||||||
/* emoji-mart dark theme overrides */
|
/* emoji-mart dark theme overrides */
|
||||||
em-emoji-picker {
|
em-emoji-picker {
|
||||||
--em-rgb-background: 17, 17, 19;
|
--em-rgb-background: 23, 33, 43; /* Telegram surface color */
|
||||||
--em-rgb-input: 26, 26, 30;
|
--em-rgb-input: 30, 44, 58;
|
||||||
--em-rgb-color: 240, 240, 240;
|
--em-rgb-color: 240, 240, 240;
|
||||||
--border-radius: 0 0 16px 16px;
|
--border-radius: 0 0 16px 16px;
|
||||||
border: none !important;
|
border: none !important;
|
||||||
|
|
||||||
|
/* Overrides for category navigation to remove blue line and add soft bg */
|
||||||
|
--category-icon-active-border-color: transparent !important;
|
||||||
|
--category-icon-active-color: #5288c1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
em-emoji-picker::part(category-icons) {
|
||||||
|
padding-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
em-emoji-picker::part(category-icon) {
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
em-emoji-picker::part(category-icon):hover {
|
||||||
|
background-color: rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
em-emoji-picker::part(category-icon-active) {
|
||||||
|
background-color: rgba(82, 136, 193, 0.15); /* Accent light bg */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Highlight for quoted messages */
|
/* Highlight for quoted messages */
|
||||||
@keyframes highlight-glow {
|
@keyframes highlight-glow {
|
||||||
0% { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.8), 0 0 20px rgba(99, 102, 241, 0.6); }
|
0% { box-shadow: 0 0 0 3px rgba(82, 136, 193, 0.8), 0 0 20px rgba(82, 136, 193, 0.6); }
|
||||||
20% { box-shadow: 0 0 0 4px rgba(99, 102, 241, 1), 0 0 30px rgba(99, 102, 241, 0.8); }
|
20% { box-shadow: 0 0 0 4px rgba(82, 136, 193, 1), 0 0 30px rgba(82, 136, 193, 0.8); }
|
||||||
100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0), 0 0 0 rgba(99, 102, 241, 0); }
|
100% { box-shadow: 0 0 0 0 rgba(82, 136, 193, 0), 0 0 0 rgba(82, 136, 193, 0); }
|
||||||
}
|
}
|
||||||
|
|
||||||
.highlight-message {
|
.highlight-message {
|
||||||
|
|||||||
+29
-6
@@ -14,17 +14,21 @@ class ApiClient {
|
|||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = timeout > 0 ? setTimeout(() => controller.abort(), timeout) : undefined;
|
const timer = timeout > 0 ? setTimeout(() => controller.abort(), timeout) : undefined;
|
||||||
|
|
||||||
const headers: HeadersInit = {
|
const isFormData = fetchOptions.body instanceof FormData;
|
||||||
'Content-Type': 'application/json',
|
const computedHeaders: Record<string, string> = {
|
||||||
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
|
...(this.token ? { Authorization: `Bearer ${this.token}` } : {}),
|
||||||
...fetchOptions.headers,
|
...(fetchOptions.headers as Record<string, string>),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isFormData && !computedHeaders['Content-Type']) {
|
||||||
|
computedHeaders['Content-Type'] = 'application/json';
|
||||||
|
}
|
||||||
|
|
||||||
let response: Response;
|
let response: Response;
|
||||||
try {
|
try {
|
||||||
response = await fetch(`${API_BASE}${endpoint}`, {
|
response = await fetch(`${API_BASE}${endpoint}`, {
|
||||||
...fetchOptions,
|
...fetchOptions,
|
||||||
headers,
|
headers: computedHeaders,
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -336,11 +340,30 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// User settings
|
// User settings
|
||||||
async updateSettings(data: { hideStoryViews?: boolean }) {
|
async updateSettings(settings: any) {
|
||||||
return this.request<User>('/users/settings', {
|
const res = await this.request('/users/settings', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(settings),
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async analyzeTelegramImport(file: File) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
const res = await this.request('/import/telegram/analyze', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData,
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async executeTelegramImport(data: { token: string; mapping: Record<string, string> }) {
|
||||||
|
const res = await this.request('/import/telegram/execute', {
|
||||||
|
method: 'POST',
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Friends
|
// Friends
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ const translations = {
|
|||||||
loadStoriesError: 'Ошибка загрузки историй',
|
loadStoriesError: 'Ошибка загрузки историй',
|
||||||
loadChatsError: 'Ошибка загрузки чатов',
|
loadChatsError: 'Ошибка загрузки чатов',
|
||||||
loadMessagesError: 'Ошибка загрузки сообщений',
|
loadMessagesError: 'Ошибка загрузки сообщений',
|
||||||
|
unreadMessages: 'Непрочитанные сообщения',
|
||||||
},
|
},
|
||||||
en: {
|
en: {
|
||||||
myProfile: 'My Profile',
|
myProfile: 'My Profile',
|
||||||
@@ -536,6 +537,7 @@ const translations = {
|
|||||||
loadStoriesError: 'Error loading stories',
|
loadStoriesError: 'Error loading stories',
|
||||||
loadChatsError: 'Error loading chats',
|
loadChatsError: 'Error loading chats',
|
||||||
loadMessagesError: 'Error loading messages',
|
loadMessagesError: 'Error loading messages',
|
||||||
|
unreadMessages: 'Unread messages',
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
+8
-25
@@ -3,10 +3,8 @@ services:
|
|||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
container_name: knot-db
|
container_name: knot-db
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
env_file:
|
||||||
POSTGRES_USER: ${POSTGRES_USER}
|
- .env
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
||||||
POSTGRES_DB: ${POSTGRES_DB}
|
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
@@ -18,22 +16,8 @@ services:
|
|||||||
dockerfile: Dockerfile.server-net
|
dockerfile: Dockerfile.server-net
|
||||||
container_name: knot-server
|
container_name: knot-server
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
env_file:
|
||||||
DATABASE_URL: ${DATABASE_URL}
|
- .env
|
||||||
DOMAIN: ${DOMAIN}
|
|
||||||
JWT_SECRET: ${JWT_SECRET}
|
|
||||||
JWT_ISSUER: ${JWT_ISSUER}
|
|
||||||
JWT_AUDIENCE: ${JWT_AUDIENCE}
|
|
||||||
TURN_URL: ${TURN_URL}
|
|
||||||
TURN_USERNAME: ${TURN_USERNAME}
|
|
||||||
TURN_PASSWORD: ${TURN_PASSWORD}
|
|
||||||
S3_ENDPOINT: ${S3_ENDPOINT}
|
|
||||||
S3_ACCESS_KEY: ${S3_ACCESS_KEY}
|
|
||||||
S3_SECRET_KEY: ${S3_SECRET_KEY}
|
|
||||||
S3_BUCKET: ${S3_BUCKET}
|
|
||||||
KNOT_MASTER_ENCRYPTION_KEY: ${KNOT_MASTER_ENCRYPTION_KEY}
|
|
||||||
KNOT_ADMIN_USER: ${KNOT_ADMIN_USER}
|
|
||||||
KNOT_ADMIN_PASSWORD: ${KNOT_ADMIN_PASSWORD}
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- minio
|
- minio
|
||||||
@@ -44,9 +28,8 @@ services:
|
|||||||
image: minio/minio
|
image: minio/minio
|
||||||
container_name: knot-minio
|
container_name: knot-minio
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
env_file:
|
||||||
MINIO_ROOT_USER: ${S3_ACCESS_KEY}
|
- .env
|
||||||
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
|
|
||||||
ports:
|
ports:
|
||||||
- "9000:9000"
|
- "9000:9000"
|
||||||
- "9001:9001"
|
- "9001:9001"
|
||||||
@@ -64,8 +47,8 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "9090:80"
|
- "9090:80"
|
||||||
environment:
|
env_file:
|
||||||
- VITE_KLIPY_API_KEY=${VITE_KLIPY_API_KEY}
|
- .env
|
||||||
depends_on:
|
depends_on:
|
||||||
- server
|
- server
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user