Fix JSON format issues with photos and add multi-photo gallery support
This commit is contained in:
76
src/handlers/likeBackHandler.ts
Normal file
76
src/handlers/likeBackHandler.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import TelegramBot from 'node-telegram-bot-api';
|
||||
import { ProfileService } from '../services/profileService';
|
||||
import { MatchingService } from '../services/matchingService';
|
||||
|
||||
export class LikeBackHandler {
|
||||
private bot: TelegramBot;
|
||||
private profileService: ProfileService;
|
||||
private matchingService: MatchingService;
|
||||
|
||||
constructor(bot: TelegramBot) {
|
||||
this.bot = bot;
|
||||
this.profileService = new ProfileService();
|
||||
this.matchingService = new MatchingService();
|
||||
}
|
||||
|
||||
// Функция для обработки обратного лайка из уведомления
|
||||
async handleLikeBack(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||
try {
|
||||
// Получаем информацию о пользователях
|
||||
const [userId, targetProfile] = await Promise.all([
|
||||
this.profileService.getUserIdByTelegramId(telegramId),
|
||||
this.profileService.getProfileByUserId(targetUserId)
|
||||
]);
|
||||
|
||||
if (!userId || !targetProfile) {
|
||||
await this.bot.sendMessage(chatId, '❌ Не удалось найти профиль');
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверяем, есть ли уже свайп
|
||||
const existingSwipe = await this.matchingService.getSwipeBetweenUsers(userId, targetUserId);
|
||||
if (existingSwipe) {
|
||||
await this.bot.sendMessage(chatId, '❓ Вы уже оценили этот профиль ранее.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Создаем свайп (лайк)
|
||||
const result = await this.matchingService.createSwipe(userId, targetUserId, 'like');
|
||||
|
||||
if (result.isMatch) {
|
||||
// Это матч!
|
||||
await this.bot.sendMessage(
|
||||
chatId,
|
||||
'🎉 *Поздравляем! Это взаимно!*\n\n' +
|
||||
`Вы и *${targetProfile.name}* понравились друг другу!\n` +
|
||||
'Теперь вы можете начать общение.',
|
||||
{
|
||||
parse_mode: 'Markdown',
|
||||
reply_markup: {
|
||||
inline_keyboard: [
|
||||
[{ text: '💬 Начать общение', callback_data: `start_chat:${targetUserId}` }],
|
||||
[{ text: '👀 Посмотреть профиль', callback_data: `view_profile:${targetUserId}` }]
|
||||
]
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
await this.bot.sendMessage(
|
||||
chatId,
|
||||
'❤️ Вам понравился профиль ' + targetProfile.name + '!\n\n' +
|
||||
'Если вы также понравитесь этому пользователю, будет создан матч.',
|
||||
{
|
||||
reply_markup: {
|
||||
inline_keyboard: [
|
||||
[{ text: '🔍 Продолжить поиск', callback_data: 'start_browsing' }]
|
||||
]
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in handleLikeBack:', error);
|
||||
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при обработке лайка');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user