// gomuks - A Matrix client written in Go.
// Copyright (C) 2024 Sumner Evans
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
import { JSX, use } from "react"
import { PulseLoader } from "react-spinners"
import { getAvatarThumbnailURL } from "@/api/media.ts"
import { useMultipleRoomMembers, useRoomTyping } from "@/api/statestore"
import { humanJoin } from "@/util/join.ts"
import { getDisplayname } from "@/util/validation.ts"
import ClientContext from "../ClientContext.ts"
import { useRoomContext } from "../roomview/roomcontext.ts"
import "./TypingNotifications.css"
const TypingNotifications = () => {
const roomCtx = useRoomContext()
const client = use(ClientContext)!
const room = roomCtx.store
const typing = useRoomTyping(room).filter(u => u !== client.userID)
const memberEvts = useMultipleRoomMembers(client, room, typing.slice(0, 5))
let loader: JSX.Element | null = null
if (typing.length > 0) {
loader =
}
const avatars: JSX.Element[] = []
const memberNames: string[] = []
for (const [sender, member] of memberEvts) {
avatars.push(
)
memberNames.push(getDisplayname(sender, member))
}
let description: JSX.Element | null = null
if (typing.length > 4) {
description =
{typing.length} users are typing
} else if (typing.length > 0) {
description =
{humanJoin(memberNames)} {typing.length === 1 ? "is" : "are"} typing
}
return
{avatars}
{description}
{loader}
}
export default TypingNotifications