Various fixes

This commit is contained in:
Ilya Laktyushin 2025-08-23 03:32:53 +04:00
parent b1ebdab0dc
commit c8230eb2e0
6 changed files with 35 additions and 19 deletions

View File

@ -72,7 +72,11 @@ public enum PeerMessagesPlaylistLocation: Equatable, SharedMediaPlaylistLocation
messages.append(Message(stableId: stableId, stableVersion: 0, id: MessageId(peerId: peerId, namespace: Namespaces.Message.Local, id: Int32(stableId)), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: 0, flags: [], tags: [.music], globalTags: [], localTags: [], customTags: [], forwardInfo: nil, author: nil, text: "", attributes: [], media: [file], peers: peers, associatedMessages: SimpleDictionary(), associatedMessageIds: [], associatedMedia: [:], associatedThreadInfo: nil, associatedStories: [:]))
}
return (messages, Int32(messages.count), true)
var canLoadMore = false
if case let .ready(canLoadMoreValue) = state.dataState {
canLoadMore = canLoadMoreValue
}
return (messages, Int32(messages.count), canLoadMore)
},
canReorder: canReorder,
at: MessageId(peerId: peerId, namespace: Namespaces.Message.Local, id: at),

View File

@ -352,6 +352,7 @@ open class ListView: ASDisplayNode, ASScrollViewDelegate, ASGestureRecognizerDel
private var currentGeneralScrollDirection: GeneralScrollDirection?
public final var generalScrollDirectionUpdated: (GeneralScrollDirection) -> Void = { _ in }
public var autoScrollWhenReordering = true
public private(set) var isReordering = false
public final var willBeginReorder: (CGPoint) -> Void = { _ in }
public final var reorderBegan: () -> Void = { }
@ -668,8 +669,12 @@ open class ListView: ASDisplayNode, ASScrollViewDelegate, ASGestureRecognizerDel
private func updateReordering(offset: CGFloat) {
if let reorderNode = self.reorderNode {
reorderNode.updateOffset(offset: offset)
self.checkItemReordering()
let updatedLocation = reorderNode.initialLocation.y + offset
if updatedLocation < self.insets.top {
} else {
reorderNode.updateOffset(offset: offset)
self.checkItemReordering()
}
}
}
@ -4662,7 +4667,7 @@ open class ListView: ASDisplayNode, ASScrollViewDelegate, ASGestureRecognizerDel
var offsetRanges = OffsetRanges()
var scrollingForReorder = false
if let reorderOffset = self.reorderNode?.currentOffset(), !self.itemNodes.isEmpty {
if self.autoScrollWhenReordering, let reorderOffset = self.reorderNode?.currentOffset(), !self.itemNodes.isEmpty {
let effectiveInsets = self.visualInsets ?? self.insets
var offset: CGFloat = 6.0

View File

@ -51,7 +51,7 @@ final class ListViewReorderingItemNode: ASDisplayNode {
var currentState: (Int, Int)?
private let copyView: CopyView
private let initialLocation: CGPoint
let initialLocation: CGPoint
init(itemNode: ListViewItemNode, initialLocation: CGPoint, hasShadow: Bool) {
self.itemNode = itemNode

View File

@ -6009,12 +6009,19 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
}
}
var previousSavedMusicTimestamp: Double?
private func displaySavedMusic() {
guard let savedMusicContext = self.data?.savedMusicContext else {
return
}
let currentTimestamp = CACurrentMediaTime()
if let previousTimestamp = self.previousSavedMusicTimestamp, currentTimestamp < previousTimestamp + 1.0 {
return
}
self.previousSavedMusicTimestamp = currentTimestamp
let peerId = self.peerId
//let peer = self.data?.peer
let initialId: Int32
if let initialFileId = self.data?.savedMusicState?.files.first?.fileId {
initialId = Int32(clamping: initialFileId.id % Int64(Int32.max))
@ -6023,7 +6030,6 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
}
let playlistLocation: PeerMessagesPlaylistLocation = .savedMusic(context: savedMusicContext, at: initialId, canReorder: peerId == self.context.account.peerId)
let _ = (self.context.sharedContext.mediaManager.globalMediaPlayerState
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self] accountStateAndType in
@ -6045,7 +6051,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
initialOrder: .regular,
playlistLocation: playlistLocation,
parentNavigationController: self.controller?.navigationController as? NavigationController,
updateMusicSaved: { [weak savedMusicContext] file, isSaved in
updateMusicSaved: self.peerId == self.context.account.peerId ? { [weak savedMusicContext] file, isSaved in
guard let savedMusicContext else {
return
}
@ -6054,7 +6060,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
} else {
let _ = savedMusicContext.removeMusic(file: file).start()
}
},
} : nil,
reorderSavedMusic: { [weak savedMusicContext] file, afterFile in
guard let savedMusicContext else {
return

View File

@ -496,6 +496,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
return .single(true)
}
})
self.historyNode.autoScrollWhenReordering = false
}
func updatePresentationData(_ presentationData: PresentationData) {
@ -606,7 +607,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
}
)
if self.historyNode.originalHistoryView?.entries.count == 1 {
if let itemId = self.controlsNode.currentItemId as? PeerMessagesMediaPlaylistItemId, itemId.messageId.namespace == Namespaces.Message.Local && itemId.messageId.peerId == self.context.account.peerId, self.historyNode.originalHistoryView?.entries.count == 1 {
if let navigationController = (self.getParentController() as? OverlayAudioPlayerControllerImpl)?.parentNavigationController {
self.requestDismiss()
navigationController.presentOverlay(controller: controller)
@ -975,7 +976,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
let fileReference: FileMediaReference = message.id.namespace == Namespaces.Message.Local ? .savedMusic(peer: peer, media: file) : .message(message: MessageReference(message), media: file)
let canSaveToProfile = !(self.savedIds?.contains(file.fileId.id) == true)
let canSaveToSavedMessages = message.id.peerId != self.context.account.peerId
let canSaveToSavedMessages = message.id.peerId != self.context.account.peerId || message.id.namespace == Namespaces.Message.Local
let _ = (context.sharedContext.chatAvailableMessageActions(engine: context.engine, accountPeerId: context.account.peerId, messageIds: [message.id], keepUpdated: false)
|> deliverOnMainQueue).startStandalone(next: { [weak self] actions in
@ -999,7 +1000,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
if canSaveToProfile {
subActions.append(
.action(ContextMenuActionItem(text: "Profile", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/User"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
.action(ContextMenuActionItem(text: "Profile", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/User"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
f(.default)
if let self {
@ -1011,7 +1012,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
if canSaveToSavedMessages {
subActions.append(
.action(ContextMenuActionItem(text: "Saved Messages", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Fave"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
.action(ContextMenuActionItem(text: "Saved Messages", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Fave"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
f(.default)
if let self {
@ -1022,7 +1023,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu
}
subActions.append(
.action(ContextMenuActionItem(text: "Files", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Save"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
.action(ContextMenuActionItem(text: "Files", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Save"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in
f(.default)
if let self {

View File

@ -1029,10 +1029,7 @@ final class OverlayPlayerControlsNode: ASDisplayNode {
//TODO:localize
let sideInset: CGFloat = 16.0
var sectionTitle = "AUDIO IN THIS CHAT"
if var peerName = self.peerName {
if peerName.count > 30 {
peerName = "\(peerName.prefix(30))"
}
if let peerName = self.peerName {
sectionTitle = "\(peerName.uppercased())'S PLAYLIST"
} else if case .custom = self.source {
sectionTitle = "YOUR PLAYLIST"
@ -1040,7 +1037,10 @@ final class OverlayPlayerControlsNode: ASDisplayNode {
let sectionTitleSize = self.sectionTitle.update(
transition: .immediate,
component: AnyComponent(
MultilineTextComponent(text: .plain(NSAttributedString(string: sectionTitle, font: Font.regular(13.0), textColor: self.presentationData.theme.chatList.sectionHeaderTextColor)))
MultilineTextComponent(
text: .plain(NSAttributedString(string: sectionTitle, font: Font.regular(13.0), textColor: self.presentationData.theme.chatList.sectionHeaderTextColor)),
truncationType: .middle
)
),
environment: {},
containerSize: CGSize(width: width - leftInset - rightInset - sideInset * 2.0, height: OverlayPlayerControlsNode.sectionHeaderHeight)