Skip to content

Commit 1beabb0

Browse files
fixed account.html users chat func
1 parent 78b7504 commit 1beabb0

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

assets/js/account.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,23 @@ document.addEventListener('DOMContentLoaded', function () {
122122
userHistory = data.userHistory;
123123

124124
// add each user to the messages pane
125-
for (const [action, name] of Object.entries(data.userHistory)) {
126-
const existinguserListElement = document.getElementById(`chat-user-${action}`);
125+
data.userHistory.forEach(userId => {
126+
const existinguserListElement = document.getElementById(`chat-user-${userId}`);
127127

128128
if (!existinguserListElement) {
129-
db.collection('Users').where('senderId', '==', action).get()
130-
.then(snapshot => {
131-
if (!snapshot.empty) {
132-
const userDoc = snapshot.docs[0].data();
129+
db.collection('Users').doc(userId).get()
130+
.then(doc => {
131+
if (doc.exists) {
132+
const userDoc = doc.data();
133133
const userBox = document.createElement('div');
134-
userBox.id = `chat-user-${action}`;
134+
userBox.id = `chat-user-${userId}`;
135135
userBox.onclick = function () {
136-
window.location = `/chat.html?chat=${action}`;
136+
window.location = `/chat.html?chat=${userId}`;
137137
}
138138

139139
const userInfo = `
140-
<div class="flex items-center space-x-4">
141-
<img class="w-12 h-12 rounded-full" src="${userDoc.profileIMG == "" ? "/assets/img/default_user.jpeg" : userDoc.profileIMG} alt="${userDoc.name}'s profile image."
140+
<div class="flex items-center space-x-4 hover:bg-gray-700 hover:bg-opacity-20 rounded-lg p-2 cursor-pointer transition duration-100">
141+
<img class="w-12 h-12 rounded-full" src="${userDoc.profileIMG == "" ? "/assets/img/default_user.jpeg" : userDoc.profileIMG}" alt="${userDoc.name}'s profile image.">
142142
<div>
143143
<div>
144144
<p class="text-sm">${userDoc.name}</p>
@@ -147,21 +147,17 @@ document.addEventListener('DOMContentLoaded', function () {
147147
</div>
148148
</div>`;
149149

150-
151150
userBox.innerHTML = userInfo;
152151
userHistoryList.appendChild(userBox);
153-
154-
// updateProgress(action, userProgressLevel / 10); // MARK:- Automatically adds lvl and pts to other users in current user's userHistory, can be removed/polished later.
155152
} else {
156-
// no user found
157-
console.error('No user found in userHistory')
153+
console.error('No user found in userHistory');
158154
}
159155
})
160156
.catch(error => {
161157
console.error('Error getting user:', error);
162158
});
163159
}
164-
}
160+
});
165161
}
166162
})
167163
} else {

0 commit comments

Comments
 (0)