Skip to content

Commit 8b70726

Browse files
authored
Keep the profile music playing when its strip is clicked again (#125)
* Keep the profile music playing when its strip is clicked again Clicking the music strip of a profile always created a new player and started it from the first track, so a track picked from the list was replaced as soon as the strip was clicked again. When the music of the same profile is already playing, only open the track list. * Open the profile music list with the state and context of the running player * Open the profile music list only for the running player's account and scroll to the playing track
1 parent de608bb commit 8b70726

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎Telegram-Mac/packages-integration/hooks/PeerInfoUIHooksInstall.swift‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ func installPeerInfoUIHooks() {
199199
return
200200
}
201201
showModal(with: PlayerListController(audioPlayer: playerView, context: context, currentContext: context, source: .profile(peer, musicFile, savedMusic, profileSavedMusic)), for: context.window)
202+
}, activeProfileMusic: { context, peerId in
203+
let context = context as! AccountContext
204+
guard context.bindings.rootNavigation().header?.contextObject is InlineAudioPlayerView.ContextObject, let controller = context.sharedContext.getAudioPlayer() as? APProfileSavedController, controller.peer.id == peerId, controller.account.id == context.account.id, let state = controller.currentState else {
205+
return nil
206+
}
207+
var playing: TelegramMediaFile?
208+
if let entry = controller.currentSong?.entry, case let .savedMusic(reference, _) = entry {
209+
playing = reference.media
210+
}
211+
return (state, controller.profileMusicContext, playing)
202212
}, executeNftLink: { link, slug, context in
203213
execute(inapp: .nft(link: link, slug: slug, context: context as! AccountContext))
204214
}, navigateToChat: { navigation, context, chatLocation, mode, focusTarget, chatLocationContextHolder in

‎packages/PeerInfoUI/Sources/PeerInfoUI/PeerInfoHeadItem.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,11 @@ class PeerInfoHeadItem<Context: AccountContextProtocol>: GeneralRowItem {
868868
return
869869
}
870870

871+
if let active = PeerInfoUIHooks.shared.activeProfileMusic(context, peer.id) {
872+
PeerInfoUIHooks.shared.showProfileMusicPlayerList(context, peer, active.playing ?? musicFile, active.state, active.context)
873+
return
874+
}
875+
871876
let controller = APProfileSavedController(context: context, peer: peer, profileMusicContext: profileSavedMusic, baseRate: FastSettings.playingRate, volume: FastSettings.volumeRate)
872877

873878
PeerInfoUIHooks.shared.showInlineAudioPlayer(controller, context, self.table, nil)

‎packages/PeerInfoUI/Sources/PeerInfoUI/PeerInfoUIHooks.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public struct PeerInfoUIHooks {
5757
public let showDisableSharingModal: (any AccountContextProtocol, PeerId, @escaping (Bool) -> Void) -> Void
5858
public let showInlineAudioPlayer: (APController, any AccountContextProtocol, TableView?, TableView?) -> Void
5959
public let showProfileMusicPlayerList: (any AccountContextProtocol, EnginePeer, TelegramMediaFile, ProfileSavedMusicContext.State, ProfileSavedMusicContext) -> Void
60+
public let activeProfileMusic: (any AccountContextProtocol, PeerId) -> (state: ProfileSavedMusicContext.State, context: ProfileSavedMusicContext, playing: TelegramMediaFile?)?
6061
public let executeNftLink: (String, String, any AccountContextProtocol) -> Void
6162
public let navigateToChat: (NavigationViewController?, any AccountContextProtocol, ChatLocation, ChatMode, ChatFocusTarget?, Atomic<ChatLocationContextHolder?>?) -> Void
6263
public var navigateToChatWithContext: ((NavigationViewController?, any AccountContextProtocol, ChatLocation, ChatMode, ChatFocusTarget?, Atomic<ChatLocationContextHolder?>?) -> Void)?
@@ -76,6 +77,7 @@ public struct PeerInfoUIHooks {
7677
showDisableSharingModal: @escaping (any AccountContextProtocol, PeerId, @escaping (Bool) -> Void) -> Void,
7778
showInlineAudioPlayer: @escaping (APController, any AccountContextProtocol, TableView?, TableView?) -> Void,
7879
showProfileMusicPlayerList: @escaping (any AccountContextProtocol, EnginePeer, TelegramMediaFile, ProfileSavedMusicContext.State, ProfileSavedMusicContext) -> Void,
80+
activeProfileMusic: @escaping (any AccountContextProtocol, PeerId) -> (state: ProfileSavedMusicContext.State, context: ProfileSavedMusicContext, playing: TelegramMediaFile?)?,
7981
executeNftLink: @escaping (String, String, any AccountContextProtocol) -> Void,
8082
navigateToChat: @escaping (NavigationViewController?, any AccountContextProtocol, ChatLocation, ChatMode, ChatFocusTarget?, Atomic<ChatLocationContextHolder?>?) -> Void,
8183
wallet: Any?) {
@@ -86,6 +88,7 @@ public struct PeerInfoUIHooks {
8688
self.showDisableSharingModal = showDisableSharingModal
8789
self.showInlineAudioPlayer = showInlineAudioPlayer
8890
self.showProfileMusicPlayerList = showProfileMusicPlayerList
91+
self.activeProfileMusic = activeProfileMusic
8992
self.executeNftLink = executeNftLink
9093
self.navigateToChat = navigateToChat
9194
self.wallet = wallet
@@ -125,6 +128,8 @@ public struct PeerInfoUIHooks {
125128
}, showDisableSharingModal: { _, _, _ in
126129
}, showInlineAudioPlayer: { _, _, _, _ in
127130
}, showProfileMusicPlayerList: { _, _, _, _, _ in
131+
}, activeProfileMusic: { _, _ in
132+
nil
128133
}, executeNftLink: { _, _, _ in
129134
}, navigateToChat: { _, _, _, _, _, _ in
130135
}, wallet: nil)

0 commit comments

Comments
 (0)