|
|
@@ -42,7 +42,12 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
@IBOutlet weak var heightTableMention: NSLayoutConstraint!
|
|
|
@IBOutlet weak var contraintBottomMention: NSLayoutConstraint!
|
|
|
public var dataPerson: [String: String?] = [:]
|
|
|
- var dataMessages: [[String: Any?]] = []
|
|
|
+ var dataMessages: [[String: Any?]] = [] {
|
|
|
+ didSet {
|
|
|
+ groupMessagesByDate()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var messagesByDate: [String: [[String: Any?]]] = [:]
|
|
|
var dataDates: [String] = []
|
|
|
var users: [User] = []
|
|
|
public var dataMessageForward: [[String: Any?]]?
|
|
|
@@ -162,6 +167,18 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
return CGFloat(fontSize)
|
|
|
}
|
|
|
|
|
|
+ private func groupMessagesByDate() {
|
|
|
+ messagesByDate = Dictionary(
|
|
|
+ grouping: dataMessages.compactMap { (msg: [String: Any?]) -> [String: Any?]? in
|
|
|
+ guard let _ = msg["chat_date"] as? String else { return nil }
|
|
|
+ return msg
|
|
|
+ },
|
|
|
+ by: { (msg: [String: Any?]) -> String in
|
|
|
+ return msg["chat_date"] as! String
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
public override func viewDidDisappear(_ animated: Bool) {
|
|
|
if self.isMovingFromParent {
|
|
|
removeAllObjectBeforeDismissVC()
|
|
|
@@ -5494,11 +5511,17 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
if !(dataMessages[indexPath!.row][TypeDataMessage.message_text] as? String ?? "").isEmpty {
|
|
|
if (dataMessages[indexPath!.row]["f_pin"] as? String ?? "") == idMe && ((dataMessages[indexPath!.row][TypeDataMessage.is_forwarded] as? Int) ?? 0) == 0 && (dataMessages[indexPath!.row][TypeDataMessage.attachment_flag] as? String ?? "") != "11" {
|
|
|
- let valueDate = Date(milliseconds: Int64(dataMessages[indexPath!.row][TypeDataMessage.server_date] as? String ?? "") ?? 0)
|
|
|
- let nowDate = Date()
|
|
|
- let diffInSeconds = nowDate.timeIntervalSince(valueDate)
|
|
|
- if diffInSeconds <= 15 * 60 {
|
|
|
- children.insert(edit, at: children.count - 1)
|
|
|
+ var textFile = dataMessages[indexPath!.row][TypeDataMessage.message_text] as? String ?? ""
|
|
|
+ if !(dataMessages[indexPath!.row][TypeDataMessage.file_id] as? String ?? "").isEmpty {
|
|
|
+ textFile = textFile.components(separatedBy: "|")[1]
|
|
|
+ }
|
|
|
+ if !textFile.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
|
+ let valueDate = Date(milliseconds: Int64(dataMessages[indexPath!.row][TypeDataMessage.server_date] as? String ?? "") ?? 0)
|
|
|
+ let nowDate = Date()
|
|
|
+ let diffInSeconds = nowDate.timeIntervalSince(valueDate)
|
|
|
+ if diffInSeconds <= 15 * 60 {
|
|
|
+ children.insert(edit, at: children.count - 1)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (dataMessages[indexPath!.row][TypeDataMessage.attachment_flag] as? String ?? "") != "11" && (dataMessages[indexPath!.row]["image_id"] as? String ?? "").isEmpty && (dataMessages[indexPath!.row]["video_id"] as? String ?? "").isEmpty && (dataMessages[indexPath!.row]["file_id"] as? String ?? "").isEmpty && (dataMessages[indexPath!.row]["audio_id"] as? String ?? "").isEmpty{
|
|
|
@@ -5585,7 +5608,10 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
listMentionWithText.removeAll()
|
|
|
listMentionInTextField.removeAll()
|
|
|
let dataMessages = self.dataMessages.filter({ $0["chat_date"] as? String ?? "" == dataDates[indexPath.section]})
|
|
|
- let oldText = dataMessages[indexPath.row][TypeDataMessage.message_text] as? String ?? ""
|
|
|
+ var oldText = dataMessages[indexPath.row][TypeDataMessage.message_text] as? String ?? ""
|
|
|
+ if !(dataMessages[indexPath.row][TypeDataMessage.file_id] as? String ?? "").isEmpty {
|
|
|
+ oldText = oldText.components(separatedBy: "|")[1]
|
|
|
+ }
|
|
|
var oldTextForTextview = oldText
|
|
|
let pattern = "@[\\w]+"
|
|
|
do {
|
|
|
@@ -5689,6 +5715,10 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
buttonSendEdit.actionHandle(controlEvents: .touchUpInside,
|
|
|
ForAction:{() -> Void in
|
|
|
var newText = self.editTextView.text ?? ""
|
|
|
+ if !(dataMessages[indexPath.row][TypeDataMessage.file_id] as? String ?? "").isEmpty {
|
|
|
+ let firstText = dataMessages[indexPath.row][TypeDataMessage.message_text] as? String ?? ""
|
|
|
+ newText = firstText.components(separatedBy: "|")[0] + "|" + newText
|
|
|
+ }
|
|
|
if newText.contains("@") && self.listMentionInTextField.count > 0 {
|
|
|
var diff: Int = 0
|
|
|
for i in 0..<self.listMentionInTextField.count {
|
|
|
@@ -5721,28 +5751,38 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
}
|
|
|
if !newText.isEmpty && newText.trimmingCharacters(in: .whitespacesAndNewlines) != oldText {
|
|
|
- let lastEdited = Int64(Date().currentTimeMillis())
|
|
|
- let message = CoreMessage_TMessageBank.editMessage(message_id: dataMessages[indexPath.row][TypeDataMessage.message_id] as? String ?? "", l_pin: dataMessages[indexPath.row][TypeDataMessage.l_pin] as? String ?? "", message_scope_id: dataMessages[indexPath.row][TypeDataMessage.message_scope_id] as? String ?? "", status: "1", message_text: newText, credential: dataMessages[indexPath.row][TypeDataMessage.credential] as? String ?? "", attachment_flag: dataMessages[indexPath.row][TypeDataMessage.attachment_flag] as? String ?? "", ex_blog_id: dataMessages[indexPath.row][TypeDataMessage.blog_id] as? String ?? "", message_large_text: "", ex_format: "", image_id: dataMessages[indexPath.row][TypeDataMessage.image_id] as? String ?? "", audio_id: dataMessages[indexPath.row][TypeDataMessage.audio_id] as? String ?? "", video_id: dataMessages[indexPath.row][TypeDataMessage.video_id] as? String ?? "", file_id: dataMessages[indexPath.row][TypeDataMessage.file_id] as? String ?? "", thumb_id: dataMessages[indexPath.row][TypeDataMessage.thumb_id] as? String ?? "", reff_id: dataMessages[indexPath.row][TypeDataMessage.reff_id] as? String ?? "", read_receipts: dataMessages[indexPath.row][TypeDataMessage.read_receipts] as? String ?? "", chat_id: dataMessages[indexPath.row][TypeDataMessage.chat_id] as? String ?? "", is_call_center: dataMessages[indexPath.row][TypeDataMessage.is_call_center] as? String ?? "", call_center_id: dataMessages[indexPath.row][TypeDataMessage.call_center_id] as? String ?? "", opposite_pin: dataMessages[indexPath.row][TypeDataMessage.opposite_pin] as? String ?? "", server_date: dataMessages[indexPath.row][TypeDataMessage.server_date] as? String ?? "", local_time_stamp: dataMessages[indexPath.row][TypeDataMessage.server_date] as? String ?? "", last_edit: lastEdited)
|
|
|
- Nexilis.addQueueMessage(message: message, isEditMessage: true)
|
|
|
- DispatchQueue.global().async {
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- do {
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "message_text" : newText,
|
|
|
- "last_edited" : lastEdited
|
|
|
- ], _where: "message_id = '\(dataMessages[indexPath.row]["message_id"] as? String ?? "")'")
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
- } catch {
|
|
|
- rollback.pointee = true
|
|
|
- print("Access database error: \(error.localizedDescription)")
|
|
|
- }
|
|
|
- })
|
|
|
+ if !(dataMessages[indexPath.row][TypeDataMessage.file_id] as? String ?? "").isEmpty {
|
|
|
+ let firstText = dataMessages[indexPath.row][TypeDataMessage.message_text] as? String ?? ""
|
|
|
+ if newText != firstText {
|
|
|
+ excEdit()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ excEdit()
|
|
|
}
|
|
|
- let idx = self.dataMessages.firstIndex(where: { $0[TypeDataMessage.message_id] as? String == dataMessages[indexPath.row][TypeDataMessage.message_id] as? String})
|
|
|
- if idx != nil{
|
|
|
- self.dataMessages[idx!][TypeDataMessage.message_text] = newText
|
|
|
- self.dataMessages[idx!][TypeDataMessage.last_edit] = lastEdited
|
|
|
- self.tableChatView.reloadRows(at: [indexPath], with: .none)
|
|
|
+ func excEdit() {
|
|
|
+ let lastEdited = Int64(Date().currentTimeMillis())
|
|
|
+ let message = CoreMessage_TMessageBank.editMessage(message_id: dataMessages[indexPath.row][TypeDataMessage.message_id] as? String ?? "", l_pin: dataMessages[indexPath.row][TypeDataMessage.l_pin] as? String ?? "", message_scope_id: dataMessages[indexPath.row][TypeDataMessage.message_scope_id] as? String ?? "", status: "1", message_text: newText, credential: dataMessages[indexPath.row][TypeDataMessage.credential] as? String ?? "", attachment_flag: dataMessages[indexPath.row][TypeDataMessage.attachment_flag] as? String ?? "", ex_blog_id: dataMessages[indexPath.row][TypeDataMessage.blog_id] as? String ?? "", message_large_text: "", ex_format: "", image_id: dataMessages[indexPath.row][TypeDataMessage.image_id] as? String ?? "", audio_id: dataMessages[indexPath.row][TypeDataMessage.audio_id] as? String ?? "", video_id: dataMessages[indexPath.row][TypeDataMessage.video_id] as? String ?? "", file_id: dataMessages[indexPath.row][TypeDataMessage.file_id] as? String ?? "", thumb_id: dataMessages[indexPath.row][TypeDataMessage.thumb_id] as? String ?? "", reff_id: dataMessages[indexPath.row][TypeDataMessage.reff_id] as? String ?? "", read_receipts: dataMessages[indexPath.row][TypeDataMessage.read_receipts] as? String ?? "", chat_id: dataMessages[indexPath.row][TypeDataMessage.chat_id] as? String ?? "", is_call_center: dataMessages[indexPath.row][TypeDataMessage.is_call_center] as? String ?? "", call_center_id: dataMessages[indexPath.row][TypeDataMessage.call_center_id] as? String ?? "", opposite_pin: dataMessages[indexPath.row][TypeDataMessage.opposite_pin] as? String ?? "", server_date: dataMessages[indexPath.row][TypeDataMessage.server_date] as? String ?? "", local_time_stamp: dataMessages[indexPath.row][TypeDataMessage.server_date] as? String ?? "", last_edit: lastEdited)
|
|
|
+ Nexilis.addQueueMessage(message: message, isEditMessage: true)
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "message_text" : newText,
|
|
|
+ "last_edited" : lastEdited
|
|
|
+ ], _where: "message_id = '\(dataMessages[indexPath.row]["message_id"] as? String ?? "")'")
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ let idx = self.dataMessages.firstIndex(where: { $0[TypeDataMessage.message_id] as? String == dataMessages[indexPath.row][TypeDataMessage.message_id] as? String})
|
|
|
+ if idx != nil{
|
|
|
+ self.dataMessages[idx!][TypeDataMessage.message_text] = newText
|
|
|
+ self.dataMessages[idx!][TypeDataMessage.last_edit] = lastEdited
|
|
|
+ self.tableChatView.reloadRows(at: [indexPath], with: .none)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
self.isEditingMessage = false
|
|
|
@@ -6791,7 +6831,8 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
|
|
|
return cellMention
|
|
|
}
|
|
|
let idMe = User.getMyPin() as String?
|
|
|
- let dataMessages = dataMessages.filter({$0["chat_date"] as? String ?? "" == dataDates[indexPath.section]})
|
|
|
+ let dateKey = dataDates[indexPath.section]
|
|
|
+ let dataMessages = messagesByDate[dateKey]!
|
|
|
let profileMessage = UIImageView()
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: "cellEditorPersonal", for: indexPath as IndexPath)
|
|
|
cell.contentView.subviews.forEach({ $0.removeConstraints($0.constraints) })
|
|
|
@@ -7412,21 +7453,6 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// if dataMessages[indexPath.row][TypeDataMessage.last_edit] != nil && dataMessages[indexPath.row][TypeDataMessage.last_edit] as! Int64 != 0 {
|
|
|
-// let editedText = UILabel()
|
|
|
-// editedText.text = "Edited".localized()
|
|
|
-// editedText.font = UIFont.systemFont(ofSize: 10 + offset(), weight: .medium)
|
|
|
-// editedText.textColor = .lightGray
|
|
|
-// cell.contentView.addSubview(editedText)
|
|
|
-// editedText.translatesAutoresizingMaskIntoConstraints = false
|
|
|
-// if (dataMessages[indexPath.row]["f_pin"] as? String == idMe) {
|
|
|
-// editedText.trailingAnchor.constraint(equalTo: timeMessage.leadingAnchor, constant: -2).isActive = true
|
|
|
-// } else {
|
|
|
-// editedText.leadingAnchor.constraint(equalTo: timeMessage.trailingAnchor, constant: 2).isActive = true
|
|
|
-// }
|
|
|
-// editedText.bottomAnchor.constraint(equalTo: containerMessage.bottomAnchor).isActive = true
|
|
|
-// }
|
|
|
-
|
|
|
let messageText = UITextView()
|
|
|
messageText.isEditable = false
|
|
|
messageText.isSelectable = true
|
|
|
@@ -9068,14 +9094,16 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
|
|
|
if tableView == tableViewConfigFile {
|
|
|
return 2
|
|
|
}
|
|
|
- let count = dataMessages.filter({ $0["chat_date"] as? String ?? "" == dataDates[section] }).count
|
|
|
- return count
|
|
|
+ let dateKey = dataDates[section]
|
|
|
+ return messagesByDate[dateKey]?.count ?? 0
|
|
|
}
|
|
|
|
|
|
@objc func contentMessageTapped(_ sender: ObjectGesture) {
|
|
|
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
+ let indexPath = sender.indexPath
|
|
|
+ let dataMessages = self.dataMessages.filter({ $0["chat_date"] as? String ?? "" == dataDates[indexPath.section]})
|
|
|
func showMedia(data: Data? = nil, url: URL? = nil, type: Int = 0) {
|
|
|
let image = UIImage(data: data ?? Data())
|
|
|
let imageViewer = MediaViewerViewController()
|
|
|
@@ -9098,7 +9126,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
|
|
|
}
|
|
|
let backButton = UIBarButtonItem(title: nil, image: UIImage(systemName: "chevron.backward"), primaryAction: backAction, menu: nil)
|
|
|
imageViewer.navigationItem.leftBarButtonItem = backButton
|
|
|
- if Nexilis.checkingAccess(key: "secure_folder_share") || sender.specFile.contains("download") || sender.specFile.contains("share") {
|
|
|
+ if (Nexilis.checkingAccess(key: "secure_folder_share") || sender.specFile.contains("download") || sender.specFile.contains("share")) && dataMessages[indexPath.row]["credential"] as? String != "1" {
|
|
|
let shareAction = UIAction { _ in
|
|
|
var activityViewController = UIActivityViewController(activityItems: [""], applicationActivities: nil)
|
|
|
if type == 1 {
|
|
|
@@ -9313,7 +9341,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource, AVAudioPla
|
|
|
}
|
|
|
let backButton = UIBarButtonItem(title: nil, image: UIImage(systemName: "chevron.backward"), primaryAction: backAction, menu: nil)
|
|
|
vcHandleFile.navigationItem.leftBarButtonItem = backButton
|
|
|
- if Nexilis.checkingAccess(key: "secure_folder_share") || sender.specFile.contains("download") || sender.specFile.contains("share") {
|
|
|
+ if (Nexilis.checkingAccess(key: "secure_folder_share") || sender.specFile.contains("download") || sender.specFile.contains("share")) && dataMessages[indexPath.row]["credential"] as? String != "1" {
|
|
|
let shareAction = UIAction { _ in
|
|
|
let fileManager = FileManager.default
|
|
|
let tempURL = fileManager.temporaryDirectory.appendingPathComponent(urlFile.lastPathComponent)
|