diff --git a/src/api/gramjs/helpers/localDb.ts b/src/api/gramjs/helpers/localDb.ts index 4c0ab4256..1e40e9c1b 100644 --- a/src/api/gramjs/helpers/localDb.ts +++ b/src/api/gramjs/helpers/localDb.ts @@ -119,7 +119,7 @@ export function addDocumentToLocalDb(document: GramJs.TypeDocument) { export function addStoryRepairInfo( media: T, peerId: string, story: GramJs.TypeStoryItem, ): T & RepairInfo { - if (!(media instanceof GramJs.Document && media instanceof GramJs.Photo)) return media; + if (!(media instanceof GramJs.Document || media instanceof GramJs.Photo)) return media; const repairableMedia = media as T & RepairInfo; repairableMedia.localRepairInfo = { type: 'story', diff --git a/src/api/gramjs/methods/client.ts b/src/api/gramjs/methods/client.ts index e801dfc9e..367461e5b 100644 --- a/src/api/gramjs/methods/client.ts +++ b/src/api/gramjs/methods/client.ts @@ -489,7 +489,6 @@ export async function repairFileReference({ url: string; }) { const parsed = parseMediaUrl(url); - if (!parsed) return undefined; const { diff --git a/src/components/story/StoryCaption.tsx b/src/components/story/StoryCaption.tsx index 013810831..4e2dcfc42 100644 --- a/src/components/story/StoryCaption.tsx +++ b/src/components/story/StoryCaption.tsx @@ -65,21 +65,22 @@ function StoryCaption({ canExpand, undefined, true, 'slow', true, ); + // Setup gradient to clip caption before button useLayoutEffect(() => { requestMeasure(() => { - if (!showMoreButtonRef.current) { + const container = contentRef.current; + const button = showMoreButtonRef.current; + if (!container || !button) { return; } - const button = showMoreButtonRef.current; - const { offsetWidth } = button; requestMutation(() => { - button.style.setProperty('--expand-button-width', `${offsetWidth}px`); + container.style.setProperty('--expand-button-width', `${offsetWidth}px`); }); }); - }, []); + }, [shouldRenderShowMore, lang]); useLayoutEffect(() => { requestForcedReflow(() => { diff --git a/src/components/story/StoryPreview.tsx b/src/components/story/StoryPreview.tsx index 9ac93301e..abca4bf4b 100644 --- a/src/components/story/StoryPreview.tsx +++ b/src/components/story/StoryPreview.tsx @@ -97,7 +97,7 @@ function StoryPreview({ export default memo(withGlobal((global, { peer }): StateProps => { const { storyViewer: { - lastViewedByPeerIds, + lastViewedByPeerId: lastViewedByPeerIds, origin, storyList, }, diff --git a/src/global/actions/ui/stories.ts b/src/global/actions/ui/stories.ts index 0b6284b75..a802878d5 100644 --- a/src/global/actions/ui/stories.ts +++ b/src/global/actions/ui/stories.ts @@ -97,7 +97,7 @@ addActionHandler('closeStoryViewer', (global, actions, payload): ActionReturnTyp isMuted, isRibbonShown, isArchivedRibbonShown, - lastViewedByPeerIds: undefined, + lastViewedByPeerId: undefined, storyList: undefined, }, }, tabId); diff --git a/src/global/intervals.ts b/src/global/intervals.ts index 82e589a6f..d64f31b22 100644 --- a/src/global/intervals.ts +++ b/src/global/intervals.ts @@ -47,10 +47,9 @@ function checkStoryExpiration() { Object.values(global.stories.byPeerId).forEach((peerStories) => { const stories = Object.values(peerStories.byId); stories.forEach((story) => { - if (!('expireDate' in story)) return; + if (story['@type'] !== 'story') return; if (story.expireDate > serverTime) return; - if ('isInProfile' in story && story.isInProfile) return; - if ('isPublic' in story && !story.isPublic) return; + if (story.isInProfile) return; global = removePeerStory(global, story.peerId, story.id); }); diff --git a/src/global/reducers/stories.ts b/src/global/reducers/stories.ts index 5bb719904..f496de2bc 100644 --- a/src/global/reducers/stories.ts +++ b/src/global/reducers/stories.ts @@ -200,8 +200,8 @@ export function updateLastViewedStoryForPeer( return updateTabState(global, { storyViewer: { ...storyViewer, - lastViewedByPeerIds: { - ...storyViewer.lastViewedByPeerIds, + lastViewedByPeerId: { + ...storyViewer.lastViewedByPeerId, [peerId]: lastViewedId, }, }, @@ -313,7 +313,7 @@ export function removePeerStory( }); Object.values(global.byTabId).forEach((tab) => { - if (tab.storyViewer.lastViewedByPeerIds?.[peerId] === storyId) { + if (tab.storyViewer.lastViewedByPeerId && tab.storyViewer.lastViewedByPeerId[peerId] === storyId) { global = updateLastViewedStoryForPeer(global, peerId, previousStoryId, tab.id); } }); diff --git a/src/global/types/tabState.ts b/src/global/types/tabState.ts index 140cc1d24..1258a2124 100644 --- a/src/global/types/tabState.ts +++ b/src/global/types/tabState.ts @@ -303,7 +303,7 @@ export type TabState = { isArchive?: boolean; // Last viewed story id in current view session. // Used for better switch animation between peers. - lastViewedByPeerIds?: Record; + lastViewedByPeerId?: Record; isPrivacyModalOpen?: boolean; isPaymentConfirmDialogOpen?: boolean; isStealthModalOpen?: boolean;