Skip to content

Commit

Permalink
1.9.6 (441)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis15yo committed Feb 10, 2025
1 parent 94b663a commit 4217806
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 64 deletions.
12 changes: 6 additions & 6 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"location" : "git@bitbucket.org:mobyrix/nicegram-assistant-ios.git",
"state" : {
"branch" : "develop",
"revision" : "53449a581782d54f595eb6538544716d410510c6"
"revision" : "1a97d5e9ca55bc4355d7c61efe1cc84583a50797"
}
},
{
Expand Down Expand Up @@ -356,8 +356,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/trustwallet/wallet-core.git",
"state" : {
"revision" : "b4bed73be374877bc5e0153f77369b6606a12950",
"version" : "4.2.6"
"revision" : "e55a95330d61bfe29a8ee9dac87afb59fe20ab73",
"version" : "4.2.9"
}
},
{
Expand All @@ -374,8 +374,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tomlokhorst/XcodeEdit",
"state" : {
"revision" : "1e761a55dd8d73b4e9cc227a297f438413953571",
"version" : "2.11.1"
"revision" : "9bc684439d16c07d7bede66ae43bb577a25d6bb1",
"version" : "2.12.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public protocol PresentationCallManager: AnyObject {
// MARK: Nicegram NCG-5828 call recording
var callCompletion: (() -> Void)? { get set }
func startRecordCall(with completion: @escaping () -> Void)
func stopRecordCall()
func stopRecordCall(needStopPartTimer: Bool)
func setupPeer(peer: EnginePeer)
func showRecordSaveToast()
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP
handler: { _ in
completion()
self.callScreen.stopRecordTimer()
self.sharedContext.callManager?.stopRecordCall()
self.sharedContext.callManager?.stopRecordCall(needStopPartTimer: true)
}
))

Expand Down
132 changes: 82 additions & 50 deletions submodules/TelegramCallsUI/Sources/PresentationCallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +1010,72 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
default: return ""
}
}
private var partTimer: Foundation.Timer?
private var partNumber: Int = 1

private let setCallRecorderHistoryUseCase = FeatCallRecorderModule.shared.setCallRecorderHistoryUseCase()
private let dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"

return dateFormatter
}()
private let partLength: TimeInterval = 60 * 30

public func startRecordCall(
with completion: @escaping () -> Void
) {
audioDevice?.startNicegramRecording(callback: { [weak self] path, duration, size in
self?.writeAudioToSaved(
from: path,
duration: duration,
size: size,
completion: completion
)
}, errorCallback: { error in
sendCallRecorderAnalytics(with: .error)
})
sendCallRecorderAnalytics(with: .start)
startPartTimer()
}

public func stopRecordCall(needStopPartTimer: Bool) {
audioDevice?.stopNicegramRecording()
if needStopPartTimer {
stopPartTimer()
}
}

public func setupPeer(peer: EnginePeer) {
self.enginePeer = peer
}

public func showRecordSaveToast() {
let (presentationData, _, _) = getDeviceAccessData()
guard let image = UIImage(bundleImageName: "RecordSave") else { return }

let content: UndoOverlayContent = .image(
image: image,
title: nil,
text: l("NicegramCallRecord.SavedMessage"),
round: true,
undoText: nil
)

DispatchQueue.main.async {
let controller = UndoOverlayController(
presentationData: presentationData,
content: content,
elevatedLayout: false,
position: .top,
animateInAsReplacement: false,
action: { _ in return false }
)

self.accountContext?.sharedContext.mainWindow?.present(controller, on: .root)
}
}

private func deleteFile(from path: String) {
let fileManager = FileManager.default

Expand Down Expand Up @@ -1045,6 +1104,11 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
localFilePath: path,
randomId: id
)
let text = if partNumber > 1 {
"\(userDisplayName)-\(dateFormatter.string(from: date))- part \(partNumber)"
} else {
"\(userDisplayName)-\(dateFormatter.string(from: date))"
}

let file = TelegramMediaFile(
fileId: EngineMedia.Id(namespace: Namespaces.Media.LocalFile, id: id),
Expand All @@ -1062,12 +1126,12 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
title: "",
performer: nil,
waveform: nil
)
),
.FileName(fileName: text)
],
alternativeRepresentations: []
)

