From 0d1e555d447ee80a39ebe709cdf74e46c788a79d Mon Sep 17 00:00:00 2001 From: copyandexecute <58366920+copyandexecute@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:04:48 +0200 Subject: [PATCH] feat: Added Feature Friends Whitelist --- src/components/invite/InvitePopup.svelte | 14 +- src/components/v2/HomeNavbar.svelte | 157 +++++++++++++++-------- 2 files changed, 114 insertions(+), 57 deletions(-) diff --git a/src/components/invite/InvitePopup.svelte b/src/components/invite/InvitePopup.svelte index 6c7f078c..1129d2ca 100644 --- a/src/components/invite/InvitePopup.svelte +++ b/src/components/invite/InvitePopup.svelte @@ -2,6 +2,9 @@ import { invoke } from "@tauri-apps/api"; import { createEventDispatcher } from "svelte"; import ConfigTextInput from "../config/inputs/ConfigTextInput.svelte"; + import { addNotification } from "../../stores/notificationStore.js"; + import { getNoRiskToken, noriskError } from "../../utils/noriskUtils.js"; + import { defaultUser } from "../../stores/credentialsStore.js"; const dispatch = createEventDispatcher(); @@ -23,17 +26,16 @@ async function inviteFriend() { if (friendIdentifier !== "") { - const loginData = options.accounts.find(acc => acc.uuid == options.currentUuid); await invoke("add_player_to_whitelist", { identifier: friendIdentifier, - noriskToken: options.experimentalMode ? loginData.experimentalToken : loginData.noriskToken, - requestUuid: options.currentUuid, + noriskToken: getNoRiskToken(), + requestUuid: $defaultUser.id, }).then(() => { alert("Successfully invited " + friendIdentifier + " to the NRC closed beta!"); hideSettings(); }).catch((e) => { - alert("An error occurred while inviting " + friendIdentifier + " to the NRC closed beta: " + e); - console.error(e); + noriskError(e); + addNotification("An error occurred while inviting " + friendIdentifier + " to the NRC closed beta: " + e); }); } } @@ -58,7 +60,7 @@

You have - { friendInviteSlots.availableSlots == -1 ? '∞' : `${friendInviteSlots.availableSlots - friendInviteSlots.previousInvites}/${friendInviteSlots.availableSlots}`} + { friendInviteSlots.availableSlots === -1 ? '∞' : `${friendInviteSlots.availableSlots - friendInviteSlots.previousInvites}/${friendInviteSlots.availableSlots}`} invites left.
You can use them to invite a friend to the NRC closed beta.

