Skip to content

Commit

Permalink
Merge pull request #555 from da7a90-backup/infinitescroll
Browse files Browse the repository at this point in the history
Fix: avatar and banner upload fixes along with infinite scroll fix in…
  • Loading branch information
gagansuie authored Jun 25, 2023
2 parents 2aaa0b1 + 8273c7d commit fcfd13f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
13 changes: 9 additions & 4 deletions src/lib/components/Channel/Chat/DrawerChat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@
showEditChannelDrawer: boolean = false
let chatHistory: any[] = [],
chatDrawerElement: HTMLElement
let cursor = "";
channel_message.subscribe((value) => {
if (!value) return
var parsedMsg = JSON.parse(value)
if (parsedMsg.eventName === `channel-message-${channel?._id}`) {
if (parsedMsg.isMessageHistory) {
chatHistory = []
cursor = parsedMsg.cursor
//chatHistory = []
// if (Array.isArray(parsedMsg.data)) {
parsedMsg.data.forEach((message: any) => {
let messages = parsedMsg.data.map((message: any) => {
message.role = setRole({
userId: message.user.userId,
channel,
currentUserId: $page.data.user?.userId
})
chatHistory.push(message)
return message;
})
chatHistory = [...chatHistory, ...messages]
// } else {
// parsedMsg = setRole(JSON.parse(parsedMsg.data))
// chatHistory.push(parsedMsg)
Expand Down Expand Up @@ -80,7 +84,8 @@
emitChatHistoryToChannel({
channelSocket: channel.socket,
channelId: channel._id,
skip: 100
skip: 100,
cursor: cursor || "none"
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/components/Channel/Stream/DropdownViewers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
viewers = viewers.concat(parsedMsg.users)
cursor = parsedMsg.cursor
}
if(parsedMsg.eventName === `channel-subscribe-${channel?.id}`){
emitGetConnectedUsers({channelSocket: channel.socket, cursor})
}
})
</script>

Expand Down
30 changes: 22 additions & 8 deletions src/lib/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,33 @@ const emitDeleteAllMessagesToChannel = ({
const emitChatHistoryToChannel = ({
channelSocket,
channelId,
skip
skip,
cursor
}: {
channelSocket: WebSocket
channelId: string
skip: number
cursor?: string
}) => {
channelSocket.send(
JSON.stringify({
eventName: `channel-message-history`,
channel: channelId,
skip
})
)
if(!cursor){
channelSocket.send(
JSON.stringify({
eventName: `channel-message-history`,
channel: channelId,
skip
})
)
} else {
channelSocket.send(
JSON.stringify({
eventName: `channel-message-history`,
channel: channelId,
skip,
cursor
})
)
}

}

const emitReactToMessage = ({
Expand Down
13 changes: 9 additions & 4 deletions src/routes/profile/[username]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ export const actions = {
addPropertyIfDefined(data, 'website', newUser)
addPropertyIfDefined(data, 'category', newUser)
addPropertyIfDefined(data, 'bio', newUser)
addPropertyIfDefined(data, 'avatar', newUser)
addPropertyIfDefined(data, 'banner', newUser)

if (data.get('avatar') !== null) {

const avatar = data.get('avatar') as File

const banner = data.get('banner') as File



if (data.get('avatar') !== null && avatar.size > 0) {
const urlLocation = await putImage(
`users/current/avatar?bucketName=avatars&originalName=${locals.user.userId}-avatar`,
data.get('avatar'),
Expand All @@ -50,7 +55,7 @@ export const actions = {
console.log(urlLocation)
}

if (data.get('banner') !== null) {
if (data.get('banner') !== null && banner.size > 0) {
const urlLocation = await putImage(
`users/current/banner?bucketName=banners&originalName=${locals.user.userId}-banner`,
data.get('banner'),
Expand Down
5 changes: 2 additions & 3 deletions src/routes/profile/[username]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let data: PageData
let showDrawer = false
let banner = data.profile?.banner || 'https://images.unsplash.com/photo-1499336315816-097655dcfbda?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=2710&amp;q=80';
</script>

{#if !data.profile}
Expand All @@ -17,9 +18,7 @@
<div class="relative block h-[31rem]">
<div
class="absolute top-0 w-full h-full bg-center bg-cover"
style="background-image: url('{data.profile?.banner
? data.profile.banner
: 'https://images.unsplash.com/photo-1499336315816-097655dcfbda?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=2710&amp;q=80'});">
style="background-image: url({banner});">
<span id="blackOverlay" class="w-full h-full absolute opacity-50 bg-black" />
</div>
</div>
Expand Down

0 comments on commit fcfd13f

Please sign in to comment.