From bc809ee3c0a36d487b3962473c6f969d85ed346f Mon Sep 17 00:00:00 2001 From: gurpreet991 Date: Thu, 13 Jul 2023 14:59:12 +0530 Subject: [PATCH 1/9] profile popover --- .../components/Channel/Chat/ChatInput.svelte | 4 +- .../components/Channel/Chat/DrawerChat.svelte | 34 ++++- .../components/Channel/Chat/Message.svelte | 32 +++- .../Channel/Chat/ProfilePopup.svelte | 140 ++++++++++++++++++ 4 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 src/lib/components/Channel/Chat/ProfilePopup.svelte diff --git a/src/lib/components/Channel/Chat/ChatInput.svelte b/src/lib/components/Channel/Chat/ChatInput.svelte index 9545e01e..42666d77 100644 --- a/src/lib/components/Channel/Chat/ChatInput.svelte +++ b/src/lib/components/Channel/Chat/ChatInput.svelte @@ -21,7 +21,7 @@ $: isHost = channel.user === $page.data.user?.userId $: viewersWithOutHost = viewers.filter((viewer) => viewer.userId !== channel.user) - +$: console.log("viewers : ", viewers) function insert(str: string, index: number, value: string) { return str.substr(0, index) + value + str.substr(index) } @@ -205,6 +205,8 @@ !chatMessage.includes('@') && (channel.user === $page.data.user?.userId || channel.mods?.includes($page.data.user?.userId)) && !showUsers + + console.log("viewersWithOutHost: ", viewersWithOutHost)
diff --git a/src/lib/components/Channel/Chat/DrawerChat.svelte b/src/lib/components/Channel/Chat/DrawerChat.svelte index b2b98183..172a7cf6 100644 --- a/src/lib/components/Channel/Chat/DrawerChat.svelte +++ b/src/lib/components/Channel/Chat/DrawerChat.svelte @@ -9,6 +9,7 @@ import { emitChatHistoryToChannel } from '$lib/websocket' import { setRole } from '$lib/utils' import LastItemInViewport from '$lib/actions/LastItemInViewport' + import ProfilePopup from './ProfilePopup.svelte' export let channel: any = undefined, showEditChannelDrawer: boolean = false, @@ -16,6 +17,9 @@ chatHistory: any[] = [] let cursor: any = undefined + let profileElt:any = null + let selectedUser:string = "" + let ignoreOutsideClick = false channel_message.subscribe((value) => { if (!value) return @@ -74,13 +78,41 @@ }) } } + + + const closeProfile = () => { + if(ignoreOutsideClick)return + profileElt = null + selectedUser = "" + } + + const onUsernameClick = (evt:any) => { + profileElt = evt.target + selectedUser = viewers.find(i => i.username == profileElt.id.substr(1))?.userId + ignoreOutsideClick = true + setTimeout(() => { + ignoreOutsideClick = false + }, 100) + } +
+ {#each chatHistory as sender} - + {/each}
diff --git a/src/lib/components/Channel/Chat/Message.svelte b/src/lib/components/Channel/Chat/Message.svelte index 4f36f292..6aedeb42 100644 --- a/src/lib/components/Channel/Chat/Message.svelte +++ b/src/lib/components/Channel/Chat/Message.svelte @@ -10,10 +10,11 @@ import { copyToClipboard, getColoredRole, setRole } from '$lib/utils' import { page } from '$app/stores' import IconChatBan from '$lib/assets/icons/chat/IconChatBan.svelte' + import { onMount } from "svelte" - export let sender: any, hostId: string, channel: any + export let sender: any, hostId: string, channel: any, onUsernameClick:any let role: string, coloredRole: any - + $: isGuest = channel?.guests?.includes(sender.user?.userId) $: showBanItem = @@ -130,6 +131,30 @@ } } + const hightlightUsername = (match:string) => { + return ` + + ${match} + + `; + } + + const parse = (msg: string) => { + return msg.replace(/@[\w-]+[,\s]/g, hightlightUsername) + } + + + onMount(() => { + const spans = document.querySelectorAll('span[name="username"]') + spans.forEach((span:any) => { + span.onclick = onUsernameClick + }) + }) + $: codeSnippet = isCodeSnippet(sender.message) ? getCodeSnippet(sender.message) : false @@ -172,7 +197,8 @@ {codeSnippet.endText} {/if} {:else} - {sender.message} + {@html parse(sender.message)} + {/if} diff --git a/src/lib/components/Channel/Chat/ProfilePopup.svelte b/src/lib/components/Channel/Chat/ProfilePopup.svelte new file mode 100644 index 00000000..44408310 --- /dev/null +++ b/src/lib/components/Channel/Chat/ProfilePopup.svelte @@ -0,0 +1,140 @@ + + + + {#if open} + + {/if} + From d3d7eadeffcba9f3ed69427e6e30ebeafacf54bf Mon Sep 17 00:00:00 2001 From: sitara-dev Date: Thu, 13 Jul 2023 19:37:37 +0530 Subject: [PATCH 2/9] profile card --- .../components/Channel/Chat/DrawerChat.svelte | 41 ++++++----- .../components/Channel/Chat/Message.svelte | 46 ++++++++---- .../Channel/Chat/ProfilePopup.svelte | 71 +++++++++++++------ 3 files changed, 104 insertions(+), 54 deletions(-) diff --git a/src/lib/components/Channel/Chat/DrawerChat.svelte b/src/lib/components/Channel/Chat/DrawerChat.svelte index 172a7cf6..67008c9a 100644 --- a/src/lib/components/Channel/Chat/DrawerChat.svelte +++ b/src/lib/components/Channel/Chat/DrawerChat.svelte @@ -17,8 +17,8 @@ chatHistory: any[] = [] let cursor: any = undefined - let profileElt:any = null - let selectedUser:string = "" + let profileElt: any = null + let selectedUser: string = '' let ignoreOutsideClick = false channel_message.subscribe((value) => { @@ -79,40 +79,43 @@ } } - const closeProfile = () => { - if(ignoreOutsideClick)return + if (ignoreOutsideClick) return profileElt = null - selectedUser = "" + selectedUser = '' } - const onUsernameClick = (evt:any) => { + const onUsernameClick = (evt: any) => { profileElt = evt.target - selectedUser = viewers.find(i => i.username == profileElt.id.substr(1))?.userId + + + const match = profileElt.id.match(/@\w+/g); + console.log('working +++', match) + if(match){ + selectedUser = viewers.find((i) => i.username == profileElt.id.substr(1))?.userId + } + else{ + selectedUser = viewers.find((i) => i.username == profileElt.id)?.userId + } + + console.log('selectedUser', selectedUser, 'viewers', viewers) ignoreOutsideClick = true setTimeout(() => { ignoreOutsideClick = false }, 100) } -
- + bind:userId={selectedUser} + onOutsideClick={closeProfile} /> {#each chatHistory as sender} - + {/each}
diff --git a/src/lib/components/Channel/Chat/Message.svelte b/src/lib/components/Channel/Chat/Message.svelte index 6aedeb42..de70893b 100644 --- a/src/lib/components/Channel/Chat/Message.svelte +++ b/src/lib/components/Channel/Chat/Message.svelte @@ -10,11 +10,14 @@ import { copyToClipboard, getColoredRole, setRole } from '$lib/utils' import { page } from '$app/stores' import IconChatBan from '$lib/assets/icons/chat/IconChatBan.svelte' - import { onMount } from "svelte" + import { onMount } from 'svelte' + import ProfilePopup from './ProfilePopup.svelte' export let sender: any, hostId: string, channel: any, onUsernameClick:any let role: string, coloredRole: any - + let profileElt: any = null + let ignoreOutsideClick = false + $: isGuest = channel?.guests?.includes(sender.user?.userId) $: showBanItem = @@ -131,8 +134,8 @@ } } - const hightlightUsername = (match:string) => { - return ` + const hightlightUsername = (match: string) => { + return ` ${match} - `; - } + ` + } const parse = (msg: string) => { return msg.replace(/@[\w-]+[,\s]/g, hightlightUsername) } - onMount(() => { const spans = document.querySelectorAll('span[name="username"]') - spans.forEach((span:any) => { + spans.forEach((span: any) => { span.onclick = onUsernameClick }) }) + // const closeProfile = () => { + // if (ignoreOutsideClick) return + // profileElt = null + // } + + // const onUsernameClick = (evt: any) => { + // profileElt = evt.target + // ignoreOutsideClick = true + // setTimeout(() => { + // ignoreOutsideClick = false + // }, 100) + // } + + $:console.log("sender",sender); + $: codeSnippet = isCodeSnippet(sender.message) ? getCodeSnippet(sender.message) : false @@ -174,11 +191,13 @@ id="b1" class="{coloredRole.textColor} font-medium">@{sender.user?.username} --> - - - @{sender.user?.username} - - + + @{sender.user?.username} + + + {/if} {#if isImage(sender.message)} imgs @@ -199,6 +218,7 @@ {:else} {@html parse(sender.message)} + {/if} diff --git a/src/lib/components/Channel/Chat/ProfilePopup.svelte b/src/lib/components/Channel/Chat/ProfilePopup.svelte index 44408310..c96efc13 100644 --- a/src/lib/components/Channel/Chat/ProfilePopup.svelte +++ b/src/lib/components/Channel/Chat/ProfilePopup.svelte @@ -10,6 +10,7 @@ export let open:boolean export let onOutsideClick:any export let elt: any + export let hideLoader= true; let self:any @@ -69,9 +70,10 @@ $: useOueryEffect(() => { if(open && userId){ + profileData = { profile: {} } loadProfile(false) } - }, [open]) + }, [open, userId]) $: profile = profileData.profile $: followerCount = profileData.followerCount || 0 @@ -81,6 +83,7 @@ $: isSelf = userId === $page.data.user?.userId $: console.log("userId: ", userId) + @@ -93,20 +96,26 @@
- {profileData.profile.avatar} + {#if !profileData?.profile?.avatar} +
+
+
+ {:else} + {profileData?.profile?.avatar} + {/if}
-

- {profileData.profile.displayName || ''} -

-

- @{profileData.profile.username || ''} -

+ {#if !profileData?.profile?.displayName && !profileData?.profile?.username} +
+
+
+ {:else} +

+ {profileData?.profile?.displayName} +

+

+ @{profileData?.profile?.username} +

+ {/if} +

- - {profileData.profile.bio || ''} + {#if !profileData?.profile?.bio && profileData?.profile?.bio == undefined && profileData?.profile?.bio == "" } +

+
+
+ {:else} + {profileData?.profile?.bio} + {/if}

- - - {followerCount} Followers - - - {followingCount} Following + {#if !followerCount && !followingCount} +
From db78edb58149244a0fde39e2cf71a11a977a671c Mon Sep 17 00:00:00 2001 From: sitara-dev Date: Fri, 14 Jul 2023 10:10:04 +0530 Subject: [PATCH 3/9] profile popup loader --- .../components/Channel/Chat/DrawerChat.svelte | 6 +----- .../components/Channel/Chat/Message.svelte | 16 ---------------- .../Channel/Chat/ProfilePopup.svelte | 19 +++++++++---------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/lib/components/Channel/Chat/DrawerChat.svelte b/src/lib/components/Channel/Chat/DrawerChat.svelte index 67008c9a..7a85ded1 100644 --- a/src/lib/components/Channel/Chat/DrawerChat.svelte +++ b/src/lib/components/Channel/Chat/DrawerChat.svelte @@ -87,18 +87,14 @@ const onUsernameClick = (evt: any) => { profileElt = evt.target - - const match = profileElt.id.match(/@\w+/g); - console.log('working +++', match) if(match){ selectedUser = viewers.find((i) => i.username == profileElt.id.substr(1))?.userId } else{ selectedUser = viewers.find((i) => i.username == profileElt.id)?.userId } - - console.log('selectedUser', selectedUser, 'viewers', viewers) + console.log("selectedUser",selectedUser, profileElt, viewers); ignoreOutsideClick = true setTimeout(() => { ignoreOutsideClick = false diff --git a/src/lib/components/Channel/Chat/Message.svelte b/src/lib/components/Channel/Chat/Message.svelte index de70893b..34fa1820 100644 --- a/src/lib/components/Channel/Chat/Message.svelte +++ b/src/lib/components/Channel/Chat/Message.svelte @@ -5,7 +5,6 @@ import IconChatQuote from '$lib/assets/icons/chat/IconChatQuote.svelte' import IconChatDelete from '$lib/assets/icons/chat/IconChatDelete.svelte' import IconChatHorizontalMore from '$lib/assets/icons/chat/IconChatHorizontalMore.svelte' - import ProfileCard from '$lib/components/Channel/Chat/ProfileCard.svelte' import { emitChannelUpdate, emitDeleteMessageToChannel } from '$lib/websocket' import { copyToClipboard, getColoredRole, setRole } from '$lib/utils' import { page } from '$app/stores' @@ -157,21 +156,6 @@ }) }) - // const closeProfile = () => { - // if (ignoreOutsideClick) return - // profileElt = null - // } - - // const onUsernameClick = (evt: any) => { - // profileElt = evt.target - // ignoreOutsideClick = true - // setTimeout(() => { - // ignoreOutsideClick = false - // }, 100) - // } - - $:console.log("sender",sender); - $: codeSnippet = isCodeSnippet(sender.message) ? getCodeSnippet(sender.message) : false diff --git a/src/lib/components/Channel/Chat/ProfilePopup.svelte b/src/lib/components/Channel/Chat/ProfilePopup.svelte index c96efc13..06754e28 100644 --- a/src/lib/components/Channel/Chat/ProfilePopup.svelte +++ b/src/lib/components/Channel/Chat/ProfilePopup.svelte @@ -7,12 +7,11 @@ import { createEffect } from '$lib/utils' export let userId: string - export let open:boolean - export let onOutsideClick:any + export let open: boolean + export let onOutsideClick: any export let elt: any - export let hideLoader= true; - let self:any + let self: any const useOueryEffect = createEffect() @@ -25,7 +24,7 @@ } const handleClickOutside = (event: any) => { - if(onOutsideClick)onOutsideClick() + if (onOutsideClick) onOutsideClick() } const doFollow = async (isFollow: any) => { @@ -69,12 +68,14 @@ } $: useOueryEffect(() => { - if(open && userId){ + if (open && userId) { profileData = { profile: {} } loadProfile(false) } }, [open, userId]) + + $:console.log("userIdd",userId); $: profile = profileData.profile $: followerCount = profileData.followerCount || 0 $: followingCount = profileData.followingCount || 0 @@ -82,8 +83,6 @@ $: top = (elt ? elt.getBoundingClientRect().top : 0) + 40 $: isSelf = userId === $page.data.user?.userId - $: console.log("userId: ", userId) - @@ -139,12 +138,12 @@ {/if}

- {#if !profileData?.profile?.bio && profileData?.profile?.bio == undefined && profileData?.profile?.bio == "" } + {#if !profileData?.profile?.bio && loading}

{:else} - {profileData?.profile?.bio} + {profileData?.profile?.bio || " "} {/if}

From 25e5268d5912669e07b0034fad28ba41bc35f6f4 Mon Sep 17 00:00:00 2001 From: sitara-dev Date: Fri, 14 Jul 2023 10:38:34 +0530 Subject: [PATCH 4/9] profile card component remove --- .../Channel/Chat/ProfileCard.svelte | 133 ------------------ 1 file changed, 133 deletions(-) delete mode 100644 src/lib/components/Channel/Chat/ProfileCard.svelte diff --git a/src/lib/components/Channel/Chat/ProfileCard.svelte b/src/lib/components/Channel/Chat/ProfileCard.svelte deleted file mode 100644 index 9c8fd838..00000000 --- a/src/lib/components/Channel/Chat/ProfileCard.svelte +++ /dev/null @@ -1,133 +0,0 @@ - - - - {#if show} - - {/if} - - - - - From d027787b0a0ed33120518ddb1d8d19081d50db7f Mon Sep 17 00:00:00 2001 From: gurpreet991 <=> Date: Fri, 14 Jul 2023 16:20:34 +0530 Subject: [PATCH 5/9] fixed profile fetch issues --- .../components/Channel/Chat/DrawerChat.svelte | 12 +++--------- .../Channel/Chat/ProfilePopup.svelte | 19 +++++++------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/lib/components/Channel/Chat/DrawerChat.svelte b/src/lib/components/Channel/Chat/DrawerChat.svelte index 7a85ded1..71ce249f 100644 --- a/src/lib/components/Channel/Chat/DrawerChat.svelte +++ b/src/lib/components/Channel/Chat/DrawerChat.svelte @@ -87,24 +87,18 @@ const onUsernameClick = (evt: any) => { profileElt = evt.target - const match = profileElt.id.match(/@\w+/g); - if(match){ - selectedUser = viewers.find((i) => i.username == profileElt.id.substr(1))?.userId - } - else{ - selectedUser = viewers.find((i) => i.username == profileElt.id)?.userId - } - console.log("selectedUser",selectedUser, profileElt, viewers); + selectedUser = profileElt.id.substr(1) ignoreOutsideClick = true setTimeout(() => { ignoreOutsideClick = false }, 100) } +
-
+
{ loading = true - const source1 = profile._id + const source1 = profileData.profile._id const source2 = $page.data.user?.userId const isFollowing = isFollow.toString() @@ -49,17 +49,18 @@ if (getProfile(userId) && !refresh) { profileData = getProfile(userId) } else { - profileData.profile = await get(`users/search/id?userId=${userId}`, auth) + profileData.profile = await get(`users/search/username?username=${userId}`, auth) + const id = profileData.profile._id profileData.followerCount = await get( - `follows/count?source=${userId}&sourceType=source1`, + `follows/count?source=${id}&sourceType=source1`, auth ) profileData.followingCount = await get( - `follows/count?source=${userId}&sourceType=source2`, + `follows/count?source=${id}&sourceType=source2`, auth ) if ($page.data.user?.userId) { - profileData.isFollowed = await get(`follows/relationship?source=${profile._id}`, auth) + profileData.isFollowed = await get(`follows/relationship?source=${id}`, auth) } setProfile(userId, profileData) @@ -138,13 +139,7 @@ {/if}

- {#if !profileData?.profile?.bio && loading} -

-
-
- {:else} - {profileData?.profile?.bio || " "} - {/if} + {profileData?.profile?.bio || " "}

{#if !followerCount && !followingCount} From 8ee77b25eca23bb2104c1567394364911b10e406 Mon Sep 17 00:00:00 2001 From: gurpreet991 <=> Date: Fri, 14 Jul 2023 16:23:54 +0530 Subject: [PATCH 6/9] fixed parsing --- src/lib/components/Channel/Chat/Message.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/components/Channel/Chat/Message.svelte b/src/lib/components/Channel/Chat/Message.svelte index 34fa1820..fc34dd67 100644 --- a/src/lib/components/Channel/Chat/Message.svelte +++ b/src/lib/components/Channel/Chat/Message.svelte @@ -146,7 +146,8 @@ } const parse = (msg: string) => { - return msg.replace(/@[\w-]+[,\s]/g, hightlightUsername) + const m = msg + " " + return m.replace(/@[\w-]+[,\s]/g, hightlightUsername).trim() } onMount(() => { From 43dee0871650ffbb1fce25d244f695b1d3c729d9 Mon Sep 17 00:00:00 2001 From: gurpreet991 <=> Date: Fri, 14 Jul 2023 16:47:08 +0530 Subject: [PATCH 7/9] update follow flow --- .../components/Channel/Chat/ProfilePopup.svelte | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lib/components/Channel/Chat/ProfilePopup.svelte b/src/lib/components/Channel/Chat/ProfilePopup.svelte index 9406879d..d80179d7 100644 --- a/src/lib/components/Channel/Chat/ProfilePopup.svelte +++ b/src/lib/components/Channel/Chat/ProfilePopup.svelte @@ -33,14 +33,19 @@ const source1 = profileData.profile._id const source2 = $page.data.user?.userId const isFollowing = isFollow.toString() + if(!profileData.isFollowed) + profileData.isFollowed = {} if (isFollowing == 'true') { await put(`follows`, { source1, source2 }, auth) + profileData.followerCount++ + profileData.isFollowed.isFollowing = true } else { await del(`follows?source1=${source1}&source2=${source2}`, auth) + profileData.followerCount-- + profileData.isFollowed.isFollowing = false } - - await loadProfile(true) + setProfile(userId, profileData) loading = false } @@ -63,6 +68,8 @@ profileData.isFollowed = await get(`follows/relationship?source=${id}`, auth) } + console.log("profileData: ", profileData) + setProfile(userId, profileData) } loading = false @@ -109,13 +116,13 @@