Skip to content

Commit

Permalink
Merge pull request #144 from Elijah-Bodden/Elijah-Bodden-patch-90
Browse files Browse the repository at this point in the history
Upgrade for v2
  • Loading branch information
Elijah-Bodden authored Oct 2, 2024
2 parents 5ed5ab2 + 52ac799 commit 298dbfa
Showing 1 changed file with 68 additions and 82 deletions.
150 changes: 68 additions & 82 deletions src/source/frontend/dist/static/scripts/UI.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/** @format */

window.addEventListener("DOMContentLoaded", async function () {
document.querySelector("#searchEntryField").value = "";
fusedStream = new FusedStream("messageFeedPane", "#messageSequence");
Expand Down Expand Up @@ -128,19 +126,12 @@ window.onload = function () {
exportToLS("doTURN", toggle.checked);
writeSetting("rtc.ICEpresets.iceServers", toggle.checked ? STUNOnly : allICEServers);
return;
} else if (toggle.dataset.objective === "communication.moderateMapInstabilityTolerance") {
writeSetting(toggle.dataset.objective, !toggle.checked);
return;
}
writeSetting(toggle.dataset.objective, toggle.checked);
});
});
Array.from(document.querySelectorAll(".settingsToggle")).forEach((element) => {
if (Object.keys(JSON.parse(localStorage.config ?? "{}")).includes(element.dataset.objective)) {
if (element.dataset.objective === "communication.moderateMapInstabilityTolerance") {
element.checked = !JSON.parse(localStorage.config)[element.dataset.objective];
return;
}
element.checked = JSON.parse(localStorage.config)[element.dataset.objective];
}
});
Expand All @@ -149,19 +140,17 @@ window.onload = function () {
element.value = JSON.parse(localStorage.config)[element.dataset.objective];
}
});
onAuthRejected((_sig, externalDetail) => {
onAuthRejected(alias => {
eventStream.log(
"system",
`Authentication request rejected by ${
CONFIG.UI.renderUnfamiliarPublicAliases
? hiddenAliasLookup[externalDetail] ?? externalDetail
: externalDetail
hiddenAliasLookup[alias] ?? alias
}`,
"transient",
["align-center", "system-message-card-error", "message-card-slim"]
);
});
onPublicError(async (_sig, externalDetail) => {
onServerError(async (message, stack) => {
var blurWrapper = document.createElement("div");
blurWrapper.style.position = "absolute";
blurWrapper.style.left =
Expand Down Expand Up @@ -189,7 +178,7 @@ window.onload = function () {
);
document.querySelector(
".fatalBody"
).innerHTML = `<div class="center">Oh no! Something went wrong!</div><br><br>If you want to retry, just reload the page. If this error persits, feel free to email <b>[email protected]</b> with this stack trace:<div class="center"></div><br>${externalDetail[0]}<br>[stack]<br>${externalDetail[1]}</div>`;
).innerHTML = `<div class="center">Oh no! Something went wrong!</div><br><br>If you want to retry, just reload the page. If this error persits, feel free to email <b>[email protected]</b> with this stack trace:<div class="center"></div><br>${message}<br>[stack]<br>${stack}</div>`;
document.querySelector(".fatalWrapper").style.visibility = "visible";
});
if (!JSON.parse(localStorage.config ?? "{}")["UI.renderUnfamiliarPublicAliases"]) {
Expand All @@ -201,66 +190,66 @@ window.onload = function () {
connectioncardcontext = new standardContextMenu("connection-card-context", "connectedNodesPane");
connectionspanel = new connectionsPanel();
connectionspanel.renderConnectionCards();
onLivePeersUpdated(() => {
Object.keys(eventHandler.dispatchWatchers)
.filter((id) => id.slice(0, 25) === "authenticationAuthorized|")
.forEach((relevantKey) => {
if (!Object.keys(livePeers).includes(relevantKey.split("|")[1])) {
eventHandler.forceReject(
relevantKey,
"The associated peer died before the route could be authenticated."
);
}
});
});
onAuthPeersUpdated((_signalID, externalDetail) => {
if (externalDetail[0] == "addition") {
if (livePeers[externalDetail[1]]) {
fusedStream.addAndLoadPeerStream(externalDetail[1]);
if (eventStream.dontAlert.includes(externalDetail[1])) {
eventStream.dontAlert.splice(eventStream.dontAlert.indexOf(externalDetail[1]), 1);
} else {
eventStream.log(
"system",
`Successfully authenticated peer session with ${
CONFIG.UI.renderUnfamiliarPublicAliases
? hiddenAliasLookup[externalDetail[1]] ?? externalDetail[1]
: externalDetail[1]
}`,
"transient",
["align-center", "system-message-card-success", "message-card-slim"]
);
}
if (
!eventHandler.handlerFrame[`consumableAuth | ${livePeers[externalDetail[1]].internalUID}`]
)
livePeers[externalDetail[1]].onConsumableAuth((_signal, _externalDetail_) => {
fusedStream.log(externalDetail[1], _externalDetail_, "remote", [
"message-card-unread",
]);
});
fusedStream.chatCache[externalDetail[1]].isActive = true;
}
}
if (externalDetail[0] == "deletion") {
fusedStream.log(externalDetail[1], "Peer session deauthenticated", "transient", [
"align-center",
"system-message-card-error",
"message-card-slim",
]);
eventStream.log(
"system",
`Peer session with ${
CONFIG.UI.renderUnfamiliarPublicAliases
? hiddenAliasLookup[externalDetail[1]] ?? externalDetail[1]
: externalDetail[1]
} deauthenticated`,
"transient",
["align-center", "system-message-card-error", "message-card-slim"]
);
fusedStream.chatCache[externalDetail[1]].isActive = false;
}
if (!(fusedStream.chatCache?.[externalDetail[1]]?.isActive ?? true)) {
// onLivePeersUpdated(() => {
// Object.keys(eventHandler.dispatchWatchers)
// .filter((id) => id.slice(0, 25) === "authenticationAuthorized|")
// .forEach((relevantKey) => {
// if (!Object.keys(livePeers).includes(relevantKey.split("|")[1])) {
// eventHandler.forceReject(
// relevantKey,
// "The associated peer died before the route could be authenticated."
// );
// }
// });
// });

onNewAuthPeer(alias => {
if (livePeers[alias]) {
fusedStream.addAndLoadPeerStream(alias);
if (eventStream.dontAlert.includes(alias)) {
eventStream.dontAlert.splice(eventStream.dontAlert.indexOf(alias), 1);
} else {
eventStream.log(
"system",
`Successfully authenticated peer session with ${
hiddenAliasLookup[alias] ?? alias
}`,
"transient",
["align-center", "system-message-card-success", "message-card-slim"]
);
}
if (
!eventHandler.handlerFrame[`consumableAuth | ${livePeers[alias].internalUID}`]
)
livePeers[alias].onConsumableAuth((_signal, _externalDetail_) => {
fusedStream.log(alias, _externalDetail_, "remote", [
"message-card-unread",
]);
});
fusedStream.chatCache[alias].isActive = true;
}
onAuthPeersUpdated(alias);
});
onLostAuthPeer(alias => {
fusedStream.log(alias, "Peer session deauthenticated", "transient", [
"align-center",
"system-message-card-error",
"message-card-slim",
]);
eventStream.log(
"system",
`Peer session with ${
hiddenAliasLookup[alias] ?? alias
} deauthenticated`,
"transient",
["align-center", "system-message-card-error", "message-card-slim"]
);
fusedStream.chatCache[alias].isActive = false;
onAuthPeersUpdated(alias);
});

async function onAuthPeersUpdated(alias) {
if (!(fusedStream.chatCache?.[alias]?.isActive ?? true)) {
document.querySelector(".sendbutton").style.setProperty("pointer-events", "none");
document.querySelector(".sendbutton").style.setProperty("filter", "brightness(330%)");
} else {
Expand All @@ -271,8 +260,8 @@ window.onload = function () {
authPeers.forEach((node) => {
Graph.updateNodeAttribute(node, "type", () => "related");
});
});
};
}
}

class RightPanel {
constructor() {
Expand Down Expand Up @@ -558,9 +547,6 @@ class FusedStream {
}
getRenderableID(ID) {
if (ID === "system") return "System";
if (!CONFIG.UI.renderUnfamiliarPublicAliases) {
return ID;
}
return hiddenAliasLookup[ID] ?? ID;
}
async log(ID, data, polarity, tags = [], adhoc = "") {
Expand Down Expand Up @@ -682,7 +668,7 @@ class standardContextMenu {
constructor(id, parentID) {
this.parentID = `#${parentID}` ?? "document";
this.container = document.querySelector(this.parentID);
this.eventhandler = new eventHandlingMechanism();
this.eventhandler = new EventHandler();
this.active = false;
this.id = id;
this.menu = document.querySelector(`#${this.id}`);
Expand Down Expand Up @@ -739,7 +725,7 @@ class connectionsPanel {
}
formatConnectionCard(label) {
return `<div class="connectedNodeCard" onclick="((event) => {if (event.target!==event.currentTarget&&event.target!==event.currentTarget.firstChild) return; rightPanel.rotateIn('messageFeedPane'); fusedStream.loadCache('${label}')})(event)"><p class="nodeCardText">@${
CONFIG.UI.renderUnfamiliarPublicAliases ? hiddenAliasLookup[label] : label
hiddenAliasLookup[label] ?? label
}</p><i class="icon kebab connection-kebab fa-solid fa-ellipsis-vertical" onclick="connectioncardcontext.click(event)" data-index="" data-reference="${label}" tabindex=0></i></div>`;
}
renderConnectionCards() {
Expand Down

0 comments on commit 298dbfa

Please sign in to comment.