diff --git a/submodules/Display/Source/TextNode.swift b/submodules/Display/Source/TextNode.swift index a4a58949d4..3a3abedbce 100644 --- a/submodules/Display/Source/TextNode.swift +++ b/submodules/Display/Source/TextNode.swift @@ -1260,40 +1260,26 @@ open class TextNode: ASDisplayNode { var effectiveLineRange = brokenLineRange var additionalTrailingLine: (CTLine, Double)? - if lineRange.length == 0 || (CTLineGetTypographicBounds(originalLine, nil, nil, nil) - CTLineGetTrailingWhitespaceWidth(originalLine) + truncationTokenWidth) < Double(lineConstrainedSize.width) { + var measureFitWidth = CTLineGetTypographicBounds(originalLine, nil, nil, nil) - CTLineGetTrailingWhitespaceWidth(originalLine) + if customTruncationToken != nil { + measureFitWidth += truncationTokenWidth + } + + if lineRange.length == 0 || measureFitWidth < Double(lineConstrainedSize.width) { if didClipLinebreak { - coreTextLine = originalLine + if lineRange.length == 0 { + coreTextLine = CTLineCreateWithAttributedString(NSAttributedString()) + } else { + coreTextLine = originalLine + } additionalTrailingLine = (truncationToken, truncationTokenWidth) - /*let mergedLine = NSMutableAttributedString() - mergedLine.append(attributedString.attributedSubstring(from: NSRange(location: lineRange.location, length: lineRange.length))) - mergedLine.append(truncatedTokenString) - - coreTextLine = CTLineCreateWithAttributedString(mergedLine) - - let runs = (CTLineGetGlyphRuns(coreTextLine) as [AnyObject]) as! [CTRun] - for run in runs { - let runAttributes: NSDictionary = CTRunGetAttributes(run) - if let _ = runAttributes["CTForegroundColorFromContext"] { - brokenLineRange.length = CTRunGetStringRange(run).location - brokenLineRange.location - break - } - } - if brokenLineRange.location + brokenLineRange.length > lineRange.location + lineRange.length { - brokenLineRange.location = lineRange.location - brokenLineRange.length = lineRange.length - } - if brokenLineRange.location + brokenLineRange.length > attributedString.length { - brokenLineRange.length = attributedString.length - brokenLineRange.location - } - effectiveLineRange = brokenLineRange*/ - truncated = true } else { coreTextLine = originalLine } } else { - coreTextLine = CTLineCreateTruncatedLine(originalLine, Double(lineConstrainedSize.width), truncationType, truncationToken) ?? truncationToken + coreTextLine = CTLineCreateTruncatedLine(originalLine, max(1.0, Double(lineConstrainedSize.width) - truncationTokenWidth), truncationType, truncationToken) ?? truncationToken let runs = (CTLineGetGlyphRuns(coreTextLine) as [AnyObject]) as! [CTRun] for run in runs { let runAttributes: NSDictionary = CTRunGetAttributes(run) diff --git a/submodules/MediaPlayer/Sources/MediaPlayer.swift b/submodules/MediaPlayer/Sources/MediaPlayer.swift index acaf62405f..67e142d587 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayer.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayer.swift @@ -1022,7 +1022,6 @@ private final class MediaPlayerContext { if isPaused && self.fadeTimer != nil { playbackStatus = .paused } else if reportRate.isZero { - //playbackStatus = .buffering(initial: false, whilePlaying: true) playbackStatus = .playing statusTimestamp = 0.0 } else { diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift index 57427331e6..714d4dfc4c 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift @@ -82,6 +82,8 @@ final class StoryItemContentComponent: Component { private var currentProgressTimerValue: Double = 0.0 private var videoProgressDisposable: Disposable? + private var ignoreBufferingTimestamp: Double = 0.0 + private var markedAsSeen: Bool = false private var contentLoaded: Bool = false @@ -252,6 +254,7 @@ final class StoryItemContentComponent: Component { override func leaveAmbientMode() { if let videoNode = self.videoNode { + self.ignoreBufferingTimestamp = CFAbsoluteTimeGetCurrent() videoNode.setSoundEnabled(true) videoNode.continueWithOverridingAmbientMode(isAmbient: false) } @@ -259,6 +262,7 @@ final class StoryItemContentComponent: Component { override func enterAmbientMode(ambient: Bool) { if let videoNode = self.videoNode { + self.ignoreBufferingTimestamp = CFAbsoluteTimeGetCurrent() if ambient { videoNode.continueWithOverridingAmbientMode(isAmbient: true) } else { @@ -369,6 +373,16 @@ final class StoryItemContentComponent: Component { isBuffering = true } + if isBuffering { + if CFAbsoluteTimeGetCurrent() - self.ignoreBufferingTimestamp < 0.3 { + isBuffering = false + } else { + self.ignoreBufferingTimestamp = 0.0 + } + } else { + self.ignoreBufferingTimestamp = 0.0 + } + if case .buffering(true, _, _, _) = videoPlaybackStatus.status { timestampAndDuration = (nil, effectiveDuration) } else if effectiveDuration > 0.0 { diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index e9e9718a4a..6de5f65225 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -3886,7 +3886,7 @@ public final class StoryItemSetContainerComponent: Component { self.requestSave() }))) - if component.slice.item.storyItem.isPublic && (component.slice.peer.addressName != nil || !component.slice.peer._asPeer().usernames.isEmpty) && component.slice.item.storyItem.expirationTimestamp > Int32(Date().timeIntervalSince1970) { + if component.slice.item.storyItem.isPublic && (component.slice.peer.addressName != nil || !component.slice.peer._asPeer().usernames.isEmpty) && (component.slice.item.storyItem.expirationTimestamp > Int32(Date().timeIntervalSince1970) || component.slice.item.storyItem.isPinned) { items.append(.action(ContextMenuActionItem(text: component.strings.Story_Context_CopyLink, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Link"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, a in