Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: avatar and banner upload fixes along with infinite scroll fix in… #555

Merged
merged 2 commits into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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