diff --git a/src/components/v2/HomeNavbar.svelte b/src/components/v2/HomeNavbar.svelte index 99039e1d..b2fc9224 100644 --- a/src/components/v2/HomeNavbar.svelte +++ b/src/components/v2/HomeNavbar.svelte @@ -5,63 +5,74 @@ import { push } from "svelte-spa-router"; import { appWindow } from "@tauri-apps/api/window"; import { onMount } from "svelte"; + import { invoke } from "@tauri-apps/api"; + import { getNoRiskToken, noriskError, noriskLog } from "../../utils/noriskUtils.js"; + import InvitePopup from "../invite/InvitePopup.svelte"; + import { addNotification } from "../../stores/notificationStore.js"; - let navItems = [ - { name: "SETTINGS", onClick: () => push("/launcher-settings"), condition: true }, - { - name: "PROFILES", - onClick: () => push("/profiles"), - condition: () => get(branches).length > 0 && get(defaultUser) != null, - }, - /* - Hallo Tim ich habe wirklich probiert es zu fixen, aber ich muss jetzt weitermachen damit wir ich schlafen kann ok - ich setze mich nochmal dran wenn du mich pingst - { - name: "SERVERS", - onClick: () => console.log("Servers clicked"), - condition: () => get(branches).length > 0 && get(defaultUser) != null, - },*/ - { - name: "ADDONS", - onClick: () => push("/addons"), - condition: () => get(branches).length > 0 && get(defaultUser) != null, - }, - { - name: "CAPES", - onClick: () => push("/capes"), - condition: () => get(branches).length > 0 && get(defaultUser) != null, - }, - /* - Ich habs wirklich probiert aber Overflow hat gekickt - { - name: "SKIN", - onClick: () => push("/skin"), - condition: () => get(defaultUser) != null, - },*/ - { - name: "QUIT", onClick: () => { - appWindow.close(); - }, condition: true, className: "quit", - }, - ]; - - navItems = navItems.sort((a, b) => b.name.length - a.name.length); - - branches.subscribe(value => { - navItems = navItems.sort((a, b) => b.name.length - a.name.length); - }); + let showInvitePopup = false; + let featureWhitelist = []; + let friendInviteSlots = {}; + + let navItems = []; + + function updateNavItems() { + navItems = [ + { name: "SETTINGS", onClick: () => push("/launcher-settings"), condition: true }, + { + name: "PROFILES", + onClick: () => push("/profiles"), + condition: () => get(branches).length > 0 && get(defaultUser) != null, + }, + /* + Hallo Tim ich habe wirklich probiert es zu fixen, aber ich muss jetzt weitermachen damit wir ich schlafen kann ok + ich setze mich nochmal dran wenn du mich pingst + { + name: "SERVERS", + onClick: () => console.log("Servers clicked"), + condition: () => get(branches).length > 0 && get(defaultUser) != null, + },*/ + { + name: "ADDONS", + onClick: () => push("/addons"), + condition: () => get(branches).length > 0 && get(defaultUser) != null, + }, + { + name: "CAPES", + onClick: () => push("/capes"), + condition: () => get(branches).length > 0 && get(defaultUser) != null, + }, + { + name: "INVITE", + onClick: () => showInvitePopup = true, + condition: () => get(branches).length > 0 && get(defaultUser) != null && featureWhitelist.includes("INVITE_FRIENDS") && (friendInviteSlots.availableSlots !== -1 && friendInviteSlots.availableSlots > friendInviteSlots.previousInvites), + }, + /* + Ich habs wirklich probiert aber Overflow hat gekickt + { + name: "SKIN", + onClick: () => push("/skin"), + condition: () => get(defaultUser) != null, + },*/ + { + name: "QUIT", onClick: () => { + appWindow.close(); + }, condition: true, className: "quit", + }, + ].sort((a, b) => b.name.length - a.name.length); + } - defaultUser.subscribe(value => { - navItems = navItems.sort((a, b) => b.name.length - a.name.length); - }); onMount(async () => { - const branchesUnlisten = branches.subscribe(value => { - navItems = navItems.sort((a, b) => b.name.length - a.name.length); + const branchesUnlisten = branches.subscribe(async value => { + await fetchFeatures(); + updateNavItems(); }); - const userUnlisten = defaultUser.subscribe(value => { - navItems = navItems.sort((a, b) => b.name.length - a.name.length); + const userUnlisten = defaultUser.subscribe(async value => { + await fetchFeatures(); + updateNavItems(); + console.log(featureWhitelist, friendInviteSlots) }); return () => { @@ -69,7 +80,51 @@ userUnlisten(); }; }); + + async function fetchFeatures() { + featureWhitelist = []; + await checkFeatureWhitelist("INVITE_FRIENDS"); + + if (featureWhitelist.includes("INVITE_FRIENDS")) { + await loadFriendInvites(); + } + } + + async function checkFeatureWhitelist(feature) { + if (!$defaultUser) return; + await invoke("check_feature_whitelist", { + feature: feature, + noriskToken: getNoRiskToken(), + uuid: $defaultUser.id, + }).then((result) => { + console.debug(feature + ":", result); + if (!result) return; + featureWhitelist.push(feature.toUpperCase().replaceAll(" ", "_")); + }).catch((reason) => { + noriskError(reason); + featureWhitelist = []; + }); + } + + async function loadFriendInvites() { + if (!$defaultUser) return; + await invoke("get_whitelist_slots", { + noriskToken: getNoRiskToken(), + uuid: $defaultUser.id, + }).then((result) => { + noriskLog("Received Whitelist Slots" + JSON.stringify(result)); + friendInviteSlots = result; + }).catch((reason) => { + noriskError(reason); + addNotification(reason); + friendInviteSlots = {}; + }); + } + +{#if showInvitePopup} + +{/if}
{#each navItems as item (item.name)}