Work on download files(private chats and groups)

This commit is contained in:
2025-08-14 19:48:29 +03:30
parent 5689cb4267
commit 27fc134ffe
13 changed files with 888 additions and 119 deletions
@@ -0,0 +1,30 @@
// DownloadIndexRegistry.java
package org.to.telegramfinalproject.Client;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public final class DownloadIndexRegistry {
private static final ConcurrentHashMap<UUID, DownloadsIndex> INSTANCES = new ConcurrentHashMap<>();
private static volatile boolean HOOK_REGISTERED = false;
private DownloadIndexRegistry() {}
public static DownloadsIndex forAccount(UUID accountId) {
registerHookOnce();
return INSTANCES.computeIfAbsent(accountId, DownloadsIndex::new);
}
public static void closeAccount(UUID accountId) {
DownloadsIndex idx = INSTANCES.remove(accountId);
if (idx != null) idx.saveQuietly();
}
private static synchronized void registerHookOnce() {
if (HOOK_REGISTERED) return;
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
for (DownloadsIndex idx : INSTANCES.values()) idx.saveQuietly();
}));
HOOK_REGISTERED = true;
}
}