9e30086af2
Stop reading image files inside gemini/mistral commands; use pre-encoded image data from message parts Rework loadImagesIfExists / loadImagesFromFileIds to return cached file_unique_ids and download only missing sizes Encode cached images to base64 when assembling the reply chain Make getPhotoMaxSize synchronous (returns PhotoSize), and map to URL only when needed Await MessageStore.put / UserStore.put and prefetch single-image downloads on message receipt
39 lines
963 B
TypeScript
39 lines
963 B
TypeScript
import {User} from "typescript-telegram-bot-api";
|
|
import {userDao} from "../index";
|
|
import {StoredUser} from "../model/stored-user";
|
|
|
|
export class UserStore {
|
|
private static map = new Map<number, StoredUser>();
|
|
|
|
static all(): Map<number, StoredUser> {
|
|
return this.map;
|
|
}
|
|
|
|
static async put(u: User): Promise<StoredUser> {
|
|
const user: StoredUser = {
|
|
id: u.id,
|
|
isBot: u.is_bot,
|
|
firstName: u.first_name,
|
|
lastName: u.last_name,
|
|
userName: u.username,
|
|
isPremium: u.is_premium,
|
|
};
|
|
|
|
this.map.set(u.id, user);
|
|
|
|
await userDao.insert(userDao.mapTo([u]));
|
|
return user;
|
|
}
|
|
|
|
static async get(id: number): Promise<StoredUser | null> {
|
|
const user = await userDao.getById({id: id});
|
|
if (!user) return null;
|
|
|
|
this.map.set(id, user);
|
|
return user;
|
|
}
|
|
|
|
static clear() {
|
|
this.map.clear();
|
|
}
|
|
} |