Skip to content

Commit

Permalink
Show User Icon for SavedUsers as well
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicMastr committed Nov 28, 2024
1 parent 0c02569 commit 071c313
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/ShowScenes.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/utils/config.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions source/utils/session.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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\ \-\_]", "")
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 071c313

Please sign in to comment.