Update static/js/01-api.js
This commit is contained in:
parent
35b6dc53d9
commit
deba4b4cfd
@ -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,9 +37,6 @@ 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 = [];
|
||||||
@ -57,11 +54,12 @@ 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;
|
||||||
@ -78,19 +76,13 @@ 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?.();
|
||||||
@ -99,8 +91,6 @@ Glow.handleUnauthorized = () => {
|
|||||||
Glow.closeReactionPopup?.();
|
Glow.closeReactionPopup?.();
|
||||||
Glow.closeMediaModal?.();
|
Glow.closeMediaModal?.();
|
||||||
Glow.endLocalCallUi?.();
|
Glow.endLocalCallUi?.();
|
||||||
Glow.profileResetCropState?.();
|
|
||||||
|
|
||||||
Glow.setSelectedAttachment?.([]);
|
Glow.setSelectedAttachment?.([]);
|
||||||
Glow.setSelectedThreadAttachment?.([]);
|
Glow.setSelectedThreadAttachment?.([]);
|
||||||
|
|
||||||
@ -132,8 +122,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) => {
|
||||||
@ -155,7 +145,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;
|
||||||
}
|
}
|
||||||
@ -169,8 +159,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) {
|
||||||
@ -183,7 +173,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;
|
||||||
@ -373,7 +363,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 =>
|
||||||
@ -440,9 +430,7 @@ Glow.apiEndGroupCall = sessionId =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
Glow.apiGetGroupCallParticipants = sessionId =>
|
Glow.apiGetGroupCallParticipants = sessionId =>
|
||||||
Glow.apiRequest(
|
Glow.apiRequest(`/api/group-calls/${encodeURIComponent(sessionId)}/participants`);
|
||||||
`/api/group-calls/${encodeURIComponent(sessionId)}/participants`
|
|
||||||
);
|
|
||||||
|
|
||||||
Glow.apiInviteToGroupCall = payload =>
|
Glow.apiInviteToGroupCall = payload =>
|
||||||
Glow.apiRequest("/api/group-calls/invite", {
|
Glow.apiRequest("/api/group-calls/invite", {
|
||||||
@ -455,75 +443,52 @@ Glow.apiListGroupCallInvites = () =>
|
|||||||
Glow.apiRequest("/api/group-calls/invites");
|
Glow.apiRequest("/api/group-calls/invites");
|
||||||
|
|
||||||
Glow.apiAcceptGroupCallInvite = inviteId =>
|
Glow.apiAcceptGroupCallInvite = inviteId =>
|
||||||
Glow.apiRequest(
|
Glow.apiRequest(`/api/group-calls/invites/${encodeURIComponent(inviteId)}/accept`, {
|
||||||
`/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(
|
Glow.apiRequest(`/api/group-calls/invites/${encodeURIComponent(inviteId)}/dismiss`, {
|
||||||
`/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({})
|
||||||
});
|
});
|
||||||
|
|
||||||
Glow.apiUnbookmarkMessage = messageId =>
|
/* disabled partial features */
|
||||||
Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/bookmark`, {
|
Glow.apiBookmarkMessage = async () => {
|
||||||
method: "DELETE"
|
throw new Error("bookmarks are currently unavailable.");
|
||||||
});
|
};
|
||||||
|
|
||||||
Glow.apiPinMessage = messageId =>
|
Glow.apiUnbookmarkMessage = async () => {
|
||||||
Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, {
|
throw new Error("bookmarks are currently unavailable.");
|
||||||
method: "POST",
|
};
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({})
|
|
||||||
});
|
|
||||||
|
|
||||||
Glow.apiUnpinMessage = messageId =>
|
Glow.apiPinMessage = async () => {
|
||||||
Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/pin`, {
|
throw new Error("pins are currently unavailable.");
|
||||||
method: "DELETE"
|
};
|
||||||
});
|
|
||||||
|
|
||||||
Glow.apiListPins = (scopeKind, scopeId) =>
|
Glow.apiUnpinMessage = async () => {
|
||||||
Glow.apiRequest(
|
throw new Error("pins are currently unavailable.");
|
||||||
`/api/pins?scope_kind=${encodeURIComponent(scopeKind)}&scope_id=${encodeURIComponent(scopeId)}`
|
};
|
||||||
);
|
|
||||||
|
|
||||||
Glow.apiListBookmarks = () =>
|
Glow.apiListPins = async () => {
|
||||||
Glow.apiRequest("/api/bookmarks");
|
throw new Error("pins are currently unavailable.");
|
||||||
|
};
|
||||||
|
|
||||||
Glow.apiCreateMessageShare = messageId =>
|
Glow.apiListBookmarks = async () => {
|
||||||
Glow.apiRequest(`/api/messages/${encodeURIComponent(messageId)}/share`, {
|
throw new Error("bookmarks are currently unavailable.");
|
||||||
method: "POST",
|
};
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({})
|
|
||||||
});
|
|
||||||
|
|
||||||
Glow.apiCreateAttachmentShare = attachmentId =>
|
Glow.apiCreateMessageShare = async () => {
|
||||||
Glow.apiRequest(`/api/attachments/${encodeURIComponent(attachmentId)}/share`, {
|
throw new Error("message sharing is currently unavailable.");
|
||||||
method: "POST",
|
};
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({})
|
|
||||||
});
|
|
||||||
|
|
||||||
Glow.apiCreateScheduledMessage = payload =>
|
Glow.apiCreateAttachmentShare = async () => {
|
||||||
Glow.apiRequest("/api/scheduled-messages", {
|
throw new Error("attachment sharing is currently unavailable.");
|
||||||
method: "POST",
|
};
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(payload)
|
Glow.apiCreateScheduledMessage = async () => {
|
||||||
});
|
throw new Error("scheduled messages are currently unavailable.");
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user