let text = "\(userDisplayName)-\(dateFormatter.string(from: date))"
let message: EnqueueMessage = .message(
text: text,
attributes: [],
Expand All @@ -1083,14 +1147,13 @@ public final class PresentationCallManagerImpl: PresentationCallManager {

DispatchQueue.main.async {
if let account = self.accountContext?.account {
let setCallRecorderHistoryUseCase = FeatCallRecorderModule.shared.setCallRecorderHistoryUseCase()
let _ = enqueueMessages(
account: account,
peerId: account.peerId,
messages: [message]
).start(next: { messagesIds in
if let messageId = messagesIds.compactMap({ $0 }).first {
setCallRecorderHistoryUseCase(
self.setCallRecorderHistoryUseCase(
with: account.peerId.toInt64(),
id: messageId.id,
text: text
Expand All @@ -1116,54 +1179,23 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
}
}

public func startRecordCall(
with completion: @escaping () -> Void
) {
audioDevice?.startNicegramRecording(callback: { [weak self] path, duration, size in
self?.writeAudioToSaved(
from: path,
duration: duration,
size: size,
completion: completion
)
}, errorCallback: { error in
sendCallRecorderAnalytics(with: .error)
})
sendCallRecorderAnalytics(with: .start)
}

public func stopRecordCall() {
audioDevice?.stopNicegramRecording()
}

public func setupPeer(peer: EnginePeer) {
self.enginePeer = peer
}

public func showRecordSaveToast() {
let (presentationData, _, _) = getDeviceAccessData()
guard let image = UIImage(bundleImageName: "RecordSave") else { return }

let content: UndoOverlayContent = .image(
image: image,
title: nil,
text: l("NicegramCallRecord.SavedMessage"),
round: true,
undoText: nil
)

DispatchQueue.main.async {
let controller = UndoOverlayController(
presentationData: presentationData,
content: content,
elevatedLayout: false,
position: .top,
animateInAsReplacement: false,
action: { _ in return false }
)
private func startPartTimer() {
guard partTimer == nil else { return }

partNumber = 1

self.accountContext?.sharedContext.mainWindow?.present(controller, on: .root)
let timer = Foundation.Timer(timeInterval: partLength, repeats: true) { [weak self] _ in
self?.stopRecordCall(needStopPartTimer: false)
self?.startRecordCall {}
self?.partNumber += 1
}
self.partTimer = timer
RunLoop.main.add(timer, forMode: .common)
}

private func stopPartTimer() {
partTimer?.invalidate()
partTimer = nil
}
//
}
8 changes: 7 additions & 1 deletion submodules/TelegramUI/Sources/ChatController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4218,7 +4218,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
var title: String?
var performer: String?
for media in message.media {
if let mediaFile = media as? TelegramMediaFile, mediaFile.isMusic {
// MARK: Nicegram NCG-5828 call recording, mediaFile.isVoice
if let mediaFile = media as? TelegramMediaFile, mediaFile.isMusic || mediaFile.isVoice {
file = mediaFile
for attribute in mediaFile.attributes {
if case let .Audio(_, _, titleValue, performerValue, _) = attribute {
Expand Down Expand Up @@ -4295,6 +4296,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let audioAsset = AVURLAsset(url: audioUrl)

var fileExtension = "mp3"
// MARK: Nicegram NCG-5828 call recording
if file.mimeType == "audio/ogg" {
fileExtension = "ogg"
}
//
if let filename = file.fileName {
if let dotIndex = filename.lastIndex(of: ".") {
fileExtension = String(filename[filename.index(after: dotIndex)...])
Expand Down
10 changes: 10 additions & 0 deletions submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,16 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
f(.default)
})))
}
// MARK: Nicegram NCG-5828 call recording
else if file.isVoice {
actions.append(.action(ContextMenuActionItem(text: chatPresentationInterfaceState.strings.Conversation_SaveToFiles, icon: { theme in
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Save"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in
controllerInteraction.saveMediaToFiles(message.id)
f(.default)
})))
}
//
break
}
}
Expand Down

0 comments on commit 4217806

Please sign in to comment.