Skip to content

Commit

Permalink
fix: hide self from online list
Browse files Browse the repository at this point in the history
  • Loading branch information
jouwdan committed Sep 12, 2023
1 parent c86ea9b commit 1e6241f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/lib/services/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export function subscribePresence(presence: Presence, courseid: string) {
}

const uniqueUsers = new Set();
const selfEmail = presence.studentEmail;

const filteredUniquePresences: PresenceObject[] = onlineUsersObj.filter((presence) => {
if (!uniqueUsers.has(presence.studentEmail)) {
if (!uniqueUsers.has(presence.studentEmail) && presence.studentEmail !== selfEmail) {
uniqueUsers.add(presence.studentEmail);
return true;
}
Expand All @@ -83,9 +84,10 @@ export function subscribePresence(presence: Presence, courseid: string) {
const filteredNewPresences = newPresences.filter((presence) => presence.channel === courseIDWithoutNetlify || presence.channel === courseIDWithNetlify);

const uniqueUsers = new Set();
const selfEmail = presence.studentEmail;

const filteredUniquePresences = filteredNewPresences.filter((presence) => {
if (!uniqueUsers.has(presence.studentEmail)) {
if (!uniqueUsers.has(presence.studentEmail) && presence.studentEmail !== selfEmail) {
uniqueUsers.add(presence.studentEmail);
return true;
}
Expand All @@ -103,7 +105,7 @@ export function subscribePresence(presence: Presence, courseid: string) {
const filteredLeftPresences = leftPresences.filter((presence) => presence.channel === courseIDWithoutNetlify || presence.channel === courseIDWithNetlify);

studentsOnline.update((count) => count - filteredLeftPresences.length);
studentsOnlineList.update((list) => list.filter((item) => !filteredLeftPresences.some((presence) => presence.user_id === item.studentEmail)));
studentsOnlineList.update((list) => list.filter((item) => !filteredLeftPresences.some((presence) => presence.user_id === item.studentEmail && presence.user_id !== selfEmail)));
});
}

Expand Down

0 comments on commit 1e6241f

Please sign in to comment.