This commit is contained in:
@@ -28,13 +28,13 @@
|
||||
}
|
||||
function render(data) {
|
||||
q('[data-nn-incoming]').innerHTML = data.incoming.length ? data.incoming.map(function (name) {
|
||||
return item(name, '<button data-action="accept" data-user="' + esc(name) + '">Annehmen</button><button data-action="decline" data-user="' + esc(name) + '">Ablehnen</button>');
|
||||
return item(name, '<button type="button" data-action="accept" data-user="' + esc(name) + '">Annehmen</button><button type="button" data-action="decline" data-user="' + esc(name) + '">Ablehnen</button>');
|
||||
}).join('') : '<span class="mf-small-hint">Keine offenen Anfragen.</span>';
|
||||
q('[data-nn-outgoing]').innerHTML = data.outgoing.length ? data.outgoing.map(function (name) {
|
||||
return item(name, '<button data-action="cancel" data-user="' + esc(name) + '">Zurückziehen</button>');
|
||||
return item(name, '<button type="button" data-action="cancel" data-user="' + esc(name) + '">Zurückziehen</button>');
|
||||
}).join('') : '<span class="mf-small-hint">Keine gesendeten Anfragen.</span>';
|
||||
q('[data-nn-connections]').innerHTML = data.connections.length ? data.connections.map(function (name) {
|
||||
return item(name, '<button data-action="chat" data-user="' + esc(name) + '" class="' + (selected === name ? 'active' : '') + '">Chat</button>');
|
||||
return item(name, '<button type="button" data-action="chat" data-user="' + esc(name) + '" class="' + (selected === name ? 'active' : '') + '">Chat</button>');
|
||||
}).join('') : '<span class="mf-small-hint">Noch keine Verbindungen.</span>';
|
||||
}
|
||||
async function refresh() {
|
||||
@@ -47,15 +47,19 @@
|
||||
async function loadChat() {
|
||||
if (!selected) return;
|
||||
var rows = await api('/messages/' + encodeURIComponent(selected));
|
||||
q('[data-nn-empty]').hidden = true;
|
||||
q('[data-nn-conversation]').hidden = false;
|
||||
q('[data-nn-partner]').textContent = selected;
|
||||
q('[data-nn-messages]').innerHTML = rows.map(function (message) {
|
||||
return '<article class="nn-message ' + (message.sender === me ? 'mine' : '') + '">' + esc(message.body) + '<small>' + esc(message.sender) + ' · ' + new Date(message.sentAt).toLocaleString('de-DE', { dateStyle: 'short', timeStyle: 'short' }) + '</small></article>';
|
||||
}).join('');
|
||||
var box = q('[data-nn-messages]');
|
||||
box.scrollTop = box.scrollHeight;
|
||||
}
|
||||
function openChat(user) {
|
||||
selected = user;
|
||||
q('[data-nn-empty]').hidden = true;
|
||||
q('[data-nn-conversation]').hidden = false;
|
||||
q('[data-nn-partner]').textContent = user;
|
||||
q('[data-nn-messages]').innerHTML = '<p class="mf-small-hint">Nachrichten werden geladen …</p>';
|
||||
}
|
||||
function message(text) {
|
||||
var hint = q('.nn-head p');
|
||||
hint.textContent = text;
|
||||
@@ -77,7 +81,11 @@
|
||||
if (!button) return;
|
||||
var user = button.dataset.user, action = button.dataset.action;
|
||||
try {
|
||||
if (action === 'chat') { selected = user; await refresh(); await loadChat(); return; }
|
||||
if (action === 'chat') {
|
||||
openChat(user);
|
||||
try { await loadChat(); } catch (error) { message(error.message); }
|
||||
return;
|
||||
}
|
||||
if (action === 'accept') await api('/requests/' + encodeURIComponent(user) + '/accept', 'POST');
|
||||
if (action === 'decline') await api('/requests/' + encodeURIComponent(user) + '/decline', 'POST');
|
||||
if (action === 'cancel') await api('/requests/' + encodeURIComponent(user), 'DELETE');
|
||||
|
||||
Reference in New Issue
Block a user