import {
bindToPage,
pageEffect,
bindPageTitle,
onPageShow,
} from "/js/router.js";
import { html, render } from "/js/lib/lit-html.js";
import { headerTemplate } from "/js/templates/header.template.js";
import { formatRelativeTime } from "/js/utils.js";
import {
getConvoPreviewText,
getDisplayName,
getGroupConvoDetails,
getLastInteraction,
getInteractionTimestamp,
MISSING_HANDLE,
} from "/js/dataHelpers.js";
import { avatarTemplate } from "/js/templates/avatar.template.js";
import { avatarGroupTemplate } from "/js/templates/avatarGroup.template.js";
import "/js/components/infinite-scroll-container.js";
import "/js/components/container-link.js";
import "/js/components/app-icon.js";
import { tryAgainButtonTemplate } from "/js/templates/tryAgainButton.template.js";
export default async function chatView({
root,
router,
layout,
context: { auth, dataLayer, chatNotificationService, newChatService },
}) {
await auth.requireAuth();
async function handleMenuClick() {
layout.openSidebar();
}
function handleNewChatClick() {
newChatService.openNewChatDialog();
}
function newChatButtonTemplate() {
return html`
`;
}
function convoItemTemplate({ convo, currentUser }) {
const groupDetails = getGroupConvoDetails(convo);
const lastInteraction = getLastInteraction(convo);
const otherMembers = convo.members.filter(
(member) => member.did !== currentUser?.did,
);
const otherUser = groupDetails ? null : otherMembers[0];
const timeAgo = lastInteraction
? formatRelativeTime(getInteractionTimestamp(lastInteraction))
: "";
const isUnread = convo.unreadCount > 0;
return html`