ArchivedChatView.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. //
  2. // ArchivedChatView.swift
  3. // Pods
  4. //
  5. // Created by Qindi on 02/06/25.
  6. //
  7. import Foundation
  8. import UIKit
  9. public class ArchivedChatView: UIViewController, UITableViewDataSource, UITableViewDelegate {
  10. let contactChatNav = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "contactChatNav") as! UINavigationController
  11. private let tableView = UITableView(frame: .zero, style: .plain)
  12. public var archivedChats: [Chat] = []
  13. var archivedChatGroupMaps: [String: [Chat]] = [:]
  14. public override func viewDidAppear(_ animated: Bool) {
  15. let navBarAppearance = UINavigationBarAppearance()
  16. navBarAppearance.configureWithOpaqueBackground()
  17. navBarAppearance.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  18. navigationController?.navigationBar.standardAppearance = navBarAppearance
  19. navigationController?.navigationBar.scrollEdgeAppearance = navBarAppearance
  20. navigationController?.navigationBar.isTranslucent = false
  21. navigationController?.navigationBar.backgroundColor = self.traitCollection.userInterfaceStyle == .dark ? .blackDarkMode : .mainColor
  22. navigationController?.navigationBar.tintColor = .white
  23. navigationController?.navigationBar.overrideUserInterfaceStyle = .dark
  24. self.setNeedsStatusBarAppearanceUpdate()
  25. navigationController?.navigationBar.barStyle = .black
  26. if self.navigationController?.isNavigationBarHidden ?? false {
  27. self.navigationController?.setNavigationBarHidden(false, animated: false)
  28. }
  29. navigationController?.navigationBar.prefersLargeTitles = false
  30. navigationController?.navigationItem.largeTitleDisplayMode = .never
  31. }
  32. public override func viewDidLoad() {
  33. Utils.addBackground(view: contactChatNav.view)
  34. reloadArchiveChat()
  35. self.title = "Archived".localized()
  36. self.navigationController?.navigationBar.topItem?.title = "".localized()
  37. self.navigationController?.navigationBar.setNeedsLayout()
  38. tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellChatArchived")
  39. tableView.dataSource = self
  40. tableView.delegate = self
  41. tableView.tableFooterView = UIView()
  42. setupTableView()
  43. }
  44. private func reloadArchiveChat() {
  45. self.archivedChatGroupMaps.removeAll()
  46. let previousChat = self.archivedChats
  47. let allChats = Chat.getData(isArchived: true)
  48. var tempChats: [Chat] = []
  49. for singleChat in allChats {
  50. guard !singleChat.groupId.isEmpty else {
  51. tempChats.append(singleChat)
  52. continue
  53. }
  54. let chatParentInPreviousChats = previousChat.first { $0.isParent && $0.groupId == singleChat.groupId }
  55. if var existingGroup = self.archivedChatGroupMaps[singleChat.groupId] {
  56. existingGroup.insert(singleChat, at: 0)
  57. self.archivedChatGroupMaps[singleChat.groupId] = existingGroup
  58. if let parentChatIndex = tempChats.firstIndex(where: { $0.groupId == singleChat.groupId && $0.isParent }) {
  59. if let counterParent = Int(tempChats[parentChatIndex].counter), let counterSingle = Int(singleChat.counter) {
  60. tempChats[parentChatIndex].counter = "\(counterParent + counterSingle)"
  61. }
  62. }
  63. if let parentExist = chatParentInPreviousChats, parentExist.isSelected,
  64. let indexParent = tempChats.firstIndex(where: { $0.isParent && $0.groupId == singleChat.groupId }) {
  65. tempChats.insert(singleChat, at: min(indexParent + existingGroup.count, tempChats.count))
  66. }
  67. } else {
  68. self.archivedChatGroupMaps[singleChat.groupId] = [singleChat]
  69. let parentChat = Chat(profile: singleChat.profile, groupName: singleChat.groupName, counter: singleChat.counter, groupId: singleChat.groupId)
  70. parentChat.isParent = true
  71. if let parentExist = chatParentInPreviousChats, parentExist.isSelected {
  72. parentChat.isSelected = true
  73. tempChats.append(parentChat)
  74. tempChats.append(singleChat)
  75. } else {
  76. tempChats.append(parentChat)
  77. }
  78. }
  79. }
  80. self.archivedChats = tempChats
  81. }
  82. private func setupTableView() {
  83. view.addSubview(tableView)
  84. tableView.translatesAutoresizingMaskIntoConstraints = false
  85. NSLayoutConstraint.activate([
  86. tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
  87. tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  88. tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
  89. tableView.rightAnchor.constraint(equalTo: view.rightAnchor)
  90. ])
  91. }
  92. public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  93. return archivedChats.count
  94. }
  95. public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  96. let fontSize = Int(SecureUserDefaults.shared.value(forKey: "font_size") ?? "0")
  97. var finalHeight = 75.0
  98. if fontSize == 4 {
  99. finalHeight += 10
  100. } else if fontSize == 6 {
  101. finalHeight += 20
  102. }
  103. return finalHeight
  104. }
  105. public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  106. tableView.deselectRow(at: indexPath, animated: true)
  107. let data = archivedChats[indexPath.row]
  108. if data.isParent {
  109. expandCollapseChats(tableView: tableView, indexPath: indexPath)
  110. return
  111. }
  112. if data.pin == "-997" {
  113. let smartChatVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "chatGptVC") as! ChatGPTBotView
  114. smartChatVC.hidesBottomBarWhenPushed = true
  115. smartChatVC.fromNotification = false
  116. navigationController?.show(smartChatVC, sender: nil)
  117. } else if data.messageScope == MessageScope.WHISPER || data.messageScope == MessageScope.CALL || data.messageScope == MessageScope.MISSED_CALL {
  118. if data.pin.isEmpty {
  119. return
  120. }
  121. let editorPersonalVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorPersonalVC") as! EditorPersonal
  122. editorPersonalVC.hidesBottomBarWhenPushed = true
  123. editorPersonalVC.unique_l_pin = data.pin
  124. navigationController?.show(editorPersonalVC, sender: nil)
  125. } else {
  126. if data.pin.isEmpty {
  127. return
  128. }
  129. let editorGroupVC = AppStoryBoard.Palio.instance.instantiateViewController(identifier: "editorGroupVC") as! EditorGroup
  130. editorGroupVC.hidesBottomBarWhenPushed = true
  131. editorGroupVC.unique_l_pin = data.pin
  132. navigationController?.show(editorGroupVC, sender: nil)
  133. }
  134. }
  135. func expandCollapseChats(tableView: UITableView, indexPath: IndexPath) {
  136. let data = archivedChats[indexPath.row]
  137. data.isSelected = !data.isSelected
  138. if data.isSelected {
  139. if let dataSubChats = self.archivedChatGroupMaps[data.groupId] {
  140. for dataSubChat in dataSubChats {
  141. if var indexParent = archivedChats.firstIndex(where: { $0.isParent && $0.groupId == data.groupId }) {
  142. archivedChats.insert(dataSubChat, at: indexParent + 1)
  143. indexParent+=1
  144. }
  145. }
  146. }
  147. } else {
  148. archivedChats.removeAll(where: { $0.isParent == false && $0.groupId == data.groupId })
  149. }
  150. tableView.reloadData()
  151. }
  152. public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  153. let cell = tableView.dequeueReusableCell(withIdentifier: "cellChatArchived", for: indexPath)
  154. let content = cell.contentView
  155. if content.subviews.count > 0 {
  156. content.subviews.forEach { $0.removeFromSuperview() }
  157. }
  158. let data = archivedChats[indexPath.row]
  159. let imageView = UIImageView()
  160. content.addSubview(imageView)
  161. imageView.translatesAutoresizingMaskIntoConstraints = false
  162. NSLayoutConstraint.activate([
  163. imageView.centerYAnchor.constraint(equalTo: content.centerYAnchor),
  164. imageView.widthAnchor.constraint(equalToConstant: 55.0),
  165. imageView.heightAnchor.constraint(equalToConstant: 55.0)
  166. ])
  167. var leadingAnchor = imageView.leadingAnchor.constraint(equalTo: content.leadingAnchor, constant: 10.0)
  168. if data.pin == "-997" {
  169. imageView.frame = CGRect(x: 0, y: 0, width: 55.0, height: 55.0)
  170. imageView.circle()
  171. if let urlGif = Bundle.resourceBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
  172. imageView.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
  173. if error == nil {
  174. imageView.animationImages = image?.images
  175. imageView.animationDuration = image?.duration ?? 0.0
  176. imageView.animationRepeatCount = 0
  177. imageView.startAnimating()
  178. }
  179. }
  180. } else if let urlGif = Bundle.resourcesMediaBundle(for: Nexilis.self).url(forResource: "pb_gpt_bot", withExtension: "gif") {
  181. imageView.sd_setImage(with: urlGif) { (image, error, cacheType, imageURL) in
  182. if error == nil {
  183. imageView.animationImages = image?.images
  184. imageView.animationDuration = image?.duration ?? 0.0
  185. imageView.animationRepeatCount = 0
  186. imageView.startAnimating()
  187. }
  188. }
  189. }
  190. } else {
  191. if !Utils.getIconDock().isEmpty && data.official == "1" {
  192. let urlString = Utils.getUrlDock()!
  193. if let cachedImage = ImageCache.shared.image(forKey: urlString) {
  194. let imageData = cachedImage
  195. imageView.image = imageData
  196. } else {
  197. DispatchQueue.global().async{
  198. Utils.fetchDataWithCookiesAndUserAgent(from: URL(string: urlString)!) { data, response, error in
  199. guard let data = data, error == nil else { return }
  200. DispatchQueue.main.async() {
  201. if UIImage(data: data) != nil {
  202. let imageData = UIImage(data: data)!
  203. imageView.image = imageData
  204. ImageCache.shared.save(image: imageData, forKey: urlString)
  205. }
  206. }
  207. }
  208. }
  209. }
  210. } else {
  211. if data.messageScope == MessageScope.WHISPER || data.messageScope == MessageScope.CALL || data.messageScope == MessageScope.MISSED_CALL || data.isParent || data.pin == "-999" {
  212. getImage(name: data.profile, placeholderImage: UIImage(named: data.pin == "-999" ? "pb_button" : (data.messageScope == MessageScope.WHISPER || data.messageScope == MessageScope.CALL || data.messageScope == MessageScope.MISSED_CALL) ? "Profile---Purple" : "Conversation---Black", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), isCircle: true, tableView: tableView, indexPath: indexPath, completion: { result, isDownloaded, image in
  213. imageView.image = image
  214. })
  215. } else {
  216. leadingAnchor = imageView.leadingAnchor.constraint(equalTo: content.leadingAnchor, constant: 40.0)
  217. let image = UIImage(named: "Conversation---Black", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)
  218. imageView.image = image
  219. }
  220. }
  221. }
  222. leadingAnchor.isActive = true
  223. let titleView = UILabel()
  224. content.addSubview(titleView)
  225. titleView.translatesAutoresizingMaskIntoConstraints = false
  226. NSLayoutConstraint.activate([
  227. titleView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
  228. titleView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
  229. ])
  230. titleView.font = UIFont.systemFont(ofSize: 14 + String.offset(), weight: .medium)
  231. let timeView = UILabel()
  232. let viewCounter = UIView()
  233. if data.counter != "0" {
  234. timeView.textColor = .systemRed
  235. content.addSubview(viewCounter)
  236. viewCounter.translatesAutoresizingMaskIntoConstraints = false
  237. NSLayoutConstraint.activate([
  238. viewCounter.widthAnchor.constraint(greaterThanOrEqualToConstant: 20),
  239. viewCounter.heightAnchor.constraint(equalToConstant: 20)
  240. ])
  241. viewCounter.backgroundColor = .systemRed
  242. viewCounter.layer.cornerRadius = 10
  243. viewCounter.clipsToBounds = true
  244. viewCounter.layer.borderWidth = 0.5
  245. viewCounter.layer.borderColor = UIColor.secondaryColor.cgColor
  246. let labelCounter = UILabel()
  247. viewCounter.addSubview(labelCounter)
  248. labelCounter.translatesAutoresizingMaskIntoConstraints = false
  249. NSLayoutConstraint.activate([
  250. labelCounter.centerYAnchor.constraint(equalTo: viewCounter.centerYAnchor),
  251. labelCounter.leadingAnchor.constraint(equalTo: viewCounter.leadingAnchor, constant: 2),
  252. labelCounter.trailingAnchor.constraint(equalTo: viewCounter.trailingAnchor, constant: -2),
  253. ])
  254. labelCounter.font = UIFont.systemFont(ofSize: 11 + String.offset())
  255. if Int(data.counter) ?? 0 > 99 {
  256. labelCounter.text = "99+"
  257. } else {
  258. labelCounter.text = data.counter
  259. }
  260. labelCounter.textColor = .secondaryColor
  261. labelCounter.textAlignment = .center
  262. }
  263. if !data.isParent {
  264. titleView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0).isActive = true
  265. titleView.text = data.name
  266. content.addSubview(timeView)
  267. timeView.translatesAutoresizingMaskIntoConstraints = false
  268. NSLayoutConstraint.activate([
  269. timeView.topAnchor.constraint(equalTo: content.topAnchor, constant: 10.0),
  270. timeView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20.0),
  271. ])
  272. timeView.textColor = .gray
  273. timeView.font = UIFont.systemFont(ofSize: 14 + String.offset())
  274. let date = Date(milliseconds: Int64(data.serverDate) ?? 0)
  275. let calendar = Calendar.current
  276. if (calendar.isDateInToday(date)) {
  277. let formatter = DateFormatter()
  278. formatter.dateFormat = "HH:mm"
  279. formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
  280. timeView.text = formatter.string(from: date as Date)
  281. } else {
  282. let startOfNow = calendar.startOfDay(for: Date())
  283. let startOfTimeStamp = calendar.startOfDay(for: date)
  284. let components = calendar.dateComponents([.day], from: startOfNow, to: startOfTimeStamp)
  285. let day = -(components.day!)
  286. if day == 1 {
  287. timeView.text = "Yesterday".localized()
  288. } else {
  289. if day < 7 {
  290. let formatter = DateFormatter()
  291. formatter.dateFormat = "EEEE"
  292. let lang: String = SecureUserDefaults.shared.value(forKey: "i18n_language") ?? "en"
  293. if lang == "id" {
  294. formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
  295. }
  296. timeView.text = formatter.string(from: date)
  297. } else {
  298. let formatter = DateFormatter()
  299. formatter.dateFormat = "M/dd/yy"
  300. formatter.locale = NSLocale(localeIdentifier: "id") as Locale?
  301. let stringFormat = formatter.string(from: date as Date)
  302. timeView.text = stringFormat
  303. }
  304. }
  305. }
  306. let messageView = UILabel()
  307. content.addSubview(messageView)
  308. messageView.translatesAutoresizingMaskIntoConstraints = false
  309. NSLayoutConstraint.activate([
  310. messageView.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: 10.0),
  311. messageView.topAnchor.constraint(equalTo: titleView.bottomAnchor),
  312. messageView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -40.0),
  313. ])
  314. messageView.textColor = .gray
  315. if data.messageText.contains("■") {
  316. data.messageText = data.messageText.components(separatedBy: "■")[0]
  317. data.messageText = data.messageText.trimmingCharacters(in: .whitespacesAndNewlines)
  318. }
  319. let text = Utils.previewMessageText(chat: data)
  320. let idMe = User.getMyPin() as String?
  321. if let attributeText = text as? NSMutableAttributedString {
  322. let stringMessage = NSMutableAttributedString(string: "")
  323. if data.fpin == idMe {
  324. if data.lock == "1" {
  325. if data.messageScope == "4" {
  326. stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12 + String.offset(), weight: .medium)]))
  327. }
  328. stringMessage.append(("🚫 _"+"You were deleted this message".localized()+"_").richText())
  329. } else {
  330. let imageStatus = NSTextAttachment()
  331. if data.messageScope != MessageScope.CALL && data.messageScope != MessageScope.MISSED_CALL {
  332. let status = getRealStatus(messageId: data.messageId)
  333. if status == "0" {
  334. imageStatus.image = UIImage(systemName: "xmark.circle")!.withTintColor(UIColor.red, renderingMode: .alwaysOriginal)
  335. } else if status == "1" {
  336. imageStatus.image = UIImage(systemName: "clock.arrow.circlepath")!.withTintColor(UIColor.lightGray, renderingMode: .alwaysOriginal)
  337. } else if status == "2" {
  338. imageStatus.image = UIImage(named: "checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
  339. } else if (status == "3") {
  340. imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.lightGray)
  341. } else if (status == "8") {
  342. imageStatus.image = UIImage(named: "message_status_ack", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal)
  343. } else {
  344. imageStatus.image = UIImage(named: "double-checklist", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withTintColor(UIColor.systemBlue)
  345. }
  346. imageStatus.bounds = CGRect(x: 0, y: -5, width: 15, height: 15)
  347. let imageStatusString = NSAttributedString(attachment: imageStatus)
  348. stringMessage.append(imageStatusString)
  349. stringMessage.append(NSAttributedString(string: " "))
  350. }
  351. if data.messageScope == "4" {
  352. stringMessage.append(NSAttributedString(string: "You".localized() + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12 + String.offset(), weight: .medium)]))
  353. }
  354. stringMessage.append(attributeText)
  355. }
  356. } else {
  357. if data.messageScope == "4" {
  358. var fullname = User.getData(pin: data.fpin, lPin: data.pin)!.fullName
  359. let components = fullname.split(separator: " ")
  360. if components.count >= 2 {
  361. fullname = components.prefix(2).joined(separator: " ")
  362. }
  363. stringMessage.append(NSAttributedString(string: fullname + ": ", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12 + String.offset(), weight: .medium)]))
  364. }
  365. if data.lock == "1" {
  366. stringMessage.append(("🚫 _"+"This message was deleted".localized()+"_").richText())
  367. } else {
  368. stringMessage.append(attributeText)
  369. }
  370. }
  371. messageView.attributedText = stringMessage
  372. }
  373. messageView.numberOfLines = 2
  374. if data.counter != "0" {
  375. viewCounter.topAnchor.constraint(equalTo: timeView.bottomAnchor, constant: 5.0).isActive = true
  376. viewCounter.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20).isActive = true
  377. }
  378. } else {
  379. titleView.centerYAnchor.constraint(equalTo: content.centerYAnchor).isActive = true
  380. titleView.text = data.groupName
  381. let iconName = (data.isSelected) ? "chevron.up.circle" : "chevron.down.circle"
  382. let imageView = UIImageView(image: UIImage(systemName: iconName))
  383. imageView.tintColor = self.traitCollection.userInterfaceStyle == .dark ? .white : .black
  384. content.addSubview(imageView)
  385. imageView.translatesAutoresizingMaskIntoConstraints = false
  386. NSLayoutConstraint.activate([
  387. imageView.trailingAnchor.constraint(equalTo: content.trailingAnchor, constant: -20),
  388. imageView.centerYAnchor.constraint(equalTo: content.centerYAnchor),
  389. imageView.widthAnchor.constraint(equalToConstant: 20),
  390. imageView.heightAnchor.constraint(equalToConstant: 20)
  391. ])
  392. if data.counter != "0" {
  393. viewCounter.trailingAnchor.constraint(equalTo: imageView.leadingAnchor, constant: -5).isActive = true
  394. viewCounter.centerYAnchor.constraint(equalTo: content.centerYAnchor).isActive = true
  395. }
  396. }
  397. cell.backgroundColor = .clear
  398. cell.separatorInset = UIEdgeInsets(top: 0, left: 60.0, bottom: 0, right: 0)
  399. return cell
  400. }
  401. public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  402. let data = archivedChats[indexPath.row]
  403. if !data.isParent {
  404. let archiveAction = UIContextualAction(style: .normal, title: nil) { (_, _, completionHandler) in
  405. DispatchQueue.global().async {
  406. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  407. do {
  408. _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
  409. "archived" : 0
  410. ], _where: "l_pin = '\(data.pin)'")
  411. } catch {
  412. rollback.pointee = true
  413. print("Access database error: \(error.localizedDescription)")
  414. }
  415. })
  416. }
  417. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
  418. self.archivedChats.remove(at: indexPath.row)
  419. tableView.deleteRows(at: [indexPath], with: .right)
  420. self.reloadArchiveChat()
  421. tableView.reloadData()
  422. if self.archivedChats.count == 0 {
  423. self.navigationController?.popViewController(animated: true)
  424. }
  425. completionHandler(true)
  426. }
  427. archiveAction.backgroundColor = .mainColor
  428. let archiveIcon = UIImage(systemName: "arrow.up.bin.fill")!.createCustomIconWithText(text: "Unarchive".localized())
  429. archiveAction.image = archiveIcon
  430. let configuration = UISwipeActionsConfiguration(actions: [archiveAction])
  431. return configuration
  432. }
  433. return nil
  434. }
  435. private func getRealStatus(messageId: String) -> String {
  436. var status = "1"
  437. Database.shared.database?.inTransaction({ (fmdb, rollback) in
  438. if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status, f_pin FROM MESSAGE_STATUS WHERE message_id='\(messageId)'") {
  439. var listStatus: [Int] = []
  440. while cursorStatus.next() {
  441. listStatus.append(Int(cursorStatus.string(forColumnIndex: 0)!)!)
  442. }
  443. cursorStatus.close()
  444. status = "\(listStatus.min() ?? 2)"
  445. }
  446. })
  447. return status
  448. }
  449. }