Story: Fix various problems (#5935)

This commit is contained in:
zubiden 2025-06-04 20:41:07 +02:00 committed by Alexander Zinchuk
parent bd096e2a01
commit eaca13c851
8 changed files with 15 additions and 16 deletions

View File

@ -119,7 +119,7 @@ export function addDocumentToLocalDb(document: GramJs.TypeDocument) {
export function addStoryRepairInfo<T extends GramJs.TypeDocument | GramJs.TypeWebDocument | GramJs.TypePhoto>(
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',

View File

@ -489,7 +489,6 @@ export async function repairFileReference({
url: string;
}) {
const parsed = parseMediaUrl(url);
if (!parsed) return undefined;
const {

View File

@ -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(() => {

View File

@ -97,7 +97,7 @@ function StoryPreview({
export default memo(withGlobal<OwnProps>((global, { peer }): StateProps => {
const {
storyViewer: {
lastViewedByPeerIds,
lastViewedByPeerId: lastViewedByPeerIds,
origin,
storyList,
},

View File

@ -97,7 +97,7 @@ addActionHandler('closeStoryViewer', (global, actions, payload): ActionReturnTyp
isMuted,
isRibbonShown,
isArchivedRibbonShown,
lastViewedByPeerIds: undefined,
lastViewedByPeerId: undefined,
storyList: undefined,
},
}, tabId);

View File

@ -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);
});

View File

@ -200,8 +200,8 @@ export function updateLastViewedStoryForPeer<T extends GlobalState>(
return updateTabState(global, {
storyViewer: {
...storyViewer,
lastViewedByPeerIds: {
...storyViewer.lastViewedByPeerIds,
lastViewedByPeerId: {
...storyViewer.lastViewedByPeerId,
[peerId]: lastViewedId,
},
},
@ -313,7 +313,7 @@ export function removePeerStory<T extends GlobalState>(
});
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);
}
});

View File

@ -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<string, number>;
lastViewedByPeerId?: Record<string, number>;
isPrivacyModalOpen?: boolean;
isPaymentConfirmDialogOpen?: boolean;
isStealthModalOpen?: boolean;