From 071c313bd0997fddf0f8892a589b210f572ae25f Mon Sep 17 00:00:00 2001 From: Jaylon Gowie Date: Wed, 27 Nov 2024 18:23:48 -0600 Subject: [PATCH] Show User Icon for SavedUsers as well --- source/ShowScenes.bs | 18 ++++++++++++++++++ source/utils/config.bs | 6 ++++++ source/utils/session.bs | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/source/ShowScenes.bs b/source/ShowScenes.bs index 1829e928b..63abfb4a5 100644 --- a/source/ShowScenes.bs +++ b/source/ShowScenes.bs @@ -77,6 +77,10 @@ function LoginFlow() user.name = savedUser.username end if + if isValid(savedUser.primaryImageTag) + user.ImageURL = UserImageURL(user.id, { "tag": savedUser.primaryImageTag }) + end if + publicUsersNodes.push(user) end if end if @@ -103,6 +107,7 @@ function LoginFlow() end for ' try to login with token from registry myToken = get_user_setting("token") + myPrimaryImageTag = get_user_setting("primaryimagetag") if myToken <> invalid ' check if token is valid print "Auth token found in registry for selected user" @@ -113,6 +118,9 @@ function LoginFlow() print "Auth token is no longer valid - deleting token" unset_user_setting("token") unset_user_setting("username") + if isValid(myPrimaryImageTag) + unset_user_setting("primaryimagetag") + end if else print "Success! Auth token is still valid" session.user.Login(currentUser, true) @@ -155,10 +163,14 @@ function LoginFlow() myUsername = get_user_setting("username") myAuthToken = get_user_setting("token") + myPrimaryImageTag = get_user_setting("primaryimagetag") if isValid(myAuthToken) and isValid(myUsername) print "Auth token found in registry" session.user.Update("authToken", myAuthToken) session.user.Update("name", myUsername) + if isValid(myPrimaryImageTag) + session.user.Update("primaryImageTag", myPrimaryImageTag) + end if print "Attempting to use API with auth token" currentUser = AboutMe() @@ -177,6 +189,9 @@ function LoginFlow() print "delete token and restart login flow" unset_user_setting("token") unset_user_setting("username") + if isValid(myPrimaryImageTag) + unset_user_setting("primaryimagetag") + end if goto start_login end if else @@ -484,6 +499,9 @@ function CreateSigninGroup(user = "") session.user.Login(activeUser, true) set_user_setting("token", activeUser.token) set_user_setting("username", username.value) + if isValid(activeUser.json.PrimaryImageTag) + set_user_setting("primaryimagetag", activeUser.json.PrimaryImageTag) + end if else session.user.Login(activeUser) end if diff --git a/source/utils/config.bs b/source/utils/config.bs index 56875fe23..1167255f9 100644 --- a/source/utils/config.bs +++ b/source/utils/config.bs @@ -127,6 +127,12 @@ function getSavedUsers() as object userArray["serverId"] = serverId end if + primaryImageTag = registry_read("primaryimagetag", userId) + if primaryImageTag <> invalid + print "Found Saved Primary Image Tag: ", primaryImageTag, " for user: ", userId + userArray["primaryImageTag"] = primaryImageTag + end if + if username <> invalid and token <> invalid and serverId <> invalid and serverId = m.global.session.server.id savedServerUsers.push(userArray) end if diff --git a/source/utils/session.bs b/source/utils/session.bs index ee9e564a4..c225b2b38 100644 --- a/source/utils/session.bs +++ b/source/utils/session.bs @@ -155,12 +155,19 @@ namespace session if userData.json = invalid ' we were passed data from AboutMe() myAuthToken = tmpSession.user.authToken + myPrimaryImageTag = tmpSession.user.primaryImageTag tmpSession.AddReplace("user", userData) tmpSession.user.AddReplace("authToken", myAuthToken) + if isValid(myPrimaryImageTag) + tmpSession.user.AddReplace("primaryImageTag", myPrimaryImageTag) + end if else ' we were passed data from a UserData object tmpSession.AddReplace("user", userData.json.User) tmpSession.user.AddReplace("authToken", userData.json.AccessToken) + if isValid(userData.json.user.PrimaryImageTag) + tmpSession.user.AddReplace("primaryImageTag", userData.json.user.PrimaryImageTag) + end if end if ' remove special characters from name regex = CreateObject("roRegex", "[^a-zA-Z0-9\ \-\_]", "") @@ -191,6 +198,9 @@ namespace session if saveCredentials set_user_setting("token", tmpSession.user.authToken) set_user_setting("username", tmpSession.user.name) + if isValid(tmpSession.user.primaryImageTag) + set_user_setting("primaryimagetag", tmpSession.user.primaryImageTag) + end if end if if m.global.session.user.settings["global.rememberme"]