Update app.py
Browse files
app.py
CHANGED
|
@@ -1853,94 +1853,7 @@ def chat():
|
|
| 1853 |
border-radius: 12px;
|
| 1854 |
background: var(--glass-bg);
|
| 1855 |
color: var(--text-light);
|
| 1856 |
-
|
| 1857 |
-
body.dark .post-select {
|
| 1858 |
-
color: var(--text-dark);
|
| 1859 |
-
}
|
| 1860 |
-
</style>
|
| 1861 |
-
</head>
|
| 1862 |
-
<body>
|
| 1863 |
-
<button class="menu-btn" onclick="toggleSidebar()">☰</button>
|
| 1864 |
-
''' + NAV_HTML + '''
|
| 1865 |
-
<button class="theme-toggle" onclick="toggleTheme()">🌙</button>
|
| 1866 |
-
<div class="container">
|
| 1867 |
-
<h1>General Chat</h1>
|
| 1868 |
-
<div class="messages" id="messages">
|
| 1869 |
-
{% for message in chat_messages %}
|
| 1870 |
-
<div class="message">
|
| 1871 |
-
<a href="{{ url_for('user_profile', username=message['sender']) }}" class="sender">{{ message['sender'] }}</a>
|
| 1872 |
-
<span class="status-dot {{ 'online' if is_user_online(message['sender']) else 'offline' }}"></span>
|
| 1873 |
-
<span class="time">({{ message['time'] }})</span>:
|
| 1874 |
-
{% if 'text' in message %}
|
| 1875 |
-
<p>{{ message['text'] }}</p>
|
| 1876 |
-
{% endif %}
|
| 1877 |
-
{% if 'file' in message %}
|
| 1878 |
-
{% if message['file_type'] == 'video' %}
|
| 1879 |
-
<video controls>
|
| 1880 |
-
<source src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" type="video/mp4">
|
| 1881 |
-
</video>
|
| 1882 |
-
{% else %}
|
| 1883 |
-
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/{{ message['file'] }}" alt="Chat file" onclick="openModal(this.src)">
|
| 1884 |
-
{% endif %}
|
| 1885 |
-
{% endif %}
|
| 1886 |
-
{% if 'post_id' in message %}
|
| 1887 |
-
{% with post = posts|selectattr('id', 'equalto', message['post_id'])|first %}
|
| 1888 |
-
{% if post %}
|
| 1889 |
-
<p>Shared: <a href="{{ url_for('post_page', post_id=message['post_id']) }}">{{ post['title'] }}</a></p>
|
| 1890 |
-
{% endif %}
|
| 1891 |
-
{% endwith %}
|
| 1892 |
-
{% endif %}
|
| 1893 |
-
</div>
|
| 1894 |
-
{% endfor %}
|
| 1895 |
-
</div>
|
| 1896 |
-
{% if is_authenticated %}
|
| 1897 |
-
<form method="POST" enctype="multipart/form-data" class="message-form">
|
| 1898 |
-
<textarea name="message" placeholder="Type a message" rows="2"></textarea>
|
| 1899 |
-
<input type="file" name="file" accept="video/*,image/*">
|
| 1900 |
-
<select name="post_id" class="post-select">
|
| 1901 |
-
<option value="">Share a post (optional)</option>
|
| 1902 |
-
{% for post in user_posts %}
|
| 1903 |
-
<option value="{{ post['id'] }}">{{ post['title'] }}</option>
|
| 1904 |
-
{% endfor %}
|
| 1905 |
-
</select>
|
| 1906 |
-
<button type="submit" class="btn">Send</button>
|
| 1907 |
-
</form>
|
| 1908 |
-
{% else %}
|
| 1909 |
-
<p style="margin-top: 15px;"><a href="{{ url_for('login') }}">Login</a> to send messages.</p>
|
| 1910 |
-
{% endif %}
|
| 1911 |
-
</div>
|
| 1912 |
-
<div class="modal" id="imageModal" onclick="closeModal(event)">
|
| 1913 |
-
<img id="modalImage" src="">
|
| 1914 |
-
</div>
|
| 1915 |
-
<script>
|
| 1916 |
-
function toggleSidebar() {
|
| 1917 |
-
document.getElementById('sidebar').classList.toggle('active');
|
| 1918 |
-
}
|
| 1919 |
-
function toggleTheme() {
|
| 1920 |
-
document.body.classList.toggle('dark');
|
| 1921 |
-
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
|
| 1922 |
-
}
|
| 1923 |
-
function openModal(src) {
|
| 1924 |
-
const modal = document.getElementById('imageModal');
|
| 1925 |
-
const modalImg = document.getElementById('modalImage');
|
| 1926 |
-
modal.style.display = 'flex';
|
| 1927 |
-
modalImg.src = src;
|
| 1928 |
-
}
|
| 1929 |
-
function closeModal(event) {
|
| 1930 |
-
if (event.target.tagName !== 'IMG') {
|
| 1931 |
-
document.getElementById('imageModal').style.display = 'none';
|
| 1932 |
-
}
|
| 1933 |
-
}
|
| 1934 |
-
window.onload = () => {
|
| 1935 |
-
if (localStorage.getItem('theme') === 'dark') document.body.classList.add('dark');
|
| 1936 |
-
const messagesDiv = document.getElementById('messages');
|
| 1937 |
-
messagesDiv.scrollTop = messagesDiv.scrollHeight;
|
| 1938 |
-
};
|
| 1939 |
-
</script>
|
| 1940 |
-
</body>
|
| 1941 |
-
</html>
|
| 1942 |
-
'''
|
| 1943 |
-
user_posts = [p for p in data['posts'] if p['uploader'] == username] if is_authenticated else []
|
| 1944 |
return render_template_string(html,
|
| 1945 |
chat_messages=chat_messages,
|
| 1946 |
username=username,
|
|
|
|
| 1853 |
border-radius: 12px;
|
| 1854 |
background: var(--glass-bg);
|
| 1855 |
color: var(--text-light);
|
| 1856 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1857 |
return render_template_string(html,
|
| 1858 |
chat_messages=chat_messages,
|
| 1859 |
username=username,
|