Hello,
Currently I am working on the friend system for an app and i'm having an issue with something, what i'd like to do is load the customData values from the localUser.friends, in this case it would be customData["ActiveImage"] for their profile/avatar image. I'm attempting to do it like this:
for (int i = 0; i < CombuManager.localUser.friends.Length; ++i) {
Debug.Log("Friends = " + CombuManager.localUser.friends.Length);
UserFile.Load (CombuManager.localUser.friends[i].id, false, 1, 12, (UserFile[] files, int recordCount, int pageCount, string error) => {
Debug.Log("Files loaded: " + files.Length);
friendsList = files;
Now i've tried adding the extension friends[i].userName but it returns a value of 0 for the detected friends even though UserFriends() debug info clearly displays there being more than one. So if i use friends[i].id i actually get the correct value of friends on the debug info display but since the friends[i] extension on the end is a string i cannot add the query friends[i].id.customData["ActiveImage"]
What would be a good way to go about doing this?
I'd like to use the UserFile.Load above to load the customData ActiveImage of the users current friends into the list and then i'll generate them using the GenerateUrlFiles call. I don't want to load all of the files from each friend into the list as that would be overload, just the ActiveImage.
Thanks ahead of time!
Sorry but I don't understand very well what you're doing nor what you would like to do...
What contains the customData "ActiveImage" of user profile and what does it matter with UserFile?
friends[i].id.customData["ActiveImage"] is wrong either way, since id is a string and customData is a property of User class, so in your case it would have been: friends[i].customData["ActiveImage"]
Anyway, if you're looking for a quick way to store profile picture of users then I would save the file URL in profile's customData after upload (I didn't understand if this is what you're already doing) so that you won't need to call UserFile.Load:
byte [] myFile = new byte [0]; // ... load the file content in myFile ... UserFile file = new UserFile (); file.name = "ProfilePicture"; file.Update (myFile, (bool success, string error) => { if (success) { CombuManager.localUser.customData ["Picture"] = file.url; CombuManager.localUser.Update (null); } });
FRANCESCO CROCETTI @ SKARED CREATIONS
Every user has the ability to store custom data and files right?
So if i upload a file (image in this case) and save the image name to the ActiveImage customData value, I then call back to that custom data in the list of files I load (15 in this case) from the server (files/images uploaded) and generate the image based on the customData value.
So ActiveImage = test, then if the file.name is "test", it generates that file (image in this case).
The code you linked isn't even close to what i'm attempting to do as currently I have no issues with uploading, storing and calling back the customData for the ActiveImage of the localUser.
Like I said, I am trying to get the data for the friends customData, when i use UserFriends() call, i can clearly see it shows the custom data values in the debug log. So I know they are there and the system has gathered it.
friends[i].id.customData["ActiveImage"] is wrong either way, since id is a string and customData is a property of User class, so in your case it would have been: friends[i].customData["ActiveImage"]
Yes I already pointed this out in the post above, here's what i said:
"but since the friends[i] extension on the end is a string i cannot add the query friends[i].id.customData["ActiveImage"]"
And i'll just include this again as it sums up what i'm trying to do:
I'd like to use the UserFile.Load above to load the customData value "ActiveImage" of the users current friends into the list and then i'll generate them using the GenerateUrlFiles call. I don't want to load all of the files from each friend into the list as that would be overload, just the ActiveImage.
Well, if you need to generate a list of UserFile for your friends' ActiveImage then here's the code:
IEnumerator LoadFriendImages() { int friendsCount = CombuManager.localUser.friends.Length; int loadedCount = 0; var friendsList = new List <UserFile> (); for (int i = 0; i < friendsCount; i++) { User user = (User)CombuManager.localUser.friends [i]; UserFile.Load (user.id, false, 1, int.MaxValue, (UserFile [] files, int recordCount, int pageCount, string error) => { loadedCount++; // Search for active image foreach (var file in files) { if (file.name.Equals (user.customData["ActiveImage"])) { friendsList.Add (file); break; } } }); } // Wait until all friends have loaded their files while (loadedCount < friendsCount) yield return null; }
But if you're only looking for a faster way to get the active image URL then I'd suggest to store also directly the URL of the image after you upload or select it as active, so you can save the call to UserFile.Load as I already mentioned (the code I posted in the previous message was there to show you this faster way), also you could store in the user customData both the name of the image ("ActiveImage") and the URL ("ActiveImageUrl") for faster access.
FRANCESCO CROCETTI @ SKARED CREATIONS
Perfect, i think this is exactly what i was looking for. I'll try it out and let you know.
Thanks for your time
Well i'm still having an issue, all the info checks out, friends amount is caught, and userfile.load returns 1 (shown in debug log) BUT the actual files are still returning 0 and since it's 0 it has no files to search through v_v
So it's catching it as far as the debug log goes but it's not at the same time, which is odd.
I made a few minor adjustments to the code but still no luck:
public IEnumerator LoadFriendImages() { friendsGalInt = CombuManager.localUser.friends.Length; int loadedCount = 0; //var friendsList2 = new List(); for (int i = 0; i < friendsGalInt; i++) { Debug.Log("Friends = " + friendsGalInt); User user = (User)CombuManager.localUser.friends [i]; UserFile.Load (user.id, false, 1, int.MaxValue, (UserFile[] files, int recordCount, int pageCount, string error) => { Debug.Log("Files loaded: " + files.Length); loadedCount++; Debug.Log("Loaded = " + loadedCount); friendsList = files; Debug.Log("Friendslist = files"); // Search for active image foreach (var file in files) { if (file.name == user.customData["ActiveImage"].ToString()) { //friendsList.Add(file); Debug.Log("ActiveImage Caught"); break; } } }); } // Wait until all friends have loaded their files while (loadedCount < friendsGalInt) { yield return null; Debug.Log("loaded count < friends count"); } }
Debug Log that shows files are caught after userfile.load is called:
TEXT: {"total":1,"results":[],"pages":1}
ERROR:
UnityEngine.Debug:Log(Object)
Combu.c__Iterator0:MoveNext() (at Assets/Combu/Scripts/CombuManager.cs:425)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
Debug Log that shows files are not caught after userfile.load is called: Debug.Log("Files loaded: " + files.Length); ------- is returning 0 for files Files loaded: 0 UnityEngine.Debug:Log(Object) c__AnonStorey7:<>m__0(UserFile[], Int32, Int32, String) (at Assets/Combu/Demo/Scripts/CombuDemo.cs:726) Combu.c__AnonStorey1`1:<>m__0(String, String) (at Assets/Combu/Scripts/UserFile.cs:167) Combu.c__Iterator0:MoveNext() (at Assets/Combu/Scripts/CombuManager.cs:428) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) |
I know for certain the ActiveImage value for the friend is there and set, the file is showing on the friends account and server.
TEXT: {"total":1,"results":[{"Id":"25","Username":"dummy","LastLoginDate":"2017-11-08 04:54:02","LastLoginIp":"108.252.164.132","ActivationCode":"","ChangePwdCode":"","Enabled":"1","LastSeen":"2017-11-08 04:54:51","CustomData":{"ActiveImage":"ssaa","gallery1.1":"ssaa","gallery1.2":"","gallery1.3":"","gallery1.4":"","gallery1.5":"","gallery2.1":"","gallery2.2":"","gallery2.3":"","gallery2.4":"","gallery2.5":"","License":"dummy?1?2017-11-26","LicenseNumber":"84S2Q-N7G9G-6D2BX-LSSMK","LicenseType":"1","LicenseValue":"2017-11-26"},"Platforms":[]}]} ERROR: UnityEngine.Debug:Log(Object) Combu.c__Iterator0:MoveNext() (at Assets/Combu/Scripts/CombuManager.cs:425) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
Oh I noticed that there was a logical error in the code I posted so I reviewed and optimized it, I tried the following code and it works on my instance:
IEnumerator LoadFriendImages() { int friendsCount = CombuManager.localUser.friends.Length; var friendsList = new List (); for (int i = 0; i < friendsCount; i++) { User user = (User)CombuManager.localUser.friends [i]; string activeImage = "" + user.customData ["ActiveImage"]; bool loaded = false; UserFile.Load (user.id, false, 1, int.MaxValue, (UserFile [] files, int recordCount, int pageCount, string error) => { // Search for active image foreach (var file in files) { if (file.name == activeImage) { friendsList.Add (file); break; } } loaded = true; }); // Wait until files have been loaded, only one request at time while (!loaded) yield return null; } Debug.Log ("LoadFriendImages finished: " + friendsList.Count + "/" + friendsCount); }
But the debug log of what's returned from server after UserFile.Load is pretty strange ("total:1,results:[]"), so please try the code above and if it's not working on your server then we should check what's happening through a Skype chat (in case you can send your Skype ID on a PM).
You may also want to check that the field "ShareType" of UserFiles is set to 0 (everybody) or 2 (friends) on your database, else only the owner can see the file.
FRANCESCO CROCETTI @ SKARED CREATIONS
This line throws an error:
var friendsList = new List ();
Error:
Assets/Combu/Demo/Scripts/CombuDemo.cs(715,26): error CS0305: Using the generic type `System.Collections.Generic.List' requires `1' type argument(s)
EDIT:
I have confirmed that the image ShareType is "Friends".
Update code posted here:
public IEnumerator LoadFriendImages() { friendsGalInt = CombuManager.localUser.friends.Length; for (int i = 0; i < friendsGalInt; i++) { Debug.Log("Friends = " + friendsGalInt); User user = (User)CombuManager.localUser.friends [i]; string activeImage = "" + user.customData ["ActiveImage"]; bool loaded = false; UserFile.Load (user.id, false, 1, int.MaxValue, (UserFile [] files, int recordCount, int pageCount, string error) => { Debug.Log("Files loaded: " + files.Length); friendsList = files; Debug.Log("Friends list = " + friendsList.Length); // Search for active image foreach (var file in files) { if (file.name == activeImage) { //friendsList.Add(file); Debug.Log("ActiveImage Caught"); break; } } loaded = true; }); // Wait until files have been loaded, only one request at time while (!loaded) yield return null; } Debug.Log ("LoadFriendImages finished: " + friendsList.Length + "/" + friendsGalInt); }
Assigning the array from web service to friendsList at every cycle (your line 17) is logically wrong because this way you are overwriting it every time, instead you should add the correct item to the list like it does at lines 21-30.
If your server is still returning no files at line 15 (files.Length is 0, but recordCount is greater than 0) then may be there's some issues in the load files webservice and we may need to make a chat on Skype to see what's happening, much faster than forum.
I tested the code that I posted earlier on my server and it worked as intended, so we need to see why it's not working on yours.
FRANCESCO CROCETTI @ SKARED CREATIONS
Actually it's not since this is only being called once, so it sets the friendsList files once and not every update. When i try to use the add feature, it just throws an error saying there is no call for add ( i use arrays and not lists as you tend to point to ). So i removed it as it was causing an issue.
The code you posted could not work as it throws an error at the empty list reference: var friendsList = new List (); <--- broken code (missing list reference)
So the fact that you say it works is indeed, very very odd.
Sure a skype session would probably be more ideal, i'll send along my skype name.
Thanks.
TsuyoiRaion said
The code you posted could not work as it throws an error at the empty list reference: var friendsList = new List (); <--- broken code (missing list reference)
It's a bug of this forum, it removed <UserFile>, of course that line was "var friendsList = new List<UserFile>();", and I didn't mean that your code was called "every update" but "every time in the 'for' cycle" (so your code is overwriting the list with the one of last user).
Anyway we can chat on Skype for faster way since it seems I cannot be clear on this, I'll add you at Monday since I'm away for the weekend.
FRANCESCO CROCETTI @ SKARED CREATIONS
Darn forum lol alright talk to you then