From deba4b4cfd7d67f9b17f7d365455805ccbd82bf6 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 2 Nov 2026 04:32:12 +0000 Subject: [PATCH] Update static/js/01-api.js --- static/js/01-api.js | 179 ++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 107 deletions(-) diff --git a/static/js/01-api.js b/static/js/01-api.js index 520edc1..4505b19 100644 --- a/static/js/01-api.js +++ b/static/js/01-api.js @@ -12,7 +12,7 @@ Glow.refreshCsrfToken = async () => { }); if (!response.ok) { - throw new Error("Could not refresh security token."); + throw new Error("could not refresh security token."); } const data = await response.json(); @@ -37,9 +37,6 @@ Glow.handleUnauthorized = () => { Glow.state.pageTypeFilter = ""; Glow.state.activeProfile = null; Glow.state.settings = null; - Glow.state.settingsSaved = null; - Glow.state.settingsDraft = null; - Glow.state.settingsDirty = false; Glow.state.selectedAttachment = []; Glow.state.selectedThreadAttachment = []; Glow.state.typingUsers = []; @@ -57,40 +54,35 @@ Glow.handleUnauthorized = () => { clearTimeout(Glow.state.pollTimer); clearTimeout(Glow.state.typingTimer); - clearTimeout(Glow.state.calls.reconnectTimer); - clearTimeout(Glow.state.calls.invitePollTimer); - clearTimeout(Glow.state.calls.participantPollTimer); - clearTimeout(Glow.state.calls.heartbeatTimer); + clearTimeout(Glow.state.calls?.reconnectTimer); + clearTimeout(Glow.state.calls?.invitePollTimer); + clearTimeout(Glow.state.calls?.participantPollTimer); + clearTimeout(Glow.state.calls?.heartbeatTimer); - Glow.state.calls.activeCall = null; - Glow.state.calls.ws = null; - Glow.state.calls.session = null; - Glow.state.calls.localStream = null; - Glow.state.calls.muted = false; - Glow.state.calls.selfPeerId = null; - Glow.state.calls.peerConnections = new Map(); - Glow.state.calls.remoteStreams = new Map(); - Glow.state.calls.participantAudioEls = new Map(); - Glow.state.calls.peers = []; - Glow.state.calls.reconnecting = false; - Glow.state.calls.joining = false; - Glow.state.calls.leaving = false; - Glow.state.calls.invites = []; - Glow.state.calls.backendParticipants = []; - Glow.state.calls.scope = null; - Glow.state.calls.statusText = "Idle"; - Glow.state.calls.metrics = { - packetLoss: null, - uptime: null, - latency: null, - elapsedSeconds: 0, - userCount: 0 - }; - Glow.state.calls.permissions = { - can_manage: false, - can_end: false, - can_invite: false - }; + if (Glow.state.calls) { + Glow.state.calls.activeCall = null; + Glow.state.calls.ws = null; + Glow.state.calls.session = null; + Glow.state.calls.localStream = null; + Glow.state.calls.muted = false; + Glow.state.calls.selfPeerId = null; + Glow.state.calls.peerConnections = new Map(); + Glow.state.calls.remoteStreams = new Map(); + Glow.state.calls.participantAudioEls = new Map(); + Glow.state.calls.peers = []; + Glow.state.calls.reconnecting = false; + Glow.state.calls.joining = false; + Glow.state.calls.leaving = false; + Glow.state.calls.invites = []; + Glow.state.calls.backendParticipants = []; + Glow.state.calls.scope = null; + Glow.state.calls.statusText = "idle"; + Glow.state.calls.permissions = { + can_manage: false, + can_end: false, + can_invite: false + }; + } Glow.clearMessages?.(); Glow.clearFeed?.(); @@ -99,8 +91,6 @@ Glow.handleUnauthorized = () => { Glow.closeReactionPopup?.(); Glow.closeMediaModal?.(); Glow.endLocalCallUi?.(); - Glow.profileResetCropState?.(); - Glow.setSelectedAttachment?.([]); Glow.setSelectedThreadAttachment?.([]); @@ -132,8 +122,8 @@ Glow.handleUnauthorized = () => { Glow.state.activeView = "feed"; Glow.updateAuthUI?.(); - Glow.showAuthNotice?.("Your session has expired. Please sign in again."); - Glow.els.authOverlay.classList.remove("hidden"); + Glow.showAuthNotice?.("your session has expired. please sign in again."); + Glow.els.authOverlay?.classList.remove("hidden"); }; Glow.apiRequest = async (url, options = {}, retryCsrf = true) => { @@ -155,7 +145,7 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => { headers }); } catch (_) { - const error = new Error("Network error. Check your connection and try again."); + const error = new Error("network error. check your connection and try again."); error.code = "network"; throw error; } @@ -169,8 +159,8 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => { } if (response.status === 403 && data.code === "blacklisted") { - Glow.showBlocked(data.error); - throw new Error(data.error || "Access blocked."); + Glow.showBlocked?.(data.error); + throw new Error(data.error || "access blocked."); } if (response.status === 403 && data.code === "csrf" && retryCsrf) { @@ -183,7 +173,7 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => { } if (!response.ok) { - const error = new Error(data.error || "Request failed."); + const error = new Error(data.error || "request failed."); error.status = response.status; error.code = data.code; error.retryAfter = data.retry_after; @@ -373,7 +363,7 @@ Glow.apiLoadHistory = params => { return Glow.apiRequest(`/api/messages/history?${qs.toString()}`); }; -/* DMs */ +/* dms */ Glow.apiListDms = () => Glow.apiRequest("/api/dms"); Glow.apiCreateDm = payload => @@ -440,9 +430,7 @@ Glow.apiEndGroupCall = sessionId => }); Glow.apiGetGroupCallParticipants = sessionId => - Glow.apiRequest( - `/api/group-calls/${encodeURIComponent(sessionId)}/participants` - ); + Glow.apiRequest(`/api/group-calls/${encodeURIComponent(sessionId)}/participants`); Glow.apiInviteToGroupCall = payload => Glow.apiRequest("/api/group-calls/invite", { @@ -455,75 +443,52 @@ Glow.apiListGroupCallInvites = () => Glow.apiRequest("/api/group-calls/invites"); Glow.apiAcceptGroupCallInvite = inviteId => - Glow.apiRequest( - `/api/group-calls/invites/${encodeURIComponent(inviteId)}/accept`, - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({}) - } - ); + Glow.apiRequest(`/api/group-calls/invites/${encodeURIComponent(inviteId)}/accept`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({}) + }); Glow.apiDismissGroupCallInvite = inviteId => - Glow.apiRequest( - `/api/group-calls/invites/${encodeURIComponent(inviteId)}/dismiss`, - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({}) - } - ); - -/* optional / not yet guaranteed on all backends */ -Glow.apiBookmarkMessage = messageId => - Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/bookmark`, { + Glow.apiRequest(`/api/group-calls/invites/${encodeURIComponent(inviteId)}/dismiss`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}) }); -Glow.apiUnbookmarkMessage = messageId => - Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/bookmark`, { - method: "DELETE" - }); +/* disabled partial features */ +Glow.apiBookmarkMessage = async () => { + throw new Error("bookmarks are currently unavailable."); +}; -Glow.apiPinMessage = messageId => - Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({}) - }); +Glow.apiUnbookmarkMessage = async () => { + throw new Error("bookmarks are currently unavailable."); +}; -Glow.apiUnpinMessage = messageId => - Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, { - method: "DELETE" - }); +Glow.apiPinMessage = async () => { + throw new Error("pins are currently unavailable."); +}; -Glow.apiListPins = (scopeKind, scopeId) => - Glow.apiRequest( - `/api/pins?scope_kind=${encodeURIComponent(scopeKind)}&scope_id=${encodeURIComponent(scopeId)}` - ); +Glow.apiUnpinMessage = async () => { + throw new Error("pins are currently unavailable."); +}; -Glow.apiListBookmarks = () => - Glow.apiRequest("/api/bookmarks"); +Glow.apiListPins = async () => { + throw new Error("pins are currently unavailable."); +}; -Glow.apiCreateMessageShare = messageId => - Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/share`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({}) - }); +Glow.apiListBookmarks = async () => { + throw new Error("bookmarks are currently unavailable."); +}; -Glow.apiCreateAttachmentShare = attachmentId => - Glow.apiRequest(`/api/attachments/${encodeURIComponent(attachmentId)}/share`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({}) - }); +Glow.apiCreateMessageShare = async () => { + throw new Error("message sharing is currently unavailable."); +}; -Glow.apiCreateScheduledMessage = payload => - Glow.apiRequest("/api/scheduled-messages", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(payload) - }); \ No newline at end of file +Glow.apiCreateAttachmentShare = async () => { + throw new Error("attachment sharing is currently unavailable."); +}; + +Glow.apiCreateScheduledMessage = async () => { + throw new Error("scheduled messages are currently unavailable."); +}; \ No newline at end of file