109 lines
5.0 KiB
HTML
109 lines
5.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Conversation with {{ other_user.username }} - aTweet</title>
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
|
<style>
|
|
.messages-container {
|
|
height: 325px;
|
|
overflow-y: auto;
|
|
border: 1px solid #38444d;
|
|
border-radius: 5px;
|
|
padding: 10px;
|
|
margin-bottom: 20px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Conversation with {{ other_user.username }}</h1>
|
|
<div class="messages-container" id="messageList">
|
|
{% for message in messages %}
|
|
<div class="message-container {% if message.sender_id == session['user_id'] %}sent{% else %}received{% endif %}">
|
|
<img src="{{ url_for('static', filename='uploads/' + (message.pfp if message.pfp else 'default_pfp.png')) }}" alt="{{ message.username }}" class="message-avatar">
|
|
<div class="message-content">
|
|
<span class="message-username">{{ message.username }}</span>
|
|
<p>{{ message.content }}</p>
|
|
{% if message.image %}
|
|
<img src="{{ url_for('static', filename='uploads/' + message.image) }}" alt="Message image" class="message-image">
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<form id="messageForm" action="{{ url_for('send_message', username=other_user.username) }}" method="POST" enctype="multipart/form-data" class="message-form">
|
|
<textarea name="content" placeholder="Type your message..." required></textarea>
|
|
<input type="file" name="image" accept="image/*">
|
|
<button type="submit" class="btn btn-primary">Send</button>
|
|
</form>
|
|
</div>
|
|
<footer>
|
|
<div class="footer-container">
|
|
<a href="{{ url_for('index') }}" class="footer-button">
|
|
<i class="fas fa-home"></i> Home
|
|
</a>
|
|
<a href="{{ url_for('profile', username=session.username) }}" class="footer-button">
|
|
<i class="fas fa-user"></i> Profile
|
|
</a>
|
|
<a href="{{ url_for('groups') }}" class="footer-button">
|
|
<i class="fas fa-users"></i> Groups
|
|
</a>
|
|
<a href="{{ url_for('dms') }}" class="footer-button">
|
|
<i class="fas fa-envelope"></i> DMs
|
|
</a>
|
|
{% if session.user_id and get_user_by_id(session.user_id)['username'] == 'avery' %}
|
|
<a href="{{ url_for('admin_panel') }}" class="footer-button">
|
|
<i class="fas fa-cog"></i> Admin Panel
|
|
</a>
|
|
{% endif %}
|
|
<a href="{{ url_for('logout') }}" class="footer-button">
|
|
<i class="fas fa-sign-out-alt"></i> Logout
|
|
</a>
|
|
</div>
|
|
</footer>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script>
|
|
let lastMessageId = 0;
|
|
|
|
function scrollToBottom() {
|
|
const messageList = document.getElementById('messageList');
|
|
messageList.scrollTop = messageList.scrollHeight;
|
|
}
|
|
|
|
function checkNewMessages() {
|
|
$.get("{{ url_for('check_new_messages', username=other_user.username) }}?last_message_id=" + lastMessageId, function(data) {
|
|
if (data.success && data.messages && data.messages.length > 0) {
|
|
const messageList = document.getElementById('messageList');
|
|
data.messages.forEach(message => {
|
|
if (message.id > lastMessageId) {
|
|
const newMessage = `
|
|
<div class="message-container ${message.sender_id == {{ session['user_id'] }} ? 'sent' : 'received'}">
|
|
<img src="{{ url_for('static', filename='uploads/') }}${message.pfp || 'default_pfp.png'}" alt="${message.username}" class="message-avatar">
|
|
<div class="message-content">
|
|
<span class="message-username">${message.username}</span>
|
|
<p>${message.content}</p>
|
|
<span class="message-timestamp">${message.created_at}</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
messageList.insertAdjacentHTML('beforeend', newMessage);
|
|
lastMessageId = message.id;
|
|
}
|
|
});
|
|
scrollToBottom();
|
|
}
|
|
});
|
|
}
|
|
|
|
scrollToBottom();
|
|
lastMessageId = {{ messages[-1].id if messages else 0 }};
|
|
|
|
setInterval(checkNewMessages, 200);
|
|
</script>
|
|
</body>
|
|
</html>
|