Update static/js/01-api.js

This commit is contained in:
dev 2026-11-02 06:11:39 +00:00
parent daa3ac6948
commit 4becc9d790

View File

@ -12,7 +12,7 @@ Glow.refreshCsrfToken = async () => {
}); });
if (!response.ok) { if (!response.ok) {
throw new Error("could not refresh security token."); throw new Error("Could not refresh security token.");
} }
const data = await response.json(); const data = await response.json();
@ -37,6 +37,9 @@ Glow.handleUnauthorized = () => {
Glow.state.pageTypeFilter = ""; Glow.state.pageTypeFilter = "";
Glow.state.activeProfile = null; Glow.state.activeProfile = null;
Glow.state.settings = null; Glow.state.settings = null;
Glow.state.settingsSaved = null;
Glow.state.settingsDraft = null;
Glow.state.settingsDirty = false;
Glow.state.selectedAttachment = []; Glow.state.selectedAttachment = [];
Glow.state.selectedThreadAttachment = []; Glow.state.selectedThreadAttachment = [];
Glow.state.typingUsers = []; Glow.state.typingUsers = [];
@ -54,12 +57,11 @@ Glow.handleUnauthorized = () => {
clearTimeout(Glow.state.pollTimer); clearTimeout(Glow.state.pollTimer);
clearTimeout(Glow.state.typingTimer); clearTimeout(Glow.state.typingTimer);
clearTimeout(Glow.state.calls?.reconnectTimer); clearTimeout(Glow.state.calls.reconnectTimer);
clearTimeout(Glow.state.calls?.invitePollTimer); clearTimeout(Glow.state.calls.invitePollTimer);
clearTimeout(Glow.state.calls?.participantPollTimer); clearTimeout(Glow.state.calls.participantPollTimer);
clearTimeout(Glow.state.calls?.heartbeatTimer); clearTimeout(Glow.state.calls.heartbeatTimer);
if (Glow.state.calls) {
Glow.state.calls.activeCall = null; Glow.state.calls.activeCall = null;
Glow.state.calls.ws = null; Glow.state.calls.ws = null;
Glow.state.calls.session = null; Glow.state.calls.session = null;
@ -76,13 +78,19 @@ Glow.handleUnauthorized = () => {
Glow.state.calls.invites = []; Glow.state.calls.invites = [];
Glow.state.calls.backendParticipants = []; Glow.state.calls.backendParticipants = [];
Glow.state.calls.scope = null; Glow.state.calls.scope = null;
Glow.state.calls.statusText = "idle"; Glow.state.calls.statusText = "Idle";
Glow.state.calls.metrics = {
packetLoss: null,
uptime: null,
latency: null,
elapsedSeconds: 0,
userCount: 0
};
Glow.state.calls.permissions = { Glow.state.calls.permissions = {
can_manage: false, can_manage: false,
can_end: false, can_end: false,
can_invite: false can_invite: false
}; };
}
Glow.clearMessages?.(); Glow.clearMessages?.();
Glow.clearFeed?.(); Glow.clearFeed?.();
@ -91,6 +99,8 @@ Glow.handleUnauthorized = () => {
Glow.closeReactionPopup?.(); Glow.closeReactionPopup?.();
Glow.closeMediaModal?.(); Glow.closeMediaModal?.();
Glow.endLocalCallUi?.(); Glow.endLocalCallUi?.();
Glow.profileResetCropState?.();
Glow.setSelectedAttachment?.([]); Glow.setSelectedAttachment?.([]);
Glow.setSelectedThreadAttachment?.([]); Glow.setSelectedThreadAttachment?.([]);
@ -122,8 +132,8 @@ Glow.handleUnauthorized = () => {
Glow.state.activeView = "feed"; Glow.state.activeView = "feed";
Glow.updateAuthUI?.(); Glow.updateAuthUI?.();
Glow.showAuthNotice?.("your session has expired. please sign in again."); Glow.showAuthNotice?.("Your session has expired. Please sign in again.");
Glow.els.authOverlay?.classList.remove("hidden"); Glow.els.authOverlay.classList.remove("hidden");
}; };
Glow.apiRequest = async (url, options = {}, retryCsrf = true) => { Glow.apiRequest = async (url, options = {}, retryCsrf = true) => {
@ -145,7 +155,7 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => {
headers headers
}); });
} catch (_) { } 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"; error.code = "network";
throw error; throw error;
} }
@ -159,8 +169,8 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => {
} }
if (response.status === 403 && data.code === "blacklisted") { if (response.status === 403 && data.code === "blacklisted") {
Glow.showBlocked?.(data.error); Glow.showBlocked(data.error);
throw new Error(data.error || "access blocked."); throw new Error(data.error || "Access blocked.");
} }
if (response.status === 403 && data.code === "csrf" && retryCsrf) { if (response.status === 403 && data.code === "csrf" && retryCsrf) {
@ -173,7 +183,7 @@ Glow.apiRequest = async (url, options = {}, retryCsrf = true) => {
} }
if (!response.ok) { if (!response.ok) {
const error = new Error(data.error || "request failed."); const error = new Error(data.error || "Request failed.");
error.status = response.status; error.status = response.status;
error.code = data.code; error.code = data.code;
error.retryAfter = data.retry_after; error.retryAfter = data.retry_after;
@ -363,7 +373,7 @@ Glow.apiLoadHistory = params => {
return Glow.apiRequest(`/api/messages/history?${qs.toString()}`); return Glow.apiRequest(`/api/messages/history?${qs.toString()}`);
}; };
/* dms */ /* DMs */
Glow.apiListDms = () => Glow.apiRequest("/api/dms"); Glow.apiListDms = () => Glow.apiRequest("/api/dms");
Glow.apiCreateDm = payload => Glow.apiCreateDm = payload =>
@ -430,7 +440,9 @@ Glow.apiEndGroupCall = sessionId =>
}); });
Glow.apiGetGroupCallParticipants = sessionId => Glow.apiGetGroupCallParticipants = sessionId =>
Glow.apiRequest(`/api/group-calls/${encodeURIComponent(sessionId)}/participants`); Glow.apiRequest(
`/api/group-calls/${encodeURIComponent(sessionId)}/participants`
);
Glow.apiInviteToGroupCall = payload => Glow.apiInviteToGroupCall = payload =>
Glow.apiRequest("/api/group-calls/invite", { Glow.apiRequest("/api/group-calls/invite", {
@ -443,52 +455,75 @@ Glow.apiListGroupCallInvites = () =>
Glow.apiRequest("/api/group-calls/invites"); Glow.apiRequest("/api/group-calls/invites");
Glow.apiAcceptGroupCallInvite = inviteId => Glow.apiAcceptGroupCallInvite = inviteId =>
Glow.apiRequest(`/api/group-calls/invites/${encodeURIComponent(inviteId)}/accept`, { Glow.apiRequest(
`/api/group-calls/invites/${encodeURIComponent(inviteId)}/accept`,
{
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({}) body: JSON.stringify({})
}); }
);
Glow.apiDismissGroupCallInvite = inviteId => 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", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({}) body: JSON.stringify({})
}); });
/* disabled partial features */ Glow.apiUnbookmarkMessage = messageId =>
Glow.apiBookmarkMessage = async () => { Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/bookmark`, {
throw new Error("bookmarks are currently unavailable."); method: "DELETE"
}; });
Glow.apiUnbookmarkMessage = async () => { Glow.apiPinMessage = messageId =>
throw new Error("bookmarks are currently unavailable."); Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, {
}; method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({})
});
Glow.apiPinMessage = async () => { Glow.apiUnpinMessage = messageId =>
throw new Error("pins are currently unavailable."); Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, {
}; method: "DELETE"
});
Glow.apiUnpinMessage = async () => { Glow.apiListPins = (scopeKind, scopeId) =>
throw new Error("pins are currently unavailable."); Glow.apiRequest(
}; `/api/pins?scope_kind=${encodeURIComponent(scopeKind)}&scope_id=${encodeURIComponent(scopeId)}`
);
Glow.apiListPins = async () => { Glow.apiListBookmarks = () =>
throw new Error("pins are currently unavailable."); Glow.apiRequest("/api/bookmarks");
};
Glow.apiListBookmarks = async () => { Glow.apiCreateMessageShare = messageId =>
throw new Error("bookmarks are currently unavailable."); Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/share`, {
}; method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({})
});
Glow.apiCreateMessageShare = async () => { Glow.apiCreateAttachmentShare = attachmentId =>
throw new Error("message sharing is currently unavailable."); Glow.apiRequest(`/api/attachments/${encodeURIComponent(attachmentId)}/share`, {
}; method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({})
});
Glow.apiCreateAttachmentShare = async () => { Glow.apiCreateScheduledMessage = payload =>
throw new Error("attachment sharing is currently unavailable."); Glow.apiRequest("/api/scheduled-messages", {
}; method: "POST",
headers: { "Content-Type": "application/json" },
Glow.apiCreateScheduledMessage = async () => { body: JSON.stringify(payload)
throw new Error("scheduled messages are currently unavailable."); });
};