From 75e96ed8a5a0befa7de49103e41334d7c9fb1de9 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Wed, 25 Feb 2026 16:28:40 +0100 Subject: [PATCH] Automatically play next voice recording when the previous one ends --- Linphone/GeneratedGit.swift | 2 +- .../Fragments/ChatBubbleView.swift | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Linphone/GeneratedGit.swift b/Linphone/GeneratedGit.swift index d6bcab926..50e57d835 100644 --- a/Linphone/GeneratedGit.swift +++ b/Linphone/GeneratedGit.swift @@ -2,6 +2,6 @@ import Foundation public enum AppGitInfo { public static let branch = "master" - public static let commit = "db9c9f183" + public static let commit = "9cc8923e3" public static let tag = "6.1.0-alpha" } diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index 5fbd97a99..2ad8d531a 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -20,6 +20,7 @@ import SwiftUI import WebKit import QuickLook +import Combine // swiftlint:disable type_body_length // swiftlint:disable cyclomatic_complexity @@ -1162,13 +1163,15 @@ struct CustomSlider: View { let eventLogMessage: EventLogMessage + @State private var timer: Timer? @State private var value: Double = 0.0 @State private var isPlaying: Bool = false - @State private var timer: Timer? + @State private var cancellable: AnyCancellable? var minTrackColor: Color = .white.opacity(0.5) var maxTrackGradient: Gradient = Gradient(colors: [Color.orangeMain300, Color.orangeMain500]) + var body: some View { GeometryReader { geometry in let radius = geometry.size.height * 0.5 @@ -1223,7 +1226,26 @@ struct CustomSlider: View { .padding(.horizontal, 10) } .clipShape(RoundedRectangle(cornerRadius: radius)) + .onAppear { + if eventLogMessage.message.attachments.first?.type == .voiceRecording { + cancellable = + NotificationCenter.default + .publisher(for: NSNotification.Name("VoiceRecording")) + .compactMap { $0.userInfo?["messageId"] as? String } + .sink { messageId in + if messageId == eventLogMessage.message.id { + conversationViewModel.startVoiceRecordPlayer( + voiceRecordPath: eventLogMessage.message.attachments.first!.full + ) + playProgress() + } + } + } + } .onDisappear { + cancellable?.cancel() + cancellable = nil + resetProgress() } } @@ -1247,7 +1269,23 @@ struct CustomSlider: View { } } } else { - resetProgress() + self.resetProgress() + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + let rows = conversationViewModel.conversationMessagesSection[0].rows + + if let index = rows.firstIndex(where: { $0.eventModel.eventLogId == eventLogMessage.message.id }), + rows.indices.contains(index - 1) { + let nextRow = rows[index - 1] + if nextRow.message.attachments.first?.type == .voiceRecording { + NotificationCenter.default.post( + name: NSNotification.Name("VoiceRecording"), + object: nil, + userInfo: ["messageId": nextRow.message.id] + ) + } + } + } } } }