ChatListStore.swift 724 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // ChatListStore.swift
  3. // Chat
  4. //
  5. // Created by Sergey Tarasov on 25.07.2022.
  6. //
  7. import Foundation
  8. import XMPPFramework
  9. import XMPPFrameworkSwift
  10. final class ChatListStore: NSObject, ObservableObject {
  11. @Published var users: [User] = []
  12. var nicknames: [String] {
  13. return users.map({ $0.nickname.isEmpty ? $0.id : $0.nickname })
  14. }
  15. override init() {
  16. super.init()
  17. }
  18. public func fetchChatList() {
  19. let xmppUsers = XMPPController.shared.xmppRosterStorage.sortedUsersByAvailabilityName() as? [XMPPUser]
  20. guard let users = xmppUsers?.compactMap({
  21. User(id: $0.jid.bare, nickname: $0.nickname.isEmpty ? $0.jid.bare : $0.nickname)
  22. }) else {
  23. return
  24. }
  25. self.users = users
  26. }
  27. }