Auto-update owner's picture using a code

@aeroengineerz7
The —> “[i]” is a looping (in a for-loop).

import wixData from 'wix-data';
import wixUsers from 'wix-users';

$w.onReady(async function () {console.log("START")
 let userID = wixUsers.currentUser.id
    console.log(await get_Owner(userID))
 let DATA = await get_Owner(userID)
    console.log("User-ID: ----> " + DATA._id)
    console.log("Owner-ID: ---> " + DATA._owner)
})


async function get_Owner (userID) {
 return wixData.query("Comments2")
    .eq("_owner", userID)
    .find()
    .then((results) => {
 let dataLength = results.items.length
        console.log(dataLength)
 if(results.items.length > 0) {
 let firstItem = results.items[0]; 
 let userComments = []
 let userPics = []

 for (var i = 0; i < dataLength; i++) {
                userComments.push(results.items[i].comment) 
                userPics.push(results.items[i].userPic) 
            }
 
 return [firstItem, userComments, userPics]
 
        }
 else {      }
        console.log("END")
    } )
    .catch( (err) => {
 let errorMsg = err;
    } );
}

Where did you find this…

profilePic.push(result.items[i].profilePicture)

…in my code?

In my code you will finde this…

userPics.push(results.items[i].userPic) 

Take a look one more time onto my DATABASES…

The code collects all pics of a users comment.
[userPic] ----> these are all the pics in the comment-section, created with every post/comment of a specific user.

Example:
When “russian-dima” (myself😆) has created 20x posts, there should also be 20x-Pics in the Comment-Database. This pics could be different, if russian-dima have changed them after several written comments.

But your aim as i understand is to REFRESH-ALL of these ALREADY-WRITTEN-COMMENTS in the comment-box, right?

And this is what you can achieve using this CODE.

The CODE is able to collect all COMMENT-PICs of a specific user (for example myself). So you have found 20x Comments=20x-Pics of a specific user.

Now what you want to do with it? You want to change them right?
This is your last step to achieve your aim.

CHANGING these 20x fonded comment-pics aof a specific user and REFRESH them with the new USER-AVATAR-PIC (every-time) when a user has changed it.

Because you use an own Member-Database, in your case you have first to change the PIC of the user in your “Member-Database”.

  1. Changing your own Profile-Pic can be done automatic (getting the new pic from PMD).
  2. Changing others UserPics have to be done manually in your Member-DB, cause you are not using the BACK-END (not using PMD).

That means, the User-Pics of Comments of each User will be only changed automatically, when the specific USER enters the COMMENT-PAGE.

Every-time a specific user enters the comment-page, all his comment-pics can be refreshed by the one pic, which is setted in your own Member-DB.

Hard to explain xD😅

EDIT:
I think i understand why you are a little bit confused.
You will need a 2-step-refreshing-process.

  1. Step-1: Refreshing Pics in your own Member-DB.
  2. Step-2: Refreshing Pics of the posted comments.