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

Virtualization revert and kill badges #740

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
297 changes: 68 additions & 229 deletions src/Actions.ts

Large diffs are not rendered by default.

340 changes: 141 additions & 199 deletions src/App.tsx

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions src/Deferred.ts

This file was deleted.

130 changes: 130 additions & 0 deletions src/components/ChatView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { findLastIndex } from 'lodash'
import React, { Fragment, useContext } from 'react'

import { isMovementMessage, Message, MessageType } from '../message'
import MessageView from './MessageView'

import { ServerSettings } from '../../server/src/types'
import '../../style/chat.css'
import {
ActivateAutoscrollAction,
DeactivateAutoscrollAction
} from '../Actions'
import { DispatchContext } from '../App'

interface Props {
messages: Message[];
autoscrollChat: boolean;
serverSettings: ServerSettings;
captionsEnabled: boolean;
}

export default function ChatView (props: Props) {
const dispatch = useContext(DispatchContext)

const handleScroll = () => {
const messageWindow = document.querySelector('#messages')
const isScrolledToBottom =
messageWindow.scrollHeight ===
messageWindow.scrollTop + messageWindow.clientHeight

if (isScrolledToBottom && !props.autoscrollChat) {
dispatch(ActivateAutoscrollAction())
} else if (!isScrolledToBottom && props.autoscrollChat) {
dispatch(DeactivateAutoscrollAction())
}
}

React.useEffect(() => {
const lastMessage = document.querySelector(
'#messages .message-wrapper:last-of-type'
)
if (lastMessage && props.autoscrollChat) {
// I was using lastMessage.scrollIntoView()
// But I was seeing odd behavior when there was only one message on-screen.
// This very TS-unfriendly code fixes taht.
(lastMessage.parentNode as Element).scrollTop =
(lastMessage as any).offsetTop -
(lastMessage.parentNode as any).offsetTop
}
})

const [shouldShowOlderMessages, setShouldShowOlderMessages] =
React.useState(false)

// This message filtering logic is kinda ugly and hard to read
function shouldRemoveMessage (m: Message) {
return (
isMovementMessage(m) &&
(props.serverSettings.movementMessagesHideRoomIds.includes(m.roomId) ||
m.numUsersInRoom > props.serverSettings.movementMessagesHideThreshold)
)
}
const messages = props.messages
.filter((msg) => {
// Hide movement messages if the room is busy enough
return !shouldRemoveMessage(msg)
})
.filter((msg) => {
// Don't show captions unless they're enabled
if (props.captionsEnabled) return true
return msg.type !== MessageType.Caption
})

const lastIndexOfMovedMessage = findLastIndex(
messages,
(message) => message.type === MessageType.MovedRoom
)
const currentRoomMessages = messages.slice(lastIndexOfMovedMessage)
const shownMessages = shouldShowOlderMessages
? messages
: currentRoomMessages

return (
<>
<button
className="link-styled-button"
onClick={() => setShouldShowOlderMessages(!shouldShowOlderMessages)}
>
{shouldShowOlderMessages ? 'Hide' : 'Show'} Older Messages
</button>
<div id="messages" onScroll={handleScroll}>
{shownMessages.slice(-150).map((m, idx) => {
let hideTimestamp = false
const previousMessage = props.messages[idx - 1]
if (previousMessage) {
// TODO: Give all messages a userId for this to be meaningful
if (
(previousMessage as any).userId &&
(m as any).userId &&
(previousMessage as any).userId === (m as any).userId
) {
const diff =
new Date(m.timestamp).getTime() -
new Date(previousMessage.timestamp).getTime()
// This is a bad way to calculate '3 minutes' and I should feel bad -em
if (diff < 1000 * 60 * 3) {
hideTimestamp = true
}
}
}

const shouldShowInterstitial = m.type === MessageType.MovedRoom

return (
<Fragment key={m.id}>
{shouldShowInterstitial ? (
<hr />
) : null}
<MessageView
message={m}
hideTimestamp={hideTimestamp}
msgIndex={idx}
/>
</Fragment>
)
})}
</div>
</>
)
}
8 changes: 0 additions & 8 deletions src/components/MessageItem/MessageItem.css

This file was deleted.

73 changes: 0 additions & 73 deletions src/components/MessageItem/MessageItem.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/MessageItem/index.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/components/MessageList/MessageList.css

This file was deleted.

71 changes: 0 additions & 71 deletions src/components/MessageList/MessageList.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/MessageList/hooks/index.ts

This file was deleted.

Loading