From 4becc9d7906c66d6c85dcac55cb80bd378cc3651 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 2 Nov 2026 06:11:39 +0000 Subject: [PATCH] Update static/js/01-api.js --- static/js/01-api.js | 179 ++++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 72 deletions(-) diff --git a/static/js/01-api.js b/static/js/01-api.js index 4505b19..520edc1 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,6 +37,9 @@ 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 = []; @@ -54,35 +57,40 @@ 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); - 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.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 + }; Glow.clearMessages?.(); Glow.clearFeed?.(); @@ -91,6 +99,8 @@ Glow.handleUnauthorized = () => { Glow.closeReactionPopup?.(); Glow.closeMediaModal?.(); Glow.endLocalCallUi?.(); + Glow.profileResetCropState?.(); + Glow.setSelectedAttachment?.([]); Glow.setSelectedThreadAttachment?.([]); @@ -122,8 +132,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) => { @@ -145,7 +155,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; } @@ -159,8 +169,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) { @@ -173,7 +183,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; @@ -363,7 +373,7 @@ Glow.apiLoadHistory = params => { return Glow.apiRequest(`/api/messages/history?${qs.toString()}`); }; -/* dms */ +/* DMs */ Glow.apiListDms = () => Glow.apiRequest("/api/dms"); Glow.apiCreateDm = payload => @@ -430,7 +440,9 @@ 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", { @@ -443,52 +455,75 @@ 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`, { + 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`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}) }); -/* disabled partial features */ -Glow.apiBookmarkMessage = async () => { - throw new Error("bookmarks are currently unavailable."); -}; +Glow.apiUnbookmarkMessage = messageId => + Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/bookmark`, { + method: "DELETE" + }); -Glow.apiUnbookmarkMessage = 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.apiPinMessage = async () => { - throw new Error("pins are currently unavailable."); -}; +Glow.apiUnpinMessage = messageId => + Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, { + method: "DELETE" + }); -Glow.apiUnpinMessage = 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.apiListPins = async () => { - throw new Error("pins are currently unavailable."); -}; +Glow.apiListBookmarks = () => + Glow.apiRequest("/api/bookmarks"); -Glow.apiListBookmarks = async () => { - throw new Error("bookmarks are currently unavailable."); -}; +Glow.apiCreateMessageShare = messageId => + Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/share`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({}) + }); -Glow.apiCreateMessageShare = async () => { - throw new Error("message sharing is currently unavailable."); -}; +Glow.apiCreateAttachmentShare = attachmentId => + Glow.apiRequest(`/api/attachments/${encodeURIComponent(attachmentId)}/share`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({}) + }); -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 +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