Spaces:
Running
Running
Update static/script.js
Browse files123 unmodified lines124125126127128129130627 unmodified lines75875976076176276376476576676723 unmodified lines79179279379479579616 unmodified lines813814815816817818819820821196 unmodified lines1018101910201021102210233 unmodified lines10271028102910301031103210335 unmodified lines10391040104110421043104421 unmodified lines1066106710681069107010711072995 unmodified lines2068206920702071207220732074149 unmodified lines2224222522262227222822292230285 unmodified lines251625172518251925202521252225232524252525262527128 unmodified lines26562657265826592660266133 unmodified lines269526962697269826992700123 unmodified linesconvOptionsBtn: $('conv-options-btn'), convOptionsModal: $('conv-options-modal'),convOptionsTitle: $('conv-options-title'),renameConvBtn: $('rename-conv-btn'), addGroupMembersBtn: $('add-group-members-btn'),blockConvUserBtn: $('block-conv-user-btn'), leaveConvBtn: $('leave-conv-btn'),refreshBlocksBtn: $('refresh-blocks-btn'), blockedUsersList: $('blocked-users-list'),settingsDisplayName: $('settings-display-name'), settingsUsername: $('settings-username'),627 unmodified linesState.isAtBottom = true;const cache = getConv(convId);renderConversationHeader(convId);renderSidebar();if (cache.ids.length === 0) {cache.loading = true;loadMessages(convId);renderEmptyLoading(convId);23 unmodified linesDOM.loadOlderBtn.classList.add('hidden');}function renderConversationHeader(convId) {const conv = convById(convId);if (!conv) return;16 unmodified linesconst online = peer.online || State.onlineUsers.has(peer.id);DOM.convPresenceDot.classList.remove('hidden');DOM.convPresenceDot.classList.toggle('offline', !online);DOM.convSubtitle.innerHTML = online? '<span class="status-dot online"></span> Online': escapeHtml(formatLastSeen(peer.last_seen));DOM.onlineBtn.style.display = '';DOM.convAvatarPh.style.display = '';DOM.convAvatar.style.display = '';196 unmodified linesif (msg.conversation.id === State.activeConvId) {renderConversationHeader(State.activeConvId);}break;case 'conversation_deleted': {3 unmodified linesState.messages.forEach(m => { if (m.conversation_id === cid) State.messages.delete(m.id); });if (State.activeConvId === cid) switchConversation(GLOBAL_CONV);renderSidebar();showToast('A group chat was deleted', 'info');break;}5 unmodified linesif (State.activeConvId === cid) switchConversation(GLOBAL_CONV);} else if (msg.conversation) {upsertConversation(msg.conversation);}renderSidebar();break;21 unmodified linesupsertConversation(msg.conversation);const peer = msg.conversation.peer;if (peer && peer.id !== State.user?.id) {showToast(`Private chat with ${displayNameOf(peer)} created`, 'success');switchConversation(msg.conversation.id);}break;995 unmodified linesif (!content && !State.pendingFile) return;if (!State.activeConvId) { showToast('No conversation selected', 'warning'); return; }const active = convById(State.activeConvId);if (active && active.is_pending) { showToast('Accept the group invite first', 'warning'); return; }if (!wsOpen()) {showToast('Not connected - message queued, sending when reconnected', 'warning');}149 unmodified linesupsertConversation(data.conversation);closeModal(DOM.convModal);switchConversation(data.conversation.id);showToast(`Private chat with ${peerName} started`, 'success');} catch (err) {showToast(err.message, 'error');finish();285 unmodified linesif (action === 'accept') {upsertConversation(data.conversation);switchConversation(cid);showToast('Group invite accepted', 'success');} else {State.conversations.delete(cid);State.convCache.delete(cid);renderSidebar();showToast('Group invite rejected', 'info');}} catch (err) {showToast(err.message, 'error');128 unmodified linesconst pending = !!conv.is_pending;DOM.renameConvBtn.style.display = pending ? 'none' : '';DOM.addGroupMembersBtn.style.display = conv.is_group && !pending ? '' : 'none';DOM.blockConvUserBtn.style.display = (!conv.is_group && conv.peer) ? '' : 'none';DOM.leaveConvBtn.style.display = (conv.is_group && !pending) ? '' : 'none';DOM.convOptionsTitle.innerHTML = `<i class="fas fa-ellipsis-h"></i> ${escapeHtml(conv.custom_name || conv.title || 'Chat Options')}`;33 unmodified linesopenModal(DOM.groupModal);});DOM.blockConvUserBtn.addEventListener('click', async () => {const conv = convById(State.activeConvId);closeModal(DOM.convOptionsModal);123 unmodified lines124125126127128129130131627 unmodified lines75976076176276376476576676776876977077177223 unmodified lines79679779879980080180280380480580680780880981081181281316 unmodified lines830831832833834835836837838839840841842843844196 unmodified lines1041104210431044104510461047104810493 unmodified lines10531054105510561057105810595 unmodified lines106510661067106810691070107110721073107421 unmodified lines1096109710981099110011011102995 unmodified lines2098209921002101210221032104149 unmodified lines2254225522562257225822592260285 unmodified lines254625472548254925502551255225532554255525562557128 unmodified lines268626872688268926902691269233 unmodified lines272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752123 unmodified linesconvOptionsBtn: $('conv-options-btn'), convOptionsModal: $('conv-options-modal'),convOptionsTitle: $('conv-options-title'),renameConvBtn: $('rename-conv-btn'), addGroupMembersBtn: $('add-group-members-btn'),deleteConvBtn: $('delete-conv-btn'), blockConvUserBtn: $('block-conv-user-btn'),leaveConvBtn: $('leave-conv-btn'),refreshBlocksBtn: $('refresh-blocks-btn'), blockedUsersList: $('blocked-users-list'),settingsDisplayName: $('settings-display-name'), settingsUsername: $('settings-username'),627 unmodified linesState.isAtBottom = true;const cache = getConv(convId);const conv = convById(convId);renderConversationHeader(convId);renderSidebar();if (conv && conv.is_pending) {cache.loading = false;renderPendingInvite(convId);} else if (cache.ids.length === 0) {cache.loading = true;loadMessages(convId);renderEmptyLoading(convId);23 unmodified linesDOM.loadOlderBtn.classList.add('hidden');}function renderPendingInvite(convId) {DOM.messagesList.innerHTML = '';if (DOM.emptyState.parentNode !== DOM.messagesList) DOM.messagesList.appendChild(DOM.emptyState);const conv = convById(convId);const name = conv ? (conv.custom_name || conv.title || (conv.peer ? displayNameOf(conv.peer) : 'this chat')) : 'this chat';DOM.emptyIcon.innerHTML = '<i class="fas fa-envelope-open-text"></i>';DOM.emptyTitle.textContent = 'Invite pending';DOM.emptySub.textContent = `Accept the invite for ${name} from the sidebar to start chatting.`;DOM.emptyState.style.display = 'flex';DOM.loadOlderBtn.classList.add('hidden');}function renderConversationHeader(convId) {const conv = convById(convId);if (!conv) return;16 unmodified linesconst online = peer.online || State.onlineUsers.has(peer.id);DOM.convPresenceDot.classList.remove('hidden');DOM.convPresenceDot.classList.toggle('offline', !online);if (conv.peer_removed) {DOM.convSubtitle.innerHTML = '<span class="status-dot warn"></span> They no longer want to chat';} else if (conv.is_pending) {DOM.convSubtitle.innerHTML = '<span class="status-dot warn"></span> Invite pending — accept to start chatting';} else {DOM.convSubtitle.innerHTML = online? '<span class="status-dot online"></span> Online': escapeHtml(formatLastSeen(peer.last_seen));}DOM.onlineBtn.style.display = '';DOM.convAvatarPh.style.display = '';DOM.convAvatar.style.display = '';196 unmodified linesif (msg.conversation.id === State.activeConvId) {renderConversationHeader(State.activeConvId);}if (msg.invite_rejected && msg.rejected_user_id && msg.rejected_user_id !== State.user?.id) {showToast('The invite was declined', 'info');}break;case 'conversation_deleted': {3 unmodified linesState.messages.forEach(m => { if (m.conversation_id === cid) State.messages.delete(m.id); });if (State.activeConvId === cid) switchConversation(GLOBAL_CONV);renderSidebar();showToast('The chat was deleted', 'info');break;}5 unmodified linesif (State.activeConvId === cid) switchConversation(GLOBAL_CONV);} else if (msg.conversation) {upsertConversation(msg.conversation);if (msg.reason === 'deleted') {const peer = msg.conversation.peer;showToast(`${peer ? displayNameOf(peer) : 'The other person'} no longer wants to chat`, 'info');}}renderSidebar();break;21 unmodified linesupsertConversation(msg.conversation);const peer = msg.conversation.peer;if (peer && peer.id !== State.user?.id) {showToast(`Private chat with ${displayNameOf(peer)} started — waiting for them to accept`, 'success');switchConversation(msg.conversation.id);}break;995 unmodified linesif (!content && !State.pendingFile) return;if (!State.activeConvId) { showToast('No conversation selected', 'warning'); return; }const active = convById(State.activeConvId);if (active && active.is_pending) { showToast('Accept the invite first', 'warning'); return; }if (!wsOpen()) {showToast('Not connected - message queued, sending when reconnected', 'warning');}149 unmodified linesupsertConversation(data.conversation);closeModal(DOM.convModal);switchConversation(data.conversation.id);showToast(`Private chat with ${peerName} started — waiting for them to accept`, 'success');} catch (err) {showToast(err.message, 'error');finish();285 unmodified linesif (action === 'accept') {upsertConversation(data.conversation);switchConversation(cid);showToast('Invite accepted', 'success');} else {State.conversations.delete(cid);State.convCache.delete(cid);renderSidebar();showToast('Invite declined', 'info');}} catch (err) {showToast(err.message, 'error');128 unmodified linesconst pending = !!conv.is_pending;DOM.renameConvBtn.style.display = pending ? 'none' : '';DOM.addGroupMembersBtn.style.display = conv.is_group && !pending ? '' : 'none';DOM.deleteConvBtn.style.display = (!conv.is_group && conv.peer && !pending) ? '' : 'none';DOM.blockConvUserBtn.style.display = (!conv.is_group && conv.peer) ? '' : 'none';DOM.leaveConvBtn.style.display = (conv.is_group && !pending) ? '' : 'none';DOM.convOptionsTitle.innerHTML = `<i class="fas fa-ellipsis-h"></i> ${escapeHtml(conv.custom_name || conv.title || 'Chat Options')}`;33 unmodified linesopenModal(DOM.groupModal);});DOM.deleteConvBtn.addEventListener('click', async () => {const conv = convById(State.activeConvId);closeModal(DOM.convOptionsModal);if (!conv || conv.is_group || !conv.peer) return;const ok = await showConfirm({title: 'Delete private chat',message: `Delete this chat with ${displayNameOf(conv.peer)}? It will be hidden for you. If they also delete it, it is removed for everyone. They will be told that you no longer want to chat.`,okText: 'Delete Chat'});if (!ok) return;try {const data = await apiDelete(`/api/conversations/${conv.id}`);State.conversations.delete(conv.id);State.convCache.delete(conv.id);if (State.activeConvId === conv.id) switchConversation(GLOBAL_CONV);renderSidebar();showToast(data.status === 'deleted' ? 'Chat deleted' : 'Chat hidden for you', 'success');requestConversations();} catch (err) { showToast(err.message, 'error'); }});DOM.blockConvUserBtn.addEventListener('click', async () => {const conv = convById(State.activeConvId);closeModal(DOM.convOptionsModal);
static/script.js+63-11