Add VoiceChannel support.

This commit is contained in:
Paul
2021-06-23 13:52:16 +01:00
parent 5df1c463a3
commit babb53c794
12 changed files with 123 additions and 59 deletions

View File

@@ -1,10 +1,10 @@
import { useContext } from "preact/hooks";
import { Hash } from "@styled-icons/feather";
import { Channels } from "revolt.js/dist/api/objects";
import { Hash, Volume2 } from "@styled-icons/feather";
import { ImageIconBase, IconBaseProps } from "./IconBase";
import { AppContext } from "../../context/revoltjs/RevoltClient";
interface Props extends IconBaseProps<Channels.GroupChannel | Channels.TextChannel> {
interface Props extends IconBaseProps<Channels.GroupChannel | Channels.TextChannel | Channels.VoiceChannel> {
isServerChannel?: boolean;
}
@@ -15,13 +15,19 @@ export default function ChannelIcon(props: Props & Omit<JSX.HTMLAttributes<HTMLI
const { size, target, attachment, isServerChannel: server, animate, children, as, ...imgProps } = props;
const iconURL = client.generateFileURL(target?.icon ?? attachment, { max_side: 256 }, animate);
const isServerChannel = server || target?.channel_type === 'TextChannel';
const isServerChannel = server || (target && (target.channel_type === 'TextChannel' || target.channel_type === 'VoiceChannel'));
if (typeof iconURL === 'undefined') {
if (isServerChannel) {
return (
<Hash size={size} />
)
if (target?.channel_type === 'VoiceChannel') {
return (
<Volume2 size={size} />
)
} else {
return (
<Hash size={size} />
)
}
}
}

View File

@@ -22,13 +22,14 @@ interface Props {
head?: boolean
}
export default function Message({ attachContext, message, contrast, content: replacement, head, queued }: Props) {
export default function Message({ attachContext, message, contrast, content: replacement, head: preferHead, queued }: Props) {
// TODO: Can improve re-renders here by providing a list
// TODO: of dependencies. We only need to update on u/avatar.
const user = useUser(message.author);
const client = useContext(AppContext);
const content = message.content as string;
const head = (message.replies && message.replies.length > 0) || preferHead;
return (
<MessageBase id={message._id}
head={head}

View File

@@ -16,7 +16,8 @@ export function useUnreads({ channel, unreads, dispatcher }: UnreadProps, contex
function checkUnread(target?: Channel) {
if (!target) return;
if (target._id !== channel._id) return;
if (target?.channel_type === "SavedMessages") return;
if (target.channel_type === "SavedMessages" ||
target.channel_type === "VoiceChannel") return;
const unread = unreads[channel._id]?.last_id;
if (target.last_message) {