${preview.requireApproval ? "Request to join" : "Join group chat"}
${preview.requireApproval
? html`Send a request to join ${name}. The group
owner will review your request before you can see messages.`
: html`You're about to join ${name}.`}
`;
}
}
export class GroupChatLinkService {
constructor(dataLayer, router) {
this.dataLayer = dataLayer;
this.router = router;
}
handleAction(actionType, preview) {
if (actionType === "copy") {
navigator.clipboard?.writeText(`https://bsky.app/chat/${preview.code}`);
showToast("Copied to clipboard", { style: "success" });
return;
}
if (!this.dataLayer.isAuthenticated) {
window.open(
`https://bsky.app/chat/${preview.code}`,
"_blank",
"noopener",
);
return;
}
if (actionType === "open") {
const convoId = preview.convo?.id ?? preview.convoId;
if (convoId) this.router.go(`/messages/${convoId}`);
return;
}
if (actionType === "join" || actionType === "request") {
JoinChatModal.open({
preview,
onSubmit: () => this.handleJoinChatModalSubmit(preview),
});
return;
}
if (actionType === "requested") {
alertModal("The group owner will review your request.", {
title: "Request pending",
});
}
}
async handleJoinChatModalSubmit(preview) {
try {
const res = await this.dataLayer.mutations.requestJoinGroupChat(
preview.code,
);
showToast(
preview.requireApproval
? "Request sent — the group owner will review your request."
: "Joined group chat",
{ style: "success" },
);
if (res?.status === "joined" && res.convo?.id) {
this.router.go(`/messages/${res.convo.id}`);
}
} catch (error) {
console.error(error);
showToast("Could not send join request. Please try again.", {
style: "error",
});
throw error;
}
}
}