alqindiirsyam 5 сар өмнө
parent
commit
398d2d58ea

+ 1 - 12
AppBuilder/AppBuilder/ViewController.swift

@@ -329,7 +329,7 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
         DispatchQueue.global().async {
             DispatchQueue.main.async { [self] in
                 if self.viewControllers?.firstIndex(of: secondTab!) != nil {
-                    let counter = queryCountCounter()
+                    let counter = APIS.getTotalCounter()
                     let indexSecondTab = self.viewControllers?.firstIndex(of: secondTab!)
                     if counter > 0 {
                         if !indicatorCounterFB.isDescendant(of: tabBar) {
@@ -362,17 +362,6 @@ class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMAB
             }
         }
     }
-    
-    private func queryCountCounter() -> Int32 {
-        var counter: Int32?
-        Database.shared.database?.inTransaction({ (fmdb, rollback) in
-            if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
-                counter = cursor.int(forColumnIndex: 0)
-                cursor.close()
-            }
-        })
-        return counter ?? 0
-    }
 
 //    override func viewDidLayoutSubviews() {
 //        super.viewDidLayoutSubviews()

+ 20 - 1
NexilisLite/NexilisLite/Source/APIS.swift

@@ -25,7 +25,26 @@ public class APIS: NSObject {
         var counter: Int32?
         Database.shared.database?.inTransaction({ (fmdb, rollback) in
             do {
-                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
+                let query = """
+                            select SUM(counter) as total_counter 
+                            from (
+                                select ms.counter from MESSAGE_SUMMARY ms, MESSAGE m, BUDDY b 
+                                where ms.l_pin = b.f_pin and ms.message_id = m.message_id and m.is_call_center = 0
+                                union all
+                                select ms.counter from MESSAGE_SUMMARY ms, MESSAGE m 
+                                where ms.l_pin = '-999' and ms.message_id = m.message_id
+                                union all
+                                select ms.counter from MESSAGE_SUMMARY ms, MESSAGE m 
+                                where ms.l_pin = '-997' and ms.message_id = m.message_id
+                                union all
+                                select ms.counter from MESSAGE_SUMMARY ms, MESSAGE m, GROUPZ b 
+                                where ms.l_pin = b.group_id and ms.message_id = m.message_id and m.is_call_center = 0
+                                union all
+                                select ms.counter from MESSAGE_SUMMARY ms, MESSAGE m, DISCUSSION_FORUM b, GROUPZ c 
+                                where b.group_id = c.group_id and ms.l_pin = b.chat_id and ms.message_id = m.message_id and m.is_call_center = 0
+                            ) as subquery
+                            """
+                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: query), cursor.next() {
                     counter = cursor.int(forColumnIndex: 0)
                     cursor.close()
                 }

+ 1 - 17
NexilisLite/NexilisLite/Source/FloatingButton/FloatingButton.swift

@@ -618,7 +618,7 @@ public class FloatingButton: UIView, UIGestureRecognizerDelegate {
     
     @objc func checkCounter() {
         DispatchQueue.global().async { [self] in
-            let counter = queryCountCounter()
+            let counter = APIS.getTotalCounter()
             if counter > 0 {
                 DispatchQueue.main.async { [self] in
                     if button_fb2 != nil && !indicatorCounterFB.isDescendant(of: button_fb2) {
@@ -653,22 +653,6 @@ public class FloatingButton: UIView, UIGestureRecognizerDelegate {
         }
     }
     
-    private func queryCountCounter() -> Int32 {
-        var counter: Int32?
-        Database.shared.database?.inTransaction({ (fmdb, rollback) in
-            do {
-                if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT SUM(counter) FROM MESSAGE_SUMMARY"), cursor.next() {
-                    counter = cursor.int(forColumnIndex: 0)
-                    cursor.close()
-                }
-            } catch {
-                rollback.pointee = true
-                print("Access database error: \(error.localizedDescription)")
-            }
-        })
-        return counter ?? 0
-    }
-    
     @objc func qmeraTap() {
         show(isShow: !isShow)
     }

+ 0 - 1
NexilisLite/NexilisLite/Source/Nexilis.swift

@@ -2325,7 +2325,6 @@ extension Nexilis: CallDelegate {
                 if Nexilis.callAPNActivated || APIS.checkAppStateisBackground() {
                     return
                 }
-                print("DATA: \(message)")
                 let dataUser = User.getDataCanNil(pin: String(deviceId))
                 if dataUser == nil {
                     DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {

+ 11 - 5
NexilisLite/NexilisLite/Source/View/Call/QmeraVideoViewController.swift

@@ -1067,8 +1067,17 @@ class QmeraVideoViewController: UIViewController {
                     }
                 }
             }
-        }
-        else if (state == Nexilis.VIDEO_CAMERA_PARAMS_CHANED){
+        } else if (state == Nexilis.VIDEO_CALL_ZOOM) && self.dataPerson.count > 1 {
+            DispatchQueue.main.async {
+                if arrayMessage[0] == arrayMessage[3] {
+                    self.zoomView.transform   = CGAffineTransform.init(scaleX: -1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
+                    self.zoomView.contentMode = .scaleAspectFit
+                } else {
+                    self.zoomView.transform   = CGAffineTransform.init(scaleX: -1.9, y: 2.2).rotated(by: (CGFloat.pi)/2)
+                    self.zoomView.contentMode = .scaleAspectFit
+                }
+            }
+        } else if (state == Nexilis.VIDEO_CAMERA_PARAMS_CHANED){
             if(arrayMessage[3] == "0"){
                 DispatchQueue.main.async {
                     if self.dataPerson.count == 1 && arrayMessage[2] == "1" && arrayMessage[4] == "1" {
@@ -1180,20 +1189,17 @@ class QmeraVideoViewController: UIViewController {
                     self.users.append(user)
                 }
                 if arrayMessage[5] == "2" && self.dataPerson.count == 1 {
-                    print("masuk 1")
                     DispatchQueue.main.async {
                         self.zoomView.transform   = CGAffineTransform.init(scaleX: -1.9, y: 2.2).rotated(by: (CGFloat.pi)/2)
                         self.zoomView.contentMode = .scaleAspectFit
                     }
                 }
                 else if self.dataPerson.count == 1 {
-                    print("masuk 2")
                     DispatchQueue.main.async {
                         self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
                         self.zoomView.contentMode = .scaleAspectFit
                     }
                 } else if self.dataPerson.count > 1 {
-                    print("masuk 3")
                     DispatchQueue.main.async {
                         self.zoomView.transform   = CGAffineTransform.init(scaleX: 1.9, y: 2.2).rotated(by: (-CGFloat.pi)/2)
                         self.zoomView.contentMode = .scaleAspectFit

+ 50 - 31
NexilisLite/NexilisLite/Source/View/Chat/EditorGroup.swift

@@ -4770,7 +4770,7 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
             let imageAudio = UIImageView()
             imageAudio.image = UIImage(systemName: "music.note", withConfiguration: UIImage.SymbolConfiguration(pointSize: 35))
             containerMessage.addSubview(imageAudio)
-            imageAudio.anchor(left: containerMessage.leftAnchor, paddingLeft: 15, centerY: containerMessage.centerYAnchor)
+            imageAudio.anchor(top: containerMessage.topAnchor, left: containerMessage.leftAnchor, bottom: containerMessage.bottomAnchor, paddingTop: 15, paddingLeft: 15, paddingBottom: 15, centerY: containerMessage.centerYAnchor)
             imageAudio.tintColor = .mainColor
             
             let playButtonAudio = UIButton(type: .system)
@@ -4786,7 +4786,7 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
                 .resize(target: CGSize(width: 15, height: 15))
             progressSliderAudio.setThumbImage(thumbImage, for: .normal)
             containerMessage.addSubview(progressSliderAudio)
-            progressSliderAudio.anchor(top: containerMessage.topAnchor, left: playButtonAudio.rightAnchor, bottom: containerMessage.bottomAnchor, right: containerMessage.rightAnchor, paddingTop: 15, paddingLeft: 10, paddingBottom: 15, paddingRight: 15)
+            progressSliderAudio.anchor(left: playButtonAudio.rightAnchor, right: containerMessage.rightAnchor, paddingLeft: 10, paddingRight: 15, centerY: containerMessage.centerYAnchor, height: 15)
             
             let timeLabelAudio = UILabel()
             timeLabelAudio.text = "0:00"
@@ -4802,6 +4802,15 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
                 let audioURL = URL(fileURLWithPath: dirPath).appendingPathComponent(audioChat)
                 var url = audioURL
                 if !FileManager.default.fileExists(atPath: audioURL.path) && !FileEncryption.shared.isSecureExists(filename: audioChat) {
+                    let activityIndicator = UIActivityIndicatorView(style: .medium)
+                    activityIndicator.translatesAutoresizingMaskIntoConstraints = false
+                    activityIndicator.startAnimating()
+                    playButtonAudio.setImage(nil, for: .normal)
+                    playButtonAudio.addSubview(activityIndicator)
+                    NSLayoutConstraint.activate([
+                        activityIndicator.centerXAnchor.constraint(equalTo: playButtonAudio.centerXAnchor),
+                        activityIndicator.centerYAnchor.constraint(equalTo: playButtonAudio.centerYAnchor)
+                    ])
                     Download().startHTTP(forKey: audioChat, isImage: false) { (name, progress) in
                         guard progress == 100 else {
                             return
@@ -4821,33 +4830,33 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
                             
                         }
                     }
-                }
-                if audioPlayers[indexPath] == nil {
-                    do {
-                        let audioPlayer = try AVAudioPlayer(contentsOf: url)
-                        audioPlayers[indexPath] = audioPlayer
-                        audioPlayer.delegate = self
-                        progressSliderAudio.maximumValue = Float(audioPlayer.duration)
-                        timeLabelAudio.text = formatTime(audioPlayer.duration)
-                    } catch {
-                        print("Error loading audio: \(error)")
+                    if audioPlayers[indexPath] == nil {
+                        do {
+                            let audioPlayer = try AVAudioPlayer(contentsOf: url)
+                            audioPlayers[indexPath] = audioPlayer
+                            audioPlayer.delegate = self
+                            progressSliderAudio.maximumValue = Float(audioPlayer.duration)
+                            timeLabelAudio.text = formatTime(audioPlayer.duration)
+                        } catch {
+                            print("Error loading audio: \(error)")
+                        }
+                    }
+                    let audioPlayer = audioPlayers[indexPath]
+                    if playingIndexPath == indexPath, let player = audioPlayer, player.isPlaying {
+                        playButtonAudio.setImage(UIImage(systemName: "pause.fill"), for: .normal)
+                    } else {
+                        playButtonAudio.setImage(UIImage(systemName: "play.fill"), for: .normal)
                     }
-                }
-                let audioPlayer = audioPlayers[indexPath]
-                if playingIndexPath == indexPath, let player = audioPlayer, player.isPlaying {
-                    playButtonAudio.setImage(UIImage(systemName: "pause.fill"), for: .normal)
-                } else {
-                    playButtonAudio.setImage(UIImage(systemName: "play.fill"), for: .normal)
-                }
 
-                // Play/Pause Button Action
-                playButtonAudio.addAction(UIAction { _ in
-                    self.playPauseAudio(indexPath: indexPath, playButton: playButtonAudio, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
-                }, for: .touchUpInside)
-                
-                progressSliderAudio.addAction(UIAction { _ in
-                    self.sliderChanged(indexPath: indexPath, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
-                }, for: .valueChanged)
+                    // Play/Pause Button Action
+                    playButtonAudio.addAction(UIAction { _ in
+                        self.playPauseAudio(indexPath: indexPath, playButton: playButtonAudio, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
+                    }, for: .touchUpInside)
+                    
+                    progressSliderAudio.addAction(UIAction { _ in
+                        self.sliderChanged(indexPath: indexPath, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
+                    }, for: .valueChanged)
+                }
             }
         }
         
@@ -5653,10 +5662,20 @@ extension EditorGroup: UITableViewDelegate, UITableViewDataSource, AVAudioPlayer
         } else {
             // Stop other players if one is already playing
             if let currentPlayingIndexPath = playingIndexPath, let currentAudioPlayer = audioPlayers[currentPlayingIndexPath] {
-                currentAudioPlayer.pause()
-                timers[currentPlayingIndexPath]?.invalidate()
-                timers[currentPlayingIndexPath] = nil
-                tableChatView.reloadRows(at: [currentPlayingIndexPath], with: .none)
+                if currentPlayingIndexPath != indexPath {
+                    currentAudioPlayer.pause()
+                    timers[currentPlayingIndexPath]?.invalidate()
+                    timers[currentPlayingIndexPath] = nil
+                    audioPlayers[currentPlayingIndexPath] = nil
+                    tableChatView.reloadRows(at: [currentPlayingIndexPath], with: .none)
+                }
+            }
+            
+            do {
+                try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
+                try AVAudioSession.sharedInstance().setActive(true)
+            } catch {
+                
             }
 
             // Play new audio

+ 50 - 31
NexilisLite/NexilisLite/Source/View/Chat/EditorPersonal.swift

@@ -6008,7 +6008,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
             let imageAudio = UIImageView()
             imageAudio.image = UIImage(systemName: "music.note", withConfiguration: UIImage.SymbolConfiguration(pointSize: 35))
             containerMessage.addSubview(imageAudio)
-            imageAudio.anchor(left: containerMessage.leftAnchor, paddingLeft: 15, centerY: containerMessage.centerYAnchor)
+            imageAudio.anchor(top: containerMessage.topAnchor, left: containerMessage.leftAnchor, bottom: containerMessage.bottomAnchor, paddingTop: 15, paddingLeft: 15, paddingBottom: 15, centerY: containerMessage.centerYAnchor)
             imageAudio.tintColor = .mainColor
             
             let playButtonAudio = UIButton(type: .system)
@@ -6024,7 +6024,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
                 .resize(target: CGSize(width: 15, height: 15))
             progressSliderAudio.setThumbImage(thumbImage, for: .normal)
             containerMessage.addSubview(progressSliderAudio)
-            progressSliderAudio.anchor(top: containerMessage.topAnchor, left: playButtonAudio.rightAnchor, bottom: containerMessage.bottomAnchor, right: containerMessage.rightAnchor, paddingTop: 15, paddingLeft: 10, paddingBottom: 15, paddingRight: 15)
+            progressSliderAudio.anchor(left: playButtonAudio.rightAnchor, right: containerMessage.rightAnchor, paddingLeft: 10, paddingRight: 15, centerY: containerMessage.centerYAnchor, height: 15)
             
             let timeLabelAudio = UILabel()
             timeLabelAudio.text = "0:00"
@@ -6040,6 +6040,15 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
                 let audioURL = URL(fileURLWithPath: dirPath).appendingPathComponent(audioChat)
                 var url = audioURL
                 if !FileManager.default.fileExists(atPath: audioURL.path) && !FileEncryption.shared.isSecureExists(filename: audioChat) {
+                    let activityIndicator = UIActivityIndicatorView(style: .medium)
+                    activityIndicator.translatesAutoresizingMaskIntoConstraints = false
+                    activityIndicator.startAnimating()
+                    playButtonAudio.setImage(nil, for: .normal)
+                    playButtonAudio.addSubview(activityIndicator)
+                    NSLayoutConstraint.activate([
+                        activityIndicator.centerXAnchor.constraint(equalTo: playButtonAudio.centerXAnchor),
+                        activityIndicator.centerYAnchor.constraint(equalTo: playButtonAudio.centerYAnchor)
+                    ])
                     Download().startHTTP(forKey: audioChat, isImage: false) { (name, progress) in
                         guard progress == 100 else {
                             return
@@ -6059,33 +6068,33 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
                             
                         }
                     }
-                }
-                if audioPlayers[indexPath] == nil {
-                    do {
-                        let audioPlayer = try AVAudioPlayer(contentsOf: url)
-                        audioPlayers[indexPath] = audioPlayer
-                        audioPlayer.delegate = self
-                        progressSliderAudio.maximumValue = Float(audioPlayer.duration)
-                        timeLabelAudio.text = formatTime(audioPlayer.duration)
-                    } catch {
-                        print("Error loading audio: \(error)")
+                    if audioPlayers[indexPath] == nil {
+                        do {
+                            let audioPlayer = try AVAudioPlayer(contentsOf: url)
+                            audioPlayers[indexPath] = audioPlayer
+                            audioPlayer.delegate = self
+                            progressSliderAudio.maximumValue = Float(audioPlayer.duration)
+                            timeLabelAudio.text = formatTime(audioPlayer.duration)
+                        } catch {
+                            print("Error loading audio: \(error)")
+                        }
+                    }
+                    let audioPlayer = audioPlayers[indexPath]
+                    if playingIndexPath == indexPath, let player = audioPlayer, player.isPlaying {
+                        playButtonAudio.setImage(UIImage(systemName: "pause.fill"), for: .normal)
+                    } else {
+                        playButtonAudio.setImage(UIImage(systemName: "play.fill"), for: .normal)
                     }
-                }
-                let audioPlayer = audioPlayers[indexPath]
-                if playingIndexPath == indexPath, let player = audioPlayer, player.isPlaying {
-                    playButtonAudio.setImage(UIImage(systemName: "pause.fill"), for: .normal)
-                } else {
-                    playButtonAudio.setImage(UIImage(systemName: "play.fill"), for: .normal)
-                }
 
-                // Play/Pause Button Action
-                playButtonAudio.addAction(UIAction { _ in
-                    self.playPauseAudio(indexPath: indexPath, playButton: playButtonAudio, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
-                }, for: .touchUpInside)
-                
-                progressSliderAudio.addAction(UIAction { _ in
-                    self.sliderChanged(indexPath: indexPath, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
-                }, for: .valueChanged)
+                    // Play/Pause Button Action
+                    playButtonAudio.addAction(UIAction { _ in
+                        self.playPauseAudio(indexPath: indexPath, playButton: playButtonAudio, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
+                    }, for: .touchUpInside)
+                    
+                    progressSliderAudio.addAction(UIAction { _ in
+                        self.sliderChanged(indexPath: indexPath, progressSlider: progressSliderAudio, timeLabel: timeLabelAudio)
+                    }, for: .valueChanged)
+                }
             }
         }
         
@@ -6879,10 +6888,20 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
         } else {
             // Stop other players if one is already playing
             if let currentPlayingIndexPath = playingIndexPath, let currentAudioPlayer = audioPlayers[currentPlayingIndexPath] {
-                currentAudioPlayer.pause()
-                timers[currentPlayingIndexPath]?.invalidate()
-                timers[currentPlayingIndexPath] = nil
-                tableChatView.reloadRows(at: [currentPlayingIndexPath], with: .none)
+                if currentPlayingIndexPath != indexPath {
+                    currentAudioPlayer.pause()
+                    timers[currentPlayingIndexPath]?.invalidate()
+                    timers[currentPlayingIndexPath] = nil
+                    audioPlayers[currentPlayingIndexPath] = nil
+                    tableChatView.reloadRows(at: [currentPlayingIndexPath], with: .none)
+                }
+            }
+            
+            do {
+                try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
+                try AVAudioSession.sharedInstance().setActive(true)
+            } catch {
+                
             }
 
             // Play new audio