buhapp-telegram/public/js/views/chats.js
root 21d281a1c6 Telegram WebApp: Mini App with map, chats, profile, reviews
- index.html with bottom tabbar (Map/Chats/Profile/Settings)
- Telegram WebApp SDK auth via /api/v1/auth/telegram
- Consent gate on first login (4 checkboxes)
- Map view with Leaflet (OSM) + nearby users + radius selector
- Chat list + single chat with WebSocket realtime
- Profile editing (drinks, activities, purposes)
- Review screen with stars + anonymous toggle
- User reviews list with stats
- User profile (public) with rating, write/block/report
- Legal pages (TERMS / PRIVACY / DISCLAIMER)
2026-08-20 17:43:16 +00:00

41 lines
1.5 KiB
JavaScript

// Chats list view
const ChatsView = {
async render(root) {
root.innerHTML = `
<div class="view">
<h1>💬 Чаты</h1>
<div id="chats-list" class="loader">Загрузка...</div>
</div>
`;
try {
const r = await API.ChatApi.listChats();
const list = document.getElementById('chats-list');
if (!r.chats || r.chats.length === 0) {
list.innerHTML = '<div class="empty">Нет чатов. Открой карту и найди кого-нибудь!</div>';
return;
}
list.innerHTML = '';
list.className = '';
r.chats.forEach((item) => {
const row = document.createElement('div');
row.className = 'list-row';
row.innerHTML = `
<div class="avatar" style="${item.other_photo ? `background-image:url(${item.other_photo})` : ''}">
${item.other_photo ? '' : escapeHtml((item.other_name || '?')[0])}
</div>
<div class="body">
<div class="name">${escapeHtml(item.other_name)}</div>
<div class="last">${escapeHtml(item.last_message || 'Нет сообщений')}</div>
</div>
${item.unread_count > 0 ? `<div class="badge">${item.unread_count}</div>` : ''}
`;
row.onclick = () => App.openChat(item.chat.id, item.other_id, item.other_name);
list.appendChild(row);
});
} catch (e) {
document.getElementById('chats-list').innerHTML = '<div class="empty">Ошибка: ' + e.message + '</div>';
}
},
};
window.ChatsView = ChatsView;