Skip to content

Commit

Permalink
Fix message-link shares (microsoft#172)
Browse files Browse the repository at this point in the history
By skipping state for messageId
  • Loading branch information
markwaddle authored Oct 25, 2024
1 parent ea57c01 commit f748061
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions workbench-app/src/routes/ShareRedeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const ShareRedeem: React.FC = () => {
const [createConversationMessage] = useCreateConversationMessageMutation();
const [removeConversationParticipant] = useRemoveConversationParticipantMutation();
const [submitted, setSubmitted] = React.useState(false);
const [messageId, setMessageId] = React.useState<string | undefined>(undefined);
const [joinAttempted, setJoinAttempted] = React.useState(false);
const conversationUtility = useConversationUtility();
const account = useAccount();
Expand All @@ -59,30 +58,33 @@ export const ShareRedeem: React.FC = () => {
const title = 'Open a shared conversation';
siteUtility.setDocumentTitle(title);

const handleClickJoin = React.useCallback(async () => {
if (!conversationShare) {
return;
}
setSubmitted(true);
try {
await redeemShare(conversationShare.id);
const hash = messageId ? `#${messageId}` : '';

// send event to notify the conversation that the user has joined
const accountName = account?.name;
if (conversationShare.conversationPermission === 'read_write' && accountName) {
await createConversationMessage({
conversationId: conversationShare.conversationId,
content: `${accountName} joined the conversation`,
messageType: 'notice',
});
const handleClickJoin = React.useCallback(
async (messageId?: string) => {
if (!conversationShare) {
return;
}
setSubmitted(true);
try {
await redeemShare(conversationShare.id);
const hash = messageId ? `#${messageId}` : '';

navigate(`/conversation/${conversationShare.conversationId}${hash}`, { replace: true });
} finally {
setSubmitted(false);
}
}, [conversationShare, redeemShare, messageId, account?.name, navigate, createConversationMessage]);
// send event to notify the conversation that the user has joined
const accountName = account?.name;
if (conversationShare.conversationPermission === 'read_write' && accountName) {
await createConversationMessage({
conversationId: conversationShare.conversationId,
content: `${accountName} joined the conversation`,
messageType: 'notice',
});
}

navigate(`/conversation/${conversationShare.conversationId}${hash}`, { replace: true });
} finally {
setSubmitted(false);
}
},
[conversationShare, redeemShare, account?.name, navigate, createConversationMessage],
);

const handleClickDuplicate = React.useCallback(async () => {
if (!conversationShare) {
Expand Down Expand Up @@ -130,9 +132,8 @@ export const ShareRedeem: React.FC = () => {
return;
}

setMessageId(linkToMessageId);
setJoinAttempted(true);
handleClickJoin();
handleClickJoin(linkToMessageId);
}, [conversationShare, conversationUtility, handleClickJoin, readyToCheckForMessageLink]);

const renderAppView = React.useCallback(
Expand Down

0 comments on commit f748061

Please sign in to comment.