diff --git a/ts/components/ToastManager.stories.tsx b/ts/components/ToastManager.stories.tsx index d2665879c31d..e3082bae8c58 100644 --- a/ts/components/ToastManager.stories.tsx +++ b/ts/components/ToastManager.stories.tsx @@ -52,7 +52,10 @@ function getToast(toastType: ToastType): AnyToast { case ToastType.ConversationArchived: return { toastType: ToastType.ConversationArchived, - parameters: { conversationId: 'some-conversation-id' }, + parameters: { + conversationId: 'some-conversation-id', + wasPinned: false, + }, }; case ToastType.ConversationMarkedUnread: return { toastType: ToastType.ConversationMarkedUnread }; diff --git a/ts/components/ToastManager.tsx b/ts/components/ToastManager.tsx index 6df79fe6b5eb..f44d901ed090 100644 --- a/ts/components/ToastManager.tsx +++ b/ts/components/ToastManager.tsx @@ -23,7 +23,10 @@ export type PropsType = { openFileInFolder: (target: string) => unknown; OS: string; onShowDebugLog: () => unknown; - onUndoArchive: (conversaetionId: string) => unknown; + onUndoArchive: ( + conversationId: string, + options?: { wasPinned?: boolean } + ) => unknown; toast?: AnyToast; megaphone?: AnyActionableMegaphone; centerToast?: boolean; @@ -166,7 +169,9 @@ export function renderToast({ toastAction={{ label: i18n('icu:conversationArchivedUndo'), onClick: () => { - onUndoArchive(String(toast.parameters.conversationId)); + onUndoArchive(String(toast.parameters.conversationId), { + wasPinned: toast.parameters.wasPinned, + }); }, }} > diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 5c8a58b72890..cd2ad2d5879d 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -1201,6 +1201,7 @@ function onArchive( throw new Error('onArchive: Conversation not found!'); } + const wasPinned = conversation.attributes.isPinned ?? false; conversation.setArchived(true); onConversationClosed(conversationId, 'archive')( @@ -1215,13 +1216,15 @@ function onArchive( toastType: ToastType.ConversationArchived, parameters: { conversationId, + wasPinned, }, }, }); }; } function onUndoArchive( - conversationId: string + conversationId: string, + options: { wasPinned?: boolean } = {} ): ThunkAction< void, RootStateType, @@ -1235,6 +1238,9 @@ function onUndoArchive( } conversation.setArchived(false); + if (options.wasPinned) { + conversation.pin(); + } showConversation({ conversationId, })(dispatch, getState, null); diff --git a/ts/types/Toast.tsx b/ts/types/Toast.tsx index d74f5849c78a..f02f36bf31c3 100644 --- a/ts/types/Toast.tsx +++ b/ts/types/Toast.tsx @@ -89,7 +89,7 @@ export type AnyToast = | { toastType: ToastType.CaptchaSolved } | { toastType: ToastType.ConversationArchived; - parameters: { conversationId: string }; + parameters: { conversationId: string; wasPinned: boolean }; } | { toastType: ToastType.ConversationMarkedUnread } | { toastType: ToastType.ConversationRemoved; parameters: { title: string